From 4a21ad99e47eb807ce70419a806ee4e4e39abc01 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Fri, 3 Jun 2016 09:02:04 +0300 Subject: [PATCH] refactoring --- dist/src/Utils.js | 11 +++++++---- dist/src/preset-options/DefaultPreset.js | 2 +- dist/src/preset-options/NoCustomNodesPreset.js | 2 +- src/Utils.ts | 13 +++++++------ src/preset-options/DefaultPreset.ts | 2 +- src/preset-options/NoCustomNodesPreset.ts | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/dist/src/Utils.js b/dist/src/Utils.js index af88dafe..79b8ca0c 100644 --- a/dist/src/Utils.js +++ b/dist/src/Utils.js @@ -42,14 +42,17 @@ class Utils { } static stringToUnicode(string) { const radix = 16; - let regexp = new RegExp('[\x00-\x7F]'), template; + let prefix, regexp = new RegExp('[\x00-\x7F]'), template; return `'${string.replace(/[\s\S]/g, (escape) => { if (regexp.test(escape)) { + prefix = '\\x'; template = '0'.repeat(2); - return `\\x${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; } - template = '0'.repeat(4); - return `\\u${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; + else { + prefix = '\\u'; + template = '0'.repeat(4); + } + return `${prefix}${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; })}'`; } } diff --git a/dist/src/preset-options/DefaultPreset.js b/dist/src/preset-options/DefaultPreset.js index 149861a2..3d3d9c2e 100644 --- a/dist/src/preset-options/DefaultPreset.js +++ b/dist/src/preset-options/DefaultPreset.js @@ -4,9 +4,9 @@ exports.DEFAULT_PRESET = Object.freeze({ debugProtection: false, debugProtectionInterval: false, disableConsoleOutput: true, + encodeUnicodeLiterals: false, reservedNames: [], rotateUnicodeArray: true, - encodeUnicodeLiterals: false, unicodeArray: true, wrapUnicodeArrayCalls: true }); diff --git a/dist/src/preset-options/NoCustomNodesPreset.js b/dist/src/preset-options/NoCustomNodesPreset.js index 2fc3ea3e..16d5ab38 100644 --- a/dist/src/preset-options/NoCustomNodesPreset.js +++ b/dist/src/preset-options/NoCustomNodesPreset.js @@ -4,9 +4,9 @@ exports.NO_CUSTOM_NODES_PRESET = Object.freeze({ debugProtection: false, debugProtectionInterval: false, disableConsoleOutput: false, + encodeUnicodeLiterals: false, reservedNames: [], rotateUnicodeArray: false, - encodeUnicodeLiterals: false, unicodeArray: false, wrapUnicodeArrayCalls: false }); diff --git a/src/Utils.ts b/src/Utils.ts index fcf9e46e..649cf3df 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -99,19 +99,20 @@ export class Utils { public static stringToUnicode (string: string): string { const radix: number = 16; - let regexp: RegExp = new RegExp('[\x00-\x7F]'), + let prefix: string, + regexp: RegExp = new RegExp('[\x00-\x7F]'), template: string; return `'${string.replace(/[\s\S]/g, (escape: string): string => { if (regexp.test(escape)) { + prefix = '\\x'; template = '0'.repeat(2); - - return `\\x${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; + } else { + prefix = '\\u'; + template = '0'.repeat(4); } - template = '0'.repeat(4); - - return `\\u${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; + return `${prefix}${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; })}'`; } } diff --git a/src/preset-options/DefaultPreset.ts b/src/preset-options/DefaultPreset.ts index 104d45ff..3f214c4a 100644 --- a/src/preset-options/DefaultPreset.ts +++ b/src/preset-options/DefaultPreset.ts @@ -5,9 +5,9 @@ export const DEFAULT_PRESET: IOptions = Object.freeze({ debugProtection: false, debugProtectionInterval: false, disableConsoleOutput: true, + encodeUnicodeLiterals: false, reservedNames: [], rotateUnicodeArray: true, - encodeUnicodeLiterals: false, unicodeArray: true, wrapUnicodeArrayCalls: true }); diff --git a/src/preset-options/NoCustomNodesPreset.ts b/src/preset-options/NoCustomNodesPreset.ts index 689a60ca..015669bb 100644 --- a/src/preset-options/NoCustomNodesPreset.ts +++ b/src/preset-options/NoCustomNodesPreset.ts @@ -5,9 +5,9 @@ export const NO_CUSTOM_NODES_PRESET: IOptions = Object.freeze({ debugProtection: false, debugProtectionInterval: false, disableConsoleOutput: false, + encodeUnicodeLiterals: false, reservedNames: [], rotateUnicodeArray: false, - encodeUnicodeLiterals: false, unicodeArray: false, wrapUnicodeArrayCalls: false });