{"bugs":{"url":"https://github.com/alexreardon/tiny-invariant/issues"},"dist":{"shasum":"200e9bf36ca15f1e1433d1de5484a82a1689cddc","tarball":"https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0-beta.1.tgz","fileCount":10,"integrity":"sha512-84SAogGoOttvJCbQZCLdu0/sYiRwU8SEaciWYDlJebVhXKthEKW9KjfCy4BcVHCJIePlqae7A88TTPducOhivA==","signatures":[{"sig":"MEQCIB+0I+V8OeJfeyNzcRGW6ZEwsJApAUiVcq8KWYGF61A0AiBVjyD1+UVc7buv7Kwt6wm/z3BP+azvWqJPb1O1KjZHDQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9608,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeMSBtCRA9TVsSAnZWagAAXasP/3J4BtzD6jNEbUN3recw\njjakPELda0e7XhNM2z275/fXqjGZxd8UNCoLVwE9fGf92+z/O495pDkiTgS+\neL5c2Nax6KH9yFj8WTvYu7WOlBghacbQFW5Ud4jCBYv6aeS2H92AWLYMiDnz\nDbMpy+8rKR26DGDioSUUWQZtm8ewegQEWmijLa2Rz3IumuQwjxW4cmZRabFP\nUkt3DukOhYramOl48qNy0YiycskylQZ9ckCwFvnx9ZUPD5UQcVqdp9EzqfhZ\n9aYYU4sJGZyYQ54/sktXm/J9hsAir3yUyiPk5a43OOjIx236MkrYOYvpuUH6\n+bMD5uDW1jzK/iXmXAZN10tHniy1Eu92BEl4DsNwUbaiLwonPAKCHkvIJBUH\nJYAE4Jpky9RdvRlVbDLkh4HcA3xgLJg4oaIBsMjfKANeuLPg6CO6it2goBsG\nWtv9d5sbghB0zXe4VI/505nmf2ZjbJCs66jaoEO08zDAZK6YtXt+uoExYeAV\nbs5IaQVgGdB09cY8rDRrsCay0mGb/eBQPhnAWju9zjon4PnyO9Ck0IVuWOQU\nwPcvrJBEyemqz4CooQ60srZc9VAiWYwlGf5iI/nwoq7qIcMn31clhQFiLrKj\nOkD3rrcBcLyUXKyRvJzrygsmZU+oeGTFIZ5Xn+ehe119BAGT+POzQimyaNVZ\ngouo\r\n=68fL\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\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) => void`\n\n- `condition` is required and can be anything\n- `message` is an optional string\n\n## Installation\n\n```bash\n# yarn\nyarn add tiny-invariant\n\n# npm\nnpm add 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 (because you _know_ you want to deduplicate this super heavy library)\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","gitHead":"c1b8c2d2f949fbee5c7a5eeccfc62ded414545c9","license":"MIT","scripts":{"lint":"yarn prettier:check","test":"yarn jest","build":"yarn build:clean && yarn build:dist && yarn build:typescript","validate":"yarn lint && yarn typecheck","typecheck":"yarn tsc --noEmit src/*.ts test/*.ts","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"},"_npmUser":{"name":"alexreardon","email":"alexreardon@gmail.com"},"homepage":"https://github.com/alexreardon/tiny-invariant#readme","keywords":["invariant","error"],"repository":{"url":"git+https://github.com/alexreardon/tiny-invariant.git","type":"git"},"_npmVersion":"6.9.0","description":"A tiny invariant function","directories":{},"maintainers":[{"name":"alexreardon","email":"alexreardon@gmail.com"}],"sideEffects":false,"_nodeVersion":"12.2.0","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^25.1.0","tslib":"^1.10.0","rimraf":"^3.0.1","rollup":"^1.30.1","ts-jest":"^25.0.0","prettier":"^1.19.1","ts-expect":"^1.1.0","typescript":"^3.7.5","@types/jest":"^25.1.0","rollup-plugin-terser":"^5.2.0","@rollup/plugin-replace":"^2.3.0","@rollup/plugin-typescript":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/tiny-invariant_1.1.0-beta.1_1580277868974_0.01547768582132436","host":"s3://npm-registry-packages"},"_id":"tiny-invariant@1.1.0-beta.1","version":"1.1.0-beta.1"}