sanex3339 9 vuotta sitten
vanhempi
commit
4a21ad99e4

+ 7 - 4
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)}`;
         })}'`;
     }
 }

+ 1 - 1
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
 });

+ 1 - 1
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
 });

+ 7 - 6
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)}`;
         })}'`;
     }
 }

+ 1 - 1
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
 });

+ 1 - 1
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
 });