@centralping/ergo 0.1.0-beta.1 → 0.1.0-beta.2
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 +14 -15
- package/http/accepts.js +1 -2
- package/http/authorization.js +1 -2
- package/http/body.js +1 -2
- package/http/cache-control.js +1 -2
- package/http/compress.js +1 -2
- package/http/cookie.js +1 -2
- package/http/cors.js +1 -2
- package/http/csrf.js +1 -2
- package/http/handler.js +1 -2
- package/http/index.js +37 -4
- package/http/json-api-query.js +1 -2
- package/http/logger.js +1 -2
- package/http/main.js +2 -3
- package/http/precondition.js +1 -2
- package/http/prefer.js +1 -2
- package/http/rate-limit.js +1 -2
- package/http/security-headers.js +1 -2
- package/http/send.js +1 -2
- package/http/timeout.js +1 -2
- package/http/url.js +1 -2
- package/http/validate.js +1 -2
- package/lib/accepts.js +1 -2
- package/lib/attach-instance.js +0 -1
- package/lib/authorization.js +1 -2
- package/lib/body/multiparse.js +1 -2
- package/lib/body/multipart/headers.js +1 -2
- package/lib/body/writer.js +1 -2
- package/lib/cookie/cookie.js +1 -2
- package/lib/cookie/index.js +0 -1
- package/lib/cookie/jar.js +16 -12
- package/lib/cookie/parse.js +1 -2
- package/lib/cors.js +1 -2
- package/lib/csrf.js +1 -2
- package/lib/from-connect.js +2 -3
- package/lib/json-api-query/index.js +0 -1
- package/lib/json-api-query/validate.js +1 -2
- package/lib/link.js +1 -2
- package/lib/prefer.js +1 -2
- package/lib/query.js +1 -2
- package/lib/rate-limit.js +1 -2
- package/lib/sanitize-quoted-string.js +0 -1
- package/lib/security-headers.js +1 -2
- package/lib/validate.js +1 -2
- package/lib/vary.js +0 -1
- package/package.json +2 -2
- package/types/http/precondition.d.ts +1 -2
- package/types/lib/attach-instance.d.ts +0 -1
- package/types/lib/cookie/jar.d.ts +4 -0
- package/types/lib/from-connect.d.ts +2 -3
- package/types/lib/prefer.d.ts +1 -2
- package/types/lib/rate-limit.d.ts +1 -2
- package/types/lib/sanitize-quoted-string.d.ts +0 -1
- package/types/lib/vary.d.ts +0 -1
- package/types/utils/compose.d.ts +1 -2
- package/types/utils/iterables/range.d.ts +1 -2
- package/utils/attempt.js +1 -2
- package/utils/buffers/index.js +0 -1
- package/utils/buffers/match.js +1 -2
- package/utils/buffers/split.js +1 -2
- package/utils/compose-with.js +1 -2
- package/utils/compose.js +1 -2
- package/utils/flat-array.js +1 -2
- package/utils/get.js +1 -2
- package/utils/http-errors.js +1 -2
- package/utils/iterables/buffer-split.js +1 -2
- package/utils/iterables/chain.js +1 -2
- package/utils/iterables/exec-all.js +1 -2
- package/utils/iterables/filter.js +1 -2
- package/utils/iterables/for-each.js +1 -2
- package/utils/iterables/from-stream.js +1 -2
- package/utils/iterables/index.js +0 -1
- package/utils/iterables/map.js +1 -2
- package/utils/iterables/range.js +1 -2
- package/utils/iterables/reduce.js +1 -2
- package/utils/iterables/take.js +1 -2
- package/utils/observables/buffer-split.js +0 -1
- package/utils/observables/chain.js +0 -1
- package/utils/observables/index.js +0 -1
- package/utils/observables/map.js +0 -1
- package/utils/observables/take.js +0 -1
- package/utils/pick.js +1 -2
- package/utils/set.js +1 -2
- package/utils/streams/index.js +0 -1
- package/utils/streams/meter.js +1 -2
- package/utils/streams/tee.js +1 -2
- package/utils/type.js +1 -2
package/lib/from-connect.js
CHANGED
|
@@ -23,12 +23,11 @@
|
|
|
23
23
|
* no-mutation convention but is accepted at the interop boundary.
|
|
24
24
|
*
|
|
25
25
|
* @module lib/from-connect
|
|
26
|
-
* @version 0.1.0
|
|
27
26
|
* @since 0.1.0
|
|
28
27
|
*
|
|
29
28
|
* @example
|
|
30
|
-
* import {compose, handler} from 'ergo';
|
|
31
|
-
* import fromConnect from 'ergo/lib/from-connect';
|
|
29
|
+
* import {compose, handler} from '@centralping/ergo';
|
|
30
|
+
* import fromConnect from '@centralping/ergo/lib/from-connect';
|
|
32
31
|
* import helmet from 'helmet';
|
|
33
32
|
*
|
|
34
33
|
* const pipeline = compose(
|
|
@@ -9,13 +9,12 @@
|
|
|
9
9
|
* to handle single-value query parameters that may be strings instead of arrays.
|
|
10
10
|
*
|
|
11
11
|
* @module lib/json-api-query/validate
|
|
12
|
-
* @version 0.1.0
|
|
13
12
|
* @since 0.1.0
|
|
14
13
|
* @requires ajv/dist/2020.js
|
|
15
14
|
* @requires ./schema.json
|
|
16
15
|
*
|
|
17
16
|
* @example
|
|
18
|
-
* import validate from 'ergo/lib/json-api-query/validate';
|
|
17
|
+
* import validate from '@centralping/ergo/lib/json-api-query/validate';
|
|
19
18
|
*
|
|
20
19
|
* const validator = validate();
|
|
21
20
|
* const valid = validator({include: ['author'], fields: {articles: ['title']}});
|
package/lib/link.js
CHANGED
|
@@ -10,13 +10,12 @@
|
|
|
10
10
|
* formatted header value into the accumulator's `headers` array for `send()`.
|
|
11
11
|
*
|
|
12
12
|
* @module lib/link
|
|
13
|
-
* @version 0.1.0
|
|
14
13
|
* @since 0.1.0
|
|
15
14
|
*
|
|
16
15
|
* @see {@link https://www.rfc-editor.org/rfc/rfc8288 RFC 8288 - Web Linking}
|
|
17
16
|
*
|
|
18
17
|
* @example
|
|
19
|
-
* import {formatLinkHeader, paginationLinks} from 'ergo/lib/link';
|
|
18
|
+
* import {formatLinkHeader, paginationLinks} from '@centralping/ergo/lib/link';
|
|
20
19
|
*
|
|
21
20
|
* const links = paginationLinks({
|
|
22
21
|
* baseUrl: '/articles',
|
package/lib/prefer.js
CHANGED
|
@@ -13,11 +13,10 @@
|
|
|
13
13
|
* - `http/prefer.js` (ergo pipeline middleware)
|
|
14
14
|
*
|
|
15
15
|
* @module lib/prefer
|
|
16
|
-
* @version 0.1.0
|
|
17
16
|
* @since 0.1.0
|
|
18
17
|
*
|
|
19
18
|
* @example
|
|
20
|
-
* import parsePrefer from 'ergo/lib/prefer';
|
|
19
|
+
* import parsePrefer from '@centralping/ergo/lib/prefer';
|
|
21
20
|
*
|
|
22
21
|
* parsePrefer('return=minimal');
|
|
23
22
|
* // {return: 'minimal'}
|
package/lib/query.js
CHANGED
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
* JSON:API query parameter parsing.
|
|
12
12
|
*
|
|
13
13
|
* @module lib/query
|
|
14
|
-
* @version 0.1.0
|
|
15
14
|
* @since 0.1.0
|
|
16
15
|
* @requires ../utils/set.js
|
|
17
16
|
*
|
|
18
17
|
* @example
|
|
19
|
-
* import parse from 'ergo/lib/query';
|
|
18
|
+
* import parse from '@centralping/ergo/lib/query';
|
|
20
19
|
*
|
|
21
20
|
* parse('include=author&fields%5Barticles%5D=title%2Cbody');
|
|
22
21
|
* // => {include: 'author', fields: {articles: ['title', 'body']}}
|
package/lib/rate-limit.js
CHANGED
|
@@ -12,11 +12,10 @@
|
|
|
12
12
|
* - `ergo-router/lib/transport/rate-limit.js` (transport-level rate limiting)
|
|
13
13
|
*
|
|
14
14
|
* @module lib/rate-limit
|
|
15
|
-
* @version 0.1.0
|
|
16
15
|
* @since 0.1.0
|
|
17
16
|
*
|
|
18
17
|
* @example
|
|
19
|
-
* import {MemoryStore, checkRateLimit, defaultKeyGenerator} from 'ergo/lib/rate-limit';
|
|
18
|
+
* import {MemoryStore, checkRateLimit, defaultKeyGenerator} from '@centralping/ergo/lib/rate-limit';
|
|
20
19
|
*
|
|
21
20
|
* const store = new MemoryStore();
|
|
22
21
|
* const key = defaultKeyGenerator(req);
|
package/lib/security-headers.js
CHANGED
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
* `{maxAge, includeSubDomains, preload}` for programmatic construction.
|
|
12
12
|
*
|
|
13
13
|
* @module lib/security-headers
|
|
14
|
-
* @version 0.1.0
|
|
15
14
|
* @since 0.1.0
|
|
16
15
|
*
|
|
17
16
|
* @example
|
|
18
|
-
* import buildSecurityHeaderTuples from 'ergo/lib/security-headers';
|
|
17
|
+
* import buildSecurityHeaderTuples from '@centralping/ergo/lib/security-headers';
|
|
19
18
|
*
|
|
20
19
|
* const tuples = buildSecurityHeaderTuples({
|
|
21
20
|
* xFrameOptions: 'SAMEORIGIN',
|
package/lib/validate.js
CHANGED
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
* Used by `http/validate.js` as the pure-logic backing implementation.
|
|
9
9
|
*
|
|
10
10
|
* @module lib/validate
|
|
11
|
-
* @version 0.1.0
|
|
12
11
|
* @since 0.1.0
|
|
13
12
|
* @requires ajv
|
|
14
13
|
* @requires ../utils/http-errors.js
|
|
15
14
|
*
|
|
16
15
|
* @example
|
|
17
|
-
* import createValidator from 'ergo/lib/validate';
|
|
16
|
+
* import createValidator from '@centralping/ergo/lib/validate';
|
|
18
17
|
*
|
|
19
18
|
* const validate = createValidator({
|
|
20
19
|
* type: 'object',
|
package/lib/vary.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centralping/ergo",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"description": "A Fast Fail REST API toolkit for Node.js -- composable middleware with structured Negotiation, Authorization, Validation, and Execution stages.",
|
|
5
5
|
"main": "http/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"publishConfig": {
|
|
110
110
|
"access": "public"
|
|
111
111
|
},
|
|
112
|
-
"homepage": "https://github.
|
|
112
|
+
"homepage": "https://centralping.github.io/packages/ergo/",
|
|
113
113
|
"funding": {
|
|
114
114
|
"type": "github",
|
|
115
115
|
"url": "https://github.com/sponsors/jasoncust"
|
|
@@ -10,11 +10,10 @@
|
|
|
10
10
|
* inspection that short-circuits before authorization, body parsing, or execution.
|
|
11
11
|
*
|
|
12
12
|
* @module http/precondition
|
|
13
|
-
* @version 0.1.0
|
|
14
13
|
* @since 0.1.0
|
|
15
14
|
*
|
|
16
15
|
* @example
|
|
17
|
-
* import {compose, precondition} from 'ergo';
|
|
16
|
+
* import {compose, precondition} from '@centralping/ergo';
|
|
18
17
|
*
|
|
19
18
|
* // Enforce on all requests (method scoping handled by pipeline builder)
|
|
20
19
|
* const pipeline = compose(
|
|
@@ -2,6 +2,10 @@ export default jar;
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates a cookie jar pre-populated from a parsed cookie object.
|
|
4
4
|
*
|
|
5
|
+
* Incoming cookie names that collide with jar prototype methods or own properties
|
|
6
|
+
* (`set`, `get`, `clear`, `toHeader`, `isJar`, `size`, `jar`) are silently dropped
|
|
7
|
+
* to prevent `TypeError` from strict-mode assignment to non-writable properties.
|
|
8
|
+
*
|
|
5
9
|
* @param {object} [cookies={}] - Initial cookie values (from `parse()`)
|
|
6
10
|
* @returns {object} - Cookie jar with `get`, `set`, `clear`, `toHeader`, `size` members
|
|
7
11
|
*/
|
|
@@ -23,12 +23,11 @@
|
|
|
23
23
|
* no-mutation convention but is accepted at the interop boundary.
|
|
24
24
|
*
|
|
25
25
|
* @module lib/from-connect
|
|
26
|
-
* @version 0.1.0
|
|
27
26
|
* @since 0.1.0
|
|
28
27
|
*
|
|
29
28
|
* @example
|
|
30
|
-
* import {compose, handler} from 'ergo';
|
|
31
|
-
* import fromConnect from 'ergo/lib/from-connect';
|
|
29
|
+
* import {compose, handler} from '@centralping/ergo';
|
|
30
|
+
* import fromConnect from '@centralping/ergo/lib/from-connect';
|
|
32
31
|
* import helmet from 'helmet';
|
|
33
32
|
*
|
|
34
33
|
* const pipeline = compose(
|
package/types/lib/prefer.d.ts
CHANGED
|
@@ -13,11 +13,10 @@
|
|
|
13
13
|
* - `http/prefer.js` (ergo pipeline middleware)
|
|
14
14
|
*
|
|
15
15
|
* @module lib/prefer
|
|
16
|
-
* @version 0.1.0
|
|
17
16
|
* @since 0.1.0
|
|
18
17
|
*
|
|
19
18
|
* @example
|
|
20
|
-
* import parsePrefer from 'ergo/lib/prefer';
|
|
19
|
+
* import parsePrefer from '@centralping/ergo/lib/prefer';
|
|
21
20
|
*
|
|
22
21
|
* parsePrefer('return=minimal');
|
|
23
22
|
* // {return: 'minimal'}
|
|
@@ -39,11 +39,10 @@ export function defaultKeyGenerator(req: object): string;
|
|
|
39
39
|
* - `ergo-router/lib/transport/rate-limit.js` (transport-level rate limiting)
|
|
40
40
|
*
|
|
41
41
|
* @module lib/rate-limit
|
|
42
|
-
* @version 0.1.0
|
|
43
42
|
* @since 0.1.0
|
|
44
43
|
*
|
|
45
44
|
* @example
|
|
46
|
-
* import {MemoryStore, checkRateLimit, defaultKeyGenerator} from 'ergo/lib/rate-limit';
|
|
45
|
+
* import {MemoryStore, checkRateLimit, defaultKeyGenerator} from '@centralping/ergo/lib/rate-limit';
|
|
47
46
|
*
|
|
48
47
|
* const store = new MemoryStore();
|
|
49
48
|
* const key = defaultKeyGenerator(req);
|
package/types/lib/vary.d.ts
CHANGED
package/types/utils/compose.d.ts
CHANGED
|
@@ -20,11 +20,10 @@ export default compose;
|
|
|
20
20
|
* of ergo's built-in middleware).
|
|
21
21
|
*
|
|
22
22
|
* @module utils/compose
|
|
23
|
-
* @version 0.2.0
|
|
24
23
|
* @since 0.1.0
|
|
25
24
|
*
|
|
26
25
|
* @example
|
|
27
|
-
* import compose from 'ergo/utils/compose';
|
|
26
|
+
* import compose from '@centralping/ergo/utils/compose';
|
|
28
27
|
*
|
|
29
28
|
* const pipeline = compose(
|
|
30
29
|
* async (req, res) => ({user: await getUser(req)}),
|
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* stepping by `step`. Mirrors Python's `range()` behaviour.
|
|
6
6
|
*
|
|
7
7
|
* @module utils/iterables/range
|
|
8
|
-
* @version 0.1.0
|
|
9
8
|
* @since 0.1.0
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
|
-
* import range from 'ergo/utils/iterables/range';
|
|
11
|
+
* import range from '@centralping/ergo/utils/iterables/range';
|
|
13
12
|
*
|
|
14
13
|
* [...range(5)] // => [0, 1, 2, 3, 4]
|
|
15
14
|
* [...range(1, 5)] // => [1, 2, 3, 4]
|
package/utils/attempt.js
CHANGED
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
* Used by `http/handler.js` to wrap the try pipeline with an error handler pipeline.
|
|
8
8
|
*
|
|
9
9
|
* @module utils/attempt
|
|
10
|
-
* @version 0.1.0
|
|
11
10
|
* @since 0.1.0
|
|
12
11
|
*
|
|
13
12
|
* @example
|
|
14
|
-
* import attempt from 'ergo/utils/attempt';
|
|
13
|
+
* import attempt from '@centralping/ergo/utils/attempt';
|
|
15
14
|
*
|
|
16
15
|
* const safe = attempt(
|
|
17
16
|
* async (req, res) => { throw new Error('oops'); },
|
package/utils/buffers/index.js
CHANGED
package/utils/buffers/match.js
CHANGED
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
* match state (`partial`) for the next chunk.
|
|
10
10
|
*
|
|
11
11
|
* @module utils/buffers/match
|
|
12
|
-
* @version 0.1.0
|
|
13
12
|
* @since 0.1.0
|
|
14
13
|
*
|
|
15
14
|
* @example
|
|
16
|
-
* import bufferMatch from 'ergo/utils/buffers/match';
|
|
15
|
+
* import bufferMatch from '@centralping/ergo/utils/buffers/match';
|
|
17
16
|
*
|
|
18
17
|
* const {matches} = bufferMatch(Buffer.from('hello world'), Buffer.from('l'));
|
|
19
18
|
* // matches => [2, 3, 9]
|
package/utils/buffers/split.js
CHANGED
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
* Returns `{buffers, partial, lookup}` where `buffers` is the array of Buffer slices.
|
|
9
9
|
*
|
|
10
10
|
* @module utils/buffers/split
|
|
11
|
-
* @version 0.1.0
|
|
12
11
|
* @since 0.1.0
|
|
13
12
|
* @requires ./match.js
|
|
14
13
|
* @requires ../get.js
|
|
15
14
|
*
|
|
16
15
|
* @example
|
|
17
|
-
* import bufferSplit from 'ergo/utils/buffers/split';
|
|
16
|
+
* import bufferSplit from '@centralping/ergo/utils/buffers/split';
|
|
18
17
|
*
|
|
19
18
|
* const {buffers} = bufferSplit(Buffer.from('a--b--c'), Buffer.from('--'));
|
|
20
19
|
* // buffers => [Buffer<'a'>, Buffer<'b'>, Buffer<'c'>]
|
package/utils/compose-with.js
CHANGED
|
@@ -21,13 +21,12 @@
|
|
|
21
21
|
* for compatibility with simple middleware that only produce domain data.
|
|
22
22
|
*
|
|
23
23
|
* @module utils/compose-with
|
|
24
|
-
* @version 0.2.0
|
|
25
24
|
* @since 0.1.0
|
|
26
25
|
* @requires ./compose.js
|
|
27
26
|
* @requires ./set.js
|
|
28
27
|
*
|
|
29
28
|
* @example
|
|
30
|
-
* import compose, {createResponseAcc} from 'ergo/utils/compose-with';
|
|
29
|
+
* import compose, {createResponseAcc} from '@centralping/ergo/utils/compose-with';
|
|
31
30
|
*
|
|
32
31
|
* const responseAcc = createResponseAcc();
|
|
33
32
|
* const pipeline = compose(
|
package/utils/compose.js
CHANGED
|
@@ -19,11 +19,10 @@
|
|
|
19
19
|
* of ergo's built-in middleware).
|
|
20
20
|
*
|
|
21
21
|
* @module utils/compose
|
|
22
|
-
* @version 0.2.0
|
|
23
22
|
* @since 0.1.0
|
|
24
23
|
*
|
|
25
24
|
* @example
|
|
26
|
-
* import compose from 'ergo/utils/compose';
|
|
25
|
+
* import compose from '@centralping/ergo/utils/compose';
|
|
27
26
|
*
|
|
28
27
|
* const pipeline = compose(
|
|
29
28
|
* async (req, res) => ({user: await getUser(req)}),
|
package/utils/flat-array.js
CHANGED
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* Equivalent to `[...args].flat()` — accepts any mix of scalars and nested arrays.
|
|
6
6
|
*
|
|
7
7
|
* @module utils/flat-array
|
|
8
|
-
* @version 0.1.0
|
|
9
8
|
* @since 0.1.0
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
|
-
* import flatArray from 'ergo/utils/flat-array';
|
|
11
|
+
* import flatArray from '@centralping/ergo/utils/flat-array';
|
|
13
12
|
*
|
|
14
13
|
* flatArray('a', ['b', 'c'], 'd') // => ['a', 'b', 'c', 'd']
|
|
15
14
|
* flatArray(1, [2, 3], 4) // => [1, 2, 3, 4]
|
package/utils/get.js
CHANGED
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* - Returns `undefined` gracefully when a step is missing (`safe: true`)
|
|
7
7
|
*
|
|
8
8
|
* @module utils/get
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
*
|
|
12
11
|
* @example
|
|
13
|
-
* import get from 'ergo/utils/get';
|
|
12
|
+
* import get from '@centralping/ergo/utils/get';
|
|
14
13
|
*
|
|
15
14
|
* get({a: {b: {c: 42}}}, 'a.b.c') // => 42
|
|
16
15
|
* get({a: null}, 'a.b.c', {safe: true}) // => undefined (no throw)
|
package/utils/http-errors.js
CHANGED
|
@@ -15,14 +15,13 @@
|
|
|
15
15
|
* catches them and forwards to `send()` for serialization.
|
|
16
16
|
*
|
|
17
17
|
* @module utils/http-errors
|
|
18
|
-
* @version 0.1.0
|
|
19
18
|
* @since 0.1.0
|
|
20
19
|
* @requires node:http
|
|
21
20
|
*
|
|
22
21
|
* @see {@link https://www.rfc-editor.org/rfc/rfc9457 RFC 9457 - Problem Details for HTTP APIs}
|
|
23
22
|
*
|
|
24
23
|
* @example
|
|
25
|
-
* import httpErrors from 'ergo/utils/http-errors';
|
|
24
|
+
* import httpErrors from '@centralping/ergo/utils/http-errors';
|
|
26
25
|
*
|
|
27
26
|
* throw httpErrors(404);
|
|
28
27
|
* // Error { name: 'NotFound', status: 404, type: 'https://...', title: 'Not Found', detail: 'Not Found' }
|
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
* Used by `lib/body/multiparse.js` for multipart boundary splitting.
|
|
9
9
|
*
|
|
10
10
|
* @module utils/iterables/buffer-split
|
|
11
|
-
* @version 0.1.0
|
|
12
11
|
* @since 0.1.0
|
|
13
12
|
* @requires ../buffers/split.js
|
|
14
13
|
*
|
|
15
14
|
* @example
|
|
16
|
-
* import {chain, bufferSplit, reduce} from 'ergo/utils/iterables';
|
|
15
|
+
* import {chain, bufferSplit, reduce} from '@centralping/ergo/utils/iterables';
|
|
17
16
|
*
|
|
18
17
|
* const chunks = [Buffer.from('a--b--c')];
|
|
19
18
|
* const result = chain(chunks, bufferSplit('--'), reduce((acc, [, b]) => [...acc, b.toString()], []));
|
package/utils/iterables/chain.js
CHANGED
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
* This is the core primitive for building lazy data pipelines with the iterable utilities.
|
|
9
9
|
*
|
|
10
10
|
* @module utils/iterables/chain
|
|
11
|
-
* @version 0.1.0
|
|
12
11
|
* @since 0.1.0
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
|
-
* import {chain, map, filter, reduce} from 'ergo/utils/iterables';
|
|
14
|
+
* import {chain, map, filter, reduce} from '@centralping/ergo/utils/iterables';
|
|
16
15
|
*
|
|
17
16
|
* chain(
|
|
18
17
|
* [1, 2, 3, 4, 5],
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* flag is added to avoid infinite loops with stateful regexes.
|
|
7
7
|
*
|
|
8
8
|
* @module utils/iterables/exec-all
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
*
|
|
12
11
|
* @example
|
|
13
|
-
* import execAll from 'ergo/utils/iterables/exec-all';
|
|
12
|
+
* import execAll from '@centralping/ergo/utils/iterables/exec-all';
|
|
14
13
|
*
|
|
15
14
|
* const findWords = execAll(/([a-z]+)/ig);
|
|
16
15
|
* [...findWords('hello world')] // => [['hello'], ['world']]
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* to the predicate (same signature as `Array.prototype.filter`).
|
|
7
7
|
*
|
|
8
8
|
* @module utils/iterables/filter
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
*
|
|
12
11
|
* @example
|
|
13
|
-
* import {chain, filter} from 'ergo/utils/iterables';
|
|
12
|
+
* import {chain, filter} from '@centralping/ergo/utils/iterables';
|
|
14
13
|
*
|
|
15
14
|
* [...chain([1, 2, 3, 4], filter(x => x % 2 === 0))] // => [2, 4]
|
|
16
15
|
*/
|
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
* for iterables, but composable in a `chain()` pipeline.
|
|
7
7
|
*
|
|
8
8
|
* @module utils/iterables/for-each
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
* @requires ./map.js
|
|
12
11
|
*
|
|
13
12
|
* @example
|
|
14
|
-
* import {chain, forEach, reduce} from 'ergo/utils/iterables';
|
|
13
|
+
* import {chain, forEach, reduce} from '@centralping/ergo/utils/iterables';
|
|
15
14
|
*
|
|
16
15
|
* chain(
|
|
17
16
|
* [1, 2, 3],
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* interface for code that receives streams and needs to iterate them.
|
|
7
7
|
*
|
|
8
8
|
* @module utils/iterables/from-stream
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
*
|
|
12
11
|
* @example
|
|
13
|
-
* import fromStream from 'ergo/utils/iterables/from-stream';
|
|
12
|
+
* import fromStream from '@centralping/ergo/utils/iterables/from-stream';
|
|
14
13
|
* import {Readable} from 'node:stream';
|
|
15
14
|
*
|
|
16
15
|
* const readable = Readable.from(['hello', ' ', 'world']);
|
package/utils/iterables/index.js
CHANGED
package/utils/iterables/map.js
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
* async generators; sync transforms produce sync generators.
|
|
7
7
|
*
|
|
8
8
|
* @module utils/iterables/map
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
* @requires ../type.js
|
|
12
11
|
*
|
|
13
12
|
* @example
|
|
14
|
-
* import {chain, map} from 'ergo/utils/iterables';
|
|
13
|
+
* import {chain, map} from '@centralping/ergo/utils/iterables';
|
|
15
14
|
*
|
|
16
15
|
* [...chain([1, 2, 3], map(x => x * 2))] // => [2, 4, 6]
|
|
17
16
|
*
|
package/utils/iterables/range.js
CHANGED
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* stepping by `step`. Mirrors Python's `range()` behaviour.
|
|
6
6
|
*
|
|
7
7
|
* @module utils/iterables/range
|
|
8
|
-
* @version 0.1.0
|
|
9
8
|
* @since 0.1.0
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
|
-
* import range from 'ergo/utils/iterables/range';
|
|
11
|
+
* import range from '@centralping/ergo/utils/iterables/range';
|
|
13
12
|
*
|
|
14
13
|
* [...range(5)] // => [0, 1, 2, 3, 4]
|
|
15
14
|
* [...range(1, 5)] // => [1, 2, 3, 4]
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* least one element, the first element is used as the initial accumulator.
|
|
7
7
|
*
|
|
8
8
|
* @module utils/iterables/reduce
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
*
|
|
12
11
|
* @example
|
|
13
|
-
* import {chain, reduce} from 'ergo/utils/iterables';
|
|
12
|
+
* import {chain, reduce} from '@centralping/ergo/utils/iterables';
|
|
14
13
|
*
|
|
15
14
|
* chain([1, 2, 3, 4], reduce((sum, x) => sum + x, 0)) // => 10
|
|
16
15
|
*/
|
package/utils/iterables/take.js
CHANGED
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* then returns (stops iteration).
|
|
6
6
|
*
|
|
7
7
|
* @module utils/iterables/take
|
|
8
|
-
* @version 0.1.0
|
|
9
8
|
* @since 0.1.0
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
|
-
* import {chain, take} from 'ergo/utils/iterables';
|
|
11
|
+
* import {chain, take} from '@centralping/ergo/utils/iterables';
|
|
13
12
|
*
|
|
14
13
|
* [...chain([1, 2, 3, 4, 5], take(3))] // => [1, 2, 3]
|
|
15
14
|
*/
|
package/utils/observables/map.js
CHANGED
package/utils/pick.js
CHANGED
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
* - Rename tuples: `pick(obj, ['a.b', 'c'])` extracts `obj.a.b` as `result.c`
|
|
7
7
|
*
|
|
8
8
|
* @module utils/pick
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
* @requires ./get.js
|
|
12
11
|
* @requires ./set.js
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
|
-
* import pick from 'ergo/utils/pick';
|
|
14
|
+
* import pick from '@centralping/ergo/utils/pick';
|
|
16
15
|
*
|
|
17
16
|
* pick({a: {b: 1}, c: 2}, 'a.b', 'c')
|
|
18
17
|
* // => {a: {b: 1}, c: 2}
|
package/utils/set.js
CHANGED
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* Array nodes are created when the next path segment is a valid integer string.
|
|
7
7
|
*
|
|
8
8
|
* @module utils/set
|
|
9
|
-
* @version 0.1.0
|
|
10
9
|
* @since 0.1.0
|
|
11
10
|
*
|
|
12
11
|
* @example
|
|
13
|
-
* import set from 'ergo/utils/set';
|
|
12
|
+
* import set from '@centralping/ergo/utils/set';
|
|
14
13
|
*
|
|
15
14
|
* const obj = {};
|
|
16
15
|
* set(obj, 'a.b.c', 42); // obj => {a: {b: {c: 42}}}
|