{"_id":"@dts-stn/invariant","name":"@dts-stn/invariant","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@dts-stn/invariant","version":"1.0.0","description":"An invariant function","keywords":["invariant","error","assert","asserts"],"homepage":"https://github.com/DTS-STN/reusable-components#readme","bugs":{"url":"https://github.com/DTS-STN/reusable-components"},"repository":{"type":"git","url":"git+https://github.com/DTS-STN/reusable-components.git","directory":"libs/javascript/invariant"},"license":"MIT","author":{"name":"Digital Technology Solutions","url":"https://github.com/DTS-STN"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"sideEffects":false,"scripts":{"build":"unbuild --sourcemap","build:ci":"npm run lint && npm run test && npm run clean && npm run build && npm run exports:check","clean":"rimraf ./dist/","exports:check":"attw --pack ./","lint":"run-p --continue-on-error \"lint:*\"","lint:eslint":"eslint .","lint:prettier":"prettier . --check","lint:typecheck":"tsc","fix":"run-p --continue-on-error fix:*","fix:eslint":"npm run lint:eslint -- --fix","fix:prettier":"npm run lint:prettier -- --write","test":"vitest run","test:coverage":"npm run test -- --coverage"},"devDependencies":{"@arethetypeswrong/cli":"^0.18.1","@eslint/compat":"^1.2.9","@eslint/js":"^9.27.0","@vitest/coverage-v8":"^3.1.4","@vitest/eslint-plugin":"^1.2.0","eslint":"^9.27.0","eslint-plugin-unicorn":"^59.0.1","globals":"^16.1.0","npm-run-all2":"^8.0.2","prettier":"^3.5.3","rimraf":"^6.0.1","typescript":"^5.8.3","typescript-eslint":"^8.32.1","unbuild":"^3.5.0","vite-tsconfig-paths":"^5.1.4","vitest":"^3.1.4"},"engines":{"node":">= 20"},"_id":"@dts-stn/invariant@1.0.0","gitHead":"f620e4d43bd9b7c9f8b70c796f6b10b155f87301","_nodeVersion":"22.15.1","_npmVersion":"11.3.0","dist":{"integrity":"sha512-uhVKL/XeS0J3pHz3serWFePOhtjYdbRFMhP2USL4thKfiUUVIsa4IdAUD/ss7BB2lAxIfbNAwhefrtzH5ERoig==","shasum":"07e01ad386810a0b42967f1653cfe1989ebcede1","tarball":"https://registry.npmjs.org/@dts-stn/invariant/-/invariant-1.0.0.tgz","fileCount":10,"unpackedSize":12597,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDJBud8HcJHgS7y7U3kO/6rSt1+sGzNolmPVDKJxKJDBAIhAJi9wGxMGFwdSMZOtPdnFl1zAryh1roj0yY4q3tW0x1v"}]},"_npmUser":{"name":"sebastien-comeau","email":"sebastien.comeau@hrsdc-rhdcc.gc.ca"},"directories":{},"maintainers":[{"name":"gregory.j.baker","email":"gregory.j.baker@hrsdc-rhdcc.gc.ca"},{"name":"nicholas.ly","email":"nicholas.ly@hrsdc-rhdcc.gc.ca"},{"name":"sebastien-comeau","email":"sebastien.comeau@hrsdc-rhdcc.gc.ca"},{"name":"stefan-oconnell","email":"stefan.oconnell@hrsdc-rhdcc.gc.ca"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/invariant_1.0.0_1747760768234_0.5881856038147164"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-20T17:06:08.166Z","1.0.0":"2025-05-20T17:06:08.433Z","modified":"2025-05-20T17:06:08.801Z"},"maintainers":[{"name":"gregory.j.baker","email":"gregory.j.baker@hrsdc-rhdcc.gc.ca"},{"name":"nicholas.ly","email":"nicholas.ly@hrsdc-rhdcc.gc.ca"},{"name":"sebastien-comeau","email":"sebastien.comeau@hrsdc-rhdcc.gc.ca"},{"name":"stefan-oconnell","email":"stefan.oconnell@hrsdc-rhdcc.gc.ca"}],"description":"An invariant function","homepage":"https://github.com/DTS-STN/reusable-components#readme","keywords":["invariant","error","assert","asserts"],"repository":{"type":"git","url":"git+https://github.com/DTS-STN/reusable-components.git","directory":"libs/javascript/invariant"},"author":{"name":"Digital Technology Solutions","url":"https://github.com/DTS-STN"},"bugs":{"url":"https://github.com/DTS-STN/reusable-components"},"license":"MIT","readme":"# 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 '@dts-stn/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 `@dts-stn/invariant`?\n\nUnlike [`tiny-invariant`](https://www.npmjs.com/package/tiny-invariant), which strips error messages in production, `@dts-stn/invariant` preserves them. This is the fundamental reason for its creation, as these messages are vital for debugging production issues.\n\n## Error Messages\n\n`@dts-stn/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 '@dts-stn/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\n## Type narrowing\n\n`@dts-stn/invariant` is useful for correctly narrowing types for `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","readmeFilename":"README.md","_rev":"1-ee8083f464dbbb3a6b88353f6c8c3099"}