ctx-core 5.5.0 → 5.7.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/be/index.d.ts +6 -2
- package/all/be/index.js +3 -2
- package/all/btoa/index.js +4 -3
- package/all/hex__base64/index.d.ts +2 -0
- package/all/hex__base64/index.js +6 -0
- package/all/hex__base64/index.test.ts +15 -0
- package/all/index.d.ts +2 -0
- package/all/index.js +2 -0
- package/all/is_entry_file/index.d.ts +4 -0
- package/all/is_entry_file/index.js +8 -0
- package/all/is_entry_file/index.test.ts +30 -0
- package/all/ms/index.js +2 -2
- package/all/promise_timeout/index.js +2 -1
- package/all/queue/index.test.ts +20 -20
- package/all/rmemo/index.js +5 -5
- package/all/rmemo__wait/index.d.ts +2 -1
- package/all/rmemo__wait/index.js +10 -4
- package/all/run/index.d.ts +4 -0
- package/all/run/index.js +7 -4
- package/all/run/index.test.ts +19 -0
- package/all/tick/index.js +4 -5
- package/all/uuid/index.d.ts +2 -0
- package/all/uuid/index.js +31 -12
- package/all/uuid/index.test.ts +27 -0
- package/crypto/index.d.ts +2 -0
- package/crypto/index.js +2 -0
- package/fs/index.d.ts +1 -0
- package/fs/index.js +1 -0
- package/package.json +18 -4
- package/rmemo/index.d.ts +1 -0
- package/rmemo/index.js +1 -0
- package/uuid/index.d.ts +1 -0
- package/uuid/index.js +1 -0
package/all/be/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { be__val__new_T, Ctx, Ctx_wide_T } from '../be_/index.js'
|
|
1
|
+
import type { be__val__new_T, be_config_T, Ctx, Ctx_wide_T } from '../be_/index.js'
|
|
2
2
|
export declare function be<
|
|
3
3
|
Out extends NonNullable<unknown>,
|
|
4
4
|
ns_T extends string = '',
|
|
5
5
|
ctx_T extends Ctx = Ctx_wide_T<ns_T>
|
|
6
|
-
>(
|
|
6
|
+
>(
|
|
7
|
+
ctx:ctx_T,
|
|
8
|
+
val_:be__val__new_T<Out, ns_T, ctx_T>,
|
|
9
|
+
config:be_config_T<ns_T>
|
|
10
|
+
):Out
|
|
7
11
|
export { be as b, }
|
package/all/be/index.js
CHANGED
|
@@ -3,9 +3,10 @@ import { be_ } from '../be_/index.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {Ctx}ctx
|
|
5
5
|
* @param {be__val__new_T}val_
|
|
6
|
+
* @param {be_config_T}[config]
|
|
6
7
|
* @returns {NonNullable<unknown>}
|
|
7
8
|
*/
|
|
8
|
-
export function be(ctx, val_) {
|
|
9
|
-
return be_(val_)(ctx)
|
|
9
|
+
export function be(ctx, val_, config) {
|
|
10
|
+
return be_(val_, config)(ctx)
|
|
10
11
|
}
|
|
11
12
|
export { be as b, }
|
package/all/btoa/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="../btoa/index.d.ts" />
|
|
2
|
+
import { process_release_name } from '../process_release_name'
|
|
2
3
|
/**
|
|
3
4
|
* @param {string}str
|
|
4
5
|
* @returns {string}
|
|
5
6
|
*/
|
|
6
7
|
export function btoa(str) {
|
|
7
8
|
return (
|
|
8
|
-
|
|
9
|
-
?
|
|
10
|
-
:
|
|
9
|
+
process_release_name
|
|
10
|
+
? new Buffer(str).toString('base64')
|
|
11
|
+
: window.btoa(str)
|
|
11
12
|
)
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { hex__base64_ } from './index.js'
|
|
4
|
+
test('hex__base64_', ()=>{
|
|
5
|
+
const uuid = '8a88c23d4a6946acb9751ab4590a470c'
|
|
6
|
+
const expected_b64 = 'iojCPUppRqy5dRq0WQpHDA=='
|
|
7
|
+
equal(hex__base64_(uuid), expected_b64)
|
|
8
|
+
// verify the isomorphic solution is the same as nodejs
|
|
9
|
+
equal(
|
|
10
|
+
Buffer
|
|
11
|
+
.from(uuid.replaceAll('-', ''), 'hex')
|
|
12
|
+
.toString('base64'),
|
|
13
|
+
expected_b64)
|
|
14
|
+
})
|
|
15
|
+
test.run()
|
package/all/index.d.ts
CHANGED
|
@@ -170,6 +170,7 @@ export * from './has_multiple/index.js'
|
|
|
170
170
|
export * from './has_some_key/index.js'
|
|
171
171
|
export * from './head_arg_a/index.js'
|
|
172
172
|
export * from './headers/index.js'
|
|
173
|
+
export * from './hex__base64/index.js'
|
|
173
174
|
export * from './hex__digest/index.js'
|
|
174
175
|
export * from './hex_int/index.js'
|
|
175
176
|
export * from './hmac/index.js'
|
|
@@ -225,6 +226,7 @@ export * from './isPrimitive/index.js'
|
|
|
225
226
|
export * from './isPromiseLike/index.js'
|
|
226
227
|
export * from './is_browser/index.js'
|
|
227
228
|
export * from './is_development/index.js'
|
|
229
|
+
export * from './is_entry_file/index.js'
|
|
228
230
|
export * from './is_production/index.js'
|
|
229
231
|
export * from './is_server/index.js'
|
|
230
232
|
export * from './is_staging/index.js'
|
package/all/index.js
CHANGED
|
@@ -170,6 +170,7 @@ export * from './has_multiple/index.js'
|
|
|
170
170
|
export * from './has_some_key/index.js'
|
|
171
171
|
export * from './head_arg_a/index.js'
|
|
172
172
|
export * from './headers/index.js'
|
|
173
|
+
export * from './hex__base64/index.js'
|
|
173
174
|
export * from './hex__digest/index.js'
|
|
174
175
|
export * from './hex_int/index.js'
|
|
175
176
|
export * from './hmac/index.js'
|
|
@@ -225,6 +226,7 @@ export * from './isPrimitive/index.js'
|
|
|
225
226
|
export * from './isPromiseLike/index.js'
|
|
226
227
|
export * from './is_browser/index.js'
|
|
227
228
|
export * from './is_development/index.js'
|
|
229
|
+
export * from './is_entry_file/index.js'
|
|
228
230
|
export * from './is_production/index.js'
|
|
229
231
|
export * from './is_server/index.js'
|
|
230
232
|
export * from './is_staging/index.js'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { process_release_name } from '../process_release_name/index.js'
|
|
2
|
+
export function is_entry_file_(url, entry_path) {
|
|
3
|
+
if (!process_release_name) return false
|
|
4
|
+
return (
|
|
5
|
+
import('node:path').then(({ resolve })=>
|
|
6
|
+
new URL(url).pathname === resolve(entry_path ?? process.argv[1]))
|
|
7
|
+
)
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import esmock from 'esmock'
|
|
2
|
+
import { resolve } from 'path'
|
|
3
|
+
import { test } from 'uvu'
|
|
4
|
+
import { equal } from 'uvu/assert'
|
|
5
|
+
import { is_entry_file_ } from './index.js'
|
|
6
|
+
test('is_entry_file_|node', async ()=>{
|
|
7
|
+
equal(
|
|
8
|
+
await is_entry_file_(import.meta.url, new URL(import.meta.url).pathname),
|
|
9
|
+
true)
|
|
10
|
+
equal(
|
|
11
|
+
await is_entry_file_(
|
|
12
|
+
import.meta.url,
|
|
13
|
+
new URL(import.meta.url).pathname.replace(
|
|
14
|
+
resolve(process.cwd()) + '/', '')),
|
|
15
|
+
true)
|
|
16
|
+
equal(
|
|
17
|
+
await is_entry_file_(import.meta.url, '/not/url'),
|
|
18
|
+
false)
|
|
19
|
+
})
|
|
20
|
+
test('is_entry_file_|browser', async ()=>{
|
|
21
|
+
const { is_entry_file_ } = await esmock('./index.js', {
|
|
22
|
+
'../process_release_name/index.js': {
|
|
23
|
+
process_release_name: undefined
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
equal(
|
|
27
|
+
is_entry_file_(import.meta.url, new URL(import.meta.url).pathname),
|
|
28
|
+
false)
|
|
29
|
+
})
|
|
30
|
+
test.run()
|
package/all/ms/index.js
CHANGED
package/all/queue/index.test.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { tick } from '../tick/index.js'
|
|
|
7
7
|
test('queue_(1).add|queue length of 1 at a time', async ()=>{
|
|
8
8
|
const queue = queue_(1)
|
|
9
9
|
const promise_o_a = [promise_o_(), promise_o_(), promise_o_()]
|
|
10
|
-
const ret_a:
|
|
10
|
+
const ret_a:unknown[] = [null, null, null]
|
|
11
11
|
queue.add(()=>promise_o_a[0].promise).then(ret=>ret_a[0] = ret)
|
|
12
12
|
queue.add(()=>promise_o_a[1].promise).then(ret=>ret_a[1] = ret)
|
|
13
13
|
queue.add(()=>promise_o_a[2].promise).then(ret=>ret_a[2] = ret)
|
|
@@ -23,17 +23,17 @@ test('queue_(1).add|queue length of 1 at a time', async ()=>{
|
|
|
23
23
|
promise_o_a[2].resolve('val2')
|
|
24
24
|
await tick()
|
|
25
25
|
equal(ret_a, ['val0', 'val1', 'val2'])
|
|
26
|
-
const close__promise__arg_aa:
|
|
26
|
+
const close__promise__arg_aa:unknown[][] = []
|
|
27
27
|
queue.close()
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
.then((...arg_a)=>
|
|
29
|
+
close__promise__arg_aa.push(arg_a))
|
|
30
30
|
await tick()
|
|
31
31
|
equal(close__promise__arg_aa, [[3]])
|
|
32
32
|
})
|
|
33
33
|
test('queue_(2).add|queue length of 2 at a time', async ()=>{
|
|
34
34
|
const queue = queue_(2)
|
|
35
35
|
const promise_o_a = [promise_o_(), promise_o_(), promise_o_(), promise_o_()]
|
|
36
|
-
const ret_a:
|
|
36
|
+
const ret_a:unknown[] = [null, null, null, null]
|
|
37
37
|
queue.add(()=>promise_o_a[0].promise).then(ret=>ret_a[0] = ret)
|
|
38
38
|
queue.add(()=>promise_o_a[1].promise).then(ret=>ret_a[1] = ret)
|
|
39
39
|
queue.add(()=>promise_o_a[2].promise).then(ret=>ret_a[2] = ret)
|
|
@@ -55,17 +55,17 @@ test('queue_(2).add|queue length of 2 at a time', async ()=>{
|
|
|
55
55
|
promise_o_a[1].resolve('val1')
|
|
56
56
|
await tick()
|
|
57
57
|
equal(ret_a, ['val0', 'val1', 'val2', 'val3'])
|
|
58
|
-
const close__promise__arg_aa:
|
|
58
|
+
const close__promise__arg_aa:unknown[][] = []
|
|
59
59
|
queue.close()
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
.then((...arg_a)=>
|
|
61
|
+
close__promise__arg_aa.push(arg_a))
|
|
62
62
|
await tick()
|
|
63
63
|
equal(close__promise__arg_aa, [[4]])
|
|
64
64
|
})
|
|
65
65
|
test('queue_(1).add_sync|queue length of 1 at a time', async ()=>{
|
|
66
66
|
const queue = queue_(1)
|
|
67
67
|
const promise_o_a = [promise_o_(), promise_o_(), promise_o_()]
|
|
68
|
-
const ret_a:
|
|
68
|
+
const ret_a:unknown[] = [null, null, null]
|
|
69
69
|
ret_a[0] = queue.add_sync(()=>promise_o_a[0].promise)
|
|
70
70
|
equal(ret_a, [1, null, null])
|
|
71
71
|
ret_a[1] = queue.add_sync(()=>promise_o_a[1].promise)
|
|
@@ -76,7 +76,7 @@ test('queue_(1).add_sync|queue length of 1 at a time', async ()=>{
|
|
|
76
76
|
test('queue_(2).add_sync|queue length of 2 at a time', async ()=>{
|
|
77
77
|
const queue = queue_(2)
|
|
78
78
|
const promise_o_a = [promise_o_(), promise_o_(), promise_o_(), promise_o_()]
|
|
79
|
-
const ret_a:
|
|
79
|
+
const ret_a:unknown[] = [null, null, null, null]
|
|
80
80
|
ret_a[0] = queue.add_sync(()=>promise_o_a[0].promise)
|
|
81
81
|
equal(ret_a, [1, null, null, null])
|
|
82
82
|
ret_a[1] = queue.add_sync(()=>promise_o_a[1].promise)
|
|
@@ -102,15 +102,15 @@ test('queue_(2).cancel|immediately stops queue discarding pending jobs|returns p
|
|
|
102
102
|
promise_o_(),
|
|
103
103
|
promise_o_()
|
|
104
104
|
]
|
|
105
|
-
const ret_a:
|
|
105
|
+
const ret_a:unknown[] = [null, null, null, null]
|
|
106
106
|
queue.add(()=>promise_o_a[0].promise).then(ret=>ret_a[0] = ret)
|
|
107
107
|
queue.add(()=>promise_o_a[1].promise).then(ret=>ret_a[1] = ret)
|
|
108
108
|
queue.add(()=>promise_o_a[2].promise).then(ret=>ret_a[2] = ret)
|
|
109
109
|
queue.add(()=>promise_o_a[3].promise).then(ret=>ret_a[3] = ret)
|
|
110
|
-
const close__promise__arg_aa:
|
|
110
|
+
const close__promise__arg_aa:unknown[][] = []
|
|
111
111
|
queue.close()
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
.then((...arg_a)=>
|
|
113
|
+
close__promise__arg_aa.push(arg_a))
|
|
114
114
|
equal(ret_a, [null, null, null, null])
|
|
115
115
|
equal(pending, undefined)
|
|
116
116
|
equal(close__promise__arg_aa, [])
|
|
@@ -134,16 +134,16 @@ test('throttle|number', async ()=>{
|
|
|
134
134
|
const queue = queue_(2)
|
|
135
135
|
const promise_o_a = [promise_o_(), promise_o_(), promise_o_(), promise_o_(), promise_o_()]
|
|
136
136
|
promise_o_a.map(pending_o=>queue.add(()=>pending_o.promise))
|
|
137
|
-
const pending__wait__arg_aa:
|
|
138
|
-
const throttle__then = (...arg_a:
|
|
137
|
+
const pending__wait__arg_aa:unknown[][] = []
|
|
138
|
+
const throttle__then = (...arg_a:unknown[])=>{
|
|
139
139
|
pending__wait__arg_aa.push(arg_a)
|
|
140
140
|
}
|
|
141
141
|
queue.throttle(5)
|
|
142
|
-
|
|
142
|
+
.then(throttle__then)
|
|
143
143
|
await tick()
|
|
144
144
|
equal(pending__wait__arg_aa, [[5]])
|
|
145
145
|
queue.throttle(3)
|
|
146
|
-
|
|
146
|
+
.then(throttle__then)
|
|
147
147
|
await tick()
|
|
148
148
|
equal(pending__wait__arg_aa, [[5]])
|
|
149
149
|
promise_o_a[0].resolve(true)
|
|
@@ -159,8 +159,8 @@ test('throttle|fn', async ()=>{
|
|
|
159
159
|
const queue = queue_(2)
|
|
160
160
|
const promise_o_a = [promise_o_(), promise_o_(), promise_o_(), promise_o_(), promise_o_()]
|
|
161
161
|
promise_o_a.map(pending_o=>queue.add(()=>pending_o.promise))
|
|
162
|
-
const pending__wait__arg_aa:
|
|
163
|
-
const throttle__then = (...arg_a:
|
|
162
|
+
const pending__wait__arg_aa:unknown[][] = []
|
|
163
|
+
const throttle__then = (...arg_a:unknown[])=>{
|
|
164
164
|
pending__wait__arg_aa.push(arg_a)
|
|
165
165
|
}
|
|
166
166
|
queue.throttle(item_count=>
|
package/all/rmemo/index.js
CHANGED
|
@@ -4,8 +4,8 @@ let cur_memo
|
|
|
4
4
|
/** @type {Set<()=>unknown>} */
|
|
5
5
|
let queue = new Set
|
|
6
6
|
/**
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
7
|
+
* @param {memo_def_T}memo_def
|
|
8
|
+
* @param {memo_subscriber_T<unknown>[]}subscriber_a
|
|
9
9
|
* @returns {memo_T}
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
@@ -80,8 +80,8 @@ export function memo_(memo_def, ...subscriber_a) {
|
|
|
80
80
|
}
|
|
81
81
|
export { memo_ as memosig_ }
|
|
82
82
|
/**
|
|
83
|
-
* @param {
|
|
84
|
-
* @param {
|
|
83
|
+
* @param {memo_def_T}memo_def
|
|
84
|
+
* @param {memo_subscriber_T<unknown>[]}subscriber_a
|
|
85
85
|
* @returns {sig_T}
|
|
86
86
|
* @private
|
|
87
87
|
*/
|
|
@@ -102,7 +102,7 @@ export function lock_memosig_(memo_def, ...subscriber_a) {
|
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* @param {unknown}init_val
|
|
105
|
-
* @param {
|
|
105
|
+
* @param {memo_subscriber_T[]}subscriber_a
|
|
106
106
|
* @returns {sig_T}
|
|
107
107
|
* @private
|
|
108
108
|
*/
|
package/all/rmemo__wait/index.js
CHANGED
|
@@ -7,9 +7,15 @@ import { memo_ } from '../rmemo/index.js'
|
|
|
7
7
|
* @param {rmemo_T}rmemo
|
|
8
8
|
* @param {(val:unknown)=>unknown}condition_fn
|
|
9
9
|
* @param {number}[timeout]
|
|
10
|
+
* @param {Error}[error]
|
|
10
11
|
* @returns {Promise<*>|Promise<unknown>}
|
|
11
12
|
*/
|
|
12
|
-
export function rmemo__wait(
|
|
13
|
+
export function rmemo__wait(
|
|
14
|
+
rmemo,
|
|
15
|
+
condition_fn,
|
|
16
|
+
timeout,
|
|
17
|
+
error
|
|
18
|
+
) {
|
|
13
19
|
let memo
|
|
14
20
|
const _subscribe_wait = new Promise(resolve=>{
|
|
15
21
|
memo = memo_(()=>{
|
|
@@ -20,9 +26,9 @@ export function rmemo__wait(rmemo, condition_fn, timeout) {
|
|
|
20
26
|
memo()
|
|
21
27
|
})
|
|
22
28
|
let promise =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
isNumber_(timeout)
|
|
30
|
+
? promise_timeout(_subscribe_wait, timeout, error)
|
|
31
|
+
: _subscribe_wait
|
|
26
32
|
// prevent GC
|
|
27
33
|
promise.m = memo
|
|
28
34
|
return promise
|
package/all/run/index.d.ts
CHANGED
package/all/run/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { nullish__none_ } from '../nullish__none/index.js'
|
|
2
1
|
/**
|
|
3
|
-
* @param
|
|
2
|
+
* @param {(...arg_a:unknown)=>unknown}fn
|
|
4
3
|
* @param {unknown}arg_a
|
|
5
4
|
* @returns {unknown}
|
|
6
5
|
*/
|
|
7
|
-
export function run(
|
|
8
|
-
return
|
|
6
|
+
export function run(...arg_a) {
|
|
7
|
+
return (
|
|
8
|
+
typeof arg_a[0] === 'function'
|
|
9
|
+
? arg_a[0](...arg_a.slice(1))
|
|
10
|
+
: arg_a[1](...arg_a[0])
|
|
11
|
+
)
|
|
9
12
|
}
|
|
10
13
|
export { run as _ }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { run } from './index.js'
|
|
4
|
+
test('run|fn first', ()=>{
|
|
5
|
+
equal(run(()=>1), 1)
|
|
6
|
+
equal(
|
|
7
|
+
run((a, b, c)=>[a, b, c],
|
|
8
|
+
0, 1, 2),
|
|
9
|
+
[0, 1, 2])
|
|
10
|
+
})
|
|
11
|
+
test('run|arg_a first', ()=>{
|
|
12
|
+
equal(run([], ()=>1), 1)
|
|
13
|
+
equal(
|
|
14
|
+
run(
|
|
15
|
+
[0, 1, 2],
|
|
16
|
+
(a, b, c)=>[a, b, c]),
|
|
17
|
+
[0, 1, 2])
|
|
18
|
+
})
|
|
19
|
+
test.run()
|
package/all/tick/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { run } from '../run/index.js'
|
|
2
1
|
/**
|
|
3
2
|
* Calls setTimeout
|
|
4
3
|
* @param {()=>unknown}[fn]
|
|
@@ -6,16 +5,16 @@ import { run } from '../run/index.js'
|
|
|
6
5
|
* @returns {Promise<unknown>}
|
|
7
6
|
*/
|
|
8
7
|
export function tick(fn, timeout = 0) {
|
|
9
|
-
return new Promise((
|
|
8
|
+
return new Promise((resolve, reject)=>{
|
|
10
9
|
if (!timeout) {
|
|
11
10
|
queueMicrotask(()=>
|
|
12
|
-
|
|
11
|
+
resolve(fn?.()))
|
|
13
12
|
} else {
|
|
14
13
|
setTimeout(()=>{
|
|
15
14
|
try {
|
|
16
|
-
|
|
15
|
+
resolve(fn?.())
|
|
17
16
|
} catch (e) {
|
|
18
|
-
|
|
17
|
+
reject(e)
|
|
19
18
|
}
|
|
20
19
|
}, timeout)
|
|
21
20
|
}
|
package/all/uuid/index.d.ts
CHANGED
package/all/uuid/index.js
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
//https://gist.github.com/LeverOne/1308368
|
|
2
1
|
export function uuid_() {
|
|
2
|
+
return crypto.randomUUID()
|
|
3
|
+
}
|
|
4
|
+
export {
|
|
5
|
+
uuid_ as _uuid,
|
|
6
|
+
uuid_ as uuid,
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @param {string}[uuid]
|
|
10
|
+
* @returns {string}
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
export function short_uuid_(uuid) {
|
|
14
|
+
uuid = (uuid ?? crypto.randomUUID()).replaceAll('-', '')
|
|
15
|
+
let str = ''
|
|
16
|
+
for (let i = 0; i < uuid.length; i += 2)
|
|
17
|
+
str += String.fromCharCode(parseInt(uuid.slice(i, i + 2), 16))
|
|
18
|
+
return btoa(str).replace('==', '')
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @returns {string}
|
|
22
|
+
* @see {@link https://gist.github.com/LeverOne/1308368}
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
export function polyfill_uuid_() {
|
|
3
26
|
let a = 0, b = ''
|
|
4
27
|
for (
|
|
5
28
|
;
|
|
6
29
|
a++ < 36;
|
|
7
|
-
b += a * 51 & 52
|
|
8
|
-
? (a ^ 15
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
).toString(16)
|
|
12
|
-
|
|
13
|
-
}
|
|
30
|
+
b += a * 51 & 52 /*if "a" is not 9 or 14 or 19 or 24*/
|
|
31
|
+
? (a ^ 15 /*if "a" is not 15*/
|
|
32
|
+
? 8 ^ Math.random() * (a ^ 20 ? 16 : 4 /*unless "a" is 20, in which case a random number from 8 to 11*/)
|
|
33
|
+
: 4 /*otherwise 4*/
|
|
34
|
+
).toString(16)
|
|
35
|
+
: '-' /*in other cases (if "a" is 9,14,19,24) insert "-"*/
|
|
36
|
+
) { /* empty */ }
|
|
14
37
|
return b
|
|
15
38
|
}
|
|
16
|
-
export {
|
|
17
|
-
uuid_ as _uuid,
|
|
18
|
-
uuid_ as uuid,
|
|
19
|
-
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { polyfill_uuid_, short_uuid_, uuid_ } from './index.js'
|
|
4
|
+
test('uuid_', ()=>{
|
|
5
|
+
equal(
|
|
6
|
+
uuid_().split('-').map(seg=>seg.length),
|
|
7
|
+
[8, 4, 4, 4, 12])
|
|
8
|
+
})
|
|
9
|
+
test('short_uuid_', ()=>{
|
|
10
|
+
equal(short_uuid_().length, 22)
|
|
11
|
+
const uuid = '8a88c23d-4a69-46ac-b975-1ab4590a470c'
|
|
12
|
+
const expected_short_uuid = 'iojCPUppRqy5dRq0WQpHDA'
|
|
13
|
+
equal(short_uuid_(uuid), expected_short_uuid)
|
|
14
|
+
// verify the isomorphic solution is the same as nodejs
|
|
15
|
+
equal(
|
|
16
|
+
Buffer
|
|
17
|
+
.from(uuid.replaceAll('-', ''), 'hex')
|
|
18
|
+
.toString('base64')
|
|
19
|
+
.replace(/==$/, ''),
|
|
20
|
+
expected_short_uuid)
|
|
21
|
+
})
|
|
22
|
+
test('polyfill_uuid_', ()=>{
|
|
23
|
+
equal(
|
|
24
|
+
polyfill_uuid_().split('-').map(seg=>seg.length),
|
|
25
|
+
[8, 4, 4, 4, 12])
|
|
26
|
+
})
|
|
27
|
+
test.run()
|
package/crypto/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export * from '../all/buffer__hex/index.js'
|
|
|
2
2
|
export * from '../all/crypto/index.js'
|
|
3
3
|
export * from '../all/crypto__sign/index.js'
|
|
4
4
|
export * from '../all/digest__algorithm/index.js'
|
|
5
|
+
export * from '../all/hex__base64/index.js'
|
|
5
6
|
export * from '../all/hex__digest/index.js'
|
|
6
7
|
export * from '../all/hmac/index.js'
|
|
7
8
|
export * from '../all/hmac_key/index.js'
|
|
9
|
+
export * from '../all/uuid/index.js'
|
package/crypto/index.js
CHANGED
|
@@ -2,6 +2,8 @@ export * from '../all/buffer__hex/index.js'
|
|
|
2
2
|
export * from '../all/crypto/index.js'
|
|
3
3
|
export * from '../all/crypto__sign/index.js'
|
|
4
4
|
export * from '../all/digest__algorithm/index.js'
|
|
5
|
+
export * from '../all/hex__base64/index.js'
|
|
5
6
|
export * from '../all/hex__digest/index.js'
|
|
6
7
|
export * from '../all/hmac/index.js'
|
|
7
8
|
export * from '../all/hmac_key/index.js'
|
|
9
|
+
export * from '../all/uuid/index.js'
|
package/fs/index.d.ts
CHANGED
package/fs/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -124,11 +124,11 @@
|
|
|
124
124
|
"@arethetypeswrong/cli": "^0.13.5",
|
|
125
125
|
"@ctx-core/preprocess": "^0.1.0",
|
|
126
126
|
"@size-limit/preset-small-lib": "^11.0.1",
|
|
127
|
-
"@types/node": "^20.10.
|
|
127
|
+
"@types/node": "^20.10.6",
|
|
128
128
|
"@types/sinon": "^17.0.2",
|
|
129
129
|
"c8": "^8.0.1",
|
|
130
130
|
"check-dts": "^0.7.2",
|
|
131
|
-
"esbuild": "^0.19.
|
|
131
|
+
"esbuild": "^0.19.11",
|
|
132
132
|
"esmock": "^2.6.0",
|
|
133
133
|
"sinon": "^17.0.1",
|
|
134
134
|
"size-limit": "^11.0.1",
|
|
@@ -211,6 +211,20 @@
|
|
|
211
211
|
"./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
|
|
212
212
|
},
|
|
213
213
|
"limit": "552 B"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "uuid",
|
|
217
|
+
"import": {
|
|
218
|
+
"./uuid": "{ uuid_ }"
|
|
219
|
+
},
|
|
220
|
+
"limit": "39 B"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"name": "short uuid",
|
|
224
|
+
"import": {
|
|
225
|
+
"./uuid": "{ short_uuid_ }"
|
|
226
|
+
},
|
|
227
|
+
"limit": "116 B"
|
|
214
228
|
}
|
|
215
229
|
],
|
|
216
230
|
"scripts": {
|
|
@@ -221,6 +235,6 @@
|
|
|
221
235
|
"test:size": "size-limit",
|
|
222
236
|
"test:type": "check-dts",
|
|
223
237
|
"test:unit": "NODE_OPTIONS=--loader=esmock tsx node_modules/uvu/bin.js . '\\.test\\.(ts|js)$'",
|
|
224
|
-
"disable:test:coverage": "c8 pnpm test
|
|
238
|
+
"disable:test:coverage": "c8 pnpm test:unit"
|
|
225
239
|
}
|
|
226
240
|
}
|
package/rmemo/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { rmemo__subscribe } from '../rmemo/index.js'
|
|
2
2
|
export { rmemo__subscribe as subscribe }
|
|
3
|
+
export * from '../all/be/index.js'
|
|
3
4
|
export * from '../all/be_/index.js'
|
|
4
5
|
export * from '../all/be_lock_memosig_triple/index.js'
|
|
5
6
|
export * from '../all/be_memo_pair/index.js'
|
package/rmemo/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { rmemo__subscribe } from '../rmemo/index.js'
|
|
2
2
|
export { rmemo__subscribe as subscribe }
|
|
3
|
+
export * from '../all/be/index.js'
|
|
3
4
|
export * from '../all/be_/index.js'
|
|
4
5
|
export * from '../all/be_lock_memosig_triple/index.js'
|
|
5
6
|
export * from '../all/be_memo_pair/index.js'
|
package/uuid/index.d.ts
CHANGED
package/uuid/index.js
CHANGED