string

string

Source:

String

Methods

(static) hamming(str1, str2) → {number}

Source:

Computes the hamming distance between two strings of identical length. This distance is always >= 0.

Example
hamming( 'john', 'john' );
// ->  0
hamming( 'sam', 'sat' );
// -> 1
hamming( 'summer', 'samuel' );
// -> 3
hamming( 'saturn', 'urn' );
// -> throws error
Parameters:
Name Type Description
str1 string

first string.

str2 string

second string.

Returns:

hamming distance between str1 and str2.

Type
number

(static) hammingNormalized(str1, str2) → {number}

Source:

Computes the normalized hamming distance between two strings. These strings may be of different lengths. Normalized distance is always between 0 and 1.

Example
hammingNormalized( 'john', 'johny' );
// ->  0.2
hammingNormalized( 'sam', 'sam' );
// -> 0
hammingNormalized( 'sam', 'samuel' );
// -> 0.5
hammingNormalized( 'saturn', 'urn' );
// -> 1
Parameters:
Name Type Description
str1 string

first string.

str2 string

second string.

Returns:

normalized hamming distance between str1 and str2.

Type
number

(static) jaro(str1, str2) → {number}

Source:

Computes the jaro distance between two strings. This distance is always between 0 and 1.

Example
jaro( 'father', 'farther' );
// ->  0.04761904761904756
jaro( 'abcdef', 'fedcba' );
// -> 0.6111111111111112
jaro( 'sat', 'urn' );
// -> 1
Parameters:
Name Type Description
str1 string

first string.

str2 string

second string.

Returns:

jaro distance between str1 and str2.

Type
number

(static) jaroWinkler(str1, str2, boostThresholdopt, scalingFactoropt) → {number}

Source:

Computes the jaro winkler distance between two strings. This distance, controlled by the scalingFactor, is always between 0 and 1.

Example
jaroWinkler( 'martha', 'marhta' );
// ->  0.03888888888888883
jaroWinkler( 'martha', 'marhta', 0.3, 0.2 );
// -> 0.022222222222222185
jaroWinkler( 'duane', 'dwayne' );
// -> .15999999999999992
Parameters:
Name Type Attributes Default Description
str1 string

first string.

str2 string

second string.

boostThreshold number <optional>
0.3

beyond which scaling is applied: it is applied only if the jaro distance between the input strings is less than or equal to this value. Any value > 1, is capped at 1 automatically.

scalingFactor number <optional>
0.1

is used to scale the distance. Such scaling, if applied, is proportional to the number of shared consecutive characters from the first character of str1 and str2. Any value > 0.25, is capped at 0.25 automatically.

Returns:

jaro winkler distance between str1 and str2.

Type
number

(static) levenshtein(str1, str2) → {number}

Source:

Computes the levenshtein distance between two strings. This distance is computed as the number of deletions, insertions, or substitutions required to transform a string to another. Levenshtein distance is always an integer with a value of 0 or more.

Example
levenshtein( 'example', 'sample' );
// ->  3
levenshtein( 'distance', 'difference' );
// -> 5
Parameters:
Name Type Description
str1 string

first string.

str2 string

second string.

Returns:

levenshtein distance between str1 and str2.

Type
number

(static) soundex(str1, str2) → {number}

Source:

Computes the soundex distance between two strings. This distance is either 1 indicating phonetic similarity or 0 indicating no similarity.

Example
soundex( 'Burroughs', 'Burrows' );
// ->  0
soundex( 'Ekzampul', 'example' );
// -> 0
soundex( 'sat', 'urn' );
// -> 1
Parameters:
Name Type Description
str1 string

first string.

str2 string

second string.

Returns:

soundex distance between str1 and str2.

Type
number