fuzzymatch.js — svelte Source File
Architecture documentation for fuzzymatch.js, a javascript file in the svelte codebase. 0 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 4057eb45_ab28_d989_1209_dfae45d590c0["fuzzymatch.js"] 6b8c189e_23e1_77d3_9ee3_3eec5012a9b2["BindDirective.js"] 6b8c189e_23e1_77d3_9ee3_3eec5012a9b2 --> 4057eb45_ab28_d989_1209_dfae45d590c0 b389a21f_6de7_2a41_34f3_8efbf9045c9c["index.js"] b389a21f_6de7_2a41_34f3_8efbf9045c9c --> 4057eb45_ab28_d989_1209_dfae45d590c0 d1869e84_a713_3c60_3aae_40e1a6b78424["extract_svelte_ignore.js"] d1869e84_a713_3c60_3aae_40e1a6b78424 --> 4057eb45_ab28_d989_1209_dfae45d590c0 style 4057eb45_ab28_d989_1209_dfae45d590c0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* @param {string} name
* @param {string[]} names
* @returns {string | null}
*/
export default function fuzzymatch(name, names) {
if (names.length === 0) return null;
const set = new FuzzySet(names);
const matches = set.get(name);
return matches && matches[0][0] > 0.7 ? matches[0][1] : null;
}
// adapted from https://github.com/Glench/fuzzyset.js/blob/master/lib/fuzzyset.js in 2016
// BSD Licensed (see https://github.com/Glench/fuzzyset.js/issues/10)
const GRAM_SIZE_LOWER = 2;
const GRAM_SIZE_UPPER = 3;
// return an edit distance from 0 to 1
/**
* @param {string} str1
* @param {string} str2
*/
function _distance(str1, str2) {
if (str1 === null && str2 === null) {
throw 'Trying to compare two null values';
}
if (str1 === null || str2 === null) return 0;
str1 = String(str1);
str2 = String(str2);
const distance = levenshtein(str1, str2);
return 1 - distance / Math.max(str1.length, str2.length);
}
// helper functions
/**
* @param {string} str1
* @param {string} str2
*/
function levenshtein(str1, str2) {
/** @type {number[]} */
const current = [];
let prev = 0;
for (let i = 0; i <= str2.length; i++) {
for (let j = 0; j <= str1.length; j++) {
let value;
if (i && j) {
if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
value = prev;
} else {
value = Math.min(current[j], current[j - 1], prev) + 1;
}
} else {
// ... (222 more lines)
Domain
Subdomains
Classes
Imported By
Source
Frequently Asked Questions
What does fuzzymatch.js do?
fuzzymatch.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in fuzzymatch.js?
fuzzymatch.js defines 6 function(s): _distance, fuzzymatch, gram_counter, iterate_grams, levenshtein, sort_descending.
What files import fuzzymatch.js?
fuzzymatch.js is imported by 3 file(s): BindDirective.js, extract_svelte_ignore.js, index.js.
Where is fuzzymatch.js in the architecture?
fuzzymatch.js is located at packages/svelte/src/compiler/phases/1-parse/utils/fuzzymatch.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/1-parse/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free