cmpstr
Version:
CmpStr is a lightweight, fast and well performing package for calculating string similarity
91 lines (88 loc) • 1.39 kB
JavaScript
// CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
import {
PhoneticRegistry,
PhoneticMappingRegistry,
Phonetic
} from './Phonetic.mjs';
class Soundex extends Phonetic {
static default = {
map: 'en',
delimiter: ' ',
length: 4,
pad: '0',
dedupe: true
};
constructor(opt = {}) {
super('soundex', opt);
}
adjustCode(code, chars) {
return chars[0].toUpperCase() + code.slice(1).replaceAll('0', '');
}
}
PhoneticRegistry.add('soundex', Soundex);
PhoneticMappingRegistry.add('soundex', 'en', {
map: {
a: '0',
e: '0',
h: '0',
i: '0',
o: '0',
u: '0',
w: '0',
y: '0',
b: '1',
f: '1',
p: '1',
v: '1',
c: '2',
g: '2',
j: '2',
k: '2',
q: '2',
s: '2',
x: '2',
z: '2',
d: '3',
t: '3',
l: '4',
m: '5',
n: '5',
r: '6'
}
});
PhoneticMappingRegistry.add('soundex', 'de', {
map: {
a: '0',
ä: '0',
e: '0',
h: '0',
i: '0',
j: '0',
o: '0',
ö: '0',
u: '0',
ü: '0',
y: '0',
b: '1',
f: '1',
p: '1',
v: '1',
w: '1',
c: '2',
g: '2',
k: '2',
q: '2',
s: '2',
ß: '2',
x: '2',
z: '2',
d: '3',
t: '3',
l: '4',
m: '5',
n: '5',
r: '6'
},
ruleset: [{ char: 'c', next: ['h'], code: '7' }]
});
export { Soundex };