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 CHANGED
@@ -5,8 +5,8 @@
5
5
 
6
6
  Programmatically edit JSONC in JavaScript.
7
7
 
8
- This is especially useful for config files that you need to make programmatic
9
- changes to. It's not recommended for very large files as this is using
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 @jsr:@david/jsonc-morph
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
- // comment
33
- "data": 123
34
- }`);
35
- let rootObj = root.asObjectOrThrow();
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
- const output = root.toString();
41
- // {
42
- // // comment
43
- // "data": {
44
- // "nested": true
45
- // },
46
- // "new_key": [456, 789, false]
47
- // }
48
- console.log(output);
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
  ```