@universal-packages/time-measurer 1.4.0 → 1.4.2
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 +30 -27
- package/package.json +18 -5
- package/sleep.d.ts +1 -1
- package/sleep.js +2 -2
- package/sleep.js.map +1 -1
package/README.md
CHANGED
@@ -12,7 +12,9 @@ Time Measurer is a simple wrap for `process.hrtime.bigint` to measure time with
|
|
12
12
|
npm install @universal-packages/time-measurer
|
13
13
|
```
|
14
14
|
|
15
|
-
##
|
15
|
+
## Global methods
|
16
|
+
|
17
|
+
#### **`startMeasurement()`**
|
16
18
|
|
17
19
|
Creates a new TimeMeasurer instance to start a measurement.
|
18
20
|
|
@@ -31,6 +33,18 @@ getAll()
|
|
31
33
|
// > All records - 2.23ms
|
32
34
|
```
|
33
35
|
|
36
|
+
#### **`sleep(milliseconds: number)`**
|
37
|
+
|
38
|
+
Time measurer ships with a convenient sleep function that takes a single parameter `time` in milliseconds, internally it is just a promise with a timeout that resolves it.
|
39
|
+
|
40
|
+
```js
|
41
|
+
import { sleep } from '@universal-packages/time-measurer'
|
42
|
+
|
43
|
+
async function awaitable() {
|
44
|
+
await sleep(2000)
|
45
|
+
}
|
46
|
+
```
|
47
|
+
|
34
48
|
## TimeMeasurer
|
35
49
|
|
36
50
|
Class `TimeMeasurer` provides an instantiable interface to start measuring time from any part of your code. The measurement starts at instancing time.
|
@@ -53,22 +67,27 @@ getAll()
|
|
53
67
|
// > All records - 2.23ms
|
54
68
|
```
|
55
69
|
|
70
|
+
### Instance methods
|
71
|
+
|
72
|
+
#### **`start()`**
|
73
|
+
|
74
|
+
Resets the initial time.
|
75
|
+
|
76
|
+
#### **`stop()`**
|
77
|
+
|
78
|
+
Returns a measurement representing the time passed from when start was called.
|
79
|
+
|
56
80
|
## Measurement
|
57
81
|
|
58
82
|
A `Measurement` object is the time representation after a measure, it provides the interface to express time as a formatted string or even as a date object.
|
59
83
|
|
60
|
-
###
|
84
|
+
### Instance methods
|
61
85
|
|
62
|
-
|
86
|
+
#### **`toString(format: TimeFormat)`**
|
63
87
|
|
64
|
-
|
65
|
-
measurement.toString()
|
66
|
-
measurement.toString('Condensed')
|
67
|
-
measurement.toString('Human')
|
68
|
-
measurement.toString('Expressive')
|
69
|
-
```
|
88
|
+
Get the time representation as a string, this function takes one param `TimeFormat`, that can be one of `Condensed`, `Human`, `Expressive`, default: `Human`.
|
70
89
|
|
71
|
-
|
90
|
+
Example output
|
72
91
|
|
73
92
|
```
|
74
93
|
2hrs 35min 51.235sec
|
@@ -86,26 +105,10 @@ It will take into account parts of the representation that are not contributing
|
|
86
105
|
51.235 Seconds
|
87
106
|
```
|
88
107
|
|
89
|
-
|
108
|
+
#### **`toDate()`**
|
90
109
|
|
91
110
|
Get the time representation as a date object this can be helpful if you want to use the `Date` api to format or do whatever with the date.
|
92
111
|
|
93
|
-
```js
|
94
|
-
measurement.toDate()
|
95
|
-
```
|
96
|
-
|
97
|
-
## Sleep
|
98
|
-
|
99
|
-
Time measurer ships with a convenient sleep function that takes a single parameter `time` in milliseconds, internally it is just a promise with a timeout that resolves it.
|
100
|
-
|
101
|
-
```js
|
102
|
-
import { sleep } from '@universal-packages/time-measurer'
|
103
|
-
|
104
|
-
async function awaitable() {
|
105
|
-
await sleep(2000)
|
106
|
-
}
|
107
|
-
```
|
108
|
-
|
109
112
|
## Typescript
|
110
113
|
|
111
114
|
This library is developed in TypeScript and shipped fully typed.
|
package/package.json
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
{
|
2
2
|
"name": "@universal-packages/time-measurer",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.2",
|
4
4
|
"description": "Utility to measure routines times with precision",
|
5
5
|
"author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)",
|
6
6
|
"license": "MIT",
|
7
7
|
"main": "index.js",
|
8
8
|
"types": "index.d.ts",
|
9
|
-
"repository": "git://git@github.com
|
9
|
+
"repository": "git://git@github.com:universal-packages/universal-time-measurer.git",
|
10
10
|
"scripts": {
|
11
11
|
"build": "tsc --p tsconfig.dis.json",
|
12
12
|
"test": "jest --watch",
|
13
13
|
"test:full": "jest --coverage --verbose",
|
14
|
-
"test:clear": "jest --clearCache"
|
14
|
+
"test:clear": "jest --clearCache",
|
15
|
+
"format": "prettier --write \"./{src,tests}/**/*.{ts,tsx,js,jsx,json}\""
|
15
16
|
},
|
16
|
-
"dependencies": {},
|
17
17
|
"devDependencies": {
|
18
|
+
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
|
18
19
|
"@types/jest": "^28.1.0",
|
19
20
|
"@types/node": "^17.0.39",
|
20
21
|
"jest": "^28.1.0",
|
21
22
|
"jest-circus": "^28.1.0",
|
23
|
+
"prettier": "^2.8.7",
|
22
24
|
"ts-jest": "^28.0.4",
|
23
25
|
"typescript": "^4.7.3"
|
24
26
|
},
|
@@ -42,6 +44,17 @@
|
|
42
44
|
"semi": false,
|
43
45
|
"singleQuote": true,
|
44
46
|
"printWidth": 180,
|
45
|
-
"trailingComma": "none"
|
47
|
+
"trailingComma": "none",
|
48
|
+
"importOrder": [
|
49
|
+
"^[./]"
|
50
|
+
],
|
51
|
+
"importOrderSeparation": true,
|
52
|
+
"importOrderSortSpecifiers": true,
|
53
|
+
"importOrderParserPlugins": [
|
54
|
+
"typescript",
|
55
|
+
"jsx",
|
56
|
+
"classProperties",
|
57
|
+
"decorators-legacy"
|
58
|
+
]
|
46
59
|
}
|
47
60
|
}
|
package/sleep.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
/** Simple awaitable timeout to sleep the process */
|
2
|
-
export default function sleep(
|
2
|
+
export default function sleep(milliseconds: number): Promise<void>;
|
package/sleep.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
/** Simple awaitable timeout to sleep the process */
|
4
|
-
async function sleep(
|
5
|
-
return new Promise((resolve) => setTimeout(() => resolve(),
|
4
|
+
async function sleep(milliseconds) {
|
5
|
+
return new Promise((resolve) => setTimeout(() => resolve(), milliseconds));
|
6
6
|
}
|
7
7
|
exports.default = sleep;
|
8
8
|
//# sourceMappingURL=sleep.js.map
|
package/sleep.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../src/sleep.ts"],"names":[],"mappings":";;AAAA,oDAAoD;AACrC,KAAK,UAAU,KAAK,CAAC,
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../src/sleep.ts"],"names":[],"mappings":";;AAAA,oDAAoD;AACrC,KAAK,UAAU,KAAK,CAAC,YAAoB;IACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAkB,EAAE,CAAC,UAAU,CAAC,GAAS,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC,CAAA;AAClG,CAAC;AAFD,wBAEC"}
|