> ## Documentation Index
> Fetch the complete documentation index at: https://docs.js-confuser.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pack

> Packs the output code into a single `Function()` call. Designed to escape strict mode constraints.

* Option name: `"pack"`

* Option values: `true/false`

<Card title="Requires Eval" type="warning">
  The obfuscated code will contain unsafe eval expressions.
  The code will not work properly in [environments that have disabled eval](https://developer.mozilla.org/en-US/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_eval_expressions).
</Card>

***

### Input / Output

This example showcases how `Pack` transforms the code. Try it out by changing the input code and see changes apply in real-time.

```js title="Input.js" lines interactive-mode="obfuscate" theme={null}
// Input.js
// Strict mode JavaScript blocks eval() access to local variables
var myVar = 'Initial Value';
eval(/* @js-confuser-var */ 'myVar' + ' = "Modified Value"');

console.log(myVar); // "Modified Value"

// Output.js
Function(
  'GDSD_L',
  'var uBfgJX="Initial Value";eval("uBfgJX"+" = \\"Modified Value\\"");return console.log(uBfgJX);',
)({});
```

***

### Bypass Strict Mode

The `Pack` option is designed to bypass strict mode constraints. This is achieved by wrapping the output code in a `Function()` call. This allows the code to be executed in a different context, where strict mode is not enforced.

Several obfuscation techniques require non-strict mode JavaScript. These include:

* Control Flow Flattening (With Statement)
* Tamper Protection (Eval scope access)

***

### Usage Example

The provided code example will obfuscate the file `input.js` and write the output to a file named `output.js`.

```js title="Usage Example" lines theme={null}
import JSConfuser from "js-confuser";
import {readFileSync, writeFileSync} from "fs";

// Read input code
const sourceCode = readFileSync("input.js", "utf8");
const options = {
  target: 'browser',
  pack: true,
};

JSConfuser.obfuscate(sourceCode, options).then((result)=>{
  // Write output code
  writeFileSync("output.js", result.code);
}).catch(err=>{
  // Error occurred
  console.error(err);  
});
```

***

#### Enabled In

* [High Preset](/presets/high): Yes
* [Medium Preset](/presets/medium): Yes
* [Low Preset](/presets/low): No
