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 + +[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) +[![GitHub stars](https://img.shields.io/github/stars/Infinitode/CloakJS.svg)](https://github.com/Infinitode/CloakJS/stargazers) +[![GitHub issues](https://img.shields.io/github/issues/Infinitode/CloakJS.svg)](https://github.com/Infinitode/CloakJS/issues) +[![jsDelivr monthly downloads](https://data.jsdelivr.com/v1/package/gh/Infinitode/CloakJS/badge?style=rounded)](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 `