microsoft / microsoft/node-jsonc-parser
Provide usage examples
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 759
- Forks
- 66
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 7
Description
Already asked in https://github.com/microsoft/node-jsonc-parser/issues/74, but it was closed by the author.
The request still stands, it would be great to have a few examples to use the library to load/parse/write JSONC files.
I shouldn't need to ask LLMs how to use something, but thankfully it helped. Here's my tsconfig.json reference sorter:
import { readFile, writeFile } from "node:fs/promises";
import * as jsonc from "jsonc-parser";
const editsOptions = {
formattingOptions: { tabSize: 2, insertSpaces: true },
};
async function sortReferences(filePath) {
const contents = await readFile(filePath, "utf8");
const json = jsonc.parse(contents);
if (!json.references) {
return;
}
json.references.sort((a, b) => a.path.localeCompare(b.path));
const edits = jsonc.modify(
contents,
["references"],
json.references,
editsOptions,
);
const newContents = jsonc.applyEdits(contents, edits);
if (contents !== newContents) {
await writeFile(filePath, newContents);
console.log(`Sorted: ${filePath}`);
}
}
for (const filePath of process.argv.slice(2)) {
void sortReferences(filePath).catch((error) => {
throw new Error(`Error sorting references in ${filePath}`, {
cause: error,
});
});
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript example in the issue and review the library's public parse, modify, and applyEdits entry points. Done means adding a few clear examples covering loading, parsing, and writing JSONC files, including the formatting and edit flow shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100