{"name":"unassert","description":"Encourages programming with assertions by providing tools to compile them away","version":"2.0.0","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/unassert-js/unassert/issues"},"contributors":[{"name":"Renée Kooi","url":"https://github.com/goto-bus-stop"}],"dependencies":{"estraverse":"^5.0.0"},"devDependencies":{"@twada/benchmark-commits":"^0.1.0","acorn":"^8.0.0","escodegen":"^2.0.0","mocha":"^10.0.0","rimraf":"^3.0.2","rollup":"^2.77.0","semistandard":"^16.0.0","snazzy":"^9.0.0"},"main":"./dist/index.cjs","exports":{"import":"./src/index.mjs","require":"./dist/index.cjs"},"homepage":"https://github.com/unassert-js/unassert","keywords":["DbC","unassert","assert","assertion"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/unassert-js/unassert.git"},"scripts":{"preversion":"npm run build && npm test","build":"rimraf dist && rollup -c","lint":"semistandard --verbose src/*.mjs test/*.mjs | snazzy","fmt":"semistandard --fix src/*.mjs test/*.mjs","test":"npm run lint && mocha test"},"semistandard":{"globals":["describe","beforeEach","it"]},"gitHead":"ba624554a8f8013fdb2b0ef16f91b8471c15f2f3","_id":"unassert@2.0.0","_nodeVersion":"18.6.0","_npmVersion":"8.13.2","dist":{"integrity":"sha512-45E+m8zz+utoQPxkkXAsKPrtjE0GzEbMwzmrcM4inlPhcOxIJRwE+AVxkZfgIWTR3gWG2Daxa7mHFRUwMUfyzg==","shasum":"a2bf2f16303c8961b68c67dc88395ae5e6dbe9af","tarball":"http://registry-npm.ywwl.com/unassert/download/unassert-2.0.0.tgz","fileCount":6,"unpackedSize":37087,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD9VqRlLIvFdgwQg0VpBOvW9+NI87Aw5B91+twHsNfQ3QIgXRom4Gm5qUD05ESwP+Ly9kqzIKc0mj6ty6I1jY31MUs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi56qCACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqdAA/8DMbzUuGovLK5SGMDZEvBW+1NzkX1ei61XxRFo8dC9gaZ0quM\r\nDLVUoBE/svaTZR4R6L+jIchpNeCZun9ObWIznNGxl76oP9bWHXkqKE4aaZ2y\r\nXoybbhfoDJckNf6Zt7LpIoujewJW17q30pW/8RVzQLk0x/mxKNExbD/Rke6V\r\nKFYlUyqOCNMZo83MAB6HWDfqVLxE4aztvcCCwTcF1hVjzun7vKMMMguygC6F\r\niZJrDzKjI3nxsJcr5FKISNMp+iqJXDK3H/j2O5SRL1xzxhgzZHf3R1qfIroA\r\niq+MdsIw+XU69ZxjHqqIn1q93WKUjNwoXvReLGurZWqxybV1j/0oCBExufTK\r\nV3IqRH+6i9bs+94C/Wg5+2/xyT9i7dUJkOHnm9hpMou2MLCdLLnF/Td7ePu+\r\nbhJVAzoTs/KE5IyIXDRJ/iSCBrfDK9nP4qmIfysx5Alquuj1WkWxsgXfNdAO\r\n9INSROAwexj7dMl2md7jy4u7kuD5OcYjSUxBbbX128FwRP871Nc8C5rAFgqy\r\nTYXvnuZU5Bg9BvDD9C74ediIzZYoP0cb74zdN/C/CmNcpgbcknfDmytfUqac\r\nw5i9pf93OFraxX7Ha3rz0pNA/Av4sQk0ymr1WSAzjB+aMPsUMph7dayVyZAw\r\n6EbEqx/QJZOIjcaj6wQA5TkZmRdCYsQoibw=\r\n=U//j\r\n-----END PGP SIGNATURE-----\r\n","size":7786,"noattachment":false,"key":"/unassert/-/unassert-2.0.0.tgz"},"_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"directories":{},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unassert_2.0.0_1659349633901_0.613971571512278"},"_hasShrinkwrap":false,"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","publish_time":1659349634140,"_cnpm_publish_time":1659349634140,"dist-tags":{"latest":"2.0.2"}}