Skip to content

Commit

Permalink
Document updated Promise based API
Browse files Browse the repository at this point in the history
  • Loading branch information
implausible committed May 5, 2020
1 parent d9e55be commit c9a89d9
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,53 @@ Linux users, make sure you have g++ >= 4.8. If this is not an option, you should
## Examples
### Simple
```js
require('cld').detect('This is a language recognition example', function(err, result) {
const cld = require('cld');

// As a promise
cld.detect('This is a language recognition example').then((result) => {
console.log(result);
});

// In an async function
async function testCld() {
const result = await cld.detect('This is a language recognition example');
console.log(result);
}
```

### Advanced
```js
var text = 'Това е пример за разпознаване на Български език';
var options = {
const cld = require('cld');
const text = 'Това е пример за разпознаване на Български език';
const options = {
isHTML : false,
languageHint : 'BULGARIAN',
encodingHint : 'ISO_8859_5',
tldHint : 'bg',
httpHint : 'bg'
};

require('cld').detect(text, options, function(err, result) {
// As a promise
cld.detect(text, options).then((result) => {
console.log(result);
});

// In an async function
async function testCld() {
const result = await cld.detect(text, options);
console.log(result);
}
```

### Legacy
Detect can be called leveraging the node callback pattern. If options are provided, the third parameter should be the callback.
```javascript
const cld = require('cld');

cld.detect('This is a language recognition example', (err, result) => {
console.log(result);
});
```

## Options

Expand Down

0 comments on commit c9a89d9

Please sign in to comment.