jsonc-morph 0.1.3 → 0.2.1
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 +25 -16
- package/esm/lib/rs_lib.internal.d.ts +1152 -120
- package/esm/lib/rs_lib.internal.d.ts.map +1 -1
- package/esm/lib/rs_lib.internal.js +1835 -282
- package/esm/lib/rs_lib.js +3414 -2819
- package/esm/mod.d.ts +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -1
- package/package.json +1 -1
- package/script/lib/rs_lib.internal.d.ts +1152 -120
- package/script/lib/rs_lib.internal.d.ts.map +1 -1
- package/script/lib/rs_lib.internal.js +1853 -285
- package/script/lib/rs_lib.js +3414 -2819
- package/script/mod.d.ts +1 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +8 -1
package/README.md
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
Programmatically edit JSONC in JavaScript.
|
|
7
7
|
|
|
8
|
-
This is especially useful for
|
|
9
|
-
|
|
8
|
+
This is especially useful for making programmatic changes to JSON config files.
|
|
9
|
+
It's not recommended for very large files as this is using
|
|
10
10
|
[jsonc-parser](https://github.com/dprint/jsonc-parser/) via Wasm under the hood.
|
|
11
11
|
|
|
12
12
|
## Install
|
|
@@ -14,7 +14,7 @@ changes to. It's not recommended for very large files as this is using
|
|
|
14
14
|
Deno:
|
|
15
15
|
|
|
16
16
|
```
|
|
17
|
-
deno add
|
|
17
|
+
deno add jsr:@david/jsonc-morph
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Or with npm:
|
|
@@ -29,21 +29,30 @@ npm install jsonc-morph
|
|
|
29
29
|
import { parse } from "@david/jsonc-morph";
|
|
30
30
|
|
|
31
31
|
const root = parse(`{
|
|
32
|
-
//
|
|
33
|
-
"data"
|
|
34
|
-
}`);
|
|
35
|
-
|
|
32
|
+
// 1
|
|
33
|
+
"data" /* 2 */: 123 // 3
|
|
34
|
+
} // 4`);
|
|
35
|
+
|
|
36
|
+
// get the root object
|
|
37
|
+
const rootObj = root.asObjectOrThrow();
|
|
38
|
+
|
|
39
|
+
// set its "data" property to have a new value
|
|
36
40
|
rootObj.getOrThrow("data").setValue({
|
|
37
41
|
"nested": true,
|
|
38
42
|
});
|
|
43
|
+
|
|
44
|
+
// append a new key
|
|
39
45
|
rootObj.append("new_key", [456, 789, false]);
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
|
|
47
|
+
// inspect the output
|
|
48
|
+
assertEquals(
|
|
49
|
+
root.toString(),
|
|
50
|
+
`{
|
|
51
|
+
// 1
|
|
52
|
+
"data" /* 2 */: {
|
|
53
|
+
"nested": true
|
|
54
|
+
}, // 3
|
|
55
|
+
"new_key": [456, 789, false]
|
|
56
|
+
} // 4`,
|
|
57
|
+
);
|
|
49
58
|
```
|