From 74e9f26a62fd431087b76d39c68fb36db8d7f69d Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sun, 7 Jun 2020 17:45:32 +0300 Subject: [PATCH] Updated README.md --- README.md | 28 ++++++++++++++++++++++++++++ test/dev/dev.ts | 18 +++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4a5d0afc..7330ae6b 100644 --- a/README.md +++ b/README.md @@ -682,6 +682,30 @@ To set format of renamed property names use [`identifierNamesGenerator`](#identi To control which properties will be renamed use [`reservedNames`](#reservedNames) option. +Example: +```ts +// input +const foo = { + prop1: 1, + prop2: 2, + calc: function () { + return this.prop1 + this.prop2; + } +}; + +console.log(foo.calc()); + +// output +const foo = { + '_0x5a9b25': 0x1, + '_0x8ea4ee': 0x2, + '_0x2fe16b': function () { + return this['_0x5a9b25'] + this['_0x8ea4ee']; + } +}; +console['log'](foo['_0x2fe16b']()); +``` + ### `reservedNames` Type: `string[]` Default: `[]` @@ -1024,6 +1048,10 @@ See: [`Kind of variables`](#kind-of-variables) See: [`Kind of variables`](#kind-of-variables) +### I enabled `renameProperties` option, and my code broke! What to do? + +Just disable this option. + ## Backers Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/javascript-obfuscator#backer)] diff --git a/test/dev/dev.ts b/test/dev/dev.ts index b7ff610f..be33446a 100644 --- a/test/dev/dev.ts +++ b/test/dev/dev.ts @@ -7,20 +7,20 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo let obfuscatedCode: string = JavaScriptObfuscator.obfuscate( ` - var x = { - baz_: 0, - foo_: 1, - calc: function() { - return this.foo_ + this.baz_; + const foo = { + prop1: 1, + prop2: 2, + calc: function () { + return this.prop1 + this.prop2; } }; - x.bar_ = 2; - x["baz_"] = 3; - console.log(x.calc()); + + console.log(foo.calc()); `, { ...NO_ADDITIONAL_NODES_PRESET, - compact: false + compact: false, + renameProperties: true } ).getObfuscatedCode();