{"_id":"@axijs/ensure","_rev":"5-190481701e5e45cc7c5738d3e1513225","name":"@axijs/ensure","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@axijs/ensure","version":"1.0.0","keywords":[],"license":"MIT","_id":"@axijs/ensure@1.0.0","maintainers":[{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"}],"homepage":"https://github.com/axijs/tools#readme","bugs":{"url":"https://github.com/axijs/tools/issues"},"dist":{"shasum":"c0003a105e2917effbe25e043e326488e1b7122b","tarball":"https://registry.npmjs.org/@axijs/ensure/-/ensure-1.0.0.tgz","fileCount":6,"integrity":"sha512-KMlrOnp7puodm2irAz6k0uMNdD16xxI7RCBPwzEpmrxZE8xbmL0bKVZjfwM/1nTX00A2PowA7Fn33WH0beMLqg==","signatures":[{"sig":"MEYCIQD24JjWl8KEP0jn75/ItwNi9KfvChdP4BueKMbcYmnwEAIhAODuKamkFDPCv1k2wmzTgzCPGkWFU/XDoPeWWEviZAbR","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16056},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"58347185448d8b9451c514f39a1c0c3583da1929","scripts":{"docs":"typedoc src/index.ts --out docs/api --options ../../typedoc.json","test":"vitest run","build":"tsup","prebuild":"npm test"},"_npmUser":{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"},"repository":{"url":"git+https://github.com/axijs/tools.git","type":"git","directory":"packages/ensure"},"_npmVersion":"11.10.0","description":"[![NPM version](https://img.shields.io/npm/v/@axijs/ensure.svg)](https://www.npmjs.com/package/@axijs/ensure)","directories":{},"_nodeVersion":"20.19.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ensure_1.0.0_1775753813794_0.054496280272264164","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@axijs/ensure","version":"1.0.1","keywords":[],"license":"MIT","_id":"@axijs/ensure@1.0.1","maintainers":[{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"}],"homepage":"https://github.com/axijs/tools/tree/main/packages/ensure","bugs":{"url":"https://github.com/axijs/tools/issues"},"dist":{"shasum":"e2ae40fdab97547577f5c88d9c300d4cbb7b1b4f","tarball":"https://registry.npmjs.org/@axijs/ensure/-/ensure-1.0.1.tgz","fileCount":6,"integrity":"sha512-yzA91iiWinDryb1UxSReHwMsKZ4ombj5BBvuQe3480qq+iaKjTMiAojGU2nhwNrBgizu7gVtR/L3S16bJ0te1A==","signatures":[{"sig":"MEQCIEuxJJ6LpLSh3xAav38cbk/HeWrpW4G+HqHsrCdfrMcAAiBoXzxP58R0IB5ymsgt6q+IuTsL6tErSTo8Lp7ZGaTMYQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16192},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"58347185448d8b9451c514f39a1c0c3583da1929","scripts":{"docs":"typedoc src/index.ts --out docs/api --options ../../typedoc.json","test":"vitest run","build":"tsup","prebuild":"npm test"},"_npmUser":{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"},"repository":{"url":"git+https://github.com/axijs/tools.git","type":"git","directory":"packages/ensure"},"_npmVersion":"11.10.0","description":"A lightweight collection of TypeScript type guards and assertions","directories":{},"_nodeVersion":"20.19.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ensure_1.0.1_1775754016629_0.1354106733358511","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@axijs/ensure","version":"1.0.2","keywords":[],"license":"MIT","_id":"@axijs/ensure@1.0.2","maintainers":[{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"}],"homepage":"https://github.com/axijs/tools/tree/main/packages/ensure","bugs":{"url":"https://github.com/axijs/tools/issues"},"dist":{"shasum":"5eec975015845706b05e36de5b811ebb17156d92","tarball":"https://registry.npmjs.org/@axijs/ensure/-/ensure-1.0.2.tgz","fileCount":6,"integrity":"sha512-j8/dnWUCCk0sNrD1gDLaKMSLjBjoogZp8IZuGDjpYKAUzSaxQsSXbUzrqZyX1OoegCJivHo6yBEn0LgZGCqKHw==","signatures":[{"sig":"MEYCIQDsyIuSi+12PDqMVxqJZFqYiGwp3krMFf1T/b2ZpBg5QwIhAJjkt/+gQH6+tvIKYibAKclJLvCbejTGxzFs6XsY+XrJ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18078},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"04492e1c5777da29e89fa1db9e9ae6d7bdc69dd4","scripts":{"docs":"typedoc src/index.ts --out docs/api --options ../../typedoc.json","test":"vitest run","build":"tsup","prebuild":"npm test"},"_npmUser":{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"},"repository":{"url":"git+https://github.com/axijs/tools.git","type":"git","directory":"packages/ensure"},"_npmVersion":"11.10.0","description":"A lightweight collection of TypeScript type guards and assertions","directories":{},"_nodeVersion":"20.19.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ensure_1.0.2_1778765387783_0.5319198949522934","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@axijs/ensure","version":"1.0.3","keywords":[],"license":"MIT","_id":"@axijs/ensure@1.0.3","maintainers":[{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"}],"homepage":"https://github.com/axijs/tools/tree/main/packages/ensure","bugs":{"url":"https://github.com/axijs/tools/issues"},"dist":{"shasum":"f293c45cc91d4f7d33c79873e7d0c554adcdcf0c","tarball":"https://registry.npmjs.org/@axijs/ensure/-/ensure-1.0.3.tgz","fileCount":6,"integrity":"sha512-fDtOlekpPseoEs+3YE6hS9S2fcko971on5e4ek12w685TBrowY/TOUKgwda87iO0rpYz2BdKDS4RXwkPqJk4qQ==","signatures":[{"sig":"MEYCIQCKIaapj0sTGajcJwaLRnP7z4RTfPYKaAfDEBE6yf4AkAIhANKWeZ7YP3Y7wVifHKKOdX2EtDmElx2X5z9XTQuZVnjH","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18770},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"46ad7a237abaf5ea69c53c9e260a97b4d89a7782","scripts":{"docs":"typedoc src/index.ts --out docs/api --options ../../typedoc.json","test":"vitest run","build":"tsup","prebuild":"npm test"},"_npmUser":{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"},"repository":{"url":"git+https://github.com/axijs/tools.git","type":"git","directory":"packages/ensure"},"_npmVersion":"11.15.0","description":"A lightweight collection of TypeScript type guards and assertions","directories":{},"_nodeVersion":"20.19.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ensure_1.0.3_1784728783020_0.24567339380505793","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@axijs/ensure","version":"1.0.4","description":"A lightweight collection of TypeScript type guards and assertions","license":"MIT","homepage":"https://github.com/axijs/tools/tree/main/packages/ensure","repository":{"type":"git","url":"git+https://github.com/axijs/tools.git","directory":"packages/ensure"},"keywords":[],"types":"./dist/index.d.ts","main":"./dist/index.js","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"tsup","prebuild":"npm test","docs":"typedoc src/index.ts --out docs/api --options ../../typedoc.json","test":"vitest run"},"gitHead":"94cb3a695adedd192a962941b4190122679ec3b8","_id":"@axijs/ensure@1.0.4","bugs":{"url":"https://github.com/axijs/tools/issues"},"_nodeVersion":"20.19.3","_npmVersion":"11.15.0","dist":{"integrity":"sha512-+47f65R43jTdPf2TFy8ocK+yYliO4LFV8SZSTraTtF+sZfXARRJ9p+TuJoyT9iOTcuSUIaHFwRjUNhK6ikZqWw==","shasum":"0d18b0066ba2920132a2a7e40fcafe46eabb5c1d","tarball":"https://registry.npmjs.org/@axijs/ensure/-/ensure-1.0.4.tgz","fileCount":6,"unpackedSize":25024,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDfcycNGUbw4V7Uv1MuhifhhWL2h34YRRIL2Owxz4J7UQIgcaKf1dp8n6wtuY4XO4u4JKz4hyjSuHPHFLLE1b/NObs="}]},"_npmUser":{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"},"directories":{},"maintainers":[{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ensure_1.0.4_1787830444169_0.6335957965144963"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-09T16:56:53.612Z","modified":"2026-08-27T11:34:04.512Z","1.0.0":"2026-04-09T16:56:53.939Z","1.0.1":"2026-04-09T17:00:16.773Z","1.0.2":"2026-05-14T13:29:47.921Z","1.0.3":"2026-07-22T13:59:43.152Z","1.0.4":"2026-08-27T11:34:04.322Z"},"bugs":{"url":"https://github.com/axijs/tools/issues"},"license":"MIT","homepage":"https://github.com/axijs/tools/tree/main/packages/ensure","keywords":[],"repository":{"type":"git","url":"git+https://github.com/axijs/tools.git","directory":"packages/ensure"},"description":"A lightweight collection of TypeScript type guards and assertions","maintainers":[{"name":"nimbuspaw","email":"nimbuspaw@gmail.com"}],"readme":"# @axijs/ensure\r\n\r\n[![NPM version](https://img.shields.io/npm/v/@axijs/ensure.svg)](https://www.npmjs.com/package/@axijs/ensure)\r\n\r\nA lightweight, zero-dependency collection of TypeScript type guards and assertions.\r\n\r\nDesigned to ensure type safety and handle runtime validation cleanly without the boilerplate.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @axijs/ensure\r\n# or\r\npnpm add @axijs/ensure\r\n# or\r\nyarn add @axijs/ensure\r\n```\r\n\r\n## Features\r\n\r\n- **Zero dependencies**: Extremely lightweight.\r\n- **Strict Type Guards**: Safely narrow down types (e.g., `isObject` correctly filters out `null` and arrays).\r\n- **Assertion Utilities**: Clean flow control with `throwIf` and `throwIfEmpty`.\r\n\r\n## Usage\r\n\r\n### 1. Assertions & Flow Control\r\n\r\nUse assertions to enforce conditions.\r\n\r\n```typescript\r\nimport {throwIfEmpty, throwIf, throwError} from '@axijs/ensure';\r\n\r\n// Example: Narrowing a potentially undefined value\r\nconst user: { name: string } | undefined = findUser();\r\n\r\nthrowIfEmpty(user, 'User not found');\r\nconsole.log(user.name);\r\n\r\n// Example: Conditional throwing\r\nconst isInvalid = validate(data);\r\nthrowIf(isInvalid, 'Data validation failed');\r\n\r\n// Example: Unconditional throw\r\nfunction notImplemented(): never {\r\n  throwError('This feature is coming soon');\r\n}\r\n```\r\n\r\n### 2. Type Guards\r\n\r\nCheck types safely at runtime while giving TypeScript the correct type context.\r\n\r\n```typescript\r\nimport {isString, isObject, isPromise, isIterable} from '@axijs/ensure';\r\n\r\nconst data: unknown = fetchData();\r\n\r\nif (isString(data)) {\r\n  console.log(data.toUpperCase());\r\n}\r\n\r\nif (isObject(data)) {\r\n  // True plain object (not null, not array)\r\n  console.log(Object.keys(data));\r\n}\r\n\r\nif (isPromise(data)) {\r\n  data.then(resolve);\r\n}\r\n\r\nif (isIterable(data)) {\r\n  for (const item of data) {\r\n    console.log(item);\r\n  }\r\n}\r\n```\r\n\r\n### 3. Emptiness Check\r\n\r\nA pair of utilities to check whether a value is conceptually \"empty\" or not.\r\n\r\n```typescript\r\nimport {isEmpty, isNotEmpty} from '@axijs/ensure';\r\n\r\nisEmpty({}); // true\r\nisEmpty(0); // false\r\nisEmpty(false); // false\r\n\r\nisNotEmpty({name: 'Alex'}); // true\r\nisNotEmpty([]); // false\r\n```\r\n\r\n### 4. Value Normalization\r\n\r\nNormalize values to a consistent format when an API accepts either a single value or an array of values.\r\n\r\n```typescript\r\nimport {ensureArray, toDelimitedString} from '@axijs/ensure';\r\n\r\nensureArray('item'); // ['item']\r\nensureArray(['one', 'two']); // ['one', 'two']\r\n\r\ntoDelimitedString('item'); // 'item'\r\ntoDelimitedString(['one', 'two']); // 'one/two'\r\ntoDelimitedString(['one', 'two'], ' | '); // 'one | two'\r\n```\r\n\r\n## API Documentation\r\n\r\nFor a complete list of available type guards, assertions, and their detailed descriptions,\r\nplease visit the [API Documentation](https://github.com/axijs/tools/tree/main/packages/ensure/docs/api).\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}