1
- "use strict" ;
2
- Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
3
- exports . unleet = void 0 ;
4
- const diacritic = require ( "diacritic" ) ;
5
- const translations_1 = require ( "./translations/translations" ) ;
1
+ import diacritic from "diacritic" ;
2
+ import { leetSymbolTranslationKeys , simpleTranslations , complexTranslations } from "./translations/translations.js" ;
6
3
const indiciesOf = ( sourceString , searchString ) => {
7
4
const indicies = [ ] ;
8
5
for ( let index = 0 ; index < sourceString . length - searchString . length ; index += 1 ) {
@@ -19,7 +16,7 @@ const isLetter = (potentialLetter) => {
19
16
return false ;
20
17
} ;
21
18
const isPotentialLeet = ( potentialLeetString ) => {
22
- for ( const leetSymbol of translations_1 . leetSymbolTranslationKeys ) {
19
+ for ( const leetSymbol of leetSymbolTranslationKeys ) {
23
20
if ( isLetter ( leetSymbol ) ) {
24
21
continue ;
25
22
}
@@ -36,7 +33,7 @@ const unleetRecurse = (lowerCaseLeetString, unleetStrings, previousStrings, comp
36
33
if ( matchingIndicies . length === 0 ) {
37
34
matchingIndicies = [ lowerCaseLeetString . indexOf ( leetSymbol ) ] ;
38
35
}
39
- const translations = translations_1 . complexTranslations [ leetSymbol ] ;
36
+ const translations = complexTranslations [ leetSymbol ] ;
40
37
for ( const translation of translations ) {
41
38
for ( const symbolIndex of matchingIndicies ) {
42
39
const newString = lowerCaseLeetString . substring ( 0 , symbolIndex ) +
@@ -55,22 +52,21 @@ const unleetRecurse = (lowerCaseLeetString, unleetStrings, previousStrings, comp
55
52
}
56
53
return unleetStrings ;
57
54
} ;
58
- const unleet = ( leetString ) => {
55
+ export const unleet = ( leetString ) => {
59
56
if ( leetString === null || leetString === undefined || leetString === "" ) {
60
57
return [ "" ] ;
61
58
}
62
59
let cleanLeetString = ( leetString + "" ) . toLowerCase ( ) ;
63
60
cleanLeetString = cleanLeetString . replace ( / \. / g, " " ) ;
64
61
cleanLeetString = cleanLeetString . replace ( / + / g, " " ) ;
65
62
cleanLeetString = diacritic . clean ( cleanLeetString ) ;
66
- for ( const leetSymbol of Object . keys ( translations_1 . simpleTranslations ) ) {
63
+ for ( const leetSymbol of Object . keys ( simpleTranslations ) ) {
67
64
while ( cleanLeetString . includes ( leetSymbol ) ) {
68
- cleanLeetString = cleanLeetString . replace ( leetSymbol , translations_1 . simpleTranslations [ leetSymbol ] [ 0 ] ) ;
65
+ cleanLeetString = cleanLeetString . replace ( leetSymbol , simpleTranslations [ leetSymbol ] [ 0 ] ) ;
69
66
}
70
67
}
71
- const complexTranslationKeys = Object . keys ( translations_1 . complexTranslations ) . filter ( function ( leetSymbol ) {
68
+ const complexTranslationKeys = Object . keys ( complexTranslations ) . filter ( function ( leetSymbol ) {
72
69
return cleanLeetString . includes ( leetSymbol ) ;
73
70
} ) ;
74
71
return Array . from ( unleetRecurse ( cleanLeetString . trim ( ) , new Set ( ) , new Set ( ) , complexTranslationKeys ) ) ;
75
72
} ;
76
- exports . unleet = unleet ;
0 commit comments