ctx-core 6.1.3 → 6.2.3
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 +116 -2
- package/all/be_/index.js +15 -11
- package/all/timeout_promise/index.js +11 -6
- package/all/timeout_promise/index.test.ts +11 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,119 @@
|
|
|
1
1
|
# ctx-core
|
|
2
|
-
ctx-core core (ctx-core^2) libraries...used by @ctx-core/* libraries. The development monorepo has been moved to @ctx-core/dev
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
The ctx-core library is a 0 dependency library with several exports to support general app development. This library has several exports to limit what is loaded into memory & to make tree-shaking less intensive. Some of the underlying functions are in multiple exports. The full list of exports is below. There is varying comprehensiveness & usage for these functions.
|
|
5
4
|
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Development Monorepo
|
|
8
|
+
|
|
9
|
+
The [development monorepo](https://github.com/ctx-core/dev) used to have the ctx-core/ctx-core project name but has been moved to make room for this package.
|
|
10
|
+
|
|
11
|
+
### ctx-core/all
|
|
12
|
+
|
|
13
|
+
A catch all export which includes all functions. ctx-core/all is used to verify that the source functions have unique names.
|
|
14
|
+
|
|
15
|
+
### ctx-core/array
|
|
16
|
+
|
|
17
|
+
### ctx-core/atob
|
|
18
|
+
|
|
19
|
+
### ctx-core/base16
|
|
20
|
+
|
|
21
|
+
### ctx-core/be
|
|
22
|
+
|
|
23
|
+
[ctx-core/be](https://github.com/ctx-core/be) is a general purpose, modular, & scalable context library. See it's Readme for more docs.
|
|
24
|
+
|
|
25
|
+
### ctx-core/btoa
|
|
26
|
+
|
|
27
|
+
### ctx-core/buffer
|
|
28
|
+
|
|
29
|
+
### ctx-core/chain
|
|
30
|
+
|
|
31
|
+
### ctx-core/class
|
|
32
|
+
|
|
33
|
+
### ctx-core/cli-args
|
|
34
|
+
|
|
35
|
+
### ctx-core/color
|
|
36
|
+
|
|
37
|
+
### ctx-core/combinators
|
|
38
|
+
|
|
39
|
+
### ctx-core/crypto
|
|
40
|
+
|
|
41
|
+
### ctx-core/currency
|
|
42
|
+
|
|
43
|
+
### ctx-core/data
|
|
44
|
+
|
|
45
|
+
### ctx-core/date
|
|
46
|
+
|
|
47
|
+
### ctx-core/debounce
|
|
48
|
+
|
|
49
|
+
### ctx-core/deep_equal
|
|
50
|
+
|
|
51
|
+
### ctx-core/dom
|
|
52
|
+
|
|
53
|
+
### ctx-core/env
|
|
54
|
+
|
|
55
|
+
### ctx-core/error
|
|
56
|
+
|
|
57
|
+
### ctx-core/event_log
|
|
58
|
+
|
|
59
|
+
### ctx-core/falsy
|
|
60
|
+
|
|
61
|
+
### ctx-core/fetch
|
|
62
|
+
|
|
63
|
+
### ctx-core/fibonacci
|
|
64
|
+
|
|
65
|
+
### ctx-core/fs
|
|
66
|
+
|
|
67
|
+
### ctx-core/function
|
|
68
|
+
|
|
69
|
+
### ctx-core/functional
|
|
70
|
+
|
|
71
|
+
### ctx-core/html
|
|
72
|
+
|
|
73
|
+
### ctx-core/http
|
|
74
|
+
|
|
75
|
+
### ctx-core/math
|
|
76
|
+
|
|
77
|
+
### ctx-core/matrix
|
|
78
|
+
|
|
79
|
+
### ctx-core/nullish
|
|
80
|
+
|
|
81
|
+
### ctx-core/number
|
|
82
|
+
|
|
83
|
+
### ctx-core/object
|
|
84
|
+
|
|
85
|
+
### ctx-core/promise
|
|
86
|
+
|
|
87
|
+
## ctx-core/queue
|
|
88
|
+
|
|
89
|
+
## ctx-core/random
|
|
90
|
+
|
|
91
|
+
## ctx-core/regex
|
|
92
|
+
|
|
93
|
+
## ctx-core/rmemo
|
|
94
|
+
|
|
95
|
+
The docs for rmemo are in https://github.com/ctx-core/rmemo. Since the source for rmemo has 0 dependencies & is isomorphic, it lives in the ctx-core/rmemo export. This allows rmemo to be used within ctx-core without added a dependency.
|
|
96
|
+
|
|
97
|
+
## ctx-core/run
|
|
98
|
+
|
|
99
|
+
## ctx-core/set
|
|
100
|
+
|
|
101
|
+
## ctx-core/sleep
|
|
102
|
+
|
|
103
|
+
## ctx-core/stream
|
|
104
|
+
|
|
105
|
+
## ctx-core/string
|
|
106
|
+
|
|
107
|
+
## ctx-core/tempfile
|
|
108
|
+
|
|
109
|
+
## ctx-core/test
|
|
110
|
+
|
|
111
|
+
## ctx-core/time
|
|
112
|
+
|
|
113
|
+
## ctx-core/tuple
|
|
114
|
+
|
|
115
|
+
## ctx-core/types
|
|
116
|
+
|
|
117
|
+
## ctx-core/uri
|
|
118
|
+
|
|
119
|
+
## ctx-core/uuid
|
package/all/be_/index.js
CHANGED
|
@@ -13,22 +13,26 @@ let _undefined
|
|
|
13
13
|
export function be_(val__new, config) {
|
|
14
14
|
let be = ctx=>{
|
|
15
15
|
let be_map = ctx.s[be.ns]
|
|
16
|
+
// @formatter:off
|
|
16
17
|
/* @if DEBUG **
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// ~ 30 B
|
|
19
|
+
if (!be_map) throw Error('ctx_no_ns: \'' + be.ns + '\'')
|
|
20
|
+
/* @endif */
|
|
20
21
|
// config is not used anymore so reusing to reduce bundle size
|
|
22
|
+
// @formatter:on
|
|
21
23
|
config = be_map.get(be.id)
|
|
22
24
|
if (config) return config[0]
|
|
25
|
+
// @formatter:off
|
|
23
26
|
/* @if DEBUG **
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
// 5-11 B
|
|
28
|
+
// circular dependency state
|
|
29
|
+
// if val__new calls this be before returning, 'cir' will be the value of this be
|
|
30
|
+
// 'cir' is used instead of 'circular' to reduce the payload by a few bytes
|
|
31
|
+
config = ['cir', ctx, be]
|
|
32
|
+
be_map.set(be.id, config)
|
|
33
|
+
config[0] = val__new(ctx, be)
|
|
34
|
+
/* @endif */
|
|
35
|
+
// @formatter:on
|
|
32
36
|
/* @if !DEBUG */
|
|
33
37
|
config = [val__new(ctx, be), ctx, be]
|
|
34
38
|
be_map.set(be.id, config)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Timeout } from '../timeout/index.js'
|
|
2
2
|
/**
|
|
3
3
|
* @param {(()=>Promise<unknown>)|Promise<unknown>}promise
|
|
4
|
-
* @param {number}ms
|
|
4
|
+
* @param {number|Infinity}ms
|
|
5
5
|
* @param {Error}[error]
|
|
6
6
|
* @returns {cancel_Promise}
|
|
7
7
|
*/
|
|
@@ -12,15 +12,20 @@ export function timeout_promise(
|
|
|
12
12
|
) {
|
|
13
13
|
error ??= new Timeout(ms)
|
|
14
14
|
let id
|
|
15
|
-
let timeout =
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let timeout =
|
|
16
|
+
ms !== Infinity
|
|
17
|
+
? new Promise((_resolve, reject)=>{
|
|
18
|
+
id = setTimeout(()=>reject(error), ms)
|
|
19
|
+
})
|
|
20
|
+
: undefined
|
|
18
21
|
let cancel_promise__resolve
|
|
19
|
-
let cancel_promise =
|
|
22
|
+
let cancel_promise =
|
|
23
|
+
new Promise(resolve=>
|
|
24
|
+
cancel_promise__resolve = resolve)
|
|
20
25
|
/** @type {cancel_Promise} */
|
|
21
26
|
let ret_promise = Promise.race([
|
|
22
27
|
typeof promise === 'function' ? promise() : promise,
|
|
23
|
-
timeout,
|
|
28
|
+
...(timeout ? [timeout] : []),
|
|
24
29
|
cancel_promise,
|
|
25
30
|
]).finally(()=>clearTimeout(id))
|
|
26
31
|
ret_promise.cancel = cancel_promise__resolve
|
|
@@ -15,6 +15,17 @@ test('timeout_promise|success', async ()=>{
|
|
|
15
15
|
equal(await promise, true)
|
|
16
16
|
equal(count, 1)
|
|
17
17
|
})
|
|
18
|
+
test('timeout_promise|Infinity|success', async ()=>{
|
|
19
|
+
let count = 0
|
|
20
|
+
const promise = timeout_promise(run(async ()=>{
|
|
21
|
+
count++
|
|
22
|
+
await sleep(10)
|
|
23
|
+
return true
|
|
24
|
+
}), Infinity)
|
|
25
|
+
equal(count, 1)
|
|
26
|
+
equal(await promise, true)
|
|
27
|
+
equal(count, 1)
|
|
28
|
+
})
|
|
18
29
|
test('timeout_promise|timeout', async ()=>{
|
|
19
30
|
let count = 0
|
|
20
31
|
let err:Error|undefined = undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.3",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -292,7 +292,7 @@
|
|
|
292
292
|
"./package.json": "./package.json"
|
|
293
293
|
},
|
|
294
294
|
"devDependencies": {
|
|
295
|
-
"@arethetypeswrong/cli": "^0.13.
|
|
295
|
+
"@arethetypeswrong/cli": "^0.13.10",
|
|
296
296
|
"@ctx-core/preprocess": "^0.1.2",
|
|
297
297
|
"@size-limit/preset-small-lib": "^11.0.2",
|
|
298
298
|
"@types/jsdom": "^21.1.6",
|