microsoft / microsoft/node-jsonc-parser
Support "replace" utility function
Personne n'a encore pris cette issue.
- Langage dominant
- TypeScript
- Étoiles
- 759
- Forks
- 66
- Merge moyen
- 5 j 10 h
- PR mergées (30 j)
- 7
Description
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;
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner la fonction existante "modify" et la manière dont elle gère les chemins, les clés et les valeurs undefined. Définissez le comportement de replace pour renommer une clé, remplacer une clé/valeur, rejeter le chemin racine et conserver la valeur lorsqu’elle est undefined ; le travail est terminé lorsque la fonction exportée produit les opérations d’édition documentées pour ces cas.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100