Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 14, 2019
1 parent 885c9ca commit 92bb474
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 99 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
node_modules
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage/
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
sudo: false
node_js:
- lts/dubnium
- node
after_script: bash <(curl -s https://codecov.io/bash)
54 changes: 0 additions & 54 deletions README.md

This file was deleted.

7 changes: 0 additions & 7 deletions example.js

This file was deleted.

14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
var distance = require("leven")
'use strict'

module.exports = function(a,b) {
if (!a || !b || !a.length || !b.length) return 0
var levenshtein = require('levenshtein-edit-distance')

module.exports = similarity

function similarity(a, b) {
if (!a || !b || a.length === 0 || b.length === 0) return 0
if (a === b) return 1
var d = distance(a.toLowerCase(),b.toLowerCase())
var d = levenshtein(a.toLowerCase(), b.toLowerCase())
var longest = Math.max(a.length, b.length)
return (longest-d)/longest
return (longest - d) / longest
}
15 changes: 15 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2014 Zeke Sikelianos <zeke@sikelianos.com>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
68 changes: 48 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
"name": "similarity",
"version": "1.1.1",
"description": "How similar are these two strings?",
"main": "index.js",
"scripts": {
"test": "tap test"
},
"repository": {
"type": "git",
"url": "https://github.com/zeke/similarity"
},
"license": "ISC",
"keywords": [
"string",
"text",
Expand All @@ -19,20 +12,55 @@
"distance",
"spelling"
],
"author": "zeke",
"license": "ISC",
"bugs": {
"url": "https://github.com/zeke/similarity/issues"
},
"homepage": "https://github.com/zeke/similarity",
"repository": "words/similarity",
"bugs": "https://github.com/words/similarity/issues",
"author": "Zeke Sikelianos <zeke@sikelianos.com> (http://zeke.sikelianos.com)",
"contributors": [
"Zeke Sikelianos <zeke@sikelianos.com> (http://zeke.sikelianos.com)",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"main": "index.js",
"files": [
"index.js"
],
"dependencies": {
"leven": "^2.0.0"
"levenshtein-edit-distance": "^2.0.0"
},
"devDependencies": {
"tap": "^0.4.13"
"nyc": "^14.0.0",
"prettier": "^1.0.0",
"remark-cli": "^7.0.0",
"remark-preset-wooorm": "^6.0.0",
"tape": "^4.0.0",
"xo": "^0.25.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false
},
"alternatives": [
"clj-fuzzy",
"jaro-winkler"
]
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}
77 changes: 77 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# similarity

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]

How similar are these two strings?

## Install

[npm][]:

```sh
npm install similarity
```

## Use

```js
var similarity = require('similarity')

similarity('food', 'food') // 1
similarity('food', 'fool') // 0.75
similarity('ding', 'plow') // 0
similarity('chicken', 'chick') // 0.714285714
similarity('es6-shim', 'es6 shim') // 0.875
similarity('ES6-Shim', 'es6 shim') // 0.875 (case insensitive)
```

## See also

Note: This module uses [Levenshtein distance][wiki] to measure similarity, but
there are many other algorithms for string comparison.
Here are a few:

* [`clj-fuzzy`](https://github.com/Yomguithereal/clj-fuzzy)
— Handy collection of algorithms dealing with fuzzy strings and phonetics
* [natural](https://github.com/NaturalNode/natural)
— General natural language facilities for node
* [`string-similarity`](https://github.com/aceakash/string-similarity)
— Finds degree of similarity between two strings, based on Dice’s
coefficient
* [`dice-coefficient`](https://github.com/words/dice-coefficient)
— Sørensen–Dice coefficient
* [`jaro-winkler`](https://github.com/jordanthomas/jaro-winkler)
— The Jaro-Winkler distance metric

## License

[ISC][license] © [Zeke Sikelianos][author]

<!-- Definitions -->

[build-badge]: https://img.shields.io/travis/words/similarity.svg

[build]: https://travis-ci.org/words/similarity

[coverage-badge]: https://img.shields.io/codecov/c/github/words/similarity.svg

[coverage]: https://codecov.io/github/words/similarity

[downloads-badge]: https://img.shields.io/npm/dm/similarity.svg

[downloads]: https://www.npmjs.com/package/similarity

[size-badge]: https://img.shields.io/bundlephobia/minzip/similarity.svg

[size]: https://bundlephobia.com/result?p=similarity

[npm]: https://www.npmjs.com

[license]: license

[author]: http://zeke.sikelianos.com

[wiki]: https://en.wikipedia.org/wiki/Levenshtein_distance
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var test = require('tape')
var similarity = require('.')

test('similarity', function(t) {
t.equal(similarity('food', 'food'), 1)
t.equal(similarity('food', 'fool'), 0.75)
t.equal(similarity('ding', 'plow'), 0)
t.equal(similarity('chicken', 'chick'), 5 / 7)
t.equal(similarity('es6-shim', 'es6 shim'), 7 / 8)
t.equal(similarity('ES6 Shim', 'es6-shim'), 7 / 8, 'it’s case insensitive')
t.end()
})
12 changes: 0 additions & 12 deletions test/index.js

This file was deleted.

0 comments on commit 92bb474

Please sign in to comment.