{"name":"onetime","version":"4.0.0","description":"Ensure a function is only called once","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/onetime.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["once","function","one","onetime","func","fn","single","call","called","prevent"],"dependencies":{"mimic-fn":"^1.0.0"},"devDependencies":{"ava":"^1.1.0","tsd-check":"^0.3.0","xo":"^0.24.0"},"gitHead":"65ad3c02a2ad06d6ec1f49ce80c98f4a5c172bf6","bugs":{"url":"https://github.com/sindresorhus/onetime/issues"},"homepage":"https://github.com/sindresorhus/onetime#readme","_id":"onetime@4.0.0","_nodeVersion":"10.15.1","_npmVersion":"6.8.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-woeNhttKxY5jRwaoDMB74JYFaJAAegWXNcXm4CLd4DBfd4ZkrQeIPol0YylMyUd5uG/g6cPAUULYlPIruQSz6A==","shasum":"143112c91abc470e9e70a7b2636ce773c1fdf5b2","tarball":"http://registry-npm.ywwl.com/onetime/download/onetime-4.0.0.tgz","fileCount":5,"unpackedSize":5117,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcePgqCRA9TVsSAnZWagAAn5UP/2yF7Iu4Gs4i4sWgyl3m\nbEW8JvbJ6ac/Xkik8CJbUdzOfCW7YO+/P9TJHX0VP0yylOuaW2r/bcap4ZpO\nXmwwSICCsLQs3DLnjNGGONjDyI8JwozR9JdzIP129KorQXesOkhamPb0PsCa\nvi2pb2TuFqNDS3WFaoxCj+U2tNIXCxv3sN4BRK9iCSx8Qme9IKT79ECDaxOh\n1YJsFoBr//z6nKgmJZ2x8NZM6vYc01AGnYwFNFbODl1O1T6Qye4jbABMI/NH\nb680FQeBfweg2jVr6CPNBr4KzAOsqiwc8DCI12E5lxnET+8oGiPCvRQ7IlX+\nrwo1OdQGofi/Pdo6al281E4ZH8NzyXgMYSabqIp49w9zQmDX2z30a3jOKWww\n5u5yYBcIlxWDuh5hjheyOVSI+bqD/iwhvkxX+sBW2SWicUZRULHsuNI+j8q7\nj0OSZ9Wnc++fpciIeBh59BQ3PhE53hsekkjxMrKwGoC3YCsjQ/WcygbCqyDh\npg63g34BRpuXt+oreIkJF+nOFmnwhCIvH0yTMnicIwTpy0qMwxsTdxf99nJa\nI8uJJJSxsfb7icQI5Oq+339FVAg2QK66eHcPWMOlEl7TyucqvwYPFUZCvuxm\nJQJyPsnOjxUTCWqzZ1TaictfK5QPQ8euKwZXEhnqoKD/0PqslTFJT+4CAWv3\nso2T\r\n=Ehwi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG0jv1mJ58PKKrDZBBXdu5H0wj6fCcCiGauN1NCAV1utAiEAvFhsB6/BojRGGtiVtf1L17xYoE22HNuBePWMPcwnlw8="}],"size":2386,"noattachment":false,"key":"/onetime/-/onetime-4.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/onetime_4.0.0_1551431721222_0.5847573580409424"},"_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":1551431721375,"_cnpm_publish_time":1551431721375,"dist-tags":{"latest":"8.0.0"}}