Skip to content

Commit 7ebb1f1

Browse files
authored
Merge pull request #2 from jaebradley/add-language-client
Add language client
2 parents 57fa12f + c660641 commit 7ebb1f1

File tree

10 files changed

+398
-50
lines changed

10 files changed

+398
-50
lines changed

.babelrc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
"presets": [
33
"@babel/preset-env"
44
],
5-
"env": {
6-
"production": {
7-
"presets": ["minify"]
8-
}
9-
},
105
"ignore": [
116
"node_modules"
7+
],
8+
"plugins": [
9+
"@babel/transform-runtime",
10+
"@babel/transform-async-to-generator"
1211
]
1312
}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ src/
77
test/
88
*.test.js
99
coverage/
10+
scripts/

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# GitHub Languages Client
2+
3+
[![Build Status](https://travis-ci.org/jaebradley/github-languages-client.svg?branch=master)](https://travis-ci.org/jaebradley/github-languages-client)
4+
[![npm](https://img.shields.io/npm/dt/express.svg)](github-https://www.npmjs.com/package/github-languages-client-client)
5+
[![npm](https://img.shields.io/npm/v/npm.svg)](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+
![advanced-search](https://imgur.com/TYoc7Qy.png)
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+
```

package-lock.json

Lines changed: 140 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)