···11+# string-sameness
22+33+Generate a score that represents how closely the same two strings are. The comparison function uses an average of:
44+55+* [Dice's Coefficient](https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient)
66+* [Cosine Similarity](https://en.wikipedia.org/wiki/Cosine_similarity)
77+* [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
88+99+weighted by the length of the content being compared (more weight for longer content).
1010+1111+The sameness is then given a **score of 0 to 100.**
1212+1313+* 0 => Totally unique pieces of content
1414+* 100 => Identical content
1515+1616+## Install/Usage
1717+1818+```
1919+npm install @foxxmd/string-samness
2020+```
2121+2222+```js
2323+import compare from '@foxxmd/string-sameness';
2424+2525+const result = compare('This is one sentence', 'This is another sentence');
2626+console.log(result);
2727+// {
2828+// "scores": {
2929+// "dice": 66.66,
3030+// "cosine": 75,
3131+// "leven": 79.16
3232+// },
3333+// "highScore": 73.61,
3434+// "highScoreWeighted": 83.58
3535+// }
3636+```
3737+3838+### Normalization
3939+4040+A third argument may be passed to `compare` to provide a list of functions to apply to the strings to compare. When not explicitly provided a default set of functions is applied to normalize the strings (to remove trivial differences):
4141+4242+* convert to lowercase
4343+* trim (remove whitespace at beginning/end)
4444+* remove non-alphanumeric characters (punctuation and newlines)
4545+* replace any instances of 2 or more consecutive whitespace with 1 whitespace
4646+4747+This default set of functions is exported as `defaultStrCompareTransformFuncs`.
4848+4949+Example of supplying your own transform functions:
5050+5151+```js
5252+import compare, {defaultStrCompareTransformFuncs} from '@foxxmd/string-sameness';
5353+5454+const myFuncs = [
5555+ ...defaultStrCompareTransformFuncs,
5656+ // replace all vowels with the letter e
5757+ (str) => str.replace(/[aeiou]/ig, 'e')
5858+]
5959+6060+const result = compare('This is one sentence', 'This is another sentence', myFuncs);
6161+```