{"id":13484282,"url":"https://github.com/unassert-js/unassert","last_synced_at":"2026-01-17T16:32:00.760Z","repository":{"id":32743267,"uuid":"36333911","full_name":"unassert-js/unassert","owner":"unassert-js","description":"Encourages programming with assertions by providing tools to compile them away.","archived":false,"fork":false,"pushed_at":"2023-06-16T11:22:27.000Z","size":230,"stargazers_count":194,"open_issues_count":12,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-12-28T11:52:39.940Z","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}},"created_at":"2015-05-27T01:09:44.000Z","updated_at":"2025-06-25T08:35:05.000Z","dependencies_parsed_at":"2024-01-13T18:25:00.335Z","dependency_job_id":"6be3eb5d-81bf-40e9-8d94-bd1137cc5694","html_url":"https://github.com/unassert-js/unassert","commit_stats":{"total_commits":195,"total_committers":4,"mean_commits":48.75,"dds":0.02564102564102566,"last_synced_commit":"b88e5e050ba857b7d639b04edffcc73c5e2d5fde"},"previous_names":["twada/unassert"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/unassert-js/unassert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Funassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Funassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Funassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Funassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unassert-js","download_url":"https://codeload.github.com/unassert-js/unassert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unassert-js%2Funassert/sbom","scorecard":{"id":908854,"data":{"date":"2025-08-11","repo":{"name":"github.com/unassert-js/unassert","commit":"595089f73ec0d2a3becc431c21e2fc61537eb423"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"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":"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/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/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":"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":"Code-Review","score":0,"reason":"Found 2/24 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":"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":"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":"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":"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 10 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":1,"reason":"9 existing vulnerabilities detected","details":["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-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","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:46.783Z","repository_id":32743267,"created_at":"2025-08-24T18:23:46.783Z","updated_at":"2025-08-24T18:23:46.783Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28511867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"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":"2024-07-31T17:01:21.854Z","updated_at":"2026-01-17T16:32:00.723Z","avatar_url":"https://github.com/unassert-js.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"[![unassert][unassert-banner]][unassert-url]\n\nEncourages [programming with assertions](https://en.wikipedia.org/wiki/Assertion_(software_development)) by providing tools to compile them away.\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\nSee: \"[unassert - encourage reliable programming by writing assertions in production](http://www.slideshare.net/t_wada/unassert)\" -- talk at NodeFest 2015, and \"One more thing...\" in talk at NodeFest 2016, titled \"[From Library to Tool - power-assert as a General Purpose Assertion Enhancement Tool](https://speakerdeck.com/twada/from-library-to-tool-power-assert-as-a-general-purpose-assertion-enhancement-tool)\"\n\n\n#### RELATED MODULES\n\n- [unassertify](https://github.com/unassert-js/unassertify): Browserify transform for unassert\n- [babel-plugin-unassert](https://github.com/unassert-js/babel-plugin-unassert): Babel plugin 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- [rollup-plugin-unassert](https://github.com/unassert-js/rollup-plugin-unassert): RollupJS plugin for unassert\n\n\nINSTALL\n---------------------------------------\n\n```\n$ npm install --save-dev unassert\n```\n\n\nEXAMPLE\n---------------------------------------\n\nFor given `math.js` below,\n\n```javascript\nconst assert = require('node:assert');\n\nfunction add (a, b) {\n  assert(typeof a === 'number');\n  console.assert(!isNaN(a));\n  assert.equal(typeof b, 'number');\n  assert.ok(!isNaN(b));\n  return a + b;\n}\n```\n\nApply `unassertAst` then generate modified code to console.\n\nvia CJS code\n```javascript\nconst { unassertAst } = require('unassert');\nconst { parse } = require('acorn');\nconst { generate } = require('escodegen');\nconst { readFileSync } = require('node:fs');\nconst { join, dirname } = require('node:path');\n\nconst filepath = join(__dirname, 'math.js');\nconst ast = parse(readFileSync(filepath), { ecmaVersion: '2022' });\nconst modifiedAst = unassertAst(ast);\n\nconsole.log(generate(modifiedAst));\n```\n\nor via ESM code\n```javascript\nimport { unassertAst } from 'unassert';\nimport { parse } from 'acorn';\nimport { generate } from 'escodegen';\nimport { readFileSync } from 'node:fs';\nimport { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst filepath = join(__dirname, 'math.js');\nconst ast = parse(readFileSync(filepath), { ecmaVersion: '2022' });\nconst modifiedAst = unassertAst(ast);\n\nconsole.log(generate(modifiedAst));\n```\n\nThen you will see assert calls disappear.\n\n```javascript\nfunction add(a, b) {\n  return a + b;\n}\n```\n\n\nAPI\n---------------------------------------\n\nunassert package exports three functions. [`unassertAst`](https://github.com/unassert-js/unassert#const-modifiedast--unassertastast-options) is the main function. [`createVisitor`](https://github.com/unassert-js/unassert#const-visitor--createvisitoroptions) and [`defaultOptions`](https://github.com/unassert-js/unassert#const-options--defaultoptions) are for customization.\n\n\n### const modifiedAst = unassertAst(ast, options)\n\n```javascript\nconst { unassertAst } = require('unassert')\n```\n\n```javascript\nimport { unassertAst } from 'unassert'\n```\n\n| return type                                                   |\n|:--------------------------------------------------------------|\n| `object` ([ECMAScript AST](https://github.com/estree/estree)) |\n\nRemove assertion calls from `ast` ([ECMAScript AST](https://github.com/estree/estree)). Default behaviour can be customized by `options`. `ast` is manipulated directly so returned `modifiedAst` will be the same instance of `ast`.\n\n#### options\n\nObject for configuration options. passed `options` is `Object.assign`ed with default options. If not passed, default options will be used.\n\n##### options.modules\n\nTarget module names for assertion call removal.\n\nFor example, the default target modules are as follows.\n\n```javascript\n{\n  modules: [\n    'assert',\n    'assert/strict',\n    'node:assert',\n    'node:assert/strict'\n  ]\n```\n\nIn this case, unassert will remove assert variable declarations such as,\n\n* `import assert from \"assert\"`\n* `import assert from \"assert/strict\"`\n* `import assert from \"node:assert\"`\n* `import assert from \"node:assert/strict\"`\n* `import * as assert from \"assert\"`\n* `import * as assert from \"node:assert\"`\n* `import * as assert from \"assert/strict\"`\n* `import * as assert from \"node:assert/strict\"`\n* `import { strict as assert } from \"assert\"`\n* `import { strict as assert } from \"node:assert\"`\n* `import { default as assert } from \"assert\"`\n* `import { default as assert } from \"node:assert\"`\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(\"assert\").strict`\n* `const assert = require(\"node:assert\").strict`\n* `const { strict: assert } = require(\"assert\")`\n* `const { strict: assert } = require(\"node: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(\"assert\").strict`\n* `assert = require(\"node:assert\").strict`\n\nIn this default case, unassert will remove assertion calls such as,\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.match(string, regexp[, message])`\n* `assert.doesNotMatch(string, regexp[, message])`\n* `assert.throws(block, [error], [message])`\n* `assert.doesNotThrow(block, [message])`\n* `await assert.rejects(asyncFn, [error], [message])`\n* `await assert.doesNotReject(asyncFn, [error], [message])`\n* `assert.fail([message])`\n* `assert.fail(actual, expected, message, operator)`\n* `assert.ifError(value)`\n\nin addition, unassert removes `console.assert` calls as well.\n\n* `console.assert(value, [message])`\n\n\n#### Auto Variable Tracking\n\nunassert automatically removes assertion calls based on their imported variable names.\n\nSo if import declaration is as follows,\n\n* `import strictAssert, { ok, equal as eq } from 'node:assert/strict';`\n\nunassert removes all `strictAssert`, `ok`, `eq` calls.\n\nPlease see [customization example](https://github.com/unassert-js/unassert#example-1) for more details.\n\n\n### const visitor = createVisitor(options)\n\n```javascript\nconst { createVisitor } = require('unassert')\n```\n\n```javascript\nimport { createVisitor } from 'unassert'\n```\n\n| return type                                                                       |\n|:----------------------------------------------------------------------------------|\n| `object` (visitor object for [estraverse](https://github.com/estools/estraverse)) |\n\nCreate visitor object to be used with `estraverse.replace`. Visitor can be customized by `options`.\n\n\n### const options = defaultOptions()\n\n```javascript\nconst { defaultOptions } = require('unassert')\n```\n\n```javascript\nimport { defaultOptions } from 'unassert'\n```\n\nReturns default options object for `unassertAst` and `createVisitor` function. In other words, returns\n\n```javascript\n{\n  modules: [\n    'assert',\n    'assert/strict',\n    'node:assert',\n    'node:assert/strict'\n  ]\n}\n```\n\nCUSTOMIZATION\n---------------------------------------\n\nYou can customize options such as target module names.\n\n```javascript\n{\n  modules: [\n    'node:assert',\n    'node:assert/strict',\n    'power-assert',\n    'invariant',\n    'nanoassert',\n    'uvu/assert'\n  ]\n}\n```\n\n### example\n\nFor given `custom.js` below,\n\n```javascript\nimport invariant from 'invariant';\nimport nassert from 'nanoassert';\nimport * as uvuassert from 'uvu/assert';\nimport { strict as powerAssert } from 'power-assert';\nimport { default as looseAssert } from 'node:assert';\nimport strictAssert, { ok, equal as eq } from 'node:assert/strict';\n\nasync function add (a, b) {\n  strictAssert(!isNaN(a));\n  looseAssert(typeof a === 'number');\n  eq(typeof b, 'number');\n  ok(!isNaN(b));\n  powerAssert(typeof a === typeof b);\n\n  nassert(!isNaN(a));\n\n  uvuassert.is(Math.sqrt(4), 2);\n  uvuassert.is(Math.sqrt(144), 12);\n  uvuassert.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  await strictAssert.rejects(prms);\n  await strictAssert.doesNotReject(prms2);\n\n  return a + b;\n}\n```\n\nApply `unassertAst` with customized options then generate modified code to console.\n\n```javascript\nimport { unassertAst } from 'unassert';\nimport { parse } from 'acorn';\nimport { generate } from 'escodegen';\nimport { readFileSync } from 'node:fs';\nimport { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst filepath = join(__dirname, 'custom.js');\nconst ast = parse(readFileSync(filepath), { ecmaVersion: '2022' });\nconst modifiedAst = unassertAst(ast, {\n  modules: [\n    'node:assert',\n    'node:assert/strict',\n    'power-assert',\n    'invariant',\n    'nanoassert',\n    'uvu/assert'\n  ]\n});\n\nconsole.log(generate(modifiedAst));\n```\n\nThen you will see all assert calls disappear.\n\n```javascript\nasync function add(a, b) {\n  return a + b;\n}\n```\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 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\nAUTHOR\n---------------------------------------\n* [Takuto Wada](https://github.com/twada)\n\n\nCONTRIBUTORS\n---------------------------------------\n* [Renée Kooi](https://github.com/goto-bus-stop)\n* [Jordan Harband](https://github.com/ljharb)\n\n\nLICENSE\n---------------------------------------\nLicensed under the [MIT](https://github.com/unassert-js/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/unassert\n[npm-image]: https://badge.fury.io/js/unassert.svg\n\n[ci-image]: https://github.com/unassert-js/unassert/workflows/Node.js%20CI/badge.svg\n[ci-url]: https://github.com/unassert-js/unassert/actions?query=workflow%3A%22Node.js+CI%22\n\n[style-url]: https://github.com/standard/semistandard\n[style-image]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg\n\n[license-url]: https://github.com/unassert-js/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%2Funassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funassert-js%2Funassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funassert-js%2Funassert/lists"}