Skip to content

Commit

Permalink
switch normalize-diacritics to diacritics
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Feb 7, 2022
1 parent d889854 commit ab01365
Show file tree
Hide file tree
Showing 4 changed files with 697 additions and 1,564 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeSync } from "normalize-diacritics";
import { remove as removeDiacritics } from "diacritics";
import * as utils from "./utils.js";
import { simpleTranslations, complexTranslations } from "./translations.js";
const unleetRecurse = (lowerCaseLeetString, unleetStrings, previousStrings, complexTranslationKeys) => {
Expand Down Expand Up @@ -32,11 +32,12 @@ export const unleet = (leetString) => {
if (leetString === null || leetString === undefined || leetString === "") {
return [""];
}
let cleanLeetString = leetString.toString().toLowerCase();
let cleanLeetString = leetString.toString();
cleanLeetString = cleanLeetString.replace(/\./g, " ");
cleanLeetString = cleanLeetString.replace(utils.whitespaceCharactersRegex, " ");
cleanLeetString = cleanLeetString.replace(/ +/g, " ");
cleanLeetString = normalizeSync(cleanLeetString);
cleanLeetString = removeDiacritics(cleanLeetString);
cleanLeetString = cleanLeetString.toLowerCase();
for (const leetSymbol of Object.keys(simpleTranslations)) {
while (cleanLeetString.includes(leetSymbol)) {
cleanLeetString = cleanLeetString.replace(leetSymbol, simpleTranslations[leetSymbol][0]);
Expand Down
11 changes: 7 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeSync } from "normalize-diacritics";
import { remove as removeDiacritics } from "diacritics";
import * as utils from "./utils.js";

import { simpleTranslations, complexTranslations } from "./translations.js";
Expand Down Expand Up @@ -58,8 +58,8 @@ export const unleet = (leetString: string | number): string[] => {
return [""];
}

// Convert to lower case
let cleanLeetString = leetString.toString().toLowerCase();
// Ensure the input is a string
let cleanLeetString = leetString.toString();

// Remove periods
cleanLeetString = cleanLeetString.replace(/\./g, " ");
Expand All @@ -71,7 +71,10 @@ export const unleet = (leetString: string | number): string[] => {
cleanLeetString = cleanLeetString.replace(/ +/g, " ");

// Remove accents
cleanLeetString = normalizeSync(cleanLeetString);
cleanLeetString = removeDiacritics(cleanLeetString);

// Convert to lower case
cleanLeetString = cleanLeetString.toLowerCase();

// Do simple translations
for (const leetSymbol of Object.keys(simpleTranslations)) {
Expand Down
Loading

0 comments on commit ab01365

Please sign in to comment.