elrh-cosca 0.2.6 → 0.2.8

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
@@ -66,18 +66,34 @@ The merger is performed using [unjs/magicast](https://github.com/unjs/magicast).
66
66
  - create a unique-union in case of arrays
67
67
  Please [report](https://github.com/AloisSeckar/elrh-cosca/issues) any logical flaws and issues of the process.
68
68
 
69
+ **Warning**: The function will fail, if the extracted object is proxied (e.g. when created using `defu`). In such case, the error would be:
70
+
71
+ ```
72
+ TypeError: 'set' on proxy: trap returned falsish for property '<YOUR_PROPERTY>'
73
+ ```
74
+
75
+ If possible, you need to alter your logic, e.g. by creating a new object via the spread operator.
76
+
77
+
69
78
  By default the function asks for confirmation before attempting to alter the `targetFile`. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts. Passsing a custom `prompt` allows tailoring your own question to the user.
70
79
 
71
80
  #### `updateJsonFile`
72
81
 
73
82
  ```ts
74
83
  async function updateJsonFile(
75
- pathToFile: string, jsonKey: string, newValues: Record<string | number | symbol, any>,
84
+ pathToFile: string, jsonKey: string, patch: JsonValue,
76
85
  force: boolean = false, prompt: string = ''
77
86
  ): Promise<void>
78
87
  ```
79
88
 
80
- Takes a path to a JSON file and injects `newValues` under `jsonKey` key.
89
+ Takes a path to a JSON file and injects `patch` under `jsonKey` key. A `patch` is of `JsonValue` - a custom type defined as follows:
90
+
91
+ ```ts
92
+ type JsonPrimitive = string | number | boolean | null
93
+ type JsonObject = { [key: string]: JsonValue }
94
+ type JsonArray = JsonValue[]
95
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray
96
+ ```
81
97
 
82
98
  Path to `targetFile` is relative to `process.cwd()`. The file must be a valid JSON file. It is parsed using plain `JSON.parse`.
83
99