microsoft / microsoft/node-jsonc-parser
Provide usage examples
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 759
- Forks
- 66
- Ø Merge
- 5 T. 10 Std.
- Gemergte PRs (30 T.)
- 7
Beschreibung
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,
});
});
}
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem TypeScript-Beispiel im Issue und überprüfe die öffentlichen Einstiegspunkte der Bibliothek für parse, modify und applyEdits. Als erledigt gilt die Ergänzung einiger klarer Beispiele zum Laden, Parsen und Schreiben von JSONC-Dateien, einschließlich des gezeigten Ablaufs für Formatierung und Bearbeitung.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- node.js, typescript
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100