Nonflavored Prescription Medicine

npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

symlar

1.1.6 • Public • Published

symlar

Calculate and verify similarity between strings


symlar npm Travis Status Codecov


Verification is 1-2 orders of magnitude faster than other libraries (leven, talisman, fast-levenshtein, js-levenshtein, levenshtein-edit-distance):

$ node benchmarks.js
 
 COMPUTATION VS VERIFICATION OF LEVENSHTEIN DISTANCE:
 
        symlar/lev                x 41.88 ops/sec ±5.40% (54 runs sampled)
        symlar/vlev               x 1,135 ops/sec ±1.26% (90 runs sampled)
        symlar/eddist             x 36.43 ops/sec ±1.02% (62 runs sampled)
        symlar/veddist            x 972 ops/sec ±1.46% (89 runs sampled)
        leven                     x 65.14 ops/sec ±0.70% (66 runs sampled)
        talisman                  x 81.01 ops/sec ±0.71% (69 runs sampled)
        fast-levenshtein          x 57.93 ops/sec ±1.07% (66 runs sampled)
        js-levenshtein            x 96.58 ops/sec ±1.40% (69 runs sampled)
        levenshtein-edit-distance x 62.36 ops/sec ±1.18% (64 runs sampled)
 
        fastest is symlar/vlev

Full API documentation

Install

npm i symlar

Usage

Node

$ node
> symlar = require('./symlar')
 
{ GAP: [Getter],
  LEVENSHTEIN: [Getter],
  EN_GB_PHONE: [Getter],
  eddist: [Getter],
  veddist: [Getter],
  lev: [Getter],
  vlev: [Getter],
  edsim: [Getter],
  vedsim: [Getter],
  phonesim: [Getter],
  vphonesim: [Getter] }

levenshtein distance

> symlar.lev('SIMILARITY', 'SIMILAR')
 
3

verify levenshtein distance

> symlar.vlev('SIMILARITY', 'SIMILAR', 3)
 
true

edit similarity

> symlar.edsim('SYMLAR', 'SIMILAR', sym.LEVENSHTEIN)
 
0.7142857142857143

verify edit similarity

> symlar.vedsim('SYMLAR', 'SIMILAR', sym.LEVENSHTEIN, .7)
 
true

phonetic similarity

> symlar.phonesim('SOW', 'SEW')
 
1

verify phonetic similarity

> symlar.vphonesim('SOW', 'SEW', .9)
 
true

custom edit similarity

> symlar.edsim('SYMLAR', 'SIMILAR', (L, R) => +(L !== R)*.5)
 
0.85

custom weighted edit distance

> symlar.eddist('SIMILARITY', 'SIMILAR',(L, R) => +(L !== R)*.5)
 
1.5

verify weighted edit distance

> symlar.veddist('SIMILARITY', 'SIMILAR',(L, R) => +(L !== R)*.5, 1)
 
false

Browser

<script src='symlar.js'></script>

symlar will be available as a global

Full API documentation

npm tasks

test

npm test

Tests are slow due to there being thousands of them, as the functions are tested generatively

coverage

npm run cover

benchmark

npm run bench

License

MIT © Jose Llarena

install

npm i symlar

Downloadsweekly downloads

22

version

1.1.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability