🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Book a DemoInstallSign in
Socket

cmpstr

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmpstr - npm Package Compare versions

Comparing version

to
1.0.3

33

index.js

@@ -6,7 +6,7 @@ /**

* @author komed3 (Paul KĂśhler)
* @version 1.0.2
* @version 1.0.3
* @license MIT
*/
'use strict'
'use strict';

@@ -87,3 +87,3 @@ /**

*/
const cpmByAlgo = ( algo, a, b, flags ) => {
const cpmByAlgo = ( algo, a, b, flags = null ) => {

@@ -113,3 +113,3 @@ switch( algo ) {

*/
const findClosest = ( algo, test, arr, flags ) => {
const findClosest = ( algo, test, arr, flags = null ) => {

@@ -149,5 +149,6 @@ let best = -Infinity,

* @param {Null|String} flags options
* @param {Float} threshold required similarity
* @returns sorted matches
*/
const bestMatch = ( algo, test, arr, flags = null ) => {
const bestMatch = ( algo, test, arr, flags = null, threshold = 0 ) => {

@@ -163,7 +164,11 @@ let matches = [],

matches.push( {
target: str,
match: pct
} );
if( pct >= threshold ) {
matches.push( {
target: str,
match: pct
} );
}
} );

@@ -337,7 +342,8 @@

* @param {Null|String} flags options
* @param {Float} threshold required similarity
* @returns sorted matches
*/
const levenshteinMatch = ( test, arr, flags = null ) => {
const levenshteinMatch = ( test, arr, flags = null, threshold = 0 ) => {
return bestMatch( 'levenshtein', test, arr, flags );
return bestMatch( 'levenshtein', test, arr, flags, threshold );

@@ -412,7 +418,8 @@ };

* @param {Null|String} flags options
* @param {Float} threshold required similarity
* @returns sorted matches
*/
const diceMatch = ( test, arr, flags = null ) => {
const diceMatch = ( test, arr, flags = null, threshold = 0 ) => {
return bestMatch( 'diceCoefficient', test, arr, flags );
return bestMatch( 'diceCoefficient', test, arr, flags, threshold );

@@ -419,0 +426,0 @@ };

@@ -10,3 +10,3 @@ {

"homepage": "https://github.com/komed3/cmpstr#readme",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",

@@ -13,0 +13,0 @@ "keywords": [

@@ -7,3 +7,3 @@ # cmpstr

Using Node.js install the package using shell command:
Using __Node.js__, install the package with the following shell command:

@@ -62,2 +62,12 @@ ```sh

### JavaScript
Using JavaScript load this package by embed this file via [jsDelivr](https://www.jsdelivr.com/package/npm/cmpstr):
```js
import cmpstr from "https://cdn.jsdelivr.net/npm/cmpstr@1.0.3/+esm";
```
Remember: To use ``import`` you need to load your JavaScript file as ``type="module"``.
## API

@@ -86,5 +96,5 @@

#### ``levenshteinMatch( str, arr [, flags = null ] )``
#### ``levenshteinMatch( str, arr [, flags = null [, threshold = 0 ] ] )``
Calculates the similarity of all strings contained in the array ``arr`` according to Levenshtein compared to ``str`` and returns an array of all samples sorted by matching in descending order.
Calculates the similarity of all strings contained in the array ``arr`` according to Levenshtein compared to ``str`` and returns an array of all samples sorted by matching in descending order. The ``threshold`` specifies the minimum required similarity.

@@ -101,5 +111,5 @@ ### Sørensen-Dice coefficient

#### ``diceMatch( str, arr [, flags = null ] )``
#### ``diceMatch( str, arr [, flags = null [, threshold = 0 ] ] )``
Calculates the similarity of all strings contained in the array ``arr`` according to Sørensen-Dice coefficient compared to ``str`` and returns an array of all samples sorted by matching in descending order.
Calculates the similarity of all strings contained in the array ``arr`` according to Sørensen-Dice coefficient compared to ``str`` and returns an array of all samples sorted by matching in descending order. The ``threshold`` specifies the minimum required similarity.

@@ -117,2 +127,6 @@ ### Flags

### 1.0.3
* Add ``threshold`` to specify the minimum required similarity
### 1.0.2

@@ -119,0 +133,0 @@