Skip to content

Commit

Permalink
switching to esm
Browse files Browse the repository at this point in the history
- dependencies updated
- switching from nyc to c8 for coverage testing
  • Loading branch information
dangowans committed Apr 19, 2021
1 parent 3e67e69 commit bba464d
Show file tree
Hide file tree
Showing 21 changed files with 3,571 additions and 1,076 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ install:
- npm --version
# install modules
- sh: npm ci
- sh: npm install -g mocha nyc
- sh: npm install -g mocha c8

before_test:
# Download codeclimate test report
- sh: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./codeclimate-test-reporter
- sh: chmod +x ./codeclimate-test-reporter

test_script:
- nyc --reporter=lcov mocha --timeout 30000
- c8 --reporter=lcov mocha --timeout 30000

after_test:
# Send test result to codeclimate
Expand Down
20 changes: 8 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unleet = void 0;
const diacritic = require("diacritic");
const translations_1 = require("./translations/translations");
import diacritic from "diacritic";
import { leetSymbolTranslationKeys, simpleTranslations, complexTranslations } from "./translations/translations.js";
const indiciesOf = (sourceString, searchString) => {
const indicies = [];
for (let index = 0; index < sourceString.length - searchString.length; index += 1) {
Expand All @@ -19,7 +16,7 @@ const isLetter = (potentialLetter) => {
return false;
};
const isPotentialLeet = (potentialLeetString) => {
for (const leetSymbol of translations_1.leetSymbolTranslationKeys) {
for (const leetSymbol of leetSymbolTranslationKeys) {
if (isLetter(leetSymbol)) {
continue;
}
Expand All @@ -36,7 +33,7 @@ const unleetRecurse = (lowerCaseLeetString, unleetStrings, previousStrings, comp
if (matchingIndicies.length === 0) {
matchingIndicies = [lowerCaseLeetString.indexOf(leetSymbol)];
}
const translations = translations_1.complexTranslations[leetSymbol];
const translations = complexTranslations[leetSymbol];
for (const translation of translations) {
for (const symbolIndex of matchingIndicies) {
const newString = lowerCaseLeetString.substring(0, symbolIndex) +
Expand All @@ -55,22 +52,21 @@ const unleetRecurse = (lowerCaseLeetString, unleetStrings, previousStrings, comp
}
return unleetStrings;
};
const unleet = (leetString) => {
export const unleet = (leetString) => {
if (leetString === null || leetString === undefined || leetString === "") {
return [""];
}
let cleanLeetString = (leetString + "").toLowerCase();
cleanLeetString = cleanLeetString.replace(/\./g, " ");
cleanLeetString = cleanLeetString.replace(/ +/g, " ");
cleanLeetString = diacritic.clean(cleanLeetString);
for (const leetSymbol of Object.keys(translations_1.simpleTranslations)) {
for (const leetSymbol of Object.keys(simpleTranslations)) {
while (cleanLeetString.includes(leetSymbol)) {
cleanLeetString = cleanLeetString.replace(leetSymbol, translations_1.simpleTranslations[leetSymbol][0]);
cleanLeetString = cleanLeetString.replace(leetSymbol, simpleTranslations[leetSymbol][0]);
}
}
const complexTranslationKeys = Object.keys(translations_1.complexTranslations).filter(function (leetSymbol) {
const complexTranslationKeys = Object.keys(complexTranslations).filter(function (leetSymbol) {
return cleanLeetString.includes(leetSymbol);
});
return Array.from(unleetRecurse(cleanLeetString.trim(), new Set(), new Set(), complexTranslationKeys));
};
exports.unleet = unleet;
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as diacritic from "diacritic";
import diacritic from "diacritic";

import { leetSymbolTranslationKeys, simpleTranslations, complexTranslations } from "./translations/translations";
import { leetSymbolTranslationKeys, simpleTranslations, complexTranslations } from "./translations/translations.js";


const indiciesOf = (sourceString: string, searchString: string) => {
Expand Down
Loading

0 comments on commit bba464d

Please sign in to comment.