{"_id":"@charpeni/one-of","_rev":"4-9eae520a2e0debb615ffd3abdc2047c8","name":"@charpeni/one-of","dist-tags":{"latest":"1.1.1"},"versions":{"0.0.1":{"name":"@charpeni/one-of","version":"0.0.1","author":"","license":"MIT","_id":"@charpeni/one-of@0.0.1","maintainers":[{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"}],"dist":{"shasum":"cfdcfc65d82e24882f6b9915a6cc359198d7f1ba","tarball":"https://registry.npmjs.org/@charpeni/one-of/-/one-of-0.0.1.tgz","fileCount":1,"integrity":"sha512-+/uHz1bWfDztxJQbyvy4tJC+PvcCAutjCaBW5Ztjr7oXnztKwEApQfva0n/9Pdt7K/OE1kYUNRg3dHobe0SxAw==","signatures":[{"sig":"MEUCIQCTan5vKaf/1x2TAl6vdtYl7m+zLmZ+Sb289/K0FkRNXgIgQMJQJV+mmUMGaz00S5OSRKBEfkAQnP5UW9AgA5NR6io=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":212},"main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"},"_npmVersion":"10.7.0","directories":{},"_nodeVersion":"20.15.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/one-of_0.0.1_1723504049964_0.664706220796353","host":"s3://npm-registry-packages"}},"1.0.0":{"name":"@charpeni/one-of","version":"1.0.0","keywords":["random","randomize","array","object","element","item","entry","value","key","math","pick"],"author":{"name":"Nicolas Charpentier","email":"nicolas.charpentier079@gmail.com"},"license":"MIT","_id":"@charpeni/one-of@1.0.0","maintainers":[{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"}],"homepage":"https://github.com/charpeni/one-of#readme","bugs":{"url":"https://github.com/charpeni/one-of/issues"},"dist":{"shasum":"1da77f35407d02bb68b2e7083ffa884f3fa50d58","tarball":"https://registry.npmjs.org/@charpeni/one-of/-/one-of-1.0.0.tgz","fileCount":7,"integrity":"sha512-hEQj/k3OVL6Lhsp5VEw0Q1aFsNTFyC9n8kIIRV6s+DR1+kfeBeyJvkV/3tAjd2n5MxLzJcD9JDCfwZ+JJdk+tA==","signatures":[{"sig":"MEQCICIf4WjD+PTw2DssNP6uSqxIVSneU0V+wfno4yScT4i2AiA4UEJHR29/72r1cweTYPRvClHIt7lASlpBZdvaHwdWVw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@charpeni%2fone-of@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":10712},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"a372ab5d87680cd96f00d0bed8bbb3033daf8786","scripts":{"lint":"eslint .","test":"jest","build":"tsup src/index.ts --format cjs,esm --dts --clean","format":"prettier --write .","prepack":"yarn build","prepare":"husky","type-check":"tsc --pretty --noEmit"},"_npmUser":{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"},"repository":{"url":"git+https://github.com/charpeni/one-of.git","type":"git"},"_npmVersion":"10.8.1","description":"Type-safe utilities to return a random element from an array or random entry from an object","directories":{},"lint-staged":{"*.{js,ts,md}":["prettier --write"]},"sideEffects":false,"_nodeVersion":"20.16.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.2.4","husky":"^9.1.4","eslint":"^9.9.0","ts-jest":"^29.2.4","prettier":"3.3.3","@eslint/js":"^9.9.0","typescript":"^5.5.4","@types/jest":"^29.5.12","expect-type":"^0.19.0","lint-staged":"^15.2.8","@types/eslint__js":"^8.42.3","typescript-eslint":"^8.1.0","eslint-plugin-import":"^2.29.1","@total-typescript/tsconfig":"^1.0.4"},"_npmOperationalInternal":{"tmp":"tmp/one-of_1.0.0_1723506515135_0.6188207256721818","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@charpeni/one-of","version":"1.1.0","keywords":["random","randomize","array","object","element","item","entry","value","key","math","pick"],"author":{"name":"Nicolas Charpentier","email":"nicolas.charpentier079@gmail.com"},"license":"MIT","_id":"@charpeni/one-of@1.1.0","maintainers":[{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"}],"homepage":"https://github.com/charpeni/one-of#readme","bugs":{"url":"https://github.com/charpeni/one-of/issues"},"dist":{"shasum":"07b4fcd14183a4e596a22326af18b2f262a09add","tarball":"https://registry.npmjs.org/@charpeni/one-of/-/one-of-1.1.0.tgz","fileCount":21,"integrity":"sha512-rdiXpLTDEqoeNbFGlXbvK/6nrP5jms9Xcc76qqX3DwBUL1N1sFRkAjI4FtDwAmhZoJxS/oKkJFzyl5xTipRiXg==","signatures":[{"sig":"MEYCIQD/5jNSoVxM54GnBmR4RApPDJHDmd5C10Et0tXkAihubwIhAPjWjYd5MSCpw8oW+mHjA0iqreBjtxr4DFa13f+52Dzu","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@charpeni%2fone-of@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":12096},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.cts","module":"./dist/index.js","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"7f2bc2836825360901d1bfe40b314babc2a7dc16","scripts":{"lint":"eslint .","test":"jest","build":"tsdown","format":"prettier --write .","prepack":"pnpm build","prepare":"husky","type-check":"tsc --pretty --noEmit","check-exports":"attw --pack ."},"_npmUser":{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"},"repository":{"url":"git+https://github.com/charpeni/one-of.git","type":"git"},"_npmVersion":"10.9.2","description":"Type-safe utilities to return a random element from an array or random entry from an object","directories":{},"lint-staged":{"*.{js,ts,md}":["prettier --write"]},"sideEffects":false,"_nodeVersion":"22.16.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.0.0","husky":"^9.1.7","eslint":"^9.28.0","tsdown":"^0.12.7","ts-jest":"^29.4.0","prettier":"3.5.3","@eslint/js":"^9.28.0","typescript":"^5.8.3","@types/jest":"^29.5.14","expect-type":"^1.2.1","lint-staged":"^16.1.0","typescript-eslint":"^8.34.0","eslint-plugin-import":"^2.31.0","@arethetypeswrong/cli":"^0.18.2","@total-typescript/tsconfig":"^1.0.4"},"_npmOperationalInternal":{"tmp":"tmp/one-of_1.1.0_1750099950558_0.43098821792143815","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@charpeni/one-of","version":"1.1.1","description":"Type-safe utilities to return a random element from an array or random entry from an object","keywords":["random","randomize","array","object","element","item","entry","value","key","math","pick"],"repository":{"type":"git","url":"git+https://github.com/charpeni/one-of.git"},"license":"MIT","author":{"name":"Nicolas Charpentier","email":"nicolas.charpentier079@gmail.com"},"sideEffects":false,"type":"module","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.cts","scripts":{"build":"tsdown","format":"prettier --write .","lint":"eslint .","prepack":"pnpm build","prepare":"husky","test":"jest","type-check":"tsc --pretty --noEmit","check-exports":"attw --pack ."},"lint-staged":{"*.{js,ts,md}":["prettier --write"]},"devDependencies":{"@arethetypeswrong/cli":"^0.18.2","@eslint/js":"^9.34.0","@total-typescript/tsconfig":"^1.0.4","@types/jest":"^30.0.0","eslint":"^9.34.0","eslint-plugin-import":"^2.32.0","expect-type":"^1.2.2","husky":"^9.1.7","jest":"^30.1.1","lint-staged":"^16.1.5","prettier":"3.6.2","ts-jest":"^29.4.1","tsdown":"^0.14.2","typescript":"^5.9.2","typescript-eslint":"^8.41.0"},"packageManager":"pnpm@10.15.0","_id":"@charpeni/one-of@1.1.1","gitHead":"ef0dcb115cb2b388d7c400b72ef7db19139240e5","bugs":{"url":"https://github.com/charpeni/one-of/issues"},"homepage":"https://github.com/charpeni/one-of#readme","_nodeVersion":"22.18.0","_npmVersion":"11.5.2","dist":{"integrity":"sha512-Rf033YybYTYv/gXQnwBTal1m9d2o6+GapcccO0w9RGehKJj51zqkvkBbwI2lTyw8Hc2/fGdUFq1uOyYY2H/w1A==","shasum":"0c2d4fe70f3861f2b8164ac6d99dd3ccf42f763e","tarball":"https://registry.npmjs.org/@charpeni/one-of/-/one-of-1.1.1.tgz","fileCount":21,"unpackedSize":12171,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@charpeni%2fone-of@1.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHaKeQr67IFZsoikqdkkzBXUwvEN0pCbct4drLqIsu2YAiBLHHS2+IHaMB+kOJMQao/r6Ce7G6OFzG027Hqhow74gw=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ffa9d199-7abf-44dd-992a-097bde89e98c"}},"directories":{},"maintainers":[{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/one-of_1.1.1_1756493094159_0.41444631264971665"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-12T23:07:29.793Z","modified":"2025-08-29T18:44:54.739Z","0.0.1":"2024-08-12T23:07:30.112Z","1.0.0":"2024-08-12T23:48:35.274Z","1.1.0":"2025-06-16T18:52:30.774Z","1.1.1":"2025-08-29T18:44:54.344Z"},"bugs":{"url":"https://github.com/charpeni/one-of/issues"},"author":{"name":"Nicolas Charpentier","email":"nicolas.charpentier079@gmail.com"},"license":"MIT","homepage":"https://github.com/charpeni/one-of#readme","keywords":["random","randomize","array","object","element","item","entry","value","key","math","pick"],"repository":{"type":"git","url":"git+https://github.com/charpeni/one-of.git"},"description":"Type-safe utilities to return a random element from an array or random entry from an object","maintainers":[{"name":"charpeni","email":"nicolas.charpentier079@gmail.com"}],"readme":"# @charpeni/one-of\n\n<img height=\"125\" src=\"https://github.com/user-attachments/assets/34f0670b-491e-4a1c-a1a8-373a252a16b5\" alt=\"library's logo\" align=\"right\">\n\n[![Version](https://badge.fury.io/js/%40charpeni%2Fone-of.svg)](https://www.npmjs.org/package/@charpeni/one-of)\n[![Monthly Downloads](https://img.shields.io/npm/dm/%40charpeni%2Fone-of)](https://www.npmjs.org/package/@charpeni/one-of)\n[![CodeCov](https://codecov.io/gh/charpeni/one-of/graph/badge.svg?token=KXQCYOMPYH)](https://codecov.io/gh/charpeni/one-of)\n[![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/charpeni/one-of/blob/main/LICENSE)\n\nType-safe and tested utilities to return a random element from an array or random entry from an object.\n\n<br />\n\n## Installation\n\n```sh\nnpm install @charpeni/one-of\n```\n\n## Usage\n\n`oneOf` is a function accepting either an array or an object and returning a random element or entry from it.\n\nIt was built mostly to be used in tests or for generating random data (it can also be used safely for any other type of behaviors, including production apps), e.g.:\n\n```tsx\n<Card color={oneOf(['red', 'blue', 'green'])}>{/* ... */}</Card>\n```\n\n<!-- prettier-ignore-start -->\n> [!NOTE]\n> `oneOf` is a type-safe function. It will infer the type of the array or object passed as an argument and return the corresponding type to ensure the return type is a union of possibilities rather than a primitive type (`1 | 2` instead of `number[]`).\n>\n> If the input is passed inlined, the `const` modifier will be applied and therefore the type will be inferred as `ReadonlyArray` or readonly `Record`. Otherwise, using `as const` is suggested.\n<!-- prettier-ignore-end -->\n\n```ts\nimport { oneOf } from '@charpeni/one-of';\n\n// Returns a random element from the array\nconst element = oneOf([1, 2, 3]); // 2\n//    ^? const element: 1 | 2 | 3\n\n// Returns a random entry from the object\nconst entry = oneOf({ a: 1, b: 2, c: 3 }); // ['b', 2]\n//    ^? const entry: ['a', 1] | ['b', 2] | ['c', 3]\n```\n\nSpecific functions are also available: `oneElementOf` and `oneEntryOf`, that's what `oneOf` uses under the hood:\n\n```ts\nimport { oneElementOf, oneEntryOf } from '@charpeni/one-of';\n\n// Returns a random element from the array\nconst element = oneElementOf([1, 2, 3]); // 2\n//    ^? const element: 1 | 2 | 3\n\n// Returns a random entry from the object\nconst entry = oneEntryOf({ a: 1, b: 2, c: 3 }); // ['b', 2]\n//    ^? const entry: ['a', 1] | ['b', 2] | ['c', 3]\n```\n\n## License\n\n@charpeni/one-of is [MIT licensed](LICENSE).\n","readmeFilename":"README.md"}