{"bugs":{"url":"https://github.com/alexreardon/tiny-invariant/issues"},"dist":{"shasum":"1cb7b7eb0340b5b7522b0a596f33572ebcdb7b65","tarball":"https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.0-beta.1.tgz","fileCount":13,"integrity":"sha512-bIHiVXhYokgI5AL2+1COsCZEwT/sumWCyKk9yuR8ksQmpCyUA0Uf6686kX8w4PdFbWWrZc1LC3e6uuz80B1jag==","signatures":[{"sig":"MEYCIQDLLYDmUWIwRQWJTAlXzGYNwKIooqMwyr6+Tc5Mx2e9rQIhAJoYQatUSukyOjoqxieY1iMZuuKe1uxRcWFmtw5QMtzE","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12240,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjM7XqACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq8QA/+O5jzGPuOCJvz36JhflUMcVxCzbgQKJ5lIa3vXi7C8xUFQv/D\r\nbR3jJCZjj6GP2sTq7Vx/umneAc4qMpRCaiS/ymX1B+oLMvqiCjc4VdWAV6FI\r\nqYMcdCWvmsnfhiizW+J7X7fCKhhoseTijNQ7guOrCBDUOiLtwoHI0lbPCJli\r\niEfogMfXro2dPalV3rf1j8MOVeDt429DBPeG7QYJxSL5PRcFqKO8jrLQM2I6\r\nPfCwGlAJCLRcjPQc0pEDsk5TzBk8RsSVps1C3Cy0pn2kZoQjQbWzdGv9JWCi\r\nIeOhX38XOtCB3eLlXRsaGIzMkA6YS2mzyMBQUcPJeJ7Cq0dEcXoiMBbAdqSE\r\nc642n+5WxHja8SrlkqnRGCcopkfJwuCctlfSYU5Vy8GrE7aCBFBgmHJSh715\r\nd/UCExQfvxIsV7g4/4Hb8ZYK7M27WoJe9yKz9wKFypX5p+ItUnYpivSM1E6g\r\nn4hx5Ntc7kKGn8bOyefePF0IVshYFOFPGFWASmr0dehfTYn1g/RUccTAuRn0\r\n+KW7WAAq8QQrptonOxqrj91gygFIEHcKhc1+8hurnlIl/qKm9gwHt6xpFY4z\r\n2IAFrUUMaVdfXtcCOQII+FCnejzrulnoVCmHxJ/bNs2Y1IEwdb3K9++Dy8v2\r\nLjJaTE4nhJO84dof8AyYyB1dmrh0mqlRzOU=\r\n=RDL4\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/tiny-invariant.cjs.js","name":"tiny-invariant","types":"dist/tiny-invariant.d.ts","author":{"name":"Alex Reardon","email":"alexreardon@gmail.com"},"module":"dist/tiny-invariant.esm.js","readme":"# tiny-invariant 🔬💥\n\n[![Build Status](https://travis-ci.org/alexreardon/tiny-invariant.svg?branch=master)](https://travis-ci.org/alexreardon/tiny-invariant)\n[![npm](https://img.shields.io/npm/v/tiny-invariant.svg)](https://www.npmjs.com/package/tiny-invariant) [![dependencies](https://david-dm.org/alexreardon/tiny-invariant.svg)](https://david-dm.org/alexreardon/tiny-invariant)\n![types](https://img.shields.io/badge/types-typescript%20%7C%20flow-blueviolet)\n[![minzip](https://img.shields.io/bundlephobia/minzip/tiny-invariant.svg)](https://www.npmjs.com/package/tiny-invariant)\n[![Downloads per month](https://img.shields.io/npm/dm/tiny-invariant.svg)](https://www.npmjs.com/package/tiny-invariant)\n\nA tiny [`invariant`](https://www.npmjs.com/package/invariant) alternative.\n\n## What is `invariant`?\n\nAn `invariant` function takes a value, and if the value is [falsy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy) then the `invariant` function will throw. If the value is [truthy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy), then the function will not throw.\n\n```js\nimport invariant from 'tiny-invariant';\n\ninvariant(truthyValue, 'This should not throw!');\n\ninvariant(falsyValue, 'This will throw!');\n// Error('Invariant violation: This will throw!');\n```\n\nYou can also provide a function to generate your message, for when your message is expensive to create\n\n```js\nimport invariant from 'tiny-invariant';\n\ninvariant(value, () => getExpensiveMessage());\n```\n\n## Why `tiny-invariant`?\n\nThe [`library: invariant`](https://www.npmjs.com/package/invariant) supports passing in arguments to the `invariant` function in a sprintf style `(condition, format, a, b, c, d, e, f)`. It has internal logic to execute the sprintf substitutions. The sprintf logic is not removed in production builds. `tiny-invariant` has dropped all of the sprintf logic. `tiny-invariant` allows you to pass a single string message. With [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) there is really no need for a custom message formatter to be built into the library. If you need a multi part message you can just do this: `invariant(condition, 'Hello, ${name} - how are you today?')`\n\n## Type narrowing\n\n`tiny-invariant` is useful for correctly narrowing types for `flow` and `typescript`\n\n```ts\nconst value: Person | null = { name: 'Alex' }; // type of value == 'Person | null'\ninvariant(value, 'Expected value to be a person');\n// type of value has been narrowed to 'Person'\n```\n\n## API: `(condition: any, message?: string | (() => string)) => void`\n\n- `condition` is required and can be anything\n- `message` optional `string` or a function that returns a `string` (`() => string`)\n\n## Installation\n\n```bash\n# yarn\nyarn add tiny-invariant\n\n# npm\nnpm install tiny-invariant --save\n```\n\n## Dropping your `message` for kb savings!\n\nBig idea: you will want your compiler to convert this code:\n\n```js\ninvariant(condition, 'My cool message that takes up a lot of kbs');\n```\n\nInto this:\n\n```js\nif (!condition) {\n  if ('production' !== process.env.NODE_ENV) {\n    invariant(false, 'My cool message that takes up a lot of kbs');\n  } else {\n    invariant(false);\n  }\n}\n```\n\n- **Babel**: recommend [`babel-plugin-dev-expression`](https://www.npmjs.com/package/babel-plugin-dev-expression)\n- **TypeScript**: recommend [`tsdx`](https://github.com/jaredpalmer/tsdx#invariant) (or you can run `babel-plugin-dev-expression` after TypeScript compiling)\n\nYour bundler can then drop the code in the `\"production\" !== process.env.NODE_ENV` block for your production builds to end up with this:\n\n```js\nif (!condition) {\n  invariant(false);\n}\n```\n\n- rollup: use [rollup-plugin-replace](https://github.com/rollup/rollup-plugin-replace) and set `NODE_ENV` to `production` and then `rollup` will treeshake out the unused code\n- Webpack: [instructions](https://webpack.js.org/guides/production/#specify-the-mode)\n\n## Builds\n\n- We have a `es` (EcmaScript module) build\n- We have a `cjs` (CommonJS) build\n- We have a `umd` (Universal module definition) build in case you needed it\n\nWe expect `process.env.NODE_ENV` to be available at module compilation. We cache this value\n\n## That's it!\n\n🤘\n","exports":{".":{"import":"./dist/esm/tiny-invariant.js","default":"./dist/tiny-invariant.cjs.js"}},"gitHead":"881973ca112e90db190cb40e19b4d3cb18ca9f95","license":"MIT","scripts":{"test":"yarn jest","build":"yarn build:clean && yarn build:dist && yarn build:typescript && yarn build:typescript:esm && yarn build:copy-esm-packagejson","validate":"yarn prettier:check && yarn typescript:check","test:size":"yarn build && yarn size-limit","build:dist":"yarn rollup --config rollup.config.js","build:flow":"cp src/tiny-invariant.js.flow dist/tiny-invariant.cjs.js.flow","build:clean":"rimraf dist","prepublishOnly":"yarn build","prettier:check":"yarn prettier --write src/** test/**","prettier:write":"yarn prettier --debug-check src/** test/**","build:typescript":"tsc ./src/tiny-invariant.ts --emitDeclarationOnly --declaration --outDir ./dist","typescript:check":"yarn tsc --noEmit src/*.ts test/*.ts","build:typescript:esm":"tsc ./src/tiny-invariant.ts --emitDeclarationOnly --declaration --outDir ./dist/esm","build:copy-esm-packagejson":"cp static/package-esm.json dist/esm/package.json"},"_npmUser":{"name":"alexreardon","email":"alexreardon@gmail.com"},"homepage":"https://github.com/alexreardon/tiny-invariant#readme","keywords":["invariant","error","assert","asserts"],"repository":{"url":"git+https://github.com/alexreardon/tiny-invariant.git","type":"git"},"size-limit":[{"path":"dist/tiny-invariant.min.js","limit":"217B"},{"path":"dist/tiny-invariant.js","limit":"267B"},{"path":"dist/tiny-invariant.cjs.js","limit":"171B"},{"path":"dist/tiny-invariant.esm.js","limit":"112B","import":"foo"}],"_npmVersion":"8.12.1","description":"A tiny invariant function","directories":{},"maintainers":[{"name":"alexreardon","email":"alexreardon@gmail.com"}],"sideEffects":false,"_nodeVersion":"18.4.0","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^29.0.3","tslib":"^2.4.0","rimraf":"^3.0.2","rollup":"^2.79.1","ts-jest":"^29.0.2","prettier":"^2.7.1","size-limit":"^8.1.0","typescript":"^4.8.4","@types/jest":"^29.0.3","expect-type":"^0.14.2","@types/rollup":"^0.54.0","rollup-plugin-terser":"^7.0.2","@rollup/plugin-replace":"^4.0.0","@rollup/plugin-typescript":"^8.5.0","@size-limit/preset-small-lib":"^8.1.0"},"_npmOperationalInternal":{"tmp":"tmp/tiny-invariant_1.3.0-beta.1_1664333290690_0.3150067752470145","host":"s3://npm-registry-packages"},"_id":"tiny-invariant@1.3.0-beta.1","version":"1.3.0-beta.1"}