refactoring

This commit is contained in:
sanex3339
2016-06-03 09:02:04 +03:00
parent f66b937ea5
commit 4a21ad99e4
6 changed files with 18 additions and 14 deletions
+7 -4
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
});