A convenience class for working with JSONC files — based on the Microsoft JSONC parser (https://github.com/microsoft/node-jsonc-parser) but more convenient to use for certain specific tasks.
Initialize a new tweaker from the given text or file. Note that there are no coalesced writes, so every successful edit will write back to the file. (If you need granular control of filesystem writees, then use the text mode and deal with the file yourself.)
_writeIfFile(): Promise<void>
getValue(path: Segment[]): unknown
Get the value at the specified path in the JSONC document. Returns undefined if the path doesn't lead to a value.
insertArrayValue(): Promise<boolean>
Insert the given value into the array at the given path. If the path does not exist in the receiver's JSONC, a new array will be created. Otherwise, the value will be inserted into the existing array.
Returns true if the edit succeeded, false otherwise. You can inspect the outErrors parameter to find out why the edit failed (maybe) — it may contain errors from the underlying Microsoft JSONC parser, or errors from this module.
fromFile(input: string): JSONCTweaker
Initialize a new tweaker from the given file — this means every change will write back to the file. There are no coalesced writes.
fromText(input: string): JSONCTweaker
Initialize a new tweaker from the given text