{"name":"onetime","version":"5.1.2","description":"Ensure a function is only called once","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/onetime.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd"},"keywords":["once","function","one","onetime","func","fn","single","call","called","prevent"],"dependencies":{"mimic-fn":"^2.1.0"},"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.1","xo":"^0.24.0"},"gitHead":"4fa3c9a40798476514fec36a1720dc85b897cc04","bugs":{"url":"https://github.com/sindresorhus/onetime/issues"},"homepage":"https://github.com/sindresorhus/onetime#readme","_id":"onetime@5.1.2","_nodeVersion":"14.5.0","_npmVersion":"6.14.7","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==","shasum":"d0e96ebb56b07476df1dd9c4806e5237985ca45e","tarball":"http://registry-npm.ywwl.com/onetime/download/onetime-5.1.2.tgz","fileCount":5,"unpackedSize":6173,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfMFyRCRA9TVsSAnZWagAAInsP/RTd8G7KIVrwux1TNO4h\nS+Ymvz0874gBCS5I8tXFkdVSVAqPUNX3undeJIAHSqV7UMdAPx8wiFDqmga1\n28xR3LA8iHSyo1pxxIboH1LWJgaG2NWIfFV/fAPLvPJzEqmQ4zU0ioYhiwjj\n+MRlfRbkvFSqF9bdIm29VEKLzJPBtLM+BnHHmHigB3IA+fkhy81oo5ESmUPC\nUBeMJyXVMHU9v6r/0PQtqfTnVD68c+1o6yfevC8P0CjOCydJlWltCfKXhMNw\nxTVUxzaU4rfEHXsosGV79jCfLDcibLVdbjAMFzq1P6HaAKSl0ry2TrHKC/o/\nusdJe6U/jqxRN9moiuyh+qxR/9heTMXGgP1xrq0m9jwJlU681vlaPcQaQlM0\nZ0x3/TC1F+Nj6vOTG3lPBunne+H/0D4vu5MSDha8uzyAJ0mHarP+/hPP9gEZ\nUB9cT2djKZATqv4S+S3WKvYZa+m5pupDzVV4YbF3XgCSBe4mB23GdzllY76x\n9SCs7s7d6jUc+0FO/WhyASagXxeqqEwsrN4GRhfUB5l2y9/Le/j7sACW+YU7\nS4c6ony0Tojzb3ncc5zbebH/tskKZb6SCd6nZFBKs/CpDNqDueIkIyjbWLPH\nHUcN6AgD/j5xyIxeIbYc0HH7bc0NovpQbGeP8sIe1o+nS2WOTnjx0LPMCUP1\noLdv\r\n=J6Zn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCSvlynRcdgHdta0H4svzquLsEgRP7Iy+uD+ExsJFl/eQIhAPxJGn9aczZEPZWZyI8oAgKAiLlTZyWB+FB7/LkcTRgI"}],"size":2741,"noattachment":false,"key":"/onetime/-/onetime-5.1.2.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/onetime_5.1.2_1597004944849_0.8241938525832997"},"_hasShrinkwrap":false,"readme":"# onetime\n\n> Ensure a function is only called once\n\nWhen called multiple times it will return the return value from the first call.\n\n*Unlike the module [once](https://github.com/isaacs/once), this one isn't naughty and extending `Function.prototype`.*\n\n## Install\n\n```sh\nnpm install onetime\n```\n\n## Usage\n\n```js\nimport onetime from 'onetime';\n\nlet index = 0;\n\nconst foo = onetime(() => ++index);\n\nfoo(); //=> 1\nfoo(); //=> 1\nfoo(); //=> 1\n\nonetime.callCount(foo); //=> 3\n```\n\n```js\nimport onetime from 'onetime';\n\nconst foo = onetime(() => {}, {throw: true});\n\nfoo();\n\nfoo();\n//=> Error: Function `foo` can only be called once\n```\n\n## API\n\n### onetime(fn, options?)\n\nReturns a function that only calls `fn` once.\n\n#### fn\n\nType: `Function`\n\nThe function that should only be called once.\n\n#### options\n\nType: `object`\n\n##### throw\n\nType: `boolean`\\\nDefault: `false`\n\nThrow an error when called more than once.\n\n### onetime.callCount(fn)\n\nReturns a number representing how many times `fn` has been called.\n\nNote: It throws an error if you pass in a function that is not wrapped by `onetime`.\n\n```js\nimport onetime from 'onetime';\n\nconst foo = onetime(() => {});\n\nfoo();\nfoo();\nfoo();\n\nconsole.log(onetime.callCount(foo));\n//=> 3\n```\n\n#### fn\n\nType: `Function`\n\nThe function to get call count from.\n","publish_time":1597004944963,"_cnpm_publish_time":1597004944963,"dist-tags":{"latest":"8.0.0"}}