@thi.ng/parse 2.1.9 → 2.2.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/CHANGELOG.md +10 -1
- package/README.md +7 -4
- package/grammar.js +2 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +5 -2
- package/xform/json.d.ts +15 -0
- package/xform/json.js +18 -0
- package/xform/number.d.ts +19 -1
- package/xform/number.js +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-06-
|
|
3
|
+
- **Last updated**: 2022-06-15T13:10:05Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/parse@2.2.0) (2022-06-15)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add new transformers (json, numbers) ([2087131](https://github.com/thi-ng/umbrella/commit/2087131))
|
|
17
|
+
- add xfJson(), json() transform
|
|
18
|
+
- add int(), hexInt(), float() transform syntax sugar
|
|
19
|
+
- add `json` as built-in tx for grammar
|
|
20
|
+
|
|
12
21
|
### [2.1.8](https://github.com/thi-ng/umbrella/tree/@thi.ng/parse@2.1.8) (2022-06-09)
|
|
13
22
|
|
|
14
23
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ node --experimental-repl-await
|
|
|
90
90
|
> const parse = await import("@thi.ng/parse");
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
Package sizes (gzipped, pre-treeshake): ESM: 5.
|
|
93
|
+
Package sizes (gzipped, pre-treeshake): ESM: 5.48 KB
|
|
94
94
|
|
|
95
95
|
## Dependencies
|
|
96
96
|
|
|
@@ -209,8 +209,10 @@ Syntax sugars for `xform(parser, fn)`:
|
|
|
209
209
|
- `collect` - collect child results into array
|
|
210
210
|
- `count` - count number of children
|
|
211
211
|
- `discard` - discard result
|
|
212
|
+
- `float` / `int` / `hexInt` - join child results and parse as number
|
|
212
213
|
- `hoist` / `hoistResult` - hoist first child / child result
|
|
213
214
|
- `join` - join child results into string
|
|
215
|
+
- `json` - join child results into string and parse as JSON
|
|
214
216
|
- `nest` - apply another parser to result
|
|
215
217
|
- `print` - print AST
|
|
216
218
|
- `replace` - replace AST node result w/ pre-configured value
|
|
@@ -373,12 +375,13 @@ transforms](#transformers):
|
|
|
373
375
|
- `binary` - parse as binary number
|
|
374
376
|
- `collect` - collect sub terms into array
|
|
375
377
|
- `discard` - discard result
|
|
378
|
+
- `float` - join & parse as floating point number
|
|
379
|
+
- `hex` - join & parse as hex integer
|
|
376
380
|
- `hoist` - replace AST node with its 1st child
|
|
377
381
|
- `hoistR` - use result of 1st child term only
|
|
382
|
+
- `int` - join & parse as integer
|
|
378
383
|
- `join` - join sub terms into single string
|
|
379
|
-
- `
|
|
380
|
-
- `int` - parse as integer
|
|
381
|
-
- `hex` - parse as hex int
|
|
384
|
+
- `json` - join & parse as JSON
|
|
382
385
|
- `print` - print out node's subtree (AST)
|
|
383
386
|
- `trim` - trim result
|
|
384
387
|
|
package/grammar.js
CHANGED
|
@@ -30,6 +30,7 @@ import { xfCount } from "./xform/count.js";
|
|
|
30
30
|
import { discard, xfDiscard } from "./xform/discard.js";
|
|
31
31
|
import { hoist, hoistResult, xfHoist, xfHoistResult } from "./xform/hoist.js";
|
|
32
32
|
import { join, xfJoin } from "./xform/join.js";
|
|
33
|
+
import { xfJson } from "./xform/json.js";
|
|
33
34
|
import { nest } from "./xform/nest.js";
|
|
34
35
|
import { xfFloat, xfInt } from "./xform/number.js";
|
|
35
36
|
import { print, xfPrint } from "./xform/print.js";
|
|
@@ -248,6 +249,7 @@ export const defGrammar = (rules, env, opts) => {
|
|
|
248
249
|
hoistR: xfHoistResult,
|
|
249
250
|
int: xfInt(10),
|
|
250
251
|
join: xfJoin,
|
|
252
|
+
json: xfJson,
|
|
251
253
|
print: xfPrint(),
|
|
252
254
|
trim: xfTrim,
|
|
253
255
|
...env,
|
package/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export * from "./xform/count.js";
|
|
|
41
41
|
export * from "./xform/discard.js";
|
|
42
42
|
export * from "./xform/hoist.js";
|
|
43
43
|
export * from "./xform/join.js";
|
|
44
|
+
export * from "./xform/json.js";
|
|
44
45
|
export * from "./xform/nest.js";
|
|
45
46
|
export * from "./xform/number.js";
|
|
46
47
|
export * from "./xform/print.js";
|
package/index.js
CHANGED
|
@@ -41,6 +41,7 @@ export * from "./xform/count.js";
|
|
|
41
41
|
export * from "./xform/discard.js";
|
|
42
42
|
export * from "./xform/hoist.js";
|
|
43
43
|
export * from "./xform/join.js";
|
|
44
|
+
export * from "./xform/json.js";
|
|
44
45
|
export * from "./xform/nest.js";
|
|
45
46
|
export * from "./xform/number.js";
|
|
46
47
|
export * from "./xform/print.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/parse",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Purely functional parser combinators & AST generation for generic inputs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -212,6 +212,9 @@
|
|
|
212
212
|
"./xform/join": {
|
|
213
213
|
"default": "./xform/join.js"
|
|
214
214
|
},
|
|
215
|
+
"./xform/json": {
|
|
216
|
+
"default": "./xform/json.js"
|
|
217
|
+
},
|
|
215
218
|
"./xform/nest": {
|
|
216
219
|
"default": "./xform/nest.js"
|
|
217
220
|
},
|
|
@@ -238,5 +241,5 @@
|
|
|
238
241
|
],
|
|
239
242
|
"year": 2020
|
|
240
243
|
},
|
|
241
|
-
"gitHead": "
|
|
244
|
+
"gitHead": "2ce8e0bd338c781f3ad48e125d8af893ab74bb6c\n"
|
|
242
245
|
}
|
package/xform/json.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Parser, ScopeTransform } from "../api.js";
|
|
2
|
+
/**
|
|
3
|
+
* First joins all children via {@link xfJoin}, then parses resulting string
|
|
4
|
+
* using `JSON.parse()`.
|
|
5
|
+
*
|
|
6
|
+
* @param scope -
|
|
7
|
+
*/
|
|
8
|
+
export declare const xfJson: ScopeTransform<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Syntax sugar for `xform(parser, xfJson)`.
|
|
11
|
+
*
|
|
12
|
+
* @param parser -
|
|
13
|
+
*/
|
|
14
|
+
export declare const json: (parser: Parser<string>) => Parser<string>;
|
|
15
|
+
//# sourceMappingURL=json.d.ts.map
|
package/xform/json.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { xform } from "../combinators/xform.js";
|
|
2
|
+
import { xfJoin } from "./join.js";
|
|
3
|
+
/**
|
|
4
|
+
* First joins all children via {@link xfJoin}, then parses resulting string
|
|
5
|
+
* using `JSON.parse()`.
|
|
6
|
+
*
|
|
7
|
+
* @param scope -
|
|
8
|
+
*/
|
|
9
|
+
export const xfJson = (scope) => {
|
|
10
|
+
scope.result = JSON.parse(xfJoin(scope).result);
|
|
11
|
+
return scope;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Syntax sugar for `xform(parser, xfJson)`.
|
|
15
|
+
*
|
|
16
|
+
* @param parser -
|
|
17
|
+
*/
|
|
18
|
+
export const json = (parser) => xform(parser, xfJson);
|
package/xform/number.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ScopeTransform } from "../api.js";
|
|
1
|
+
import type { Parser, ScopeTransform } from "../api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Higher order transform. First joins all children via {@link xfJoin},
|
|
4
4
|
* then parses resulting string into an integer with given `radix`.
|
|
@@ -6,6 +6,18 @@ import type { ScopeTransform } from "../api.js";
|
|
|
6
6
|
* @param radix -
|
|
7
7
|
*/
|
|
8
8
|
export declare const xfInt: (radix?: number) => ScopeTransform<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Syntax sugar for `xform(parser, xfInt(10))`
|
|
11
|
+
*
|
|
12
|
+
* @param parser
|
|
13
|
+
*/
|
|
14
|
+
export declare const int: (parser: Parser<string>) => Parser<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Syntax sugar for `xform(parser, xfInt(16))`
|
|
17
|
+
*
|
|
18
|
+
* @param parser
|
|
19
|
+
*/
|
|
20
|
+
export declare const hexInt: (parser: Parser<string>) => Parser<string>;
|
|
9
21
|
/**
|
|
10
22
|
* First joins all children via {@link xfJoin}, then parses resulting
|
|
11
23
|
* string into a floating point value.
|
|
@@ -13,4 +25,10 @@ export declare const xfInt: (radix?: number) => ScopeTransform<string>;
|
|
|
13
25
|
* @param scope -
|
|
14
26
|
*/
|
|
15
27
|
export declare const xfFloat: ScopeTransform<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Syntax sugar for `xform(parser, xfFloat)`
|
|
30
|
+
*
|
|
31
|
+
* @param parser
|
|
32
|
+
*/
|
|
33
|
+
export declare const float: (parser: Parser<string>) => Parser<string>;
|
|
16
34
|
//# sourceMappingURL=number.d.ts.map
|
package/xform/number.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { xform } from "../combinators/xform.js";
|
|
1
2
|
import { xfJoin } from "./join.js";
|
|
2
3
|
/**
|
|
3
4
|
* Higher order transform. First joins all children via {@link xfJoin},
|
|
@@ -9,6 +10,18 @@ export const xfInt = (radix = 10) => (scope) => {
|
|
|
9
10
|
scope.result = parseInt(xfJoin(scope).result, radix);
|
|
10
11
|
return scope;
|
|
11
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Syntax sugar for `xform(parser, xfInt(10))`
|
|
15
|
+
*
|
|
16
|
+
* @param parser
|
|
17
|
+
*/
|
|
18
|
+
export const int = (parser) => xform(parser, xfInt(10));
|
|
19
|
+
/**
|
|
20
|
+
* Syntax sugar for `xform(parser, xfInt(16))`
|
|
21
|
+
*
|
|
22
|
+
* @param parser
|
|
23
|
+
*/
|
|
24
|
+
export const hexInt = (parser) => xform(parser, xfInt(16));
|
|
12
25
|
/**
|
|
13
26
|
* First joins all children via {@link xfJoin}, then parses resulting
|
|
14
27
|
* string into a floating point value.
|
|
@@ -19,3 +32,9 @@ export const xfFloat = (scope) => {
|
|
|
19
32
|
scope.result = parseFloat(xfJoin(scope).result);
|
|
20
33
|
return scope;
|
|
21
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Syntax sugar for `xform(parser, xfFloat)`
|
|
37
|
+
*
|
|
38
|
+
* @param parser
|
|
39
|
+
*/
|
|
40
|
+
export const float = (parser) => xform(parser, xfFloat);
|