🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

time-loom

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

time-loom - npm Package Compare versions

Comparing version
1.0.3
to
1.1.0
+19
dist/index.js
"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);
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,mDAAiC"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":""}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debounce = void 0;
const debounce = (func, delay) => {
let timeoutId;
return function (...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
};
exports.debounce = debounce;
//# sourceMappingURL=debounce.js.map
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/utils/debounce.ts"],"names":[],"mappings":";;;AAEO,MAAM,QAAQ,GAAG,CAAC,IAAiB,EAAE,KAAa,EAAe,EAAE;IACtE,IAAI,SAAyB,CAAC;IAC9B,OAAO,UAAU,GAAG,IAAW;QAC3B,YAAY,CAAC,SAAS,CAAC,CAAC;QACxB,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3B,CAAC,EAAE,KAAK,CAAC,CAAC;IACd,CAAC,CAAC;AACN,CAAC,CAAA;AARY,QAAA,QAAQ,YAQpB"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
const throttle = (func, interval) => {
let lastExecuted = 0;
return function (...args) {
const now = Date.now();
if (now - lastExecuted >= interval) {
func.apply(this, args);
lastExecuted = now;
}
};
};
exports.throttle = throttle;
//# sourceMappingURL=throttle.js.map
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../src/utils/throttle.ts"],"names":[],"mappings":";;;AAEO,MAAM,QAAQ,GAAG,CAAC,IAAiB,EAAE,QAAgB,EAAe,EAAE;IACzE,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,OAAO,UAAU,GAAG,IAAW;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,GAAG,GAAG,YAAY,IAAI,QAAQ,EAAE,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACvB,YAAY,GAAG,GAAG,CAAC;QACvB,CAAC;IACL,CAAC,CAAC;AACN,CAAC,CAAC;AATW,QAAA,QAAQ,YASnB"}
+7
-4
{
"name": "time-loom",
"version": "1.0.3",
"version": "1.1.0",
"description": "",
"main": "dist/src/index.js",
"type": "module",
"main": "dist/index.js",
"types": "src/index.d.ts",
"files": [
"dist/**/*"
],
"scripts": {

@@ -25,2 +28,2 @@ "build": "tsc",

}
}
}

@@ -18,3 +18,3 @@ # Time Loom

const { debounce, throttle } = require('time-loom');
import { debounce, throttle } from "time-loom";

@@ -21,0 +21,0 @@ // Example usage of debounce

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../src/index");
jest.useFakeTimers();
describe('Debouncing Utility', () => {
describe('debounce', () => {
it('should debounce a function', () => {
const callback = jest.fn();
const debouncedFunction = (0, index_1.debounce)(callback, 100);
debouncedFunction();
jest.advanceTimersByTime(50);
debouncedFunction();
jest.advanceTimersByTime(50);
// The callback should not have been called yet
expect(callback).not.toHaveBeenCalled();
// Advance timers to trigger the debounced function
jest.advanceTimersByTime(100);
// Now, the callback should be called once
expect(callback).toHaveBeenCalledTimes(1);
});
});
});
//# sourceMappingURL=debounce.test.js.map
{"version":3,"file":"debounce.test.js","sourceRoot":"","sources":["../../__test__/debounce.test.ts"],"names":[],"mappings":";;AAAA,wCAAwC;AAExC,IAAI,CAAC,aAAa,EAAE,CAAC;AACrB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;QACxB,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;YAC3B,MAAM,iBAAiB,GAAG,IAAA,gBAAQ,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAElD,iBAAiB,EAAE,CAAC;YACpB,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;YAC7B,iBAAiB,EAAE,CAAC;YACpB,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;YAC7B,+CAA+C;YAC/C,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;YACxC,mDAAmD;YACnD,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC9B,0CAA0C;YAC1C,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../src/index");
jest.useFakeTimers();
describe('Throttling Utility', () => {
describe('throttle', () => {
it('should throttle a function', () => {
const callback = jest.fn();
const throttledFunction = (0, index_1.throttle)(callback, 100);
throttledFunction();
jest.advanceTimersByTime(50);
throttledFunction();
// Advance timers to trigger the throttled function
jest.advanceTimersByTime(50);
// Now, the callback should be called once
expect(callback).toHaveBeenCalledTimes(1);
});
});
});
//# sourceMappingURL=throttle.test.js.map
{"version":3,"file":"throttle.test.js","sourceRoot":"","sources":["../../__test__/throttle.test.ts"],"names":[],"mappings":";;AAAA,wCAAwC;AAExC,IAAI,CAAC,aAAa,EAAE,CAAC;AACrB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAChC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;QACxB,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;YAC3B,MAAM,iBAAiB,GAAG,IAAA,gBAAQ,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAElD,iBAAiB,EAAE,CAAC;YACpB,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;YAC7B,iBAAiB,EAAE,CAAC;YACpB,mDAAmD;YACnD,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;YAC7B,0CAA0C;YAC1C,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debounce = void 0;
const debounce = (func, delay) => {
let timeoutId;
return function (...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
};
exports.debounce = debounce;
//# sourceMappingURL=debounce.js.map
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/debounce.ts"],"names":[],"mappings":";;;AAEO,MAAM,QAAQ,GAAG,CAAC,IAAiB,EAAE,KAAa,EAAe,EAAE;IACtE,IAAI,SAAyB,CAAC;IAC9B,OAAO,UAAU,GAAG,IAAW;QAC3B,YAAY,CAAC,SAAS,CAAC,CAAC;QACxB,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3B,CAAC,EAAE,KAAK,CAAC,CAAC;IACd,CAAC,CAAC;AACN,CAAC,CAAA;AARY,QAAA,QAAQ,YAQpB"}
"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("./debounce"), exports);
__exportStar(require("./throttle"), exports);
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,6CAA2B"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
const throttle = (func, interval) => {
let lastExecuted = 0;
return function (...args) {
const now = Date.now();
if (now - lastExecuted >= interval) {
func.apply(this, args);
lastExecuted = now;
}
};
};
exports.throttle = throttle;
//# sourceMappingURL=throttle.js.map
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../src/throttle.ts"],"names":[],"mappings":";;;AAEO,MAAM,QAAQ,GAAG,CAAC,IAAiB,EAAE,QAAgB,EAAe,EAAE;IACzE,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,OAAO,UAAU,GAAG,IAAW;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,GAAG,GAAG,YAAY,IAAI,QAAQ,EAAE,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACvB,YAAY,GAAG,GAAG,CAAC;QACvB,CAAC;IACL,CAAC,CAAC;AACN,CAAC,CAAC;AATW,QAAA,QAAQ,YASnB"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
{
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}
import { AnyFunction } from "./types";
export const debounce = (func: AnyFunction, delay: number): AnyFunction => {
let timeoutId: NodeJS.Timeout;
return function (...args: any[]): void {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
export * from './debounce';
export * from './throttle';
import { AnyFunction } from "./types";
export const throttle = (func: AnyFunction, interval: number): AnyFunction => {
let lastExecuted = 0;
return function (...args: any[]): void {
const now = Date.now();
if (now - lastExecuted >= interval) {
func.apply(this, args);
lastExecuted = now;
}
};
};
export type AnyFunction = (...args: any[]) => void;
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES6",
"baseUrl": "src",
"outDir": "dist",
"sourceMap": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"esModuleInterop": true
},
"include": [
"src/**/*",
"__test__"
],
}