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

docs: add instruction to query objects with npm view #5527

Merged
merged 2 commits into from
Sep 22, 2022

Conversation

moonith
Copy link
Contributor

@moonith moonith commented Sep 17, 2022

Add missing section to npm view docs.

Current documentation of npm view does not describe how one can query field that is an object.
After checking the code and finding:

const parseSqBrackets = str => {
const index = sqBracketsMatcher(str)
// once we find square brackets, we recursively parse all these
if (index) {
const preSqBracketPortion = index[1]
// we want to have a `new String` wrapper here in order to differentiate
// between multiple occurences of the same string, e.g:
// foo.bar[foo.bar] should split into { foo: { bar: { 'foo.bar': {} } }
/* eslint-disable-next-line no-new-wrappers */
const foundKey = new String(index[2])
const postSqBracketPortion = index[3]
// we keep track of items found during this step to make sure
// we don't try to split-separate keys that were defined within
// square brackets, since the key name itself might contain dots
sqBracketItems.add(foundKey)
// returns an array that contains either dot-separate items (that will
// be splitted appart during the next step OR the fully parsed keys
// read from square brackets, e.g:
// foo.bar[1.0.0].a.b -> ['foo.bar', '1.0.0', 'a.b']
return [
...parseSqBrackets(preSqBracketPortion),
foundKey,
...(postSqBracketPortion ? parseSqBrackets(postSqBracketPortion) : []),
]
}
// at the end of parsing, any usage of the special empty-bracket syntax
// (e.g: foo.array[]) has not yet been parsed, here we'll take care
// of parsing it and adding a special symbol to represent it in
// the resulting list of keys
return replaceAppendSymbols(str)
}

I was able to query it.

I believe putting this section will make it less cryptic.

References

@moonith moonith requested a review from a team as a code owner September 17, 2022 00:15
@moonith moonith changed the title add instruction to query objects with npm view docs: add instruction to query objects with npm view Sep 17, 2022
@lukekarrys
Copy link
Contributor

Thanks for the change! I agree that a docs update here is really nice to make this behavior easier to find. However, I'm not able to run that command in my shell. I tried both zsh 5.8.1 (x86_64-apple-darwin21.0) and GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin21), but neither of those outputted anything.

Can you share an example of where you are running this command and its output?

@lukekarrys lukekarrys added the Awaiting Information further information is requested label Sep 21, 2022
Copy link
Contributor

@lukekarrys lukekarrys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes until we can confirm the best cross-shell way to run this type of command.

@moonith
Copy link
Contributor Author

moonith commented Sep 21, 2022

Hey, that was a typo on my end. I've made a major version 14 instead of 4. Try running it now - it will work

@moonith moonith requested a review from lukekarrys September 21, 2022 23:17
@lukekarrys
Copy link
Contributor

I should've caught that 😄 Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Information further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants