topkat-utils 1.2.112 → 1.2.116
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/coverage/clover.xml +176 -97
- package/coverage/coverage-final.json +16 -15
- package/coverage/lcov-report/clean-stack-trace.ts.html +1 -1
- package/coverage/lcov-report/config.ts.html +1 -1
- package/coverage/lcov-report/error-utils.ts.html +1 -1
- package/coverage/lcov-report/index.html +43 -28
- package/coverage/lcov-report/is-empty.ts.html +1 -1
- package/coverage/lcov-report/is-nodejs.ts.html +1 -1
- package/coverage/lcov-report/is-object.ts.html +1 -1
- package/coverage/lcov-report/isset.ts.html +1 -1
- package/coverage/lcov-report/logger-utils.ts.html +65 -47
- package/coverage/lcov-report/loop-utils.ts.html +1 -1
- package/coverage/lcov-report/math-utils.ts.html +232 -0
- package/coverage/lcov-report/object-utils.ts.html +1 -1
- package/coverage/lcov-report/regexp-utils.ts.html +1 -1
- package/coverage/lcov-report/remove-circular-json-stringify.ts.html +1 -1
- package/coverage/lcov-report/string-utils.ts.html +1 -1
- package/coverage/lcov-report/timer-utils.ts.html +69 -9
- package/coverage/lcov-report/transaction-utils.ts.html +1 -1
- package/coverage/lcov.info +237 -104
- package/dist/src/logger-utils.d.ts +2 -1
- package/dist/src/logger-utils.js +8 -2
- package/dist/src/logger-utils.js.map +1 -1
- package/dist/src/timer-utils.d.ts +13 -0
- package/dist/src/timer-utils.js +21 -1
- package/dist/src/timer-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/logger-utils.ts +8 -2
- package/src/timer-utils.ts +20 -0
package/src/timer-utils.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
//----------------------------------------
|
|
5
5
|
import { cliProgressBar, C } from './logger-utils'
|
|
6
6
|
import { DescriptiveError } from './error-utils'
|
|
7
|
+
import { round2 } from './math-utils'
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
export async function timeout(ms, fn = () => { /* */ }) { return new Promise(res => setTimeout(res, ms)).then(fn) }
|
|
@@ -66,4 +67,23 @@ export async function retryWithDelay(
|
|
|
66
67
|
await timeout(n * 1000)
|
|
67
68
|
await callback()
|
|
68
69
|
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Use this timer to measure code performances.
|
|
73
|
+
* @example ```
|
|
74
|
+
const time = perfTimer()
|
|
75
|
+
|
|
76
|
+
for(let i = 0; i < 9999;i++) longProcess()
|
|
77
|
+
|
|
78
|
+
console.log('Process took ' + time.end())
|
|
79
|
+
```
|
|
80
|
+
*/
|
|
81
|
+
export function perfTimer(unit: 'ms' | 'seconds' = 'seconds') {
|
|
82
|
+
return {
|
|
83
|
+
start: Date.now(),
|
|
84
|
+
end() {
|
|
85
|
+
const msSinceStart = Date.now() - this.start
|
|
86
|
+
return unit === 'ms' ? msSinceStart + ' ' + unit : round2(msSinceStart / 1000) + ' ' + unit
|
|
87
|
+
}
|
|
88
|
+
}
|
|
69
89
|
}
|