// Copyright Abridged, Inc. 2023,2024. All Rights Reserved. // Node module: @collabland/common // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT const similarChars: {[prop: string]: string[]} = { c: [ 'ℂ', '℃', 'Ⅽ', 'ⅽ', 'ↅ', '∁', '⊂', '⊆', '⊊', '⊏', '⊑', '⋤', '⋐', 'Ⓒ', '⒞', '⟈', '€', '₢', ], o: [ '⊙', '⊚', '⌀', '⍤', '⍥', '⎔', 'ⓞ', '○', '◌', '◎', '◯', '◉', '▢', '◴', '◵', '◶', '◷', '⚆', '⚇', '⚪', '⚬', '⟳', '⟲', ], l: [ 'Ⅰ', 'Ⅼ', 'ⅼ', 'Ⅱ', '↿', '⇂', '∟', '∣', '∤', '∥', '⌊', '⌞', '⍳', '⎢', '⎣', '⎥', '⎪', '⎮', '⎜', '⎟', '⎱', '⎳', '⎸', '⎹', '⎿', '⏐', 'Ⓛ', 'ⓛ', '│', '┃', '║', '╽', '╿', '▎', '▏', '▕', '❘', '❙', '₤', 'ₗ', ], a: ['₳', 'Å', 'ₐ'], b: ['ⓑ', 'Ⓑ', '♭', '₿'], n: ['∩', '⊓', '⋂', '⋒', 'ⓝ', '⒩', 'Ⓝ'], d: ['ⅆ', 'ⅾ', 'Ⅾ', '₫'], }; export function normalizeWord(str: string): string { const englishCharMapping: any = {}; for (const c in similarChars) { for (const ch of similarChars[c]) { englishCharMapping[ch] = c; } } let englishStr: string = str.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); for (const ch in englishCharMapping) { englishStr = englishStr.replace( new RegExp(ch, 'gi'), englishCharMapping[ch], ); } englishStr = englishStr.replace(/[^A-Z0-9]+/gi, '').toLowerCase(); return englishStr; }