Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
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!
FAQs
🚀 The fastest and easiest「didyoumean」in the universe via levenshtein algorithm
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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.