{"_id":"@d.richardcarl/tiny-invariant","_rev":"4-372d9a32a2e5dde0cd8f90ce960ffdd8","name":"@d.richardcarl/tiny-invariant","dist-tags":{"latest":"1.3.3"},"versions":{"1.3.3":{"name":"@d.richardcarl/tiny-invariant","version":"1.3.3","keywords":["invariant","error","assert","asserts"],"author":{"name":"d.richardcarl","email":"d.richardcarl@gmail.com"},"license":"MIT","_id":"@d.richardcarl/tiny-invariant@1.3.3","maintainers":[{"name":"d.richardcarl","email":"d.richardcarl@gmail.com"}],"homepage":"https://github.com/drichardcarl/tiny-invariant#readme","bugs":{"url":"https://github.com/drichardcarl/tiny-invariant/issues"},"dist":{"shasum":"cbdd7894322975bd5e19b21305055358f9793801","tarball":"https://registry.npmjs.org/@d.richardcarl/tiny-invariant/-/tiny-invariant-1.3.3.tgz","fileCount":13,"integrity":"sha512-vSZtMIgRBERPXgZwW+E9ZhPHXZEjpLgKVwYJwqNdjcQd0stU/zMu2Oty7nxmUlALCaLq2I0sSfJiQgdBCliL2g==","signatures":[{"sig":"MEUCIE6P8ttEqibLby6Iv9H3SRagrEJIhskCLhy7iW6D9WmDAiEAgWbnSsrV3Brnfc6ogicNXDi6JAe5AsyXFlXxGRvqY8Y=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13891},"main":"dist/tiny-invariant.cjs.js","types":"dist/tiny-invariant.d.ts","module":"dist/tiny-invariant.esm.js","exports":{".":{"import":"./dist/esm/tiny-invariant.js","default":{"types":"./dist/tiny-invariant.d.ts","default":"./dist/tiny-invariant.cjs.js"}}},"gitHead":"b5587cf4ba45e257bce49053c3345b6614324252","scripts":{"test":"yarn jest","build":"yarn build:clean && yarn build:dist && yarn build:typescript && yarn build:typescript:esm","validate":"yarn prettier:check && yarn typescript:check","test:size":"yarn build && yarn size-limit","build:dist":"yarn rollup --config rollup.config.mjs","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":"tsc --noEmit","build:typescript:esm":"tsc ./src/tiny-invariant.ts --emitDeclarationOnly --declaration --outDir ./dist/esm"},"_npmUser":{"name":"d.richardcarl","email":"d.richardcarl@gmail.com"},"deprecated":"Package has been moved to https://www.npmjs.com/package/@devdrc/tiny-invariant","repository":{"url":"git+https://github.com/drichardcarl/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":"10.7.0","description":"A tiny invariant function","directories":{},"sideEffects":false,"_nodeVersion":"22.2.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tslib":"^2.6.2","rimraf":"^5.0.5","rollup":"^4.12.0","ts-jest":"^29.1.2","prettier":"^3.2.5","size-limit":"^11.0.2","typescript":"^5.3.3","@types/jest":"^29.5.12","@types/node":"^20.11.24","expect-type":"^0.18.0","@types/rollup":"^0.54.0","rollup-plugin-terser":"^7.0.2","@rollup/plugin-replace":"^5.0.5","@rollup/plugin-typescript":"^11.1.6","@size-limit/preset-small-lib":"^11.0.2"},"_npmOperationalInternal":{"tmp":"tmp/tiny-invariant_1.3.3_1730469149841_0.7280076728073577","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-11-01T13:52:29.741Z","modified":"2025-01-14T06:06:56.291Z","1.3.3":"2024-11-01T13:52:30.072Z"},"bugs":{"url":"https://github.com/drichardcarl/tiny-invariant/issues"},"author":{"name":"d.richardcarl","email":"d.richardcarl@gmail.com"},"license":"MIT","homepage":"https://github.com/drichardcarl/tiny-invariant#readme","keywords":["invariant","error","assert","asserts"],"repository":{"url":"git+https://github.com/drichardcarl/tiny-invariant.git","type":"git"},"description":"A tiny invariant function","maintainers":[{"name":"devdrc","email":"d.richardcarl+devdrc@gmail.com"}],"readme":"# tiny-invariant 🔬💥\n\n**This package is a modified version of the original [`tiny-invariant`](https://www.npmjs.com/package/tiny-invariant)**\n- Error messages are not stripped on all `NODE_ENV`s\n- When exception is thrown and if error message is not provided, it defaults to \"Invariant failed\"\n- Thrown error messages are not prefixed with \"Invariant failed\", it's just either the provided message or \"Invariant failed\"\n\n*All credits to the original creator(s) of this library*\n\n\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/alexreardon/tiny-invariant/test.yml)\n![types](https://img.shields.io/badge/types-typescript%20%7C%20flow-blueviolet)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/tiny-invariant)\n![NPM Downloads](https://img.shields.io/npm/dm/tiny-invariant)\n\n`tiny-invariant` is a _tiny_, widely-supported, zero-dependency alternative to [`invariant`](https://www.npmjs.com/package/invariant).\n\n`tiny-invariant` - when every byte counts!\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```ts\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 code for `sprintf` logic and instead encourages consumers to leverage [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) for message formatting.\n\n```ts\ninvariant(condition, `Hello, ${name} - how are you today?`);\n```\n\n## Error Messages\n\n`tiny-invariant` allows you to pass a `string` message, or a function that returns a `string` message. Using a function that returns a message is helpful when your message is expensive to create.\n\n```ts\nimport invariant from 'tiny-invariant';\n\ninvariant(condition, `Hello, ${name} - how are you today?`);\n\n// Using a function is helpful when your message is expensive\ninvariant(value, () => getExpensiveMessage());\n```\n\nWhen `process.env.NODE_ENV` is set to `production`, the message will be replaced with the generic message `Invariant failed`.\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```ts\ninvariant(condition, 'My cool message that takes up a lot of kbs');\n```\n\nInto this:\n\n```ts\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```ts\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","readmeFilename":"README.md"}