@softsky/utils 2.4.0 → 2.5.1

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 CHANGED
@@ -107,7 +107,14 @@ ${\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}}$ UUID - Get unique id
110
+ ${\textsf{\color{ForestGreen}const}}$ generateNumberId - Get unique number id
111
+
112
+ ---
113
+ ${\textsf{\color{CornflowerBlue}function}}$ UUID - Get universally unique string id.
114
+ You can get information then id was generated using extractUUIDDate(uuid)
115
+
116
+ ---
117
+ ${\textsf{\color{CornflowerBlue}function}}$ extractUUIDDate - Extract exact date of uuid generation
111
118
 
112
119
  ---
113
120
  ${\textsf{\color{CornflowerBlue}function}}$ createCashedFunction - Creates cached function. All arguments/results are cached.
package/dist/control.d.ts CHANGED
@@ -2,8 +2,15 @@
2
2
  * Utils related to code execution flow.
3
3
  */
4
4
  import { AwaitedObject, JSONSerializable } from './types';
5
- /** Get unique id */
6
- export declare const UUID: () => number;
5
+ /** Get unique number id */
6
+ export declare const generateNumberId: () => number;
7
+ /**
8
+ * Get universally unique string id.
9
+ * You can get information then id was generated using extractUUIDDate(uuid)
10
+ */
11
+ export declare function UUID(): string;
12
+ /** Extract exact date of uuid generation */
13
+ export declare function extractUUIDDate(uuid: string): Date;
7
14
  /**
8
15
  * Creates cached function. All arguments/results are cached.
9
16
  * Returns [
package/dist/control.js CHANGED
@@ -1,9 +1,26 @@
1
1
  /**
2
2
  * Utils related to code execution flow.
3
3
  */
4
+ let stringIdInc = 0;
4
5
  let _uuid = Date.now() * 1000;
5
- /** Get unique id */
6
- export const UUID = () => _uuid++;
6
+ /** Get unique number id */
7
+ export const generateNumberId = () => _uuid++;
8
+ const SESSION_ID = ((Math.random() * 2_147_483_648) | 0).toString(16);
9
+ /**
10
+ * Get universally unique string id.
11
+ * You can get information then id was generated using extractUUIDDate(uuid)
12
+ */
13
+ export function UUID() {
14
+ if (stringIdInc === 46_655)
15
+ stringIdInc = 0;
16
+ else
17
+ stringIdInc++;
18
+ return `${Date.now().toString(36).padStart(11, '0')}${(++stringIdInc).toString(36).padStart(3, '0')}${SESSION_ID}`;
19
+ }
20
+ /** Extract exact date of uuid generation */
21
+ export function extractUUIDDate(uuid) {
22
+ return new Date(Number.parseInt(uuid.slice(0, 11), 36));
23
+ }
7
24
  /**
8
25
  * Creates cached function. All arguments/results are cached.
9
26
  * Returns [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softsky/utils",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "JavaScript/TypeScript utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {