From 4003d62a7d94ba9c2e937ecf1db8d2aad9598783 Mon Sep 17 00:00:00 2001
From: johanbeytell1 <107624055+johanbeytell1@users.noreply.github.com>
Date: Sun, 11 Oct 2026 14:52:26 +0000
Subject: [PATCH] Add CloakJS library, docs, tests, and minification workflow
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
---
.github/workflows/minify.yml | 37 +++
README.md | 102 ++++++++
cloakjs.js | 466 +++++++++++++++++++++++++++++++++++
cloakjs.min.js | 9 +
test/cloakjs.test.js | 120 +++++++++
5 files changed, 734 insertions(+)
create mode 100644 .github/workflows/minify.yml
create mode 100644 README.md
create mode 100644 cloakjs.js
create mode 100644 cloakjs.min.js
create mode 100644 test/cloakjs.test.js
diff --git a/.github/workflows/minify.yml b/.github/workflows/minify.yml
new file mode 100644
index 0000000..e316084
--- /dev/null
+++ b/.github/workflows/minify.yml
@@ -0,0 +1,37 @@
+name: Update minified CloakJS
+
+on:
+ push:
+ branches:
+ - '**'
+ paths:
+ - cloakjs.js
+
+permissions:
+ contents: write
+
+jobs:
+ minify:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: '22'
+ - name: Minify and verify
+ run: |
+ node --test
+ npm exec --yes --package=terser@5.44.0 -- terser cloakjs.js --compress --mangle --comments '/^!/' --output cloakjs.min.js
+ node --check cloakjs.min.js
+ node -e 'const c = require("./cloakjs.min.js"); const source = require("./cloakjs.js"); if (c.VERSION !== source.VERSION || typeof c.obfuscate !== "function") process.exit(1); const vm = require("node:vm"); const logs = []; vm.runInNewContext(c.obfuscate("console.log(\"ok\")", "high"), { console: { log: x => logs.push(x) }, atob, TextDecoder }); if (logs[0] !== "ok") process.exit(1)'
+ - name: Commit minified file if changed
+ run: |
+ git add -- cloakjs.min.js
+ if git diff --cached --quiet; then
+ echo 'Minified file is already up to date.'
+ exit 0
+ fi
+ git config user.name 'github-actions[bot]'
+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
+ git commit -m 'chore: update minified CloakJS'
+ git push origin "HEAD:${GITHUB_REF}"
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ebe4f53
--- /dev/null
+++ b/README.md
@@ -0,0 +1,102 @@
+# CloakJS 1.2.0
+
+[](LICENSE)
+[](https://github.com/Infinitode/CloakJS/stargazers)
+[](https://github.com/Infinitode/CloakJS/issues)
+[](https://www.jsdelivr.com/package/gh/Infinitode/CloakJS)
+
+CloakJS is a single-file, dependency-free JavaScript obfuscator for the browser and Node.js. It can rename some identifiers, encode strings and numbers, and optionally add a dispatcher and decoy statements. It returns JavaScript source code; it does **not** run the code for you.
+
+> [!IMPORTANT]
+> Obfuscation makes source less readable, **not secure**. Never put secrets, credentials or security-critical checks in client-side JavaScript. CloakJS uses a small lexer rather than a full JavaScript parser; test transformed output in the environment where it will run. It is intended for classic scripts, not ES modules, JSX or TypeScript.
+
+## Getting started
+
+Download [`cloakjs.js`](cloakjs.js) (readable) or [`cloakjs.min.js`](cloakjs.min.js) (minified), or load either from [jsDelivr](https://www.jsdelivr.com/package/gh/Infinitode/CloakJS) after the files are available on the repository's `main` branch:
+
+```html
+
+
+
+
+```
+
+For reproducible deployments, replace `@main` with a published tag or commit hash (once available). The minified file is generated from `cloakjs.js` with Terser; there is no npm release to install. The badge above displays jsDelivr's live download information rather than a hard-coded count and may not show data until the files have been published on `main`.
+
+In Node.js (modern Node with `atob`, `TextEncoder` and `TextDecoder`):
+
+```js
+const CloakJS = require('./cloakjs.js');
+const result = CloakJS.obfuscateWithStats('console.log("hello")', 'high');
+console.log(result.code);
+console.log(result.stats, result.warnings);
+```
+
+The file is UMD: it also works as an AMD module, or as the global `CloakJS` in a normal `