Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
didyoumean3
Advanced tools
🚀 the super fast and easy didyoumean which use dice-coefficient and levenshtein
notice: Covers most situations and still needs to be optimized, i will do better!
npm i didyoumean3
// if none match return null
didyoumean3('', ['anything']); // null
// else will a object like 👇:
{
winner: 'the best matched item',
matches: [
{
score: 0.1,
target: 'item'
},
//...
]
}
// or you can use a custom function to specify the result, just add an option "result"
didyoumean3('', ['anything'], { result: x => x || 'no matched!' });
const didyoumean3 = require('didyoumean3').default
// or if you are using TypeScript or ES module
import didyoumean3 from 'didyoumean3'
let input = 'insargrm'
let list = [
'facebook', 'INSTAgram', ' in stagram', 'baidu', 'twitter', 'wechat', 'instagram', 'linkedin'
]
// levenshtein
didyoumean3(input, list)?.winner // instagram
// dice-coefficient
didyoumean3(input, list, { similar: 'dice' })?.winner // instagram
// or use your custom algorithm
// notice: If you customize the algorithm, the optimal route must take the minimum
const your_leven = require('some/your_leven');
const your_comparator = (a: number, b: number) => a < b;
didyoumean3(input, list, { similar: your_leven })
// specify the way you get the value
const val = item => item.id;
didyoumean3(input, [{id: 'facebook'}, {id: 'baidu'}, {id: 'instagram'}], { vaL })?.winner; // {id: 'instagram'}
I'm lazy, I just give the declaration file 👇
export interface Val {
(x: string | object): string
}
export interface Similar {
(a: string, b: string, opts?: Partial<Options>): number
}
export interface Return {
(x: any): any
}
export interface Normalize {
(x: string): string
}
// dice-coefficient or levenshtein
export type BuiltInSimilar = 'dice' | 'leven'
export type Result <T extends string | object> = {
winner: T,
matches: ReadonlyArray<T>,
[key: string]: any
} | null
/**
* @type {boolean} ignore: ignore case 'A' -> 'a'
* @type {boolean} trim: ' a bcs ' -> 'a bcs'
* @type {boolean} trimAll: ' a bcs' -> 'abcs'
* @type {boolean} diacritics: 'café' -> 'café'.normalize()
* @type {Function} val: when you need find the best result in a object list, it's useful
* @type {string | Function} similar: use builtin shortest edit-distance algorithm or yours
* @type {Function} result: you can custom your return result
* @type {Function} filter: you can filter the data into the returned results
*/
export type Options = {
ignore?: boolean;
trim?: boolean;
trimAll?: boolean;
diacritics?: boolean;
normalize?: Normalize;
val?: Val;
similar?: BuiltInSimilar | Similar;
result?: Return;
filter?: Filter;
};
didyoumean x 194,593 ops/sec ±1.07% (84 runs sampled)
didyoumean2 x 311,318 ops/sec ±0.63% (90 runs sampled)
didyoumean3-leven x 510,067 ops/sec ±0.48% (84 runs sampled)
didyoumean3-dice x 294,427 ops/sec ±0.46% (85 runs sampled)
Fastest is didyoumean3-leven
nobody now.
Both issure and pr are welcome!
v-1.1.4
FAQs
🚀 The fastest and easiest「didyoumean」in the universe via levenshtein algorithm
The npm package didyoumean3 receives a total of 576 weekly downloads. As such, didyoumean3 popularity was classified as not popular.
We found that didyoumean3 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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.