{"name":"onetime","version":"5.1.1","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":"59e0ad2204b5d44b448a71afb13f228d1977f07f","bugs":{"url":"https://github.com/sindresorhus/onetime/issues"},"homepage":"https://github.com/sindresorhus/onetime#readme","_id":"onetime@5.1.1","_nodeVersion":"14.5.0","_npmVersion":"6.14.5","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-ZpZpjcJeugQfWsfyQlshVoowIIQ1qBGSVll4rfDq6JJVO//fesjoX808hXWfBjY+ROZgpKDI5TRSRBSoJiZ8eg==","shasum":"5c8016847b0d67fcedb7eef254751cfcdc7e9418","tarball":"http://registry-npm.ywwl.com/onetime/download/onetime-5.1.1.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\nwsFcBAEBCAAQBQJfJpVjCRA9TVsSAnZWagAA2xQP/2GUXW7XqJBsodgB7rig\nzrVUJhnp0fxhrAf6zqeeCkCnBJRNGQToqg+c+wZVoMo70+r+vwH3sGbJXJLd\n7vraWS3wJBGrrImzLDGck4YF0DKQ4vzNBrWvEpdTZhiJp3/IUSY2C5GJ8CyB\nMiR8Q66/ylWf8OqbRsbCn4iGPCnm4aOGHObXVVehbHgIxPgzKnykp4bRjr3P\nDTrKolDIOGQV5poP0BK0qBeYvLcWeCDa/+nAUVxjXNVsBrpfeXeqjfUkfmAf\nuKdFiD/b0DCo4qcpKu9TNB77ZYraUDHSYrISwt7A2TffhzGzIUX1liZ5oDyh\nYrvHok8Fc7Rf0fvKpCdoNdsrkUpWtS+ESS7usSnp5c/Kb9Vq1nCPeoSyS2Kh\nswlP1n1JHzDsDUa3aeS9jZV7KxxERIJZfOXAwpzzHG3d7HaVa379C7BslKSY\nL6PhlYZesTXg/j8qRyXdOppF1T145VvV8JLHKpvj38v+F8P8t6LnHUAeFuAE\nW7c81AFYgPckuIzlu5cwY1kuFXE5y9uXv/5HxneOe1s+jjTYTM+i8BYEOMPp\nx1BTymCRNlm7X+uHQkrxsEp94UIUBXFM0XGgtf4wwr7vS/lyxVtZiADrTjlC\nccNfRI7GowFc6DFUBTqqJAUXaHfDVBapOHSuYVYRjlzXUuPznysun2tPa5PC\n8EMe\r\n=/FeN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFGklvIdWWjxf5NBdjrjwjkjpzM0FsGsvUedoAknnjWwAiEA35WN5BfEIzrPEzU29e/DtOS2LkBEpIYtIZPQ+lf+h/o="}],"size":2751,"noattachment":false,"key":"/onetime/-/onetime-5.1.1.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/onetime_5.1.1_1596364130751_0.20576953897408923"},"_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":1596364130856,"_cnpm_publish_time":1596364130856,"dist-tags":{"latest":"8.0.0"}}