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

question: how to remove property from object #136

Open
bhainesva opened this issue Jan 15, 2021 · 0 comments
Open

question: how to remove property from object #136

bhainesva opened this issue Jan 15, 2021 · 0 comments

Comments

@bhainesva
Copy link

I'd like to remove a property with a specific name from an object. For example given:

const x = {
  numprop: 3, // important comment about the numprop
  filter: {
     test: "hi",
  },
  objprop: {
     a: "a"
  },
}

I'd like to remove the filter property and end up with:

const x = {
  numprop: 3, // important comment about the numprop
  objprop: {
     a: "a"
  },
}

My first attempt was grasp 'obj.props[key=#filter]' -R '' but this leaves an extra comma where the property was removed.

I also tried grasp 'obj! > prop[key=#filter]' -R '{\n{{.props[key!=#filter] | join ",\n" }}\n}' which does work, but since it rewrites the whole object it also removes any comments on the parts of the object I want to keep. Is there an alternative to avoid this?

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

No branches or pull requests

1 participant