{"id":38967505,"url":"https://github.com/unassert-js/babel-plugin-unassert","last_synced_at":"2026-01-17T16:32:25.272Z","repository":{"id":32701828,"uuid":"36291309","full_name":"unassert-js/babel-plugin-unassert","owner":"unassert-js","description":"Babel plugin to encourage reliable programming by writing assertions in production code, and compiling them away from release.","archived":false,"fork":false,"pushed_at":"2023-03-04T03:04:59.000Z","size":386,"stargazers_count":59,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-02T02:20:50.647Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unassert-js.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-26T11:23:36.000Z","updated_at":"2022-04-27T15:04:32.000Z","dependencies_parsed_at":"2024-06-18T15:37:00.423Z","dependency_job_id":"721b7f30-c3a8-450f-a3ec-da741e6dc0c2","html_url":"https://github.com/unassert-js/babel-plugin-unassert","commit_stats":{"total_commits":143,"total_committers":3,"mean_commits":"47.666666666666664","dds":"0.013986013986013957","last_synced_commit":"1c1510870f015f33e3f584218cd9f16fe149a861"},"previous_names":["twada/babel-plugin-unassert"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/unassert-js/babel-plugin-unassert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Fbabel-plugin-unassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Fbabel-plugin-unassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Fbabel-plugin-unassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Fbabel-plugin-unassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unassert-js","download_url":"https://codeload.github.com/unassert-js/babel-plugin-unassert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Fbabel-plugin-unassert/sbom","scorecard":{"id":908852,"data":{"date":"2025-08-11","repo":{"name":"github.com/unassert-js/babel-plugin-unassert","commit":"1c1510870f015f33e3f584218cd9f16fe149a861"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/18 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/node.js.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/unassert-js/babel-plugin-unassert/node.js.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/unassert-js/babel-plugin-unassert/node.js.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 16 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"13 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T18:23:44.211Z","repository_id":32701828,"created_at":"2025-08-24T18:23:44.211Z","updated_at":"2025-08-24T18:23:44.211Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28386143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T12:01:30.995Z","status":"ssl_error","status_checked_at":"2026-01-13T12:00:09.625Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-17T16:32:25.113Z","updated_at":"2026-01-17T16:32:25.259Z","avatar_url":"https://github.com/unassert-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"babel-plugin-unassert\n================================\n\n[Babel](https://babeljs.io/) plugin for unassert: Encourages [programming with assertions](https://en.wikipedia.org/wiki/Assertion_(software_development)) by providing tools to compile them away.\n\n[![unassert][unassert-banner]][unassert-url]\n\n[![Build Status][ci-image]][ci-url]\n[![NPM version][npm-image]][npm-url]\n[![Code Style][style-image]][style-url]\n[![License][license-image]][license-url]\n\nbabel-plugin-unassert removes assertions on build. So you can use assertions to declare preconditions, postconditions and invariants.\n\n\n#### RELATED MODULES\n\n- [unassert](https://github.com/unassert-js/unassert): Encourages programming with assertions by providing tools to compile them away.\n- [unassertify](https://github.com/unassert-js/unassertify): Browserify transform for unassert\n- [webpack-unassert-loader](https://github.com/unassert-js/webpack-unassert-loader): Webpack loader for unassert\n- [gulp-unassert](https://github.com/unassert-js/gulp-unassert): Gulp plugin for unassert\n- [unassert-cli](https://github.com/unassert-js/unassert-cli): CLI for unassert\n\n\nINSTALL\n---------------------------------------\n\n```\n$ npm install --save-dev babel-plugin-unassert\n```\n\n\nCAUTION\n---------------------------------------\n\nBabel7 is incompatible with Babel6. Babel6 is incompatible with Babel5.\n\nFor Babel6, you need to use [the 2.x release of babel-plugin-unassert](https://github.com/unassert-js/babel-plugin-unassert/tree/2.x).\n\n```\n$ npm install --save-dev babel-plugin-unassert@2\n```\n\nFor Babel 5 or lower, you need to use the 1.x release of babel-plugin-unassert.\n\n```\n$ npm install --save-dev babel-plugin-unassert@1\n```\n\n\nHOW TO USE\n---------------------------------------\n\n\n### via [.babelrc.js](https://babeljs.io/docs/en/configuration#babelrcjs)\n\n```javascript\nconst presets = ['@babel/env'];\nconst plugins = [];\n\nif (process.env.NODE_ENV === 'production') {\n  plugins.push('babel-plugin-unassert');\n}\n\nmodule.exports = { presets, plugins };\n```\n\n```\n$ babel /path/to/src/target.js \u003e /path/to/build/target.js\n```\n\n\n### via [@babel/cli](https://babeljs.io/docs/en/babel-cli)\n\n```\n$ babel --plugins babel-plugin-unassert /path/to/src/target.js \u003e /path/to/build/target.js\n```\n\n\n### via [@babel/core](https://babeljs.io/docs/en/babel-core/)\n\n```javascript\nconst babel = require('@babel/core');\nconst transformed = babel.transformFileSync('/path/to/src/target.js', {\n  presets: ['@babel/env'],\n  plugins: ['babel-plugin-unassert']\n});\nconsole.log(transformed.code);\n```\n\n\nEXAMPLE\n---------------------------------------\n\nFor given `math.js` below,\n\n```javascript\n'use strict';\n\nconst assert = require('assert');\n\nfunction add (a, b) {\n  console.assert(typeof a === 'number');\n  assert(!isNaN(a));\n  assert.equal(typeof b, 'number');\n  assert.ok(!isNaN(b));\n  return a + b;\n}\n```\n\nRun `babel-cli` with `--plugins babel-plugin-unassert` option to transform.\n\n```\n$ babel --plugins babel-plugin-unassert /path/to/demo/math.js \u003e /path/to/build/math.js\n```\n\nYou will see assert calls and declarations disappear.\n\n```javascript\n'use strict';\n\nfunction add(a, b) {\n  return a + b;\n}\n```\n\n\n#### ES6 module and power-assert support\n\nbabel-plugin-unassert supports ES6 module syntax and [power-assert](https://github.com/power-assert-js/power-assert).\n\nFor given [babel.config.js](https://babeljs.io/docs/en/configuration#babelconfigjs),\n\n```javascript\nmodule.exports = function (api) {\n  const presets = ['@babel/env'];\n  const plugins = [];\n\n  if (api.env(['development', 'test'])) {\n    presets.push('babel-preset-power-assert');\n  }\n\n  if (api.env('production')) {\n    plugins.push('babel-plugin-unassert');\n  }\n\n  return {\n    presets,\n    plugins\n  };\n};\n```\n\nand production code below,\n\n```javascript\nimport assert from 'assert';\n\nclass Calc {\n  add (a, b) {\n    assert(!(isNaN(a) || isNaN(b)));\n    assert(typeof a === 'number');\n    assert(typeof b === 'number');\n    return a + b;\n  }\n}\n```\n\nthen it becomes in production,\n\n```javascript\n'use strict';\n\nclass Calc {\n  add(a, b) {\n    return a + b;\n  }\n}\n```\n\nand in development, produces power-assert messages like below\n\n```\nAssertionError:   # example.js:5\n\n  assert(!(isNaN(a) || isNaN(b)))\n         | |     |  |  |     |\n         | |     |  |  true  NaN\n         | false 3  true\n         false\n```\n\n\nSUPPORTED PATTERNS\n---------------------------------------\n\nAssertion expressions are removed when they match patterns below. In other words, babel-plugin-unassert removes assertion calls that are compatible with Node.js standard [assert](https://nodejs.org/api/assert.html) API (and `console.assert`).\n\n* `assert(value, [message])`\n* `assert.ok(value, [message])`\n* `assert.equal(actual, expected, [message])`\n* `assert.notEqual(actual, expected, [message])`\n* `assert.strictEqual(actual, expected, [message])`\n* `assert.notStrictEqual(actual, expected, [message])`\n* `assert.deepEqual(actual, expected, [message])`\n* `assert.notDeepEqual(actual, expected, [message])`\n* `assert.deepStrictEqual(actual, expected, [message])`\n* `assert.notDeepStrictEqual(actual, expected, [message])`\n* `assert.fail([message])`\n* `assert.fail(actual, expected, message, operator)`\n* `assert.throws(block, [error], [message])`\n* `assert.doesNotThrow(block, [message])`\n* `assert.rejects(asyncFn, [error], [message])`\n* `assert.doesNotReject(asyncFn, [error], [message])`\n* `assert.ifError(value)`\n* `console.assert(value, [message])`\n\nbabel-plugin-unassert also removes assert variable declarations such as,\n\n* `const assert = require(\"assert\")`\n* `const assert = require(\"node:assert\")`\n* `const assert = require(\"assert\").strict`\n* `const assert = require(\"node:assert\").strict`\n* `const assert = require(\"power-assert\")`\n* `const assert = require(\"power-assert\").strict`\n* `import assert from \"assert\"`\n* `import assert from \"node:assert\"`\n* `import assert from \"power-assert\"`\n* `import * as assert from \"assert\"`\n* `import * as assert from \"node:assert\"`\n* `import * as assert from \"power-assert\"`\n* `import {strict as assert} from \"assert\"`\n* `import {strict as assert} from \"node:assert\"`\n* `import {strict as assert} from \"power-assert\"`\n\nand assignments.\n\n* `assert = require(\"assert\")`\n* `assert = require(\"node:assert\")`\n* `assert = require(\"assert\").strict`\n* `assert = require(\"node:assert\").strict`\n* `assert = require(\"power-assert\")`\n* `assert = require(\"power-assert\").strict`\n\n\n\nCUSTOMIZATION\n---------------------------------------\n\nYou can customize [Plugin Options](https://babeljs.io/docs/en/plugins#plugin-options) such as assertion patterns.\n\n\ninput:\n\n```javascript\n'use strict';\n\nvar invariant = require('invariant');\nconst nassert = require('nanoassert');\nimport * as uassert from 'uvu/assert';\n\n\nfunction add (a, b) {\n    nassert(!isNaN(a));\n\n    uassert.is(Math.sqrt(4), 2);\n    uassert.is(Math.sqrt(144), 12);\n    uassert.is(Math.sqrt(2), Math.SQRT2);\n\n    invariant(someTruthyVal, 'This will not throw');\n    invariant(someFalseyVal, 'This will throw an error with this message');\n\n    return a + b;\n}\n```\n\noutput:\n\n```javascript\n'use strict';\n\nfunction add(a, b) {\n  return a + b;\n}\n```\n\n\nvia [Config Files](https://babeljs.io/docs/en/config-files)\n\n```json\n{\n  \"presets\": [\n    ...\n  ],\n  \"plugins\": [\n    [\"babel-plugin-unassert\", {\n      \"variables\": [\n        \"assert\",\n        \"invariant\",\n        \"nassert\",\n        \"uassert\"\n      ],\n      \"modules\": [\n        \"assert\",\n        \"node:assert\",\n        \"invariant\",\n        \"nanoassert\",\n        \"uvu/assert\"\n      ]\n    }]\n  ]\n}\n```\n\nor via [@babel/register](https://babeljs.io/docs/en/babel-register).\n\n```javascript\nrequire('@babel/register')({\n  presets: [...],\n  plugins: [\n    ['babel-plugin-unassert', {\n      variables: [\n        'assert',\n        'invariant',\n        'nassert',\n        'uassert'\n      ],\n      modules: [\n        'assert',\n        'node:assert',\n        'invariant',\n        'nanoassert',\n        'uvu/assert'\n      ]\n    }]\n  ]\n});\n```\n\nor via ['@babel/core'](https://babeljs.io/docs/en/babel-core/),\n\n```javascript\nconst babel = require('@babel/core');\nconst jsCode = fs.readFileSync('/path/to/test/some_test.js');\nconst transformed = babel.transform(jsCode, {\n  presets: [...],\n  plugins: [\n    ['babel-plugin-unassert', {\n      variables: [\n        'assert',\n        'invariant',\n        'nassert',\n        'uassert'\n      ],\n      modules: [\n        'assert',\n        'node:assert',\n        'invariant',\n        'nanoassert',\n        'uvu/assert'\n      ]\n    }]\n  ]\n});\nconsole.log(transformed.code);\n```\n\n\n\n\n\n#### options\n\n| type     | default value       |\n|:---------|:--------------------|\n| `object` | objects shown below |\n\nConfiguration options for `babel-plugin-unassert`. If not passed, default options will be used.\n\n```javascript\n{\n  variables: [\n    'assert'\n  ],\n  modules: [\n    'assert',\n    'power-assert',\n    'node:assert'\n  ]\n}\n```\n\n\nAUTHOR\n---------------------------------------\n* [Takuto Wada](https://github.com/twada)\n\n\nCONTRIBUTORS\n---------------------------------------\n* [Notas Hellout](https://github.com/make-github-pseudonymous-again)\n\n\nOUR SUPPORT POLICY\n---------------------------------------\n\nWe support Node under maintenance. In other words, we stop supporting old Node version when [their maintenance ends](https://github.com/nodejs/LTS).\n\nThis means that any other environment is not supported.\n\nNOTE: If babel-plugin-unassert works in any of the unsupported environments, it is purely coincidental and has no bearing on future compatibility. Use at your own risk.\n\n\nLICENSE\n---------------------------------------\nLicensed under the [MIT](https://github.com/unassert-js/babel-plugin-unassert/blob/master/LICENSE) license.\n\n\n[unassert-url]: https://github.com/unassert-js/unassert\n[unassert-banner]: https://raw.githubusercontent.com/unassert-js/unassert-js-logo/master/banner/banner-official-fullcolor.png\n\n[npm-url]: https://npmjs.org/package/babel-plugin-unassert\n[npm-image]: https://badge.fury.io/js/babel-plugin-unassert.svg\n\n[ci-image]: https://github.com/unassert-js/babel-plugin-unassert/workflows/Node.js%20CI/badge.svg\n[ci-url]: https://github.com/unassert-js/babel-plugin-unassert/actions?query=workflow%3A%22Node.js+CI%22\n\n[style-url]: https://github.com/Flet/semistandard\n[style-image]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg\n\n[license-url]: https://github.com/unassert-js/babel-plugin-unassert/blob/master/LICENSE\n[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funassert-js%2Fbabel-plugin-unassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funassert-js%2Fbabel-plugin-unassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funassert-js%2Fbabel-plugin-unassert/lists"}