diff --git a/lib/node_modules/@stdlib/utils/debounce/README.md b/lib/node_modules/@stdlib/utils/debounce/README.md new file mode 100644 index 000000000000..39532ae9543d --- /dev/null +++ b/lib/node_modules/@stdlib/utils/debounce/README.md @@ -0,0 +1,60 @@ + + +# Debounce + +> Trigger a function only once in the given time interval. + +
+ +## Usage + +```javascript +const debounce = require( '@stdlib/utils/debounce' ); +``` + +#### debounce( fun, wait ) + +You can debounce a callback for a `300ms` period: + +```javascript +const debounce = require( '@stdlib/utils/debounce' ); +const debouncedCallback = debounce(() => { + someFunction(); + console.log("Function is done"); +}, 300); +``` + +You can pass a function directly as the first argument. + +```javascript +const debounce = require( '@stdlib/utils/debounce' ); +const debouncedFunction = debounce(someFunction, 300); +``` + +
+ + + + + + diff --git a/lib/node_modules/@stdlib/utils/debounce/lib/index.js b/lib/node_modules/@stdlib/utils/debounce/lib/index.js new file mode 100644 index 000000000000..27c4b0604cf9 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/debounce/lib/index.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Trigger a function only once in the given time interval. +* +* @param {Function} fun - the function to debounce +* @param {number} wait - the interval to wait +* @returns {boolean} boolean indicating if the property was successfully set +* @module @stdlib/utils/debounce +* +* @example +* const debounce = require( '@stdlib/utils/debounce' ); +* +* const debouncedCallback = debounce(() => { +* someFunction(); +* console.log("Function is done"); +* }, 300); +* +* @example +* const debounce = require( '@stdlib/utils/debounce' ); +* +* const debouncedFunction = debounce(someFunction, 300); +*/ + +function debounce(fun, wait) { + let timeoutId; + return function(...args) { + if (timeoutId) { + clearTimeout(timeoutId); + } + timeoutId = setTimeout(() => { + fun.apply(null, args); + }, wait); + } +} + + +// EXPORTS // + +module.exports = debounce; diff --git a/lib/node_modules/@stdlib/utils/debounce/package.json b/lib/node_modules/@stdlib/utils/debounce/package.json new file mode 100644 index 000000000000..0518942ed913 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/debounce/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/utils/debounce", + "version": "0.0.0", + "description": "Trigger a function only once in the given time interval.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "debounce", + "settimeout", + "timeout", + "throttle" + ] +}