{"name":"debounce-promise","version":"1.1.0","description":"Create a debounced version of a promise returning function","main":"dist/index","scripts":{"test":"babel-tap test && eslint .","lint":"eslint .","prepublish":"babel index.js --source-maps --out-dir dist","postpublish":"rm -Rf dist"},"repository":{"type":"git","url":"git+https://github.com/bjoerge/debounce-promise.git"},"keywords":["promise","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":"^5.8.23","babel-eslint":"^4.1.3","babel-tap":"^3.0.1","eslint":"^1.7.1","eslint-config-bengler":"^0.3.5","eslint-plugin-import":"^0.8.1","tap":"^2.1.1"},"gitHead":"049cffaddba7c99ea4d3d0bcf864bfaf92f315b5","_id":"debounce-promise@1.1.0","_shasum":"ffa1ac87d09b8dd7613f07a6bbb2cec66f8a5c0f","_from":".","_npmVersion":"3.8.1","_nodeVersion":"4.4.0","_npmUser":{"name":"bjoerge","email":"bjoerge@gmail.com"},"dist":{"shasum":"ffa1ac87d09b8dd7613f07a6bbb2cec66f8a5c0f","tarball":"http://registry-npm.ywwl.com/debounce-promise/download/debounce-promise-1.1.0.tgz","integrity":"sha512-oMgtVTIODQTVl1J7GtFgX8HLwD8og6Xdnj3d6MiJQSOhW9XPBtr6v1x1Zwg63S81uG6u4gZfriASDwrJT6dGKA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCz9dz+23X/XFI8ldbuBrrmHd3ZivGDS4TzgVg4/b16VwIhAIQpC8cqAZec2E6Zw5jGI6MnS4PZ5qNomVPcDutl6nzW"}],"size":3496,"noattachment":false,"key":"/debounce-promise/-/debounce-promise-1.1.0.tgz"},"maintainers":[{"name":"bjoerge","email":"bjoerge@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/debounce-promise-1.1.0.tgz_1459498914282_0.3927962095476687"},"directories":{},"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":1459498916719,"_cnpm_publish_time":1459498916719,"dist-tags":{"latest":"3.1.2"}}