Skip to content

Commit c9a89d9

Browse files
committed
Document updated Promise based API
1 parent d9e55be commit c9a89d9

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,53 @@ Linux users, make sure you have g++ >= 4.8. If this is not an option, you should
1919
## Examples
2020
### Simple
2121
```js
22-
require('cld').detect('This is a language recognition example', function(err, result) {
22+
const cld = require('cld');
23+
24+
// As a promise
25+
cld.detect('This is a language recognition example').then((result) => {
2326
console.log(result);
2427
});
28+
29+
// In an async function
30+
async function testCld() {
31+
const result = await cld.detect('This is a language recognition example');
32+
console.log(result);
33+
}
2534
```
2635

2736
### Advanced
2837
```js
29-
var text = 'Това е пример за разпознаване на Български език';
30-
var options = {
38+
const cld = require('cld');
39+
const text = 'Това е пример за разпознаване на Български език';
40+
const options = {
3141
isHTML : false,
3242
languageHint : 'BULGARIAN',
3343
encodingHint : 'ISO_8859_5',
3444
tldHint : 'bg',
3545
httpHint : 'bg'
3646
};
3747

38-
require('cld').detect(text, options, function(err, result) {
48+
// As a promise
49+
cld.detect(text, options).then((result) => {
3950
console.log(result);
4051
});
52+
53+
// In an async function
54+
async function testCld() {
55+
const result = await cld.detect(text, options);
56+
console.log(result);
57+
}
4158
```
4259

60+
### Legacy
61+
Detect can be called leveraging the node callback pattern. If options are provided, the third parameter should be the callback.
62+
```javascript
63+
const cld = require('cld');
64+
65+
cld.detect('This is a language recognition example', (err, result) => {
66+
console.log(result);
67+
});
68+
```
4369

4470
## Options
4571

0 commit comments

Comments
 (0)