https://github.com/jaebradley/github-languages-client
📖 NodeJS Client for GitHub Languages
https://github.com/jaebradley/github-languages-client
github-language github-languages nodejs npm npm-package programming-language programming-languages
Last synced: 4 months ago
JSON representation
📖 NodeJS Client for GitHub Languages
- Host: GitHub
- URL: https://github.com/jaebradley/github-languages-client
- Owner: jaebradley
- License: mit
- Created: 2018-04-06T19:49:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-12T19:41:09.000Z (over 3 years ago)
- Last Synced: 2024-10-16T08:31:24.346Z (9 months ago)
- Topics: github-language, github-languages, nodejs, npm, npm-package, programming-language, programming-languages
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/github-languages-client
- Size: 1.32 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GitHub Languages Client

[](https://codecov.io/gh/jaebradley/github-languages-client)
[](https://www.npmjs.com/package/github-languages-client)

[](https://www.npmjs.com/package/github-languages-client)
A `NodeJS` client to get languages GitHub knows about for [`Advanced Search`](https://github.com/search/advanced), for example.

## Implementation
`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.
I convert this `languages.yml` file to [a JSON file](~/src/languages.json). [1](#languages-job-footnote)
I then read from this file when instantiating the `GitHubLanguagesClient`.
For fuzzy-searching, I use [the `fuse` library](http://fusejs.io/).
## API
### Constructor
The default constructor parameters, used for fuzzy-searching, are
```javascript
{
maxPatternLength = 32,
caseSensitive = false,
includeScore = false,
shouldSort = true,
threshold = 0.6,
location = 0,
distance = 100,
minMatchCharLength = 1,
}
```The [`fuse.io` site](http://fusejs.io/) 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`](src/languages.json) file as a `JavaScript` object.
```javascript
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.
```javascript
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.