Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from aceakash/release-notes
Browse files Browse the repository at this point in the history
Release notes
  • Loading branch information
aceakash authored Oct 2, 2018
2 parents b869c16 + 08ff7bc commit 16c348e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 55 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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)
51 changes: 25 additions & 26 deletions compare-strings.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
31 changes: 3 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 16c348e

Please sign in to comment.