Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@types/string-similarity
Advanced tools
TypeScript definitions for string-similarity
@types/string-similarity is a TypeScript type definition package for the string-similarity library. This library is used to find the degree of similarity between two strings, find the best match for a string from a list of strings, and more.
Compare Two Strings
This feature allows you to compare two strings and get a similarity score between 0 and 1, where 1 means the strings are identical.
const stringSimilarity = require('string-similarity');
const similarity = stringSimilarity.compareTwoStrings('hello', 'hallo');
console.log(similarity); // Output: 0.8
Find Best Match
This feature allows you to find the best match for a given string from a list of strings. It returns an object containing the best match and its similarity rating.
const stringSimilarity = require('string-similarity');
const matches = stringSimilarity.findBestMatch('hello', ['hi', 'hallo', 'hey']);
console.log(matches.bestMatch); // Output: { target: 'hallo', rating: 0.8 }
Find Ratings for All Matches
This feature allows you to get similarity ratings for all matches in a list of strings. It returns an array of objects, each containing a target string and its similarity rating.
const stringSimilarity = require('string-similarity');
const matches = stringSimilarity.findBestMatch('hello', ['hi', 'hallo', 'hey']);
console.log(matches.ratings); // Output: [{ target: 'hi', rating: 0.2 }, { target: 'hallo', rating: 0.8 }, { target: 'hey', rating: 0.4 }]
string-similarity is the core library that @types/string-similarity provides type definitions for. It offers the same functionalities but without TypeScript type definitions.
string-similarity-js is another library for comparing string similarity. It offers similar functionalities but may have different algorithms and performance characteristics.
string-similarity-score is a library focused on providing similarity scores between strings. It offers similar functionalities but may have different methods for calculating similarity.
npm install --save @types/string-similarity
This package contains type definitions for string-similarity (https://github.com/aceakash/string-similarity#readme).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/string-similarity.
export as namespace stringSimilarity;
/**
* 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-insensitive.
*
* @param string1 The first string
* @param string2 The second string
* @returns A fraction from 0 to 1, both inclusive. Higher number indicates more similarity.
*/
export function compareTwoStrings(string1: string, string2: string): number;
/**
* Compares `mainString` against each string in `targetStrings`.
*
* @argument mainString: The string to match each target string against.
* @argument targetStrings: Each string in this array will be matched against the main string.
* @returns 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.
*/
export function findBestMatch(mainString: string, targetStrings: string[]): BestMatch;
export interface Rating {
target: string;
rating: number;
}
export interface BestMatch {
ratings: Rating[];
bestMatch: Rating;
bestMatchIndex: number;
}
These definitions were written by ragtime, BendingBender, and Piotr Błażejewicz.
FAQs
TypeScript definitions for string-similarity
The npm package @types/string-similarity receives a total of 38,859 weekly downloads. As such, @types/string-similarity popularity was classified as popular.
We found that @types/string-similarity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.