{"_id":"gulp-debounce","_rev":"6-848a65486a1bfd81bc88d0558c05dfec","name":"gulp-debounce","time":{"modified":"2022-06-18T16:55:45.660Z","created":"2015-08-13T21:30:59.265Z","1.0.0":"2015-08-13T21:30:59.265Z","1.0.1":"2016-02-02T22:50:37.626Z","1.0.2":"2016-02-08T11:18:28.613Z"},"maintainers":[{"name":"mnzaki","email":"mnzaki@gmail.com"}],"dist-tags":{"latest":"1.0.2"},"description":"Debounce a gulp stream to prevent the same event firing multiple times","readme":"# [gulp](https://github.com/gulpjs/gulp)-debounce\n[![NPM version][npm-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![Dependency Status][depstat-image]][depstat-url]\n\nStream debouncing that works.\n\nThis plugin will debounce a stream, that means it will remove/collect duplicate\nsuccessive events and emit just one after a short timeout. This is useful if you\nwant to prevent unnecessary triggering of build logic when a file is changing\ntoo fast. For example because [vim][vim-answer] (or [Coda 2][coda-question]) is saving a copy\nand then deleting and moving the file, causing three events to trigger instead\nof one and your build system to churn along unnecessarily.\n\n\n## Installation\n\n`npm install --save-dev gulp-debounce`\n\n## Usage\n\nYou can use it to prevent unnecessary sass rebuilds:\n```js\nvar gulp       = require('gulp'),\n    size       = require('gulp-size'),\n    sass       = require('gulp-sass'),\n    watch      = require('gulp-watch'),\n    debounce   = require('gulp-debounce'),\n    sourcemaps = require('gulp-sourcemaps');\n\ngulp.task('watch', function () {\n  return gulp.src('src/**/*.scss')\n    .pipe(watch('src/**/*.scss'))\n    .pipe(debounce({ wait: 1000 }))\n    // whenever a scss file changes before 1000ms have elapsed\n    // since the last change, then the event will not be passed along\n    .pipe(sourcemaps.init())\n    .pipe(sass())\n    .pipe(sourcemaps.write('.'))\n    .pipe(gulp.dest('build'))\n    .pipe(size({showFiles: true}));\n});\n```\n\n## API\n\n### debounce([options])\n\nCreates a pass through stream that will debounce events passing through it,\nbundling similar events into just one.\n\n#### Options\n\n#### options.wait\nType: `Number`\nDefault: `1000`\n\n> Milliseconds to wait before letting an event through. If another event similar\n> to this one arrives in that time period, then the timer is restarted and another\n> `wait` interval must pass.\n\n#### options.immediate\nType: `Boolean`\nDefault: `false`\n\n> When `true`, the first event to arrive passes through, and then all other\n> matching events are dropped until the `wait` interval elapses.\n> You do *not* normally want this, use at your own risk.\n\n#### options.hashingFn\nType: `Function`\nDefault: `function (vinyl) { return vinyl.path; }`\n\n> The function used to hash events for comparison. The default is to use the\n> file path for comparison.\n\nYou could, for example, differentiate between `add`/`change` and `other`\nevents:\n\n```js\ngulp.watch('src/**/*.scss')\n.pipe(debounce({\n  wait: 1000,\n  hashingFn: function (vinyl) {\n    // this function will hash add/change events to:\n    // \"true-path/from/vinyl/object\"\n    // and all other events to\n    // \"false-path/from/vinyl/object\"\n    var t = vinyl.event === 'add' || vinyl.event === 'change';\n    return t+\"-\"+vinyl.path;\n  }\n}))\n```\n\n## License\n\nMIT (c) 2016 Mina Nagy Zaki (mnzaki@gmail.com)\n\n[npm-url]: https://npmjs.org/package/gulp-debounce\n[npm-image]: http://img.shields.io/npm/v/gulp-debounce.svg?style=flat\n[npm-downloads-image]: https://img.shields.io/npm/dt/gulp-debounce.svg\n\n[depstat-url]: https://david-dm.org/mnzaki/gulp-debounce\n[depstat-image]: http://img.shields.io/david/mnzaki/gulp-debounce.svg?style=flat\n\n[coda-question]: http://stackoverflow.com/questions/21608480/gulp-js-watch-task-runs-twice-when-saving-files\n[vim-answer]: http://stackoverflow.com/a/23309948/2115616\n","versions":{"1.0.1":{"name":"gulp-debounce","version":"1.0.1","description":"Debounce a gulp stream to prevent the same event firing multiple times","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+ssh://git@github.com/mnzaki/gulp-debounce.git"},"keywords":["gulp","debounce","stream","watch","gulpplugin","gulp-plugin"],"author":{"name":"Mina Nagy Zaki","email":"mnzaki@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/mnzaki/gulp-debounce/issues"},"homepage":"https://github.com/mnzaki/gulp-debounce#readme","dependencies":{"gulp-util":"^3.0.7","through":"^2.3.8"},"engine":"node >= 0.10","gitHead":"6d99663e8af71f2b26d7c1fa73db60ec220af916","_id":"gulp-debounce@1.0.1","_shasum":"6aefbfbdcdcd8ce54105d33351d962aaa2c11335","_from":".","_npmVersion":"3.5.3","_nodeVersion":"5.4.1","_npmUser":{"name":"mnzaki","email":"mnzaki@gmail.com"},"dist":{"shasum":"6aefbfbdcdcd8ce54105d33351d962aaa2c11335","tarball":"https://registry.npmjs.org/gulp-debounce/-/gulp-debounce-1.0.1.tgz","integrity":"sha512-Kst2dUaNFy3U2BAga75opQdXwc8oVfNVMWROQbck2eh+3CKE/dOlUO1yqL/uY7/wHet3cT645SnFAztYbgqvug==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCj/6O5hHSVTRUdk6OB9j074g+oVJfTyN7vool4RRoNXgIgCxSB4eDsm3uKapl2fQ5wKGKn9celrh9wmjC4VB+LwOs="}]},"maintainers":[{"name":"mnzaki","email":"mnzaki@gmail.com"}],"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/gulp-debounce-1.0.1.tgz_1454453435186_0.34924856876023114"}},"1.0.2":{"name":"gulp-debounce","version":"1.0.2","description":"Debounce a gulp stream to prevent the same event firing multiple times","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+ssh://git@github.com/mnzaki/gulp-debounce.git"},"keywords":["gulp","debounce","stream","events","watch","gulpplugin","gulp-plugin"],"author":{"name":"Mina Nagy Zaki","email":"mnzaki@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/mnzaki/gulp-debounce/issues"},"homepage":"https://github.com/mnzaki/gulp-debounce#readme","dependencies":{"through":"^2.3.8"},"engine":"node >= 0.10","gitHead":"0eb1922360d68ffaf5afbb17913ef736af2bb5d7","_id":"gulp-debounce@1.0.2","_shasum":"0b943e812973e3003f980d88fc0d77e7996d9db9","_from":".","_npmVersion":"3.5.3","_nodeVersion":"5.4.1","_npmUser":{"name":"mnzaki","email":"mnzaki@gmail.com"},"dist":{"shasum":"0b943e812973e3003f980d88fc0d77e7996d9db9","tarball":"https://registry.npmjs.org/gulp-debounce/-/gulp-debounce-1.0.2.tgz","integrity":"sha512-Vz9LwUeCOW0GU8sND1lT842qaBlk/UFyBfu2ML74MuCmex3I1LB4bLALO1rqo0oTIgT3QapaQUKFg5RtAkBYEA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDlCFuzS5sObbJRWwu0zxUQL4oWb2p6eYvkRqbwJkjFugIhAM0uTMcnHvKyj9JqVo5koZUFHa9k8a5DGIP5LfsWNWeJ"}]},"maintainers":[{"name":"mnzaki","email":"mnzaki@gmail.com"}],"_npmOperationalInternal":{"host":"packages-5-east.internal.npmjs.com","tmp":"tmp/gulp-debounce-1.0.2.tgz_1454930307295_0.1912014246918261"}}},"homepage":"https://github.com/mnzaki/gulp-debounce#readme","keywords":["gulp","debounce","stream","events","watch","gulpplugin","gulp-plugin"],"repository":{"type":"git","url":"git+ssh://git@github.com/mnzaki/gulp-debounce.git"},"author":{"name":"Mina Nagy Zaki","email":"mnzaki@gmail.com"},"bugs":{"url":"https://github.com/mnzaki/gulp-debounce/issues"},"license":"MIT","readmeFilename":"README.md"}