diff --git a/README.md b/README.md index 9e2bd5c..d509531 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,22 @@ string-similarity Finds degree of similarity between two strings, based on [Dice's Coefficient](http://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient), which is mostly better than [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance). +## Table of Contents + +* [Usage](#usage) +* [API](#api) + * [compareTwoStrings(string1, string2)](#comparetwostringsstring1-string2) + * [Arguments](#arguments) + * [Returns](#returns) + * [Examples](#examples) + * [findBestMatch(mainString, targetStrings)](#findbestmatchmainstring-targetstrings) + * [Arguments](#arguments-1) + * [Returns](#returns-1) + * [Examples](#examples-1) +* [Release Notes](#release-notes) + * [2.0.0](#200) + + ## Usage Install using: @@ -89,5 +105,12 @@ stringSimilarity.findBestMatch('Olive-green table for sale, in extremely good co rating: 0.7073170731707317 } } ``` +## Release Notes + +### 2.0.0 +* Removed production dependencies +* Updated to ES6 (this breaks backward-compatibility for pre-ES6 apps) + + ![Build status](https://codeship.com/projects/2aa453d0-0959-0134-8a76-4abcb29fe9b4/status?branch=master) [![Known Vulnerabilities](https://snyk.io/test/github/aceakash/string-similarity/badge.svg)](https://snyk.io/test/github/aceakash/string-similarity) diff --git a/compare-strings.js b/compare-strings.js index bdbcfdb..aa65181 100644 --- a/compare-strings.js +++ b/compare-strings.js @@ -1,25 +1,7 @@ -function flattenDeep (arr) { - return Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)) , []) : [arr]; -} - -function areArgsValid (mainString, targetStrings) { - if (typeof mainString !== 'string') return false; - if (!Array.isArray(targetStrings)) return false; - if (!targetStrings.length) return false; - if (targetStrings.find(s => typeof s !== 'string')) return false; - return true; -} - -function letterPairs (str) { - const pairs = []; - for (let i = 0, max = str.length - 1; i < max; i++) pairs[i] = str.substring(i, i + 2); - return pairs; -} - -function wordLetterPairs (str) { - const pairs = str.toUpperCase().split(' ').map(letterPairs); - return flattenDeep(pairs); -} +module.exports = { + compareTwoStrings, + findBestMatch +}; function compareTwoStrings (str1, str2) { if (!str1.length && !str2.length) return 1; // if both are empty strings @@ -49,8 +31,25 @@ function findBestMatch (mainString, targetStrings) { return { ratings, bestMatch }; } +function flattenDeep (arr) { + return Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)) , []) : [arr]; +} -module.exports = { - compareTwoStrings, - findBestMatch -}; +function areArgsValid (mainString, targetStrings) { + if (typeof mainString !== 'string') return false; + if (!Array.isArray(targetStrings)) return false; + if (!targetStrings.length) return false; + if (targetStrings.find(s => typeof s !== 'string')) return false; + return true; +} + +function letterPairs (str) { + const pairs = []; + for (let i = 0, max = str.length - 1; i < max; i++) pairs[i] = str.substring(i, i + 2); + return pairs; +} + +function wordLetterPairs (str) { + const pairs = str.toUpperCase().split(' ').map(letterPairs); + return flattenDeep(pairs); +} diff --git a/package-lock.json b/package-lock.json index d3c5184..d6fec0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,9 +33,9 @@ "dev": true }, "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -78,31 +78,6 @@ "integrity": "sha512-pa9tbBWgU0EE4SWgc85T4sa886ufuQdsgruQANhECYjwqgV4z7Vw/499aCaP8ZH79JDS4vhm8doDG9HO4+e4sA==", "dev": true }, - "lodash.every": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/lodash.every/-/lodash.every-4.6.0.tgz", - "integrity": "sha1-64mYS+vENkJ5uzrvu9HKGb+mxqc=" - }, - "lodash.flattendeep": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", - "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=" - }, - "lodash.foreach": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.foreach/-/lodash.foreach-4.5.0.tgz", - "integrity": "sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM=" - }, - "lodash.map": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/lodash.map/-/lodash.map-4.6.0.tgz", - "integrity": "sha1-dx7Hg540c9nEzeKLGTlMNWL09tM=" - }, - "lodash.maxby": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/lodash.maxby/-/lodash.maxby-4.6.0.tgz", - "integrity": "sha1-CCJABo88eiJ6oAqDgOTzjPB4bj0=" - }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", diff --git a/package.json b/package.json index 0468611..f571169 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "string-similarity", - "version": "1.2.2", + "version": "2.0.0", "description": "Finds degree of similarity between strings, based on Dice's Coefficient, which is mostly better than Levenshtein distance.", "main": "compare-strings.js", "scripts": {