{"version":"1.0.1","name":"@lukeed/csprng","repository":{"type":"git","url":"git+https://github.com/lukeed/csprng.git"},"description":"An alias package for `crypto.randomBytes` in Node.js and/or browsers","unpkg":"browser/index.min.js","browser":"browser/index.mjs","module":"node/index.mjs","main":"node/index.js","types":"index.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"exports":{".":{"browser":{"import":"./browser/index.mjs","require":"./browser/index.js"},"import":"./node/index.mjs","require":"./node/index.js"},"./node":{"import":"./node/index.mjs","require":"./node/index.js"},"./browser":{"import":"./browser/index.mjs","require":"./browser/index.js"},"./package.json":"./package.json"},"engines":{"node":">=8"},"scripts":{"build":"bundt","test":"uvu -r esm test"},"modes":{"browser":"src/browser.js","node":"src/node.js"},"keywords":["crypto","browser","isomorphic","getRandomValues","randomFill","random","csprng"],"devDependencies":{"bundt":"1.1.1","esm":"3.2.25","uvu":"0.5.2"},"publishConfig":{"access":"public"},"gitHead":"1a63cf8d207ab9ee99c8e25663593d72262cd79d","bugs":{"url":"https://github.com/lukeed/csprng/issues"},"homepage":"https://github.com/lukeed/csprng#readme","_id":"@lukeed/csprng@1.0.1","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-uSvJdwQU5nK+Vdf6zxcWAY2A8r7uqe+gePwLWzJ+fsQehq18pc0I2hJKwypZ2aLM90+Er9u1xn4iLJPZ+xlL4g==","shasum":"625e93a0edb2c830e3c52ce2d67b9d53377c6a66","tarball":"http://registry-npm.ywwl.com/@lukeed/csprng/download/@lukeed/csprng-1.0.1.tgz","fileCount":12,"unpackedSize":5816,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCd/+L3RQOsuzqRQ0w7H4v+Rz+41oP9qdcZDQbr0h4ErwIgCvpISSlmL22ylIG4OsIjm3lmXRx7dcJyVpy8CV42JgI="}],"size":2721,"noattachment":false,"key":"/@lukeed/csprng/-/@lukeed/csprng-1.0.1.tgz"},"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/csprng_1.0.1_1637556050346_0.12969226903005704"},"_hasShrinkwrap":false,"readme":"# @lukeed/csprng ![CI](https://github.com/lukeed/csprng/workflows/CI/badge.svg) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/csprng)](https://codecov.io/gh/lukeed/csprng)\n\n> A tiny (~90B) isomorphic wrapper for `crypto.randomBytes` in Node.js and browsers.\n\n***Why?***\n\nThis package allows you/dependents to import a cryptographically secure generator (CSPRNG) _without_ worrying about (aka, checking the runtime environment for) the different `crypto` implementations. Instead, by extracting a `random` function into a third-party/external package, one can rely on bundlers and/or module resolution to load the correct implementation for the desired environment.\n\nIn other words, one can include the browser-specific implementation when bundling for the browser, completely ignoring the Node.js code – or vice versa.\n\nBy default, this module is set up to work with Rollup, webpack, and Node's native ESM _and_ CommonJS path resolutions.\n\n## Install\n\n```\n$ npm install --save @lukeed/csprng\n```\n\n\n## Usage\n\n***General Usage***\n\n```js\n// Rely on bundlers/environment detection\nimport { random } from '@lukeed/csprng';\n\nconst array = random(12);\n// browser => Uint8Array(12) [...]\n// Node.js => <Buffer ...>\n```\n\n***Specific Environment***\n\n```js\n// Choose the \"browser\" implementation explicitly.\n//=> ! NOTE ! Will break in Node.js environments!\nimport { random } from '@lukeed/csprng/browser';\n\nconst array = random(1024);\n//=> Uint8Array(1024) [...]\n\n// ---\n\n// Choose the \"node\" implementation explicitly.\n//=> ! NOTE ! Will break in browser environments!\nimport { random } from '@lukeed/csprng/node';\n\nconst array = random(1024);\n//=> <Buffer ...>\n```\n\n\n## API\n\n### random(length)\nReturns: `Buffer` or `Uint8Array`\n\nReturns a typed array of given `length`.\n\n\n#### length\nType: `Number`\n\nThe desired length of your output TypedArray.\n\n\n## Related\n\n- [uid](https://github.com/lukeed/uid) - A tiny (134B) and fast utility to randomize unique IDs of fixed length\n- [@lukeed/uuid](https://github.com/lukeed/uuid) - A tiny (230B), fast, and cryptographically secure UUID (V4) generator for Node and the browser\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","publish_time":1637556050489,"_cnpm_publish_time":1637556050489,"dist-tags":{"latest":"1.1.0"}}