Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: patch function for editing JSON5 while preserving comments (WIP) #262

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

giacomorebonato
Copy link

@giacomorebonato giacomorebonato commented Mar 7, 2022

This branch adds a patch function to the public API.

Its purpose is to allow the editing of a JSON5 object while preserving the comments in the file.
The API works like this.

let json5Text = `
  {
    hello: 'world' // this is a comment
  }
`

json5.patch(
  json5Text,
  {
    hello: 'world',
    my: 'friend'
  }
)

/* returns a string like this 
`
  {
    hello: 'world', // this is a comment
    my: 'friend'
  }
`

*/

Note that the comment is still present in the string. The above example is the most simple I can imagine, but it should work in many other cases that I mean to cover in the tests.

What do you think? Would you be welcoming such an addition @jordanbtucker ?
Happy to ultimate the work if so and I'll close the PR if you believe that it's out of the scope of this library.

Mentioning that:

@giacomorebonato giacomorebonato changed the title Proposal: add a patch function for editing while preserving comments (WIP) Proposal: patch function for editing JSON5 while preserving comments (WIP) Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant