{"_id":"@bytegenius/wrap-with-noop","name":"@bytegenius/wrap-with-noop","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@bytegenius/wrap-with-noop","version":"0.1.0","description":"Wrap a function with a specified number of argument using a noop and/or throw a Error.","main":"src/index.js","keywords":["wrap-with-noop","noop","no-op"],"author":{"name":"Nnamdi Michael Okpala"},"license":"ISC","_id":"@bytegenius/wrap-with-noop@0.1.0","types":"./src/index.d.ts","_nodeVersion":"20.5.1","_npmVersion":"10.1.0","dist":{"integrity":"sha512-4sUbA+IfKMYqfvL81+VI4H/ZwrskZ4jIaUhkiEbei+rWTidTDQYOGLAJEd7csJOMqNgxjU8usPeBSEkBXJf5wA==","shasum":"694e67a3d31f8a7c3f836e7d4d42620b2501c869","tarball":"https://registry.npmjs.org/@bytegenius/wrap-with-noop/-/wrap-with-noop-0.1.0.tgz","fileCount":5,"unpackedSize":3705,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCkr51/N6GvfB+oid927Rqpde9HvRIg9yvFArbedzCoAQIgTdXR178DVPZdFwqIViYXKBpYTf4xh/LdOQpHmL0vzSY="}]},"_npmUser":{"name":"bytegenius","email":"bytegenius-official@protonmail.com"},"directories":{},"maintainers":[{"name":"bytegenius","email":"bytegenius-official@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wrap-with-noop_0.1.0_1697037942168_0.3392418502775094"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-11T15:25:42.013Z","0.1.0":"2023-10-11T15:25:42.527Z","modified":"2023-10-11T15:25:42.824Z"},"maintainers":[{"name":"bytegenius","email":"bytegenius-official@protonmail.com"}],"description":"Wrap a function with a specified number of argument using a noop and/or throw a Error.","keywords":["wrap-with-noop","noop","no-op"],"author":{"name":"Nnamdi Michael Okpala"},"license":"ISC","readme":"# wrap-with-noop\r\n\r\n`wrap-with-noop` is a simple utility for wrapping a function and adding argument count validation. This package allows you to either perform a no-op (return a default value) or throw an error when the function is called with an incorrect number of arguments.\r\n\r\n## Installation\r\n\r\nYou can install this package using npm or yarn:\r\n\r\n```bash\r\nnpm install wrap-with-noop\r\n```\r\n\r\nor\r\n\r\n```bash\r\nyarn add wrap-with-noop\r\n```\r\n\r\n## Usage\r\n\r\nTo use `wrap-with-noop`, require the package in your Node.js application:\r\n\r\n```javascript\r\nconst wrapWithNoOp = require('wrap-with-noop');\r\n```\r\n\r\n### Example\r\n\r\nHere's an example of how to use `wrapWithNoOp`:\r\n\r\n```javascript\r\nconst wrappedFunction = wrapWithNoOp(\r\n  (a, b) => a + b,\r\n  2,\r\n  { silent: true }\r\n);\r\n\r\nconst result = wrappedFunction(3);\r\n\r\nconsole.log(result); // This will print \"undefined\" because it's silent\r\n```\r\n\r\nIn this example, we are wrapping a function that expects at least two arguments. When the wrapped function is called with only one argument, it returns `undefined` because the `silent` option is set to `true`. If the `silent` option were set to `false`, it would throw an error.\r\n\r\n### API\r\n\r\n#### `wrapWithNoOp(fn, requiredArgs, { silent })`\r\n\r\n- `fn`: The function you want to wrap with argument checking.\r\n- `requiredArgs`: An integer representing the minimum number of arguments `fn` should receive.\r\n- `{ silent }`: An options object that includes a `silent` property (default is `false`). If `silent` is `false`, the function throws an error when the argument check fails. If `silent` is `true`, it returns `undefined` (no-op) when the argument check fails.\r\n\r\n## License\r\n\r\nThis package is open-source and available under the [MIT License](LICENSE).\r\n\r\n","readmeFilename":"README.md"}