> ## 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.

# Dispatcher

> Creates a middleman function to process function calls.

* Option name: `"dispatcher"`

* Option values: `true/false/0-1/Function`

***

### Input / Output

This example showcases how `Dispatcher` 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
function print(x) {
  console.log(x);
}

print('Hello World'); // "Hello World"

// Output.js
var w54PLh = Object.create(null),
  QPr1R_j;
function D26rUi(D26rUi, yONwwba, j6eFi1, YkXjg4U = {}) {
  var FDWqeXP,
    Ot_Bph = {
      A9P6pS: function () {
        var [D26rUi] = QPr1R_j;
        console.log(D26rUi);
      },
    };
  if (yONwwba === 'd9h12bLSjK') {
    QPr1R_j = [];
  }
  if (yONwwba === 'FQv6d0ITiT') {
    function NOMEkuW() {
      var yONwwba = function (...yONwwba) {
          QPr1R_j = yONwwba;
          return Ot_Bph[D26rUi].apply(this);
        },
        j6eFi1 = YkXjg4U[D26rUi];
      if (j6eFi1) {
        kHg4HT(yONwwba, j6eFi1);
      }
      return yONwwba;
    }
    FDWqeXP = w54PLh[D26rUi] || (w54PLh[D26rUi] = NOMEkuW());
  } else {
    FDWqeXP = Ot_Bph[D26rUi]();
  }
  return j6eFi1 === 'buXQgrlZef'
    ? {
        g2PN10Gtdu: FDWqeXP,
      }
    : FDWqeXP;
}
function kHg4HT() {}
((QPr1R_j = ['Hello World']), D26rUi('A9P6pS'));
```

***

### Custom Implementation

#### `options.dispatcher(fnName)`

Control which functions are changed. Returns a `boolean`.

| Parameter | Type     | Description                               |
| --------- | -------- | ----------------------------------------- |
| `fnName`  | `string` | The function name proposed to be changed. |

***

### 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',
  dispatcher: 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 (50%)
* [Low Preset](/presets/low): Yes (25%)
