Skip to content

Commit

Permalink
Port to ES6 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 authored and devongovett committed Jun 17, 2019
1 parent 82cab72 commit da9b221
Show file tree
Hide file tree
Showing 11 changed files with 1,354 additions and 1,198 deletions.
13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ Unicode Tries are generally precompiled from data in the Unicode database
for faster runtime performance. To build a Unicode Trie, use the
`UnicodeTrieBuilder` class.

```coffeescript
UnicodeTrieBuilder = require 'unicode-trie/builder'
```js
const UnicodeTrieBuilder = require('unicode-trie/builder');

# create a trie
t = new UnicodeTrieBuilder
// create a trie
let t = new UnicodeTrieBuilder();

# optional parameters for default value, and error value
# if not provided, both are set to 0
t = new UnicodeTrieBuilder 10, 999
// optional parameters for default value, and error value
// if not provided, both are set to 0
t = new UnicodeTrieBuilder(10, 999);

# set individual values and ranges
t.set 0x4567, 99
t.setRange 0x40, 0xe7, 0x1234
// set individual values and ranges
t.set(0x4567, 99);
t.setRange(0x40, 0xe7, 0x1234);

# you can lookup a value if you like
t.get 0x4567 # => 99
// you can lookup a value if you like
t.get(0x4567); // => 99

# get a compiled trie (returns a UnicodeTrie object)
trie = t.freeze()
// get a compiled trie (returns a UnicodeTrie object)
const trie = t.freeze();

# write compressed trie to a binary file
fs.writeFile 'data.trie', t.toBuffer()
// write compressed trie to a binary file
fs.writeFile('data.trie', t.toBuffer());
```

## Using a precompiled Trie
Expand All @@ -59,16 +59,16 @@ Once you've built a precompiled trie, you can load it into the
`UnicodeTrie` class, which is a readonly representation of the
trie. From there, you can lookup values.

```coffeescript
UnicodeTrie = require 'unicode-trie'
fs = require 'fs'
```js
const UnicodeTrie = require('unicode-trie');
const fs = require('fs');

# load serialized trie from binary file
data = fs.readFileSync 'data.trie'
trie = new UnicodeTrie data
// load serialized trie from binary file
const data = fs.readFileSync('data.trie');
const trie = new UnicodeTrie(data);

# lookup a value
trie.get 0x4567 # => 99
// lookup a value
trie.get(0x4567); // => 99
```

## License
Expand Down
Loading

0 comments on commit da9b221

Please sign in to comment.