kled
v0.1.6
Published
Fuzzy Matching Library with Levenshtein Edit Distance, Tailored for Korean Language Support
Downloads
12
Maintainers
Readme
kled.js
Fuzzy Matching Library with Levenshtein Edit Distance, Tailored for Korean Language Support
Also available in: 한국어
APIs
distance(a: string, b: string, caseSensitive: bool): number
Calculate the Levenshtein distance between two strings.
Parameters
a
: a stringb
: another stringcaseSensitive
: optional parameter (default: false), determines whether to consider case sensitivity.
Returns
The Levenshtein distance between the input strings.
matches(needle: string, haystack: string, caseSensitive: bool): number
Calculate the similarity score between two strings, providing a numerical value between 0 and 1. If the "haystack" does not contain the "needle," the function returns 0.
It also supports partial Korean letter matching. For example, "ㅇㄴ" and "아녀" matches "안녕" with a slightly lower score than "안녕", which exactly matches the haystack.
Parameters
needle
: a string to search forhaystack
: a string to search incaseSensitive
: optional parameter (default: false), determines whether to consider case sensitivity.
Returns
A similarity score between the input strings, where 0 indicates no similarity, and 1 indicates a perfect match based on the number of matched letters and their positions.
Usage
import { distance, matches } from 'kled';
const levenshteinDistance = distance('hello', 'hola');
console.log(`Levenshtein Distance: ${levenshteinDistance}`);
const similarityScore = matches('abc', 'abCde');
console.log(`Similarity Score: ${similarityScore}`);
Reporting Issues
Please report issues here if you find any.
License
MIT