@oscarpalmer/atoms 0.188.0 → 0.188.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/dist/index.mjs +7 -6
- package/dist/string/index.mjs +7 -6
- package/package.json +1 -1
- package/src/string/index.ts +13 -11
package/dist/index.mjs
CHANGED
|
@@ -3061,23 +3061,22 @@ function dedent(value, ...values) {
|
|
|
3061
3061
|
*/
|
|
3062
3062
|
function getUuid(html) {
|
|
3063
3063
|
const forHTML = html === true;
|
|
3064
|
-
let uuid;
|
|
3065
3064
|
while (true) {
|
|
3066
3065
|
const bytes = new Uint8Array(16);
|
|
3067
3066
|
crypto.getRandomValues(bytes);
|
|
3068
3067
|
bytes[6] = bytes[6] & 15 | 64;
|
|
3069
3068
|
bytes[8] = bytes[8] & 63 | 128;
|
|
3070
3069
|
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, ZERO)).join("");
|
|
3071
|
-
|
|
3072
|
-
|
|
3070
|
+
const first = hex.substring(0, 8);
|
|
3071
|
+
if (forHTML && NUMERICAL_PREFIX_PATTERN.test(first)) continue;
|
|
3072
|
+
return [
|
|
3073
|
+
first,
|
|
3073
3074
|
hex.substring(8, 12),
|
|
3074
3075
|
hex.substring(12, 16),
|
|
3075
3076
|
hex.substring(16, 20),
|
|
3076
3077
|
hex.substring(20, 32)
|
|
3077
|
-
].join(
|
|
3078
|
-
if (!forHTML || !NUMERICAL_PREFIX_PATTERN.test(uuid)) break;
|
|
3078
|
+
].join(forHTML ? DELIMITER_UUID_HTML : DELIMITER_UUID_DEFAULT);
|
|
3079
3079
|
}
|
|
3080
|
-
return uuid;
|
|
3081
3080
|
}
|
|
3082
3081
|
/**
|
|
3083
3082
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
@@ -3119,6 +3118,8 @@ function truncate(value, length, suffix) {
|
|
|
3119
3118
|
const truncatedLength = length - actualSuffixLength;
|
|
3120
3119
|
return `${value.slice(0, truncatedLength)}${actualSuffix}`;
|
|
3121
3120
|
}
|
|
3121
|
+
const DELIMITER_UUID_DEFAULT = "-";
|
|
3122
|
+
const DELIMITER_UUID_HTML = "_";
|
|
3122
3123
|
const NUMERICAL_PREFIX_PATTERN = /^\d/;
|
|
3123
3124
|
const ZERO = "0";
|
|
3124
3125
|
//#endregion
|
package/dist/string/index.mjs
CHANGED
|
@@ -32,23 +32,22 @@ function dedent(value, ...values) {
|
|
|
32
32
|
*/
|
|
33
33
|
function getUuid(html) {
|
|
34
34
|
const forHTML = html === true;
|
|
35
|
-
let uuid;
|
|
36
35
|
while (true) {
|
|
37
36
|
const bytes = new Uint8Array(16);
|
|
38
37
|
crypto.getRandomValues(bytes);
|
|
39
38
|
bytes[6] = bytes[6] & 15 | 64;
|
|
40
39
|
bytes[8] = bytes[8] & 63 | 128;
|
|
41
40
|
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, ZERO)).join("");
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const first = hex.substring(0, 8);
|
|
42
|
+
if (forHTML && NUMERICAL_PREFIX_PATTERN.test(first)) continue;
|
|
43
|
+
return [
|
|
44
|
+
first,
|
|
44
45
|
hex.substring(8, 12),
|
|
45
46
|
hex.substring(12, 16),
|
|
46
47
|
hex.substring(16, 20),
|
|
47
48
|
hex.substring(20, 32)
|
|
48
|
-
].join(
|
|
49
|
-
if (!forHTML || !NUMERICAL_PREFIX_PATTERN.test(uuid)) break;
|
|
49
|
+
].join(forHTML ? DELIMITER_UUID_HTML : DELIMITER_UUID_DEFAULT);
|
|
50
50
|
}
|
|
51
|
-
return uuid;
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
54
53
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
@@ -90,6 +89,8 @@ function truncate(value, length, suffix) {
|
|
|
90
89
|
const truncatedLength = length - actualSuffixLength;
|
|
91
90
|
return `${value.slice(0, truncatedLength)}${actualSuffix}`;
|
|
92
91
|
}
|
|
92
|
+
const DELIMITER_UUID_DEFAULT = "-";
|
|
93
|
+
const DELIMITER_UUID_HTML = "_";
|
|
93
94
|
const NUMERICAL_PREFIX_PATTERN = /^\d/;
|
|
94
95
|
const ZERO = "0";
|
|
95
96
|
//#endregion
|
package/package.json
CHANGED
package/src/string/index.ts
CHANGED
|
@@ -92,8 +92,6 @@ export function getUuid(): string;
|
|
|
92
92
|
export function getUuid(html?: unknown): string {
|
|
93
93
|
const forHTML = html === true;
|
|
94
94
|
|
|
95
|
-
let uuid: string;
|
|
96
|
-
|
|
97
95
|
while (true) {
|
|
98
96
|
const bytes = new Uint8Array(16);
|
|
99
97
|
|
|
@@ -105,20 +103,20 @@ export function getUuid(html?: unknown): string {
|
|
|
105
103
|
|
|
106
104
|
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, ZERO)).join('');
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
const first = hex.substring(0, 8);
|
|
107
|
+
|
|
108
|
+
if (forHTML && NUMERICAL_PREFIX_PATTERN.test(first)) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return [
|
|
113
|
+
first,
|
|
110
114
|
hex.substring(8, 12),
|
|
111
115
|
hex.substring(12, 16),
|
|
112
116
|
hex.substring(16, 20),
|
|
113
117
|
hex.substring(20, 32),
|
|
114
|
-
].join(
|
|
115
|
-
|
|
116
|
-
if (!forHTML || !NUMERICAL_PREFIX_PATTERN.test(uuid)) {
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
118
|
+
].join(forHTML ? DELIMITER_UUID_HTML : DELIMITER_UUID_DEFAULT);
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
return uuid;
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
/**
|
|
@@ -182,6 +180,10 @@ export function truncate(value: string, length: number, suffix?: string): string
|
|
|
182
180
|
|
|
183
181
|
// #region Variables
|
|
184
182
|
|
|
183
|
+
const DELIMITER_UUID_DEFAULT = '-';
|
|
184
|
+
|
|
185
|
+
const DELIMITER_UUID_HTML = '_';
|
|
186
|
+
|
|
185
187
|
const NUMERICAL_PREFIX_PATTERN = /^\d/;
|
|
186
188
|
|
|
187
189
|
const ZERO = '0';
|