Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@statx/utils

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@statx/utils - npm Package Compare versions

Comparing version
1.2.0
to
1.2.1
+3
build/throttle.d.ts
type Func = (...args: any[]) => any;
export declare const throttle: <F extends Func>(f: F, time: number) => (...args: Parameters<F>) => Promise<ReturnType<F>>;
export {};
/* eslint-disable @typescript-eslint/no-explicit-any */
export const throttle = (f, time) => {
let lastCall = 0;
let timer = 0;
const promises = [];
return (...args) => {
return new Promise((r) => {
const currtime = Date.now();
const diffTime = currtime - lastCall;
if (diffTime > time || lastCall === 0) {
r(f(...args));
lastCall = currtime;
return;
}
promises.push(r);
if (timer) {
return;
}
timer = setTimeout(() => {
const data = f(...args);
promises.forEach((r) => r(data));
timer = 0;
lastCall = currtime;
}, time);
});
};
};
//# sourceMappingURL=throttle.js.map
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../src/throttle.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAKvD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,CAAI,EACJ,IAAY,EAC0C,EAAE;IACxD,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,KAAK,GAA4B,CAAC,CAAA;IAEtC,MAAM,QAAQ,GAA8B,EAAE,CAAA;IAE9C,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,OAAO,IAAI,OAAO,CAAgB,CAAC,CAAC,EAAE,EAAE;YACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAC3B,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;YAEpC,IAAI,QAAQ,GAAG,IAAI,IAAI,QAAQ,KAAK,CAAC,EAAE;gBACrC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;gBACb,QAAQ,GAAG,QAAQ,CAAA;gBACnB,OAAM;aACP;YACD,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAChB,IAAI,KAAK,EAAE;gBACT,OAAM;aACP;YACD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACtB,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;gBACvB,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;gBAChC,KAAK,GAAG,CAAC,CAAA;gBACT,QAAQ,GAAG,QAAQ,CAAA;YACrB,CAAC,EAAE,IAAI,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC,CAAA"}
/* eslint-disable @typescript-eslint/no-explicit-any */
type Func = (...args: any[]) => any
type Promises<T> = (value: PromiseLike<T>) => void
export const throttle = <F extends Func>(
f: F,
time: number,
): ((...args: Parameters<F>) => Promise<ReturnType<F>>) => {
let lastCall = 0
let timer: NodeJS.Timeout | number = 0
const promises: Promises<ReturnType<F>>[] = []
return (...args: any[]) => {
return new Promise<ReturnType<F>>((r) => {
const currtime = Date.now()
const diffTime = currtime - lastCall
if (diffTime > time || lastCall === 0) {
r(f(...args))
lastCall = currtime
return
}
promises.push(r)
if (timer) {
return
}
timer = setTimeout(() => {
const data = f(...args)
promises.forEach((r) => r(data))
timer = 0
lastCall = currtime
}, time)
})
}
}
+1
-3

@@ -1,3 +0,1 @@

type Func = (...args: any[]) => any;
export declare const throttle: <F extends Func>(f: F, time: number) => (...args: Parameters<F>) => Promise<ReturnType<F>>;
export {};
export * from './throttle.js';

@@ -1,28 +0,2 @@

/* eslint-disable @typescript-eslint/no-explicit-any */
export const throttle = (f, time) => {
let lastCall = 0;
let timer = 0;
const promises = [];
return (...args) => {
return new Promise((r) => {
const currtime = Date.now();
const diffTime = currtime - lastCall;
if (diffTime > time || lastCall === 0) {
r(f(...args));
lastCall = currtime;
return;
}
promises.push(r);
if (timer) {
return;
}
timer = setTimeout(() => {
const data = f(...args);
promises.forEach((r) => r(data));
timer = 0;
lastCall = currtime;
}, time);
});
};
};
export * from './throttle.js';
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAKvD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,CAAI,EACJ,IAAY,EAC0C,EAAE;IACxD,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,KAAK,GAA4B,CAAC,CAAA;IAEtC,MAAM,QAAQ,GAA8B,EAAE,CAAA;IAE9C,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,OAAO,IAAI,OAAO,CAAgB,CAAC,CAAC,EAAE,EAAE;YACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAC3B,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;YAEpC,IAAI,QAAQ,GAAG,IAAI,IAAI,QAAQ,KAAK,CAAC,EAAE;gBACrC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;gBACb,QAAQ,GAAG,QAAQ,CAAA;gBACnB,OAAM;aACP;YACD,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAChB,IAAI,KAAK,EAAE;gBACT,OAAM;aACP;YACD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACtB,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;gBACvB,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;gBAChC,KAAK,GAAG,CAAC,CAAA;gBACT,QAAQ,GAAG,QAAQ,CAAA;YACrB,CAAC,EAAE,IAAI,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
{
"name": "@statx/utils",
"version": "1.2.0",
"version": "1.2.1",
"private": false,

@@ -59,3 +59,3 @@ "description": "Extry tiny smart statx manager",

},
"gitHead": "c68923f3acd6f586c813dbf66894fcda3fc7ec2a"
"gitHead": "28a43df0d7829d37e288b90357438dbd8c776f6b"
}

@@ -1,37 +0,1 @@

/* eslint-disable @typescript-eslint/no-explicit-any */
type Func = (...args: any[]) => any
type Promises<T> = (value: PromiseLike<T>) => void
export const throttle = <F extends Func>(
f: F,
time: number,
): ((...args: Parameters<F>) => Promise<ReturnType<F>>) => {
let lastCall = 0
let timer: NodeJS.Timeout | number = 0
const promises: Promises<ReturnType<F>>[] = []
return (...args: any[]) => {
return new Promise<ReturnType<F>>((r) => {
const currtime = Date.now()
const diffTime = currtime - lastCall
if (diffTime > time || lastCall === 0) {
r(f(...args))
lastCall = currtime
return
}
promises.push(r)
if (timer) {
return
}
timer = setTimeout(() => {
const data = f(...args)
promises.forEach((r) => r(data))
timer = 0
lastCall = currtime
}, time)
})
}
}
export * from './throttle.js'