Enable

The enable directive allows you to enable a transformation in a specific block or statement.

Take for instance the following example:

// @jscrambler enable regexObfuscation
/\sMSIE\s[6-9]\./test(navigator.userAgent)

This enables Regex Obfuscation in any regular expression found in the statement or block that comes immediately after the Code Annotation. The resulting code would look something like this:

/[\r\u2028\u1680\t\v\u2000-\u200a\u00a0\u3000\f\n\u205f\u180e\u202f\u2029 ]\x4d\x53\x49\u0045[ \u205f\u202f\u2000-\u200a\f\u3000\u180e\u00a0\t\v\u2028\u2029\r\n\u1680][96-78]\./.test(navigator.userAgent);

If you want to enable the transformation for the whole JavaScript source file you can use the global modifier. This is useful when you want to force a transformation to a specific JavaScript file but not to the whole JavaScript application, and also when preceding each statement or block in the JavaScript file would be too troublesome.

// @jscrambler global enable regexObfuscation
function isSE () {
  return /google|yahoo|bing/.test(document.domain);
}

function isOldIE () {
  return /\sMSIE\s[6-9]\./.test(navigator.userAgent);
}

The resulting code would look something like this:

// @jscrambler global enable regexObfuscation
function isSE() {
    return /\u0067\157\x6f\u0067\154\145|\u0079\x61\150\x6f\157|\142\u0069\x6e\u0067/.test(document.domain);
}
function isOldIE() {
    return /[\u2000-\u200a\u202f\u2028\u1680\u3000\v\u180e\u00a0\u2029\t\f\r\n\u205f ]\u004d\123\111\105[\r\u1680\u205f\u202f\n\u180e\u2000-\u200a\f\u3000\u2028\u00a0\u2029\v \t][7-96]\./.test(navigator.userAgent);
}

However, imagine that you have a huge number of regular expressions in your JavaScript source code and there are a few that you don't want to be targeted by Regex Obfuscation. To solve this, you can enable the transformation globally and use the disable directive for the regular expressions you don't want to obfuscate. If you want to read more about the disable directive check the Disable documentation.