+0
-1
@@ -19,2 +19,1 @@ "use strict"; | ||
| __exportStar(require("./utils/throttle"), exports); | ||
| //# sourceMappingURL=index.js.map |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=types.js.map |
+18
-15
@@ -6,21 +6,25 @@ "use strict"; | ||
| var _a, _b; | ||
| let timeoutId; | ||
| let lastArgs; | ||
| let lastCallTime; | ||
| const leading = (_a = options === null || options === void 0 ? void 0 : options.leading) !== null && _a !== void 0 ? _a : false; | ||
| const trailing = (_b = options === null || options === void 0 ? void 0 : options.trailing) !== null && _b !== void 0 ? _b : true; | ||
| const maxWait = options === null || options === void 0 ? void 0 : options.maxWait; | ||
| var timeoutId; | ||
| var lastArgs; | ||
| var lastCallTime; | ||
| var leading = (_a = options === null || options === void 0 ? void 0 : options.leading) !== null && _a !== void 0 ? _a : false; | ||
| var trailing = (_b = options === null || options === void 0 ? void 0 : options.trailing) !== null && _b !== void 0 ? _b : true; | ||
| var maxWait = options === null || options === void 0 ? void 0 : options.maxWait; | ||
| function invokeFunc() { | ||
| if (lastArgs) { | ||
| lastCallTime = Date.now(); | ||
| func(...lastArgs); | ||
| func.apply(void 0, lastArgs); | ||
| lastArgs = null; | ||
| } | ||
| } | ||
| const debounced = function (...args) { | ||
| const currentTime = Date.now(); | ||
| var debounced = function () { | ||
| var args = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| args[_i] = arguments[_i]; | ||
| } | ||
| var currentTime = Date.now(); | ||
| if (!lastCallTime && !leading) { | ||
| lastCallTime = currentTime; | ||
| } | ||
| const remainingDelay = delay - (currentTime - lastCallTime); | ||
| var remainingDelay = delay - (currentTime - lastCallTime); | ||
| if (remainingDelay <= 0 || remainingDelay > delay) { | ||
@@ -32,3 +36,3 @@ if (timeoutId) { | ||
| lastCallTime = currentTime; | ||
| return func(...args); // Ensure to return the result of func | ||
| return func.apply(void 0, args); // Ensure to return the result of func | ||
| } | ||
@@ -40,3 +44,3 @@ else if (!timeoutId && trailing) { | ||
| }; | ||
| debounced.cancel = () => { | ||
| debounced.cancel = function () { | ||
| if (timeoutId) { | ||
@@ -49,3 +53,3 @@ clearTimeout(timeoutId); | ||
| }; | ||
| debounced.flush = () => { | ||
| debounced.flush = function () { | ||
| if (timeoutId) { | ||
@@ -57,3 +61,3 @@ clearTimeout(timeoutId); | ||
| if (maxWait !== undefined) { | ||
| const maxWaitHandler = () => { | ||
| var maxWaitHandler = function () { | ||
| if (timeoutId) { | ||
@@ -69,2 +73,1 @@ clearTimeout(timeoutId); | ||
| exports.debounce = debounce; | ||
| //# sourceMappingURL=debounce.js.map |
+15
-10
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.throttle = void 0; | ||
| function throttle(func, wait, options = {}) { | ||
| let timeout = null; | ||
| let previous = 0; | ||
| const throttled = function (...args) { | ||
| const now = Date.now(); | ||
| function throttle(func, wait, options) { | ||
| if (options === void 0) { options = {}; } | ||
| var timeout = null; | ||
| var previous = 0; | ||
| var throttled = function () { | ||
| var _this = this; | ||
| var args = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| args[_i] = arguments[_i]; | ||
| } | ||
| var now = Date.now(); | ||
| if (!previous && options.leading === false) | ||
| previous = now; | ||
| const remaining = wait - (now - previous); | ||
| var remaining = wait - (now - previous); | ||
| if (remaining <= 0 || remaining > wait) { | ||
@@ -21,10 +27,10 @@ if (timeout) { | ||
| else if (!timeout && options.trailing !== false) { | ||
| timeout = setTimeout(() => { | ||
| timeout = setTimeout(function () { | ||
| previous = options.leading === false ? 0 : Date.now(); | ||
| timeout = null; | ||
| func.apply(this, args); | ||
| func.apply(_this, args); | ||
| }, remaining); | ||
| } | ||
| }; | ||
| throttled.cancel = () => { | ||
| throttled.cancel = function () { | ||
| if (timeout) { | ||
@@ -39,2 +45,1 @@ clearTimeout(timeout); | ||
| exports.throttle = throttle; | ||
| //# sourceMappingURL=throttle.js.map |
+2
-2
| { | ||
| "name": "time-loom", | ||
| "version": "2.0.0", | ||
| "version": "2.0.1", | ||
| "description": "", | ||
@@ -11,3 +11,3 @@ "main": "dist/index.js", | ||
| "scripts": { | ||
| "clean": "del-cli ./build/*", | ||
| "clean": "del-cli ./dist/*", | ||
| "build": "npm run clean && tsc", | ||
@@ -14,0 +14,0 @@ "prepublishOnly": "npm test", |
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var index_1 = require("../src/index"); | ||
| jest.useFakeTimers(); | ||
| describe('Debouncing Utility', function () { | ||
| describe('debounce', function () { | ||
| it('should debounce a function', function () { | ||
| var callback = jest.fn(); | ||
| var debounced = (0, index_1.debounce)(callback, 100); | ||
| debounced(); | ||
| jest.advanceTimersByTime(50); | ||
| debounced(); | ||
| expect(callback).not.toHaveBeenCalled(); | ||
| jest.advanceTimersByTime(100); | ||
| expect(callback).toHaveBeenCalledTimes(1); | ||
| debounced.cancel(); | ||
| debounced.flush(); | ||
| }); | ||
| }); | ||
| }); |
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var index_1 = require("../src/index"); | ||
| jest.useFakeTimers(); | ||
| describe('Throttling Utility', function () { | ||
| describe('throttle', function () { | ||
| it('should throttle a function', function () { | ||
| var callback = jest.fn(); | ||
| var throttled = (0, index_1.throttle)(callback, 100); | ||
| throttled(); | ||
| jest.advanceTimersByTime(50); | ||
| throttled(); | ||
| expect(callback).toHaveBeenCalledTimes(1); | ||
| throttled.cancel(); | ||
| }); | ||
| }); | ||
| }); |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,mDAAiC"} |
| export * from './utils/debounce'; | ||
| export * from './utils/throttle'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./utils/debounce"), exports); | ||
| __exportStar(require("./utils/throttle"), exports); |
| export type AnyFunction = (...args: any[]) => void; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| import { DebounceOptions, DebouncedFunction } from "../types/debounce"; | ||
| export declare function debounce<T extends (...args: any[]) => void>(func: T, delay: number, options?: DebounceOptions): DebouncedFunction<T>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.debounce = void 0; | ||
| function debounce(func, delay, options) { | ||
| var _a, _b; | ||
| var timeoutId; | ||
| var lastArgs; | ||
| var lastCallTime; | ||
| var leading = (_a = options === null || options === void 0 ? void 0 : options.leading) !== null && _a !== void 0 ? _a : false; | ||
| var trailing = (_b = options === null || options === void 0 ? void 0 : options.trailing) !== null && _b !== void 0 ? _b : true; | ||
| var maxWait = options === null || options === void 0 ? void 0 : options.maxWait; | ||
| function invokeFunc() { | ||
| if (lastArgs) { | ||
| lastCallTime = Date.now(); | ||
| func.apply(void 0, lastArgs); | ||
| lastArgs = null; | ||
| } | ||
| } | ||
| var debounced = function () { | ||
| var args = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| args[_i] = arguments[_i]; | ||
| } | ||
| var currentTime = Date.now(); | ||
| if (!lastCallTime && !leading) { | ||
| lastCallTime = currentTime; | ||
| } | ||
| var remainingDelay = delay - (currentTime - lastCallTime); | ||
| if (remainingDelay <= 0 || remainingDelay > delay) { | ||
| if (timeoutId) { | ||
| clearTimeout(timeoutId); | ||
| timeoutId = null; | ||
| } | ||
| lastCallTime = currentTime; | ||
| return func.apply(void 0, args); // Ensure to return the result of func | ||
| } | ||
| else if (!timeoutId && trailing) { | ||
| lastArgs = args; | ||
| timeoutId = setTimeout(invokeFunc, remainingDelay); | ||
| } | ||
| }; | ||
| debounced.cancel = function () { | ||
| if (timeoutId) { | ||
| clearTimeout(timeoutId); | ||
| timeoutId = null; | ||
| lastArgs = null; | ||
| lastCallTime = 0; | ||
| } | ||
| }; | ||
| debounced.flush = function () { | ||
| if (timeoutId) { | ||
| clearTimeout(timeoutId); | ||
| invokeFunc(); | ||
| } | ||
| }; | ||
| if (maxWait !== undefined) { | ||
| var maxWaitHandler = function () { | ||
| if (timeoutId) { | ||
| clearTimeout(timeoutId); | ||
| invokeFunc(); | ||
| } | ||
| }; | ||
| setInterval(maxWaitHandler, maxWait); | ||
| } | ||
| return debounced; | ||
| } | ||
| exports.debounce = debounce; |
| import { ThrottleControl, ThrottleOptions } from "../types/throttle"; | ||
| export declare function throttle<T extends (...args: any[]) => void>(func: T, wait: number, options?: ThrottleOptions): T & ThrottleControl; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.throttle = void 0; | ||
| function throttle(func, wait, options) { | ||
| if (options === void 0) { options = {}; } | ||
| var timeout = null; | ||
| var previous = 0; | ||
| var throttled = function () { | ||
| var _this = this; | ||
| var args = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| args[_i] = arguments[_i]; | ||
| } | ||
| var now = Date.now(); | ||
| if (!previous && options.leading === false) | ||
| previous = now; | ||
| var remaining = wait - (now - previous); | ||
| if (remaining <= 0 || remaining > wait) { | ||
| if (timeout) { | ||
| clearTimeout(timeout); | ||
| timeout = null; | ||
| } | ||
| previous = now; | ||
| func.apply(this, args); | ||
| } | ||
| else if (!timeout && options.trailing !== false) { | ||
| timeout = setTimeout(function () { | ||
| previous = options.leading === false ? 0 : Date.now(); | ||
| timeout = null; | ||
| func.apply(_this, args); | ||
| }, remaining); | ||
| } | ||
| }; | ||
| throttled.cancel = function () { | ||
| if (timeout) { | ||
| clearTimeout(timeout); | ||
| timeout = null; | ||
| } | ||
| previous = 0; | ||
| }; | ||
| return throttled; | ||
| } | ||
| exports.throttle = throttle; |
| {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":""} |
| {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/utils/debounce.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ,CACpB,IAAO,EACP,KAAa,EACb,OAAyB;;IAEzB,IAAI,SAAgC,CAAC;IACrC,IAAI,QAA8B,CAAC;IACnC,IAAI,YAAoB,CAAC;IAEzB,MAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,KAAK,CAAC;IAC1C,MAAM,QAAQ,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,IAAI,CAAC;IAC3C,MAAM,OAAO,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC;IAEjC,SAAS,UAAU;QACf,IAAI,QAAQ,EAAE,CAAC;YACX,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;YAClB,QAAQ,GAAG,IAAI,CAAC;QACpB,CAAC;IACL,CAAC;IAED,MAAM,SAAS,GAAyB,UAAU,GAAG,IAAmB;QACpE,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE/B,IAAI,CAAC,YAAY,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5B,YAAY,GAAG,WAAW,CAAC;QAC/B,CAAC;QAED,MAAM,cAAc,GAAG,KAAK,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,CAAC;QAE5D,I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,CAAC,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO,SAAgC,CAAC;AAC5C,CAAC;AAtCD,4BAsCC"} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
9411
-50.15%11
-59.26%137
-54.79%1
Infinity%