{"name":"debounce-promise","version":"3.1.2","description":"Create a debounced version of a promise returning function","main":"dist/index","runkitExampleFilename":"./example.js","scripts":{"test":"tap --node-arg -r --node-arg babel-register --node-arg -r --node-arg babel-polyfill test && npm run lint","lint":"standard | snazzy","compile":"babel index.js --source-maps --out-dir dist","clean":"rimraf dist","prepare":"in-publish && npm run compile || not-in-publish","postpublish":"in-publish && npm run clean || not-in-publish"},"repository":{"type":"git","url":"git+https://github.com/bjoerge/debounce-promise.git"},"keywords":["promise","batch","accumulate","debounce","throttle","ratelimit"],"author":{"name":"Bjørge Næss"},"license":"MIT","bugs":{"url":"https://github.com/bjoerge/debounce-promise/issues"},"homepage":"https://github.com/bjoerge/debounce-promise","devDependencies":{"babel-cli":"^6.5.2","babel-plugin-transform-async-to-generator":"^6.16.0","babel-polyfill":"^6.16.0","babel-preset-es2015":"^6.16.0","babel-register":"^6.16.3","eslint":"^3.8.0","in-publish":"^2.0.0","rimraf":"^2.5.4","snazzy":"^5.0.0","standard":"^8.4.0","tap":"^7.1.2"},"dependencies":{},"gitHead":"d85e8d1298e8789af13afa8267517b49a81d95d8","_id":"debounce-promise@3.1.2","_npmVersion":"6.4.1","_nodeVersion":"8.15.0","_npmUser":{"name":"bjoerge","email":"bjoerge@gmail.com"},"dist":{"integrity":"sha512-rZHcgBkbYavBeD9ej6sP56XfG53d51CD4dnaw989YX/nZ/ZJfgRx/9ePKmTNiUiyQvh4mtrMoS3OAWW+yoYtpg==","shasum":"320fb8c7d15a344455cd33cee5ab63530b6dc7c5","tarball":"http://registry-npm.ywwl.com/debounce-promise/download/debounce-promise-3.1.2.tgz","fileCount":13,"unpackedSize":18739,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJczyHjCRA9TVsSAnZWagAA/b8P/1dOpVku1y3BL2sXAN93\nQi1XLZcCO4NeSrhJX1kc3balVEJdh7TbtQanGqf8QfVYY8ErCZ1LVXFJttKC\n3GJqLG6E+43J0CUgIKCh3zL4EN5G7QCKJOs+UREwH+62AJDewnu72XMOOuAL\n/BAwtYF5nI4/LcZUPVY49BPI0rbGJOG5ikSpiYVCplXQkfF0Sj4hRk7JL9a/\nV4ixtAGOAWvWfo/WNtnLemoFTJ3ese7kyQs7n/aC1s9NSV2zcywLWb+M+EB7\nFrc70GB4cYdC1gsofVgHOWKIVQM+IrpZqL91S/uILS4arjrTMITmKa7UeJUt\n3aFgI4Iq9SGndbqxsAM7MUbpLkpkOIK0SHqPFvxb1zwQoEjJeD29+2bQt/Oh\nPaxWwBbnMQg7xl7EcniZAdWSR2ep2GsTdSSpol8sniwej7i8XrD0KtdPJG7s\nMgq5ybzfgjdbwioODKHL/VLuFMxedjkNz5ZaZgd2+DwoQkbU5h83oNloE5X5\nXTRjUa636LkirLYvvQIo3Ws6UJL1uxwhYDfyTYmOXAyRuDINMSV64xIpsRJd\nJoaoO0m+z8JnSO1Q62Wu0kySZH8mEzuS+eBcGIYx6n5VR4GdX4PMPDBgeBsc\nqF2HE673G9qlFF4BksAVpScYJELxcAWoi5p1naN/PWjcYq0fyXS9eiSOBARN\njohf\r\n=jr3j\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICoioc+gAwXayApuFwPKTVxfUFIYmwqob6K/nXtWPFOfAiEAi++hChGVB8EZ7nlwuQ5ecOOesv7bQezhFUQNz4//A3o="}],"size":5744,"noattachment":false,"key":"/debounce-promise/-/debounce-promise-3.1.2.tgz"},"maintainers":[{"name":"bjoerge","email":"bjoerge@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/debounce-promise_3.1.2_1557078499298_0.2929519344714415"},"_hasShrinkwrap":false,"readme":"# debounce-promise\n\n[![Build Status](https://travis-ci.org/bjoerge/debounce-promise.svg)](https://travis-ci.org/bjoerge/debounce-promise)\n[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n\n[![NPM](https://nodei.co/npm/debounce-promise.png)](https://nodei.co/npm/debounce-promise/)\n\nCreate a debounced version of a promise returning function\n\n## Install\n\n    npm i -S debounce-promise\n\n\n## Usage example\n\n```js\n\nvar debounce = require('debounce-promise')\n\nfunction expensiveOperation(value) {\n  return Promise.resolve(value)\n}\n\nvar saveCycles = debounce(expensiveOperation, 100);\n\n[1, 2, 3, 4].forEach(num => {\n  return saveCycles('call no #' + num).then(value => {\n    console.log(value)\n  })\n})\n\n// Will only call expensiveOperation once with argument `4` and print:\n//=> call no #4\n//=> call no #4\n//=> call no #4\n//=> call no #4\n```\n\n### With leading=true\n\n```js\nvar debounce = require('debounce-promise')\n\nfunction expensiveOperation(value) {\n  return Promise.resolve(value)\n}\n\nvar saveCycles = debounce(expensiveOperation, 100, {leading: true});\n\n[1, 2, 3, 4].forEach(num => {\n  return saveCycles('call no #' + num).then(value => {\n    console.log(value)\n  })\n})\n\n//=> call no #1\n//=> call no #4\n//=> call no #4\n//=> call no #4\n```\n\n### With accumulate=true\n\n```js\nvar debounce = require('debounce-promise')\n\nfunction squareValues (argTuples) {\n  return Promise.all(argTuples.map(args => args[0] * args[0]))\n}\n\nvar square = debounce(squareValues, 100, {accumulate: true});\n\n[1, 2, 3, 4].forEach(num => {\n  return square(num).then(value => {\n    console.log(value)\n  })\n})\n\n//=> 1\n//=> 4\n//=> 9\n//=> 16\n```\n\n## Api\n`debounce(func, [wait=0], [{leading: true|false, accumulate: true|false})`\n\nReturns a debounced version of `func` that delays invoking until after `wait` milliseconds.\n\nSet `leading: true` if you\nwant to call `func` and return its promise immediately.\n\nSet `accumulate: true` if you want the debounced function to be called with an array of all the arguments received while waiting.\n\nSupports passing a function as the `wait` parameter, which provides a way to lazily or dynamically define a wait timeout.\n\n\n## Example timeline illustration\n\n```js\nfunction refresh() {\n  return fetch('/my/api/something')\n}\nconst debounced = debounce(refresh, 100)\n```\n\n```\ntime (ms) ->   0 ---  10  ---  50  ---  100 ---\n-----------------------------------------------\ndebounced()    | --- P(1) --- P(1) --- P(1) ---\nrefresh()      | --------------------- P(1) ---\n```\n\n```js\nconst debounced = debounce(refresh, 100, {leading: true})\n```\n```\ntime (ms) ->   0 ---  10  ---  50  ---  100 ---  110 ---\n--------------------------------------------------------\ndebounced()    | --- P(1) --- P(2) --- P(2) --- P(2) ---\nrefresh()      | --- P(1) --------------------- P(2) ---\n```\n","publish_time":1557078499417,"_cnpm_publish_time":1557078499417,"dist-tags":{"latest":"3.1.2"}}