Skip to content

jaebradley/github-languages-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GitHub Languages Client

GitHub Languages Client codecov npm npm bundle size npm-total-downloads GitHub

A NodeJS client to get languages GitHub knows about for Advanced Search, for example.

advanced-search

Implementation

GitHub maintains a linguist repository that contains a languages.yml file that seems to represent the set of languages that GitHub knows about.

I convert this languages.yml file to a JSON file. 1

I then read from this file when instantiating the GitHubLanguagesClient.

For fuzzy-searching, I use the fuse library.

API

Constructor

The default constructor parameters, used for fuzzy-searching, are

{
  maxPatternLength = 32,
  caseSensitive = false,
  includeScore = false,
  shouldSort = true,
  threshold = 0.6,
  location = 0,
  distance = 100,
  minMatchCharLength = 1,
}

The fuse.io site gives a good explanation of why and how these values are used.

getAllLanguages

This static method returns the complete array of all languages available, and the metadata associated with each language. It essentially returns the src/languages.json file as a JavaScript object.

import GitHubLanguagesClient from 'github-languages-client';

const allLanguages = GitHubLanguagesClient.getAllLanguages();

search

This class method returns fuzzy-search text matching on the language's name, aliases, and extensions.

import GitHubLanguagesClient from 'github-languages-client';

const client = new GitHubLanguagesClient();

const matchingLanguages = client.search('JavaScript');

// {
//   type: 'programming',
//   tmScope: 'source.js',
//   aceMode: 'javascript',
//   codemirrorMode: 'javascript',
//   codemirrorMimeType: 'text/javascript',
//   color: '#f1e05a',
//   aliases: [ 'js', 'node', 'javascript' ],
//   extensions:
//     [ '.js',
//       '._js',
//       '.bones',
//       '.es',
//       '.es6',
//       '.frag',
//       '.gs',
//       '.jake',
//       '.jsb',
//       '.jscad',
//       '.jsfl',
//       '.jsm',
//       '.jss',
//       '.mjs',
//       '.njs',
//       '.pac',
//       '.sjs',
//       '.ssjs',
//       '.xsjs',
//       '.xsjslib' ],
//   filenames: [ 'Jakefile' ],
//   interpreters: [ 'node' ],
//   languageId: 183,
//   name: 'JavaScript',
//   wrap: 'false',
//   searchable: 'true' },
// { type: 'programming',
//   color: '#00a6a6',
//   extensions: [ '.ms', '.mcr' ],
//   tmScope: 'source.maxscript',
//   aceMode: 'text',
//   languageId: 217,
//   name: 'MAXScript',
//   aliases: [ 'maxscript' ],
//   wrap: 'false',
//   searchable: 'true' },
//   etc., etc.

Footnotes

  • 1 I have a Travis CI job that runs daily and opens PRs against this repository if it detects changes in the `languages.yml` file.