@softsky/utils 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +10 -0
- package/dist/types.d.ts +2 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -108,6 +108,8 @@ it will still check them by reference.
|
|
|
108
108
|
|
|
109
109
|
## time
|
|
110
110
|
Timers, CRON, etc.
|
|
111
|
+
### function measurePerformance
|
|
112
|
+
Measure performance of a function
|
|
111
113
|
### function cronInterval
|
|
112
114
|
Like setInterval but with cron. Returns clear function.
|
|
113
115
|
### function getNextCron
|
package/dist/time.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Timers, CRON, etc.
|
|
3
3
|
*/
|
|
4
|
+
/** Measure performance of a function */
|
|
5
|
+
export declare function measurePerformance(function_: () => unknown, timeCheck?: number): number;
|
|
4
6
|
/** Like setInterval but with cron. Returns clear function. */
|
|
5
7
|
export declare function cronInterval(function_: () => unknown, cronString: string): () => void;
|
|
6
8
|
/** Find next cron tick after passed date */
|
package/dist/time.js
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { HOUR_MS } from './consts';
|
|
5
5
|
import { ValidationError } from './errors';
|
|
6
|
+
/** Measure performance of a function */
|
|
7
|
+
export function measurePerformance(function_, timeCheck = 16.6) {
|
|
8
|
+
const endTime = performance.now() + timeCheck;
|
|
9
|
+
let executions = 0;
|
|
10
|
+
while (performance.now() < endTime) {
|
|
11
|
+
function_();
|
|
12
|
+
executions++;
|
|
13
|
+
}
|
|
14
|
+
return executions;
|
|
15
|
+
}
|
|
6
16
|
/** Like setInterval but with cron. Returns clear function. */
|
|
7
17
|
export function cronInterval(function_, cronString) {
|
|
8
18
|
let timeout;
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/** Make keys in object optional */
|
|
5
5
|
export type Optional<T, K extends keyof any> = Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>;
|
|
6
|
+
/** Get contructor type of an instance */
|
|
7
|
+
export type Constructor<T> = abstract new (..._arguments: never[]) => T;
|
|
6
8
|
/** Recursively resolves promises in objects and arrays */
|
|
7
9
|
export type AwaitedObject<T> = {
|
|
8
10
|
[K in keyof T]: T[K] extends Promise<infer U> ? U : T[K] extends object ? AwaitedObject<T[K]> : T[K];
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softsky/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "JavaScript/TypeScript utilities",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "eslint \"./src/**/*.ts\" --fix && tsc",
|
|
8
|
-
"gen-readme": "bun ./generate-readme.ts"
|
|
8
|
+
"gen-readme": "bun ./generate-readme.ts",
|
|
9
|
+
"prepare": "bun run lint && bun run gen-readme"
|
|
9
10
|
},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|