diff --git a/dist/src/Utils.js b/dist/src/Utils.js index 8b09d938..bdaab6d9 100644 --- a/dist/src/Utils.js +++ b/dist/src/Utils.js @@ -21,7 +21,11 @@ class Utils { return newArray; } static decToHex(dec) { - return (dec + Math.pow(16, 6)).toString(16).substr(-6).replace(Utils.hexRepetitiveZerosRegExp, ''); + const decToHexSliceValue = -6, exponent = 6, radix = 16; + return (dec + Math.pow(radix, exponent)) + .toString(radix) + .substr(decToHexSliceValue) + .replace(Utils.hexRepetitiveZerosRegExp, ''); } static getRandomInteger(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; @@ -37,8 +41,9 @@ class Utils { return obj; } static stringToUnicode(string) { + const radix = 16, unicodeSliceValue = -4; return `'${string.replace(/[\s\S]/g, (escape) => { - return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`; + return `\\u${('0000' + escape.charCodeAt(0).toString(radix)).slice(unicodeSliceValue)}`; })}'`; } } diff --git a/src/Utils.ts b/src/Utils.ts index 0a934f36..ad3a5b89 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -45,7 +45,14 @@ export class Utils { * @returns {string} */ public static decToHex(dec: number): string { - return (dec + Math.pow(16, 6)).toString(16).substr(-6).replace(Utils.hexRepetitiveZerosRegExp, ''); + const decToHexSliceValue: number = -6, + exponent: number = 6, + radix: number = 16; + + return (dec + Math.pow(radix, exponent)) + .toString(radix) + .substr(decToHexSliceValue) + .replace(Utils.hexRepetitiveZerosRegExp, ''); } /** @@ -90,8 +97,11 @@ export class Utils { * @returns {string} */ public static stringToUnicode (string: string): string { + const radix: number = 16, + unicodeSliceValue: number = -4; + return `'${string.replace(/[\s\S]/g, (escape: string): string => { - return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`; + return `\\u${('0000' + escape.charCodeAt(0).toString(radix)).slice(unicodeSliceValue)}`; })}'`; } }