Gathering detailed insights and metrics for calculate-string-similarity
Gathering detailed insights and metrics for calculate-string-similarity
Gathering detailed insights and metrics for calculate-string-similarity
Gathering detailed insights and metrics for calculate-string-similarity
A Node.js package to calculate string similarity
npm install calculate-string-similarity
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
21 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Apr 15, 2024
Latest Version
1.0.9
Package Id
calculate-string-similarity@1.0.9
Unpacked Size
20.50 kB
Size
5.59 kB
File Count
6
NPM Version
10.2.3
Node Version
21.2.0
Published on
Apr 14, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
The calculate-string-similarity package is designed to provide advanced functionalities for comparing strings in Node.js applications. String matching and comparison are fundamental operations in many software applications, ranging from spell correction to text analysis and beyond. This package aims to simplify and enhance these operations by offering a comprehensive set of features and options.
String Matching: The package offers robust string matching capabilities, allowing developers to compare strings with precision and accuracy.
Advanced Comparison: It goes beyond simple string equality checks and provides options for advanced comparison, including case sensitivity, order sensitivity, and more.
Customization: Developers can customize the comparison process according to their specific requirements. This includes fine-tuning parameters such as case sensitivity and order sensitivity to achieve the desired results.
1npm install calculate-string-similarity
You can install calculate-string-similarity via npm:
The calculate-string-similarity
package provides functionality for comparing strings with various options, including case sensitivity and order sensitivity.
1const { getSimilarity } = require('calculate-string-similarity'); 2 3console.log("Test cases for getSimilarity function:"); 4console.log("----------------------------------------"); 5 6// Test case 1: Case-sensitive and order-sensitive comparison with identical strings 7console.log("Test case 1:", getSimilarity("hello", "hello")); // Expected output: 100 8 9// Test case 2: Case-insensitive comparison with identical strings 10console.log("Test case 2:", getSimilarity("hello", "HELLO", { caseSensitive: false })); // Expected output: 100 11 12// Test case 3: Case-sensitive and order-sensitive comparison with different strings 13console.log("Test case 3:", getSimilarity("hello", "holle", { caseSensitive: true, orderSensitive: true })); // Expected output: 60 14 15// Test case 4: Case-insensitive and order-insensitive comparison with partially different strings 16console.log("Test case 4:", getSimilarity("hello", "holle", { caseSensitive: false, orderSensitive: false })); // Expected output: 100 17 18// Test case 5: Custom strings with partial similarity 19console.log("Test case 5:", getSimilarity("apple", "aple")); // Expected output: 80 20 21// Test case 6: Null input strings 22try { 23 getSimilarity(null, "HELLO", { caseSensitive: false }); 24} catch (error) { 25 console.log("Test case 6:", error.message); // Expected output: "Input strings are required." 26} 27 28// Test case 7: Invalid input parameters 29try { 30 getSimilarity("hello", "HELLO", { caseSensitive: "false" }); 31} catch (error) { 32 console.log("Test case 7:", error.message); // Expected output: "Invalid input parameters." 33}
string1
: The first string to compare.string2
: The second string to compare.options
: An optional object containing additional parameters:
caseSensitive
: A boolean indicating whether the comparison should be case-sensitive. Default is true
.orderSensitive
: A boolean indicating whether the comparison should be order-sensitive. Default is true
.This package provides a utility function getSimilarities
to calculate similarities between a given input string and an array of strings. It can be useful for various applications such as spell correction, autocomplete suggestions, and text analysis.
1const { getSimilarities } = require('calculate-string-similarity'); 2const inputString = "apple"; 3const stringList = ["appl", "apricot", "orange", "banana", "pineapple"]; 4 5console.log("Test cases for getSimilarities function:"); 6console.log("------------------------------------------"); 7 8// Test case 8: Case-sensitive and order-sensitive comparison with custom threshold and ordering 9console.log("Test case 11:", getSimilarities("apple", ["aple", "banana", "orange"], { caseSensitive: true, orderSensitive: true, threshold: 30, thresholdType: '>=', orderBy: 'similarity', order: 'ascending', numberOfOutputs: 2 })); 10// Expected output: [{ Input: 'aple', Similarity: 80 }, { Input: 'banana', Similarity: 0 }] 11 12// Test case 9: Case-insensitive comparison with custom threshold and ordering 13console.log("Test case 12:", getSimilarities("apple", ["aple", "banana", "orange"], { caseSensitive: false, threshold: 60, thresholdType: '<=', orderBy: 'string', order: 'descending' })); 14// Expected output: [{ Input: 'orange', Similarity: 0 }, { Input: 'aple', Similarity: 80 }] 15 16// Test case 10: Default behavior with order-insensitive comparison and custom threshold 17console.log("Test case 13:", getSimilarities("apple", ["aple", "banana", "orange"], { orderSensitive: false, threshold: 70, thresholdType: '>' })); 18// Expected output: [{ Input: 'aple', Similarity: 80 }] 19 20// Test case 11: Null input strings 21try { 22 getSimilarities(null, ["aple", "banana", "orange"], { caseSensitive: false }); 23} catch (error) { 24 console.log("Test case 14:", error.message); // Expected output: "Input strings are required." 25} 26 27// Test case 12: Invalid input parameters 28try { 29 getSimilarities("apple", ["aple", "banana", "orange"], { caseSensitive: "false" }); 30} catch (error) { 31 console.log("Test case 15:", error.message); // Expected output: "Invalid input parameters." 32} 33// Test case 13: Case-insensitive comparison with custom threshold and ordering 34console.log("Test case 12:", getSimilarities("apple", ["aple", "banana", "orange"], { caseSensitive: false, threshold: 60, thresholdType: '<=', orderBy: 'string', order: 'descending' })); 35// Expected output: [{ Input: 'orange', Similarity: 0 }, { Input: 'aple', Similarity: 80 }] 36 37// Test case 14: Default behavior with order-insensitive comparison and custom threshold 38console.log("Test case 13:", getSimilarities("apple", ["aple", "banana", "orange"], { orderSensitive: false, threshold: 70, thresholdType: '>' })); 39// Expected output: [{ Input: 'aple', Similarity: 80 }] 40 41// Test case 15: Null input strings 42try { 43 getSimilarities(null, ["aple", "banana", "orange"], { caseSensitive: false }); 44} catch (error) { 45 console.log("Test case 14:", error.message); // Expected output: "Input strings are required." 46} 47 48// Test case 16: Invalid input parameters 49try { 50 getSimilarities("apple", ["aple", "banana", "orange"], { caseSensitive: "false" }); 51} catch (error) { 52 console.log("Test case 15:", error.message); // Expected output: "Invalid input parameters." 53}
inputString
: The input string for which similarities need to be calculated.stringList
: An array of strings against which the similarity of the input string will be calculated.options
: An optional object containing additional parameters:
threshold
: The minimum similarity percentage required for a string to be considered similar. Default is 0
.thresholdType
: The type of threshold comparison to be applied for similarity percentage. It determines whether the similarity percentage should be greater than (>
), greater than or equal to (>=
), less than (<
), or less than or equal to (<=
) the specified threshold value. Default is >
.orderBy
: The parameter to order the results by, either 'similarity'
or 'name'
. Default is 'similarity'
.order
: The order in which to sort the results, either 'ascending'
or 'descending'
. Default is 'descending'
.numberOfOutputs
: The number of top similarity results to return. Default is Infinity
.
No vulnerabilities found.
No security vulnerabilities found.