Skip to content

Commit

Permalink
feat: add js-obfuscator options.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 29, 2022
1 parent 219f6cd commit e26da4b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
33 changes: 28 additions & 5 deletions packages/js-obfuscator/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export default function JSObfuscator() {
const resultProps: ResultProps['codeProps'] = {
style: { height: 'calc(100vh - 87px)', overflow: 'auto', margin: 0 },
};
const resetHandle = () => {
setPreset('allOptions');
setOptions({ ...allOptions });
};
const presetData: CheckboxOptionProps[] = [
{
type: 'radio',
Expand Down Expand Up @@ -107,10 +111,7 @@ export default function JSObfuscator() {
name: 'options',
checked: preset === 'allOptions',
children: <Fragment>{t<string>('allOptions')}</Fragment>,
onChange: ({ target }) => {
setPreset('allOptions');
setOptions({ ...allOptions });
},
onChange: resetHandle,
},
];
const optionsElement = [
Expand Down Expand Up @@ -333,6 +334,28 @@ export default function JSObfuscator() {
setOptions({ ...options, ...{ sourceMapBaseUrl: target.value } });
},
},
{
checked: !!options.transformObjectKeys,
children: (
<Fragment>
transformObjectKeys <Info>{t<string>('transformObjectKeys')}</Info>
</Fragment>
),
onChange: ({ target }) => {
setOptions({ ...options, ...{ transformObjectKeys: target.checked } });
},
},
{
checked: !!options.unicodeEscapeSequence,
children: (
<Fragment>
unicodeEscapeSequence <Info>{t<string>('unicodeEscapeSequence')}</Info>
</Fragment>
),
onChange: ({ target }) => {
setOptions({ ...options, ...{ unicodeEscapeSequence: target.checked } });
},
},
];
return (
<Wrapper>
Expand Down Expand Up @@ -371,7 +394,7 @@ export default function JSObfuscator() {
style={{ maxWidth: 420 }}
extra={
<Fragment>
<Button onClick={() => setOptions(allOptions)}>{t<string>('Reset', { ns: 'common' })}</Button>
<Button onClick={resetHandle}>{t<string>('Reset', { ns: 'common' })}</Button>
<Button onClick={() => setOptions({})}>{t<string>('None', { ns: 'common' })}</Button>
</Fragment>
}
Expand Down
15 changes: 13 additions & 2 deletions packages/js-obfuscator/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,19 @@ export const allOptions: ObfuscatorOptions = {
// stringArrayThreshold: number;
target: 'browser',
// target: TTypeFromEnum<typeof ObfuscationTarget>;
// transformObjectKeys: boolean;
// unicodeEscapeSequence: boolean;
/**
* Default: false
*
* Enables transformation of object keys.
*/
transformObjectKeys: false,
/**
* Default: false
*
* Allows to enable/disable string conversion to unicode escape sequence.
* Unicode escape sequence increases code size greatly and strings easily can be reverted to their original view. Recommended to enable this option only for small source code.
*/
unicodeEscapeSequence: false,
};

/**
Expand Down
4 changes: 3 additions & 1 deletion website/public/locales/cn/js-obfuscator.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@
"sourceMapBaseUrl": "当sourceMapMode:“separate”时,将基url设置为源映射导入url",
"sourceMapFileName": "当sourceMapMode:“separate”时,设置输出源映射的文件名。",

"target": "允许为模糊代码设置目标环境。可用值:`browser`,`browser-no-eval`,`node`。当前 `browser` 和`node`目标的输出代码是相同的,但某些特定于`browser`的选项不允许与`node`目标一起使用。`browser-no-eval`目标的输出代码未使用eval。"
"target": "允许为模糊代码设置目标环境。可用值:`browser`,`browser-no-eval`,`node`。当前 `browser` 和`node`目标的输出代码是相同的,但某些特定于`browser`的选项不允许与`node`目标一起使用。`browser-no-eval`目标的输出代码未使用eval。",
"transformObjectKeys": "启用对象关键点的变换。",
"unicodeEscapeSequence": "允许启用/禁用字符串转换为unicode转义序列。Unicode转义序列大大增加了代码大小,字符串可以很容易地恢复到原始视图。建议仅对小型源代码启用此选项。"
}
4 changes: 3 additions & 1 deletion website/public/locales/en/js-obfuscator.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
"sourceMapBaseUrl": "Sets base url to the source map import url when sourceMapMode: 'separate'.",
"sourceMapFileName": "Sets file name for output source map when sourceMapMode: 'separate'.",

"target": "Allows to set target environment for obfuscated code. Available values: `browser` `browser-no-eval` `node`. Currently output code for browser and node targets is identical, but some browser-specific options are not allowed to use with node target. Output code for browser-no-eval target is not using eval."
"target": "Allows to set target environment for obfuscated code. Available values: `browser` `browser-no-eval` `node`. Currently output code for browser and node targets is identical, but some browser-specific options are not allowed to use with node target. Output code for browser-no-eval target is not using eval.",
"transformObjectKeys": "Enables transformation of object keys.",
"unicodeEscapeSequence": "Allows to enable/disable string conversion to unicode escape sequence. Unicode escape sequence increases code size greatly and strings easily can be reverted to their original view. Recommended to enable this option only for small source code."
}

0 comments on commit e26da4b

Please sign in to comment.