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

Commit 07cbc8d

Browse files
committed
update readme
1 parent 7ab3d72 commit 07cbc8d

File tree

1 file changed

+59
-40
lines changed

1 file changed

+59
-40
lines changed

README.md

+59-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
string-similarity
2-
=================
1+
# string-similarity
32

43
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).
54

@@ -8,17 +7,17 @@ Finds degree of similarity between two strings, based on [Dice's Coefficient](ht
87
- [string-similarity](#string-similarity)
98
- [Table of Contents](#table-of-contents)
109
- [Usage](#usage)
11-
- [For Node.js](#for-nodejs)
12-
- [For browser apps](#for-browser-apps)
10+
- [For Node.js](#for-nodejs)
11+
- [For browser apps](#for-browser-apps)
1312
- [API](#api)
1413
- [compareTwoStrings(string1, string2)](#comparetwostringsstring1-string2)
15-
- [Arguments](#arguments)
16-
- [Returns](#returns)
17-
- [Examples](#examples)
14+
- [Arguments](#arguments)
15+
- [Returns](#returns)
16+
- [Examples](#examples)
1817
- [findBestMatch(mainString, targetStrings)](#findbestmatchmainstring-targetstrings)
19-
- [Arguments](#arguments-1)
20-
- [Returns](#returns-1)
21-
- [Examples](#examples-1)
18+
- [Arguments](#arguments-1)
19+
- [Returns](#returns-1)
20+
- [Examples](#examples-1)
2221
- [Release Notes](#release-notes)
2322
- [2.0.0](#200)
2423
- [3.0.0](#300)
@@ -27,7 +26,6 @@ Finds degree of similarity between two strings, based on [Dice's Coefficient](ht
2726
- [4.0.2](#402)
2827
- [4.0.3](#403)
2928

30-
3129
## Usage
3230

3331
#### For Node.js
@@ -41,11 +39,15 @@ npm install string-similarity --save
4139
In your code:
4240

4341
```javascript
44-
var stringSimilarity = require('string-similarity');
42+
var stringSimilarity = require("string-similarity");
4543

46-
var similarity = stringSimilarity.compareTwoStrings('healed', 'sealed');
44+
var similarity = stringSimilarity.compareTwoStrings("healed", "sealed");
4745

48-
var matches = stringSimilarity.findBestMatch('healed', ['edward', 'sealed', 'theatre']);
46+
var matches = stringSimilarity.findBestMatch("healed", [
47+
"edward",
48+
"sealed",
49+
"theatre",
50+
]);
4951
```
5052

5153
#### For browser apps
@@ -73,32 +75,38 @@ The package contains two methods:
7375
Returns a fraction between 0 and 1, which indicates the degree of similarity between the two strings. 0 indicates completely different strings, 1 indicates identical strings. The comparison is case-sensitive.
7476

7577
##### Arguments
76-
78+
7779
1. string1 (string): The first string
7880
2. string2 (string): The second string
79-
81+
8082
Order does not make a difference.
81-
83+
8284
##### Returns
83-
85+
8486
(number): A fraction from 0 to 1, both inclusive. Higher number indicates more similarity.
8587

8688
##### Examples
87-
89+
8890
```javascript
89-
stringSimilarity.compareTwoStrings('healed', 'sealed');
91+
stringSimilarity.compareTwoStrings("healed", "sealed");
9092
// → 0.8
9193

92-
stringSimilarity.compareTwoStrings('Olive-green table for sale, in extremely good condition.',
93-
'For sale: table in very good condition, olive green in colour.');
94+
stringSimilarity.compareTwoStrings(
95+
"Olive-green table for sale, in extremely good condition.",
96+
"For sale: table in very good condition, olive green in colour."
97+
);
9498
// → 0.6060606060606061
9599

96-
stringSimilarity.compareTwoStrings('Olive-green table for sale, in extremely good condition.',
97-
'For sale: green Subaru Impreza, 210,000 miles');
100+
stringSimilarity.compareTwoStrings(
101+
"Olive-green table for sale, in extremely good condition.",
102+
"For sale: green Subaru Impreza, 210,000 miles"
103+
);
98104
// → 0.2558139534883721
99105

100-
stringSimilarity.compareTwoStrings('Olive-green table for sale, in extremely good condition.',
101-
'Wanted: mountain bike with at least 21 gears.');
106+
stringSimilarity.compareTwoStrings(
107+
"Olive-green table for sale, in extremely good condition.",
108+
"Wanted: mountain bike with at least 21 gears."
109+
);
102110
// → 0.1411764705882353
103111
```
104112

@@ -112,16 +120,18 @@ Compares `mainString` against each string in `targetStrings`.
112120
2. targetStrings (Array): Each string in this array will be matched against the main string.
113121

114122
##### Returns
123+
115124
(Object): An object with a `ratings` property, which gives a similarity rating for each target string, a `bestMatch` property, which specifies which target string was most similar to the main string, and a `bestMatchIndex` property, which specifies the index of the bestMatch in the targetStrings array.
116125

117126
##### Examples
127+
118128
```javascript
119129
stringSimilarity.findBestMatch('Olive-green table for sale, in extremely good condition.', [
120-
'For sale: green Subaru Impreza, 210,000 miles',
121-
'For sale: table in very good condition, olive green in colour.',
130+
'For sale: green Subaru Impreza, 210,000 miles',
131+
'For sale: table in very good condition, olive green in colour.',
122132
'Wanted: mountain bike with at least 21 gears.'
123133
]);
124-
//
134+
//
125135
{ ratings:
126136
[ { target: 'For sale: green Subaru Impreza, 210,000 miles',
127137
rating: 0.2558139534883721 },
@@ -132,34 +142,43 @@ stringSimilarity.findBestMatch('Olive-green table for sale, in extremely good co
132142
bestMatch:
133143
{ target: 'For sale: table in very good condition, olive green in colour.',
134144
rating: 0.6060606060606061 },
135-
bestMatchIndex: 1
145+
bestMatchIndex: 1
136146
}
137147
```
138148

139149
## Release Notes
140150

141151
### 2.0.0
142-
* Removed production dependencies
143-
* Updated to ES6 (this breaks backward-compatibility for pre-ES6 apps)
152+
153+
- Removed production dependencies
154+
- Updated to ES6 (this breaks backward-compatibility for pre-ES6 apps)
144155

145156
### 3.0.0
146-
* Performance improvement for `compareTwoStrings(..)`: now O(n) instead of O(n^2)
147-
* The algorithm has been tweaked slightly to disregard spaces and word boundaries. This will change the rating values slightly but not enough to make a significant difference
148-
* Adding a `bestMatchIndex` to the results for `findBestMatch(..)` to point to the best match in the supplied `targetStrings` array
157+
158+
- Performance improvement for `compareTwoStrings(..)`: now O(n) instead of O(n^2)
159+
- The algorithm has been tweaked slightly to disregard spaces and word boundaries. This will change the rating values slightly but not enough to make a significant difference
160+
- Adding a `bestMatchIndex` to the results for `findBestMatch(..)` to point to the best match in the supplied `targetStrings` array
149161

150162
### 3.0.1
151-
* Refactoring: removed unused functions; used `substring` instead of `substr`
152-
* Updated dependencies
163+
164+
- Refactoring: removed unused functions; used `substring` instead of `substr`
165+
- Updated dependencies
153166

154167
### 4.0.1
155-
* Distributing as an UMD build to be used in browsers.
168+
169+
- Distributing as an UMD build to be used in browsers.
156170

157171
### 4.0.2
158-
* Update dependencies to latest versions.
172+
173+
- Update dependencies to latest versions.
159174

160175
### 4.0.3
161-
* Make compatible with IE and ES5. Also, update deps. (see [PR56](https://github.com/aceakash/string-similarity/pull/56))
162176

177+
- Make compatible with IE and ES5. Also, update deps. (see [PR56](https://github.com/aceakash/string-similarity/pull/56))
178+
179+
### 4.0.4
180+
181+
- Simplify some conditional statements. Also, update deps. (see [PR50](https://github.com/aceakash/string-similarity/pull/50))
163182

164183
![Build status](https://codeship.com/projects/2aa453d0-0959-0134-8a76-4abcb29fe9b4/status?branch=master)
165184
[![Known Vulnerabilities](https://snyk.io/test/github/aceakash/string-similarity/badge.svg)](https://snyk.io/test/github/aceakash/string-similarity)

0 commit comments

Comments
 (0)