@softsky/utils 2.5.1 → 2.5.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 +8 -1
- package/dist/control.d.ts +10 -3
- package/dist/control.js +20 -12
- package/dist/formatting.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,11 +107,18 @@ ${\textsf{\color{ForestGreen}const}}$ SEC_MS - Milliseconds in a second
|
|
|
107
107
|
## Control
|
|
108
108
|
Utils related to code execution flow.
|
|
109
109
|
|
|
110
|
-
${\textsf{\color{ForestGreen}const}}$
|
|
110
|
+
${\textsf{\color{ForestGreen}const}}$ SESSION_ID - Id generated only once per session
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
${\textsf{\color{CornflowerBlue}function}}$ UUID - Get universally unique string id.
|
|
114
114
|
You can get information then id was generated using extractUUIDDate(uuid)
|
|
115
|
+
- 13 char - timestamp
|
|
116
|
+
- 13 char - SESSION_ID
|
|
117
|
+
- 4 char - incremental id
|
|
118
|
+
|
|
119
|
+
30 char total.
|
|
120
|
+
|
|
121
|
+
USING CUSTOM TIMESTAMP MAY RESULT IN COLLISSIONS
|
|
115
122
|
|
|
116
123
|
---
|
|
117
124
|
${\textsf{\color{CornflowerBlue}function}}$ extractUUIDDate - Extract exact date of uuid generation
|
package/dist/control.d.ts
CHANGED
|
@@ -2,13 +2,20 @@
|
|
|
2
2
|
* Utils related to code execution flow.
|
|
3
3
|
*/
|
|
4
4
|
import { AwaitedObject, JSONSerializable } from './types';
|
|
5
|
-
/**
|
|
6
|
-
export declare const
|
|
5
|
+
/** Id generated only once per session */
|
|
6
|
+
export declare const SESSION_ID: string;
|
|
7
7
|
/**
|
|
8
8
|
* Get universally unique string id.
|
|
9
9
|
* You can get information then id was generated using extractUUIDDate(uuid)
|
|
10
|
+
* - 13 char - timestamp
|
|
11
|
+
* - 13 char - SESSION_ID
|
|
12
|
+
* - 4 char - incremental id
|
|
13
|
+
*
|
|
14
|
+
* 30 char total.
|
|
15
|
+
*
|
|
16
|
+
* USING CUSTOM TIMESTAMP MAY RESULT IN COLLISSIONS
|
|
10
17
|
*/
|
|
11
|
-
export declare function UUID(): string;
|
|
18
|
+
export declare function UUID(timestamp?: number): string;
|
|
12
19
|
/** Extract exact date of uuid generation */
|
|
13
20
|
export declare function extractUUIDDate(uuid: string): Date;
|
|
14
21
|
/**
|
package/dist/control.js
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utils related to code execution flow.
|
|
3
3
|
*/
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
let lastIncId = Math.floor(Math.random() * 0x1_00_00);
|
|
5
|
+
/** Id generated only once per session */
|
|
6
|
+
export const SESSION_ID = Math.floor(Math.random() * 0x10_00_00_00_00_00_00)
|
|
7
|
+
.toString(16)
|
|
8
|
+
.padStart(13, '0');
|
|
9
9
|
/**
|
|
10
10
|
* Get universally unique string id.
|
|
11
11
|
* You can get information then id was generated using extractUUIDDate(uuid)
|
|
12
|
+
* - 13 char - timestamp
|
|
13
|
+
* - 13 char - SESSION_ID
|
|
14
|
+
* - 4 char - incremental id
|
|
15
|
+
*
|
|
16
|
+
* 30 char total.
|
|
17
|
+
*
|
|
18
|
+
* USING CUSTOM TIMESTAMP MAY RESULT IN COLLISSIONS
|
|
12
19
|
*/
|
|
13
|
-
export function UUID() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
export function UUID(timestamp = Date.now()) {
|
|
21
|
+
let inc = (++lastIncId).toString(16).padStart(4, '0');
|
|
22
|
+
if (inc.length === 5) {
|
|
23
|
+
lastIncId = 0;
|
|
24
|
+
inc = '0000';
|
|
25
|
+
}
|
|
26
|
+
return `${timestamp.toString(16).padStart(13, '0')}${inc}${SESSION_ID}`;
|
|
19
27
|
}
|
|
20
28
|
/** Extract exact date of uuid generation */
|
|
21
29
|
export function extractUUIDDate(uuid) {
|
|
22
|
-
return new Date(Number.parseInt(uuid.slice(0,
|
|
30
|
+
return new Date(Number.parseInt(uuid.slice(0, 13), 16));
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
25
33
|
* Creates cached function. All arguments/results are cached.
|
package/dist/formatting.js
CHANGED
|
@@ -80,7 +80,7 @@ export function formatNumber(time, min = 0, ranges = FORMAT_NUMBER_RANGES) {
|
|
|
80
80
|
break;
|
|
81
81
|
if (time < start && !pad)
|
|
82
82
|
continue;
|
|
83
|
-
let value = (
|
|
83
|
+
let value = Math.floor(time / start).toString();
|
|
84
84
|
time %= start;
|
|
85
85
|
if (pad)
|
|
86
86
|
value = value.padStart(pad, '0');
|