Skip to content

Commit 4b1133f

Browse files
committed
Init commit
0 parents  commit 4b1133f

10 files changed

+139
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.js text eol=lf

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
yarn.lock

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- '8'
4+
- '6'
5+
- '4'

.yo-rc.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"generator-nm": {
3+
"promptValues": {
4+
"githubUsername": "niksrc",
5+
"website": "https://gradeup.github.io"
6+
}
7+
}
8+
}

index.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
function detectLang({text, ...params}, cb) {
4+
const self = this;
5+
return self.transport.request({
6+
path: '/_langdetect',
7+
method: 'POST',
8+
body: {text},
9+
...params
10+
}, cb);
11+
}
12+
13+
function plugin(Client) {
14+
Client.prototype.detectLang = detectLang;
15+
}
16+
17+
module.exports = detectLang;
18+
module.exports.plugin = plugin;

license

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Nikhil Srivastava <[email protected]> (gradeup.github.io)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "elasticsearch-detectlang",
3+
"version": "0.0.0",
4+
"description": "Elasticsearch js plugin for langdetect",
5+
"license": "MIT",
6+
"repository": "gradeup/elasticsearch-detectlang",
7+
"author": {
8+
"name": "Nikhil Srivastava",
9+
"email": "[email protected]",
10+
"url": "https://niksrc.cc"
11+
},
12+
"engines": {
13+
"node": ">=4"
14+
},
15+
"scripts": {
16+
"test": "xo"
17+
},
18+
"files": [
19+
"index.js"
20+
],
21+
"keywords": [
22+
"elasticsearch",
23+
"language",
24+
"detect",
25+
"elasticsearch plugin"
26+
],
27+
"dependencies": {},
28+
"devDependencies": {
29+
"ava": "^0.20.0",
30+
"xo": "^0.18.2"
31+
}
32+
}

readme.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# elasticsearch-detectlang
2+
> Elasticsearch js plugin for [langdetect](https://github.com/jprante/elasticsearch-langdetect) module
3+
4+
## Install
5+
6+
```
7+
$ npm install elasticsearch-detectlang
8+
```
9+
10+
11+
## Usage
12+
13+
```js
14+
'use strict';
15+
16+
const hosts = ['127.0.0.1'];
17+
const elasticsearch = require('elasticsearch');
18+
const esDetectLang = require('elasticsearch-detectlang');
19+
20+
const client = new elasticsearch.Client({
21+
hosts,
22+
plugins: [esDetectLang.plugin],
23+
});
24+
25+
client
26+
.detectLang({ text: 'Hello World' })
27+
.then(console.log)
28+
// => { "languages": [{ "language": "en", "probability": 0.9999955765197549 }] }
29+
```
30+
31+
## API
32+
33+
### client.detectLang({ text }, cb)
34+
35+
#### text.
36+
37+
Type: `string`
38+
39+
The text whose language is to be determined
40+
41+
#### cb
42+
43+
Type: `function`<br>
44+
Default: `noop`
45+
46+
Callback function to be called with result. If missing it returns a promise
47+
48+
## License
49+
50+
MIT © [Nikhil Srivastava](https://twitter.com/_niksrc)

0 commit comments

Comments
 (0)