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

Allow negative indexes in json operators #7849

Merged

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Nov 21, 2023

Fixes #7839.

This PR allows negative indexes to be used as input to the JSON operators: -1 means last item of the array, -2 means next-to-last item, and so on. A negative index that would go "past" the start of the array will be treated as an invalid index, e.g. in an array of length 5, the index -5 would be the first item in the list, but trying to do jsonget[-6] would produce an empty result. Similarly, trying to do jsonset[-6],[newValue] would return the original JSON data unchanged, just as jsonset does with any other invalid index.

Negative indexes will be treated as counting from the end, so -1 means
last item of the array, -2 means next-to-last item, and so on.
Copy link

vercel bot commented Nov 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview Nov 21, 2023 3:03am

@Jermolene
Copy link
Owner

Looks good thanks @rmunn

@Jermolene Jermolene merged commit ab72cc7 into Jermolene:master Nov 21, 2023
4 checks passed
munnox pushed a commit to munnox/TiddlyWiki5 that referenced this pull request Dec 24, 2023
* Add unit tests for negative indexes in json ops

* Allow negative indexes in JSON operators

Negative indexes will be treated as counting from the end, so -1 means
last item of the array, -2 means next-to-last item, and so on.

* Add documentation for negative indexes
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.

[IDEA] Allow negative indexes in jsonget/set/etc operators for array access from end
2 participants