|
| 1 | +# GitHub Languages Client |
| 2 | + |
| 3 | +[](https://travis-ci.org/jaebradley/github-languages-client) |
| 4 | +[](github-https://www.npmjs.com/package/github-languages-client-client) |
| 5 | +[](https://www.npmjs.com/package/github-languages-client) |
| 6 | + |
| 7 | + |
| 8 | +A `NodeJS` client to get languages GitHub knows about for [`Advanced Search`](https://github.com/search/advanced), for example. |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +## Implementation |
| 13 | + |
| 14 | +`GitHub` maintains [a `linguist` repository](https://github.com/github/linguist) that contains [a `languages.yml` file](https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml) that seems to represent the set of languages that `GitHub` knows about. |
| 15 | + |
| 16 | +I have [a script](~/scripts/getLanguages.js) that makes a request to [the `raw.githubusercontent` API for this file](https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml), converts the `YAML` to `JSON`, `camelCases` fields (and adds in some default values), and writes the output to [the `src/languages.json`](~/src/languages.json) file. |
| 17 | + |
| 18 | +I then read from this file when instantiating the `GitHubLanguagesClient`. |
| 19 | + |
| 20 | +For fuzzy-searching, I use [the `fuse` library](http://fusejs.io/). |
| 21 | + |
| 22 | +## API |
| 23 | + |
| 24 | +### Constructor |
| 25 | + |
| 26 | +The default constructor parameters, used for fuzzy-searching, are |
| 27 | + |
| 28 | +```javascript |
| 29 | +{ |
| 30 | + maxPatternLength = 32, |
| 31 | + caseSensitive = false, |
| 32 | + includeScore = false, |
| 33 | + shouldSort = true, |
| 34 | + threshold = 0.6, |
| 35 | + location = 0, |
| 36 | + distance = 100, |
| 37 | + minMatchCharLength = 1, |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +The [`fuse.io` site](http://fusejs.io/) gives a good explanation of why and how these values are used. |
| 42 | + |
| 43 | +### `getAllLanguages` |
| 44 | + |
| 45 | +This `static` method returns the complete array of all languages available, and the metadata associated with each language. |
| 46 | + |
| 47 | +```javascript |
| 48 | +import GitHubLanguagesClient from 'github-languages-client'; |
| 49 | + |
| 50 | +const allLanguages = GitHubLanguagesClient.getAllLanguages(); |
| 51 | +``` |
| 52 | + |
| 53 | +### `search` |
| 54 | + |
| 55 | +This `class` method returns fuzzy-search text matching on the language's name, aliases, and extensions. |
| 56 | + |
| 57 | +```javascript |
| 58 | +import GitHubLanguagesClient from 'github-languages-client'; |
| 59 | + |
| 60 | +const matchingLanguages = GitHubLanguagesClient.get('JavaScript'); |
| 61 | + |
| 62 | +// { |
| 63 | +// type: 'programming', |
| 64 | +// tmScope: 'source.js', |
| 65 | +// aceMode: 'javascript', |
| 66 | +// codemirrorMode: 'javascript', |
| 67 | +// codemirrorMimeType: 'text/javascript', |
| 68 | +// color: '#f1e05a', |
| 69 | +// aliases: [ 'js', 'node', 'javascript' ], |
| 70 | +// extensions: |
| 71 | +// [ '.js', |
| 72 | +// '._js', |
| 73 | +// '.bones', |
| 74 | +// '.es', |
| 75 | +// '.es6', |
| 76 | +// '.frag', |
| 77 | +// '.gs', |
| 78 | +// '.jake', |
| 79 | +// '.jsb', |
| 80 | +// '.jscad', |
| 81 | +// '.jsfl', |
| 82 | +// '.jsm', |
| 83 | +// '.jss', |
| 84 | +// '.mjs', |
| 85 | +// '.njs', |
| 86 | +// '.pac', |
| 87 | +// '.sjs', |
| 88 | +// '.ssjs', |
| 89 | +// '.xsjs', |
| 90 | +// '.xsjslib' ], |
| 91 | +// filenames: [ 'Jakefile' ], |
| 92 | +// interpreters: [ 'node' ], |
| 93 | +// languageId: 183, |
| 94 | +// name: 'JavaScript', |
| 95 | +// wrap: 'false', |
| 96 | +// searchable: 'true' }, |
| 97 | +// { type: 'programming', |
| 98 | +// color: '#00a6a6', |
| 99 | +// extensions: [ '.ms', '.mcr' ], |
| 100 | +// tmScope: 'source.maxscript', |
| 101 | +// aceMode: 'text', |
| 102 | +// languageId: 217, |
| 103 | +// name: 'MAXScript', |
| 104 | +// aliases: [ 'maxscript' ], |
| 105 | +// wrap: 'false', |
| 106 | +// searchable: 'true' }, |
| 107 | +// etc., etc. |
| 108 | +``` |
0 commit comments