JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 170804
  • Score
    100M100P100Q160395F
  • License MIT

compressed-trie data-structure

Package Exports

  • efrt

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (efrt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

trie-based compression of word-data
npm i efrt

efrt is a prefix/suffix trie optimised for compression of english words.

it is based on mckoss/lookups by Mike Koss and bits.js by Steve Hanov

  • squeeze a list of words into a very compact form
  • reduce filesize/bandwidth a bunch
  • ensure unpacking overhead is negligible
  • word-lookups are critical-path

By doing the fancy stuff ahead-of-time, efrt lets you ship much bigger word-lists to the client-side, without much hassle.

var efrt = require('efrt')
var words = [
  'coolage',
  'cool',
  'cool cat',
  'cool.com',
  'coolamungo'
];

//pack these words as tightly as possible
var compressed = efrt.pack(words);
//cool0;! cat,.com,a0;ge,mungo

//create a lookup-trie
var trie = efrt.unpack(compressed);

//hit it!
console.log(trie.has('cool'));//true
console.log(trie.has('miles davis'));//false

Demo!

the words you input should be pretty normalized. Spaces and unicode are good, but numbers, case-sensitivity, and some punctuation are not (yet) supported.

IE9+

<script src="https://unpkg.com/efrt@latest/builds/efrt.min.js"></script>
<script>
  var smaller=efrt.pack(['larry','curly','moe'])
  var trie=efrt.unpack(smaller)
  console.log(trie.has('moe'))
</script>

if you're doing the second step in the client, you can load just the unpack-half of the library(~3k):

<script src="https://unpkg.com/efrt@latest/builds/efrt-unpack.min.js"></script>
<script>
  var trie=unpack(compressedStuff);
  trie.has('miles davis');
</script>