ctx-core 6.4.4 → 6.5.0
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/all/uuid/index.d.ts +2 -1
- package/all/uuid/index.js +16 -6
- package/all/uuid/index.test.ts +5 -2
- package/package.json +13 -6
package/all/uuid/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export {
|
|
|
3
3
|
uuid_ as _uuid,
|
|
4
4
|
uuid_ as uuid,
|
|
5
5
|
}
|
|
6
|
-
export declare function short_uuid_(
|
|
6
|
+
export declare function short_uuid_():string
|
|
7
|
+
export declare function uuid__compact(uuid:string):string
|
|
7
8
|
export declare function polyfill_uuid_(uuid?:string):string
|
package/all/uuid/index.js
CHANGED
|
@@ -5,21 +5,31 @@ export {
|
|
|
5
5
|
uuid_ as _uuid,
|
|
6
6
|
uuid_ as uuid,
|
|
7
7
|
}
|
|
8
|
+
export function short_uuid_() {
|
|
9
|
+
let uuid = crypto.randomUUID()
|
|
10
|
+
let str = ''
|
|
11
|
+
for (let i = 0; i < uuid.length; i += 2) {
|
|
12
|
+
if (uuid[i] === '-') ++i
|
|
13
|
+
str += String.fromCharCode(parseInt(uuid.slice(i, i + 2), 16))
|
|
14
|
+
}
|
|
15
|
+
return btoa(str).slice(0, 22)
|
|
16
|
+
}
|
|
8
17
|
/**
|
|
9
|
-
* @param {string}
|
|
18
|
+
* @param {string}uuid
|
|
10
19
|
* @returns {string}
|
|
11
20
|
* @private
|
|
12
21
|
*/
|
|
13
|
-
export function
|
|
14
|
-
uuid = (uuid ?? crypto.randomUUID()).replaceAll('-', '')
|
|
22
|
+
export function uuid__compact(uuid) {
|
|
15
23
|
let str = ''
|
|
16
|
-
for (let i = 0; i < uuid.length; i += 2)
|
|
24
|
+
for (let i = 0; i < uuid.length; i += 2) {
|
|
25
|
+
if (uuid[i] === '-') ++i
|
|
17
26
|
str += String.fromCharCode(parseInt(uuid.slice(i, i + 2), 16))
|
|
18
|
-
|
|
27
|
+
}
|
|
28
|
+
return btoa(str).slice(0, 22)
|
|
19
29
|
}
|
|
20
30
|
/**
|
|
21
31
|
* @returns {string}
|
|
22
|
-
* @see {
|
|
32
|
+
* @see {https://gist.github.com/LeverOne/1308368}
|
|
23
33
|
* @private
|
|
24
34
|
*/
|
|
25
35
|
export function polyfill_uuid_() {
|
package/all/uuid/index.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test } from 'uvu'
|
|
2
2
|
import { equal } from 'uvu/assert'
|
|
3
|
-
import { polyfill_uuid_, short_uuid_, uuid_ } from './index.js'
|
|
3
|
+
import { polyfill_uuid_, short_uuid_, uuid_, uuid__compact } from './index.js'
|
|
4
4
|
test('uuid_', ()=>{
|
|
5
5
|
equal(
|
|
6
6
|
uuid_().split('-').map(seg=>seg.length),
|
|
@@ -8,9 +8,11 @@ test('uuid_', ()=>{
|
|
|
8
8
|
})
|
|
9
9
|
test('short_uuid_', ()=>{
|
|
10
10
|
equal(short_uuid_().length, 22)
|
|
11
|
+
})
|
|
12
|
+
test('uuid__compact', ()=>{
|
|
11
13
|
const uuid = '8a88c23d-4a69-46ac-b975-1ab4590a470c'
|
|
12
14
|
const expected_short_uuid = 'iojCPUppRqy5dRq0WQpHDA'
|
|
13
|
-
equal(
|
|
15
|
+
equal(uuid__compact(uuid), expected_short_uuid)
|
|
14
16
|
// verify the isomorphic solution is the same as nodejs
|
|
15
17
|
equal(
|
|
16
18
|
Buffer
|
|
@@ -18,6 +20,7 @@ test('short_uuid_', ()=>{
|
|
|
18
20
|
.toString('base64')
|
|
19
21
|
.replace(/==$/, ''),
|
|
20
22
|
expected_short_uuid)
|
|
23
|
+
equal(uuid__compact('8a88c23d4a6946acb9751ab4590a470c'), expected_short_uuid)
|
|
21
24
|
})
|
|
22
25
|
test('polyfill_uuid_', ()=>{
|
|
23
26
|
equal(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -300,7 +300,7 @@
|
|
|
300
300
|
"@ctx-core/preprocess": "^0.1.2",
|
|
301
301
|
"@size-limit/preset-small-lib": "^11.0.2",
|
|
302
302
|
"@types/jsdom": "^21.1.6",
|
|
303
|
-
"@types/node": "^20.11.
|
|
303
|
+
"@types/node": "^20.11.20",
|
|
304
304
|
"@types/sinon": "^17.0.3",
|
|
305
305
|
"c8": "^9.1.0",
|
|
306
306
|
"check-dts": "^0.7.2",
|
|
@@ -389,18 +389,25 @@
|
|
|
389
389
|
"limit": "589 B"
|
|
390
390
|
},
|
|
391
391
|
{
|
|
392
|
-
"name": "
|
|
392
|
+
"name": "uuid_",
|
|
393
393
|
"import": {
|
|
394
394
|
"./uuid": "{ uuid_ }"
|
|
395
395
|
},
|
|
396
|
-
"limit": "
|
|
396
|
+
"limit": "41 B"
|
|
397
397
|
},
|
|
398
398
|
{
|
|
399
|
-
"name": "
|
|
399
|
+
"name": "short_uuid_",
|
|
400
400
|
"import": {
|
|
401
401
|
"./uuid": "{ short_uuid_ }"
|
|
402
402
|
},
|
|
403
|
-
"limit": "
|
|
403
|
+
"limit": "113 B"
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
"name": "uuid__compact",
|
|
407
|
+
"import": {
|
|
408
|
+
"./uuid": "{ uuid__compact }"
|
|
409
|
+
},
|
|
410
|
+
"limit": "107 B"
|
|
404
411
|
}
|
|
405
412
|
],
|
|
406
413
|
"scripts": {
|