microsoft / microsoft/node-jsonc-parser
Support "replace" utility function
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 759
- Forks
- 66
- Ø Merge
- 5 T. 10 Std.
- Gemergte PRs (30 T.)
- 7
Beschreibung
Similar to the "modify" function, but allowing the key to be changed too.
The two use cases I have in mind for this is:
- Renaming a key in-place while retaining the existing value
- Replacing an existing key/value with new key/value in the same place
Of course, the existing modify function could be overloaded to support this, but I suggest a new function because:
- It's not valid to supply the root for a replace
- The meaning of undefined value param changes
Example of how this would look if "replace" is implemented:
/**
* Computes the edit operations needed to replace a key/value in the JSON document.
*
* @param documentText The input text
* @param path The path of the value to change. The path represents either to a property or an array item.
* If the path points to an non-existing property or item, an error will be thrown.
* @param key The new key name for the specified property or item.
* @param value The new value for the specified property or item. If the value is undefined,
* the existing value will be retained.
* @param options Options
* @returns The edit operations describing the changes to the original document, following the format described in {@linkcode EditResult}.
* To apply the edit operations to the input, use {@linkcode applyEdits}.
*/
export function replace(text: string, path: JSONPath, key: string, value: any, options: ModificationOptions): EditResult;
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 der Überprüfung der vorhandenen Funktion "modify" und ihrer Behandlung von Pfaden, Schlüsseln und undefined-Werten. Definiere das Replace-Verhalten für das Umbenennen eines Schlüssels, das Ersetzen eines Schlüssel/Wert-Paars, das Zurückweisen des Root-Pfads und das Beibehalten des Werts, wenn er undefined ist; fertig ist die Aufgabe, wenn die exportierte Funktion für diese Fälle die dokumentierten Edit-Operationen erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100