{"name":"onetime","version":"6.0.0","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"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"test":"xo && ava && tsd"},"keywords":["once","function","one","onetime","func","fn","single","call","called","prevent"],"dependencies":{"mimic-fn":"^4.0.0"},"devDependencies":{"ava":"^3.15.0","tsd":"^0.14.0","xo":"^0.38.2"},"gitHead":"e5fd86f2303546a2d9cc82f2a72c3ea840f6a2dc","bugs":{"url":"https://github.com/sindresorhus/onetime/issues"},"homepage":"https://github.com/sindresorhus/onetime#readme","_id":"onetime@6.0.0","_nodeVersion":"12.20.1","_npmVersion":"6.14.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==","shasum":"7c24c18ed1fd2e9bca4bd26806a33613c77d34b4","tarball":"http://registry-npm.ywwl.com/onetime/download/onetime-6.0.0.tgz","fileCount":5,"unpackedSize":5882,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgbwmVCRA9TVsSAnZWagAARaAQAIYR90u67hRC49WkfGqS\n9OQMcfbMt4ftU1V5Je1ksDpkbXjb+ZOFCk+oCuQd/PXLY4x0g6oJxKb4BDbk\n7KnHD0divsyJi0zhFh/YrGppudlOyfRNjMayyBjlfXXtcVRkf7EWYYILqBSo\nzukCbwPoi17vTWPhhz13PCdnfhGMzLpZuBd41LSkv58tb70ocwWND3NVGn39\n+ZlR5B70FkUVnshl9OMZW9Zpn+6BUzYvKu58uT9lUCcNt2EIvNZi72nXiOLt\naOlTSCqHkjpA6Jag4uJf45qj4cJbaHBKI9MhvKusxOTmuaTzi54omfXNmfjb\nRotyFDsb3B2nhpuKN7yfNjWpRiT0Ky0TRBGL361AKsTdvKFTtkkIzPfkltIh\n0ZtA7hYrEt71K7jHGkkJQtO/dlTxkhqfxOD/rZFVpi5oxF+q/l2tnqf8ryT8\ncPB4Sn8pQoUtH3z5kS5n13rdg31S7OyC7226zc/ztLbitZDaWgFdIMpIn0La\nh862sPaesXn9brcbkOTohEj2VTEZGnatEwfEx64pOYEm3ws5Z2N6VxUKiJaV\nLC+WNtHqFOlKvos85jGdYPuNUc+1A5SB2hOMTsNmR7ycsExf98PppPF6X803\nb8OLhbOWCjAUr9SzHWrznaE28BuBozd9yn2SQhV1nrMKC5n1K/JjJkshmVp0\nZBq1\r\n=ELkF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFqcBwB60cJl2njYtLGOfrmMBQlvZSTXg7j9oKZNuo/UAiB0uaXy3+XFJB/ZoDIz5Vv/rdTuRumoFHfmNTYsH+rQjg=="}],"size":2620,"noattachment":false,"key":"/onetime/-/onetime-6.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/onetime_6.0.0_1617889684671_0.003830851530065793"},"_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":1617889684866,"_cnpm_publish_time":1617889684866,"dist-tags":{"latest":"8.0.0"}}