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

WIP Feature request for object conversion #19

Open
linw1995 opened this issue Jul 30, 2020 · 0 comments
Open

WIP Feature request for object conversion #19

linw1995 opened this issue Jul 30, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@linw1995
Copy link
Owner

linw1995 commented Jul 30, 2020

Implements a simple and easy for usage syntax for object conversion.

Functions

Common Conversion

assert parse("${a:b, b:a}") \
    .find({"a": 1, "b": 2}) == [{"b": 1, "a": 2}], "swaps values between a and b" 
assert parse("${username:author_name, age:author_age}") \
    .find({
        "author_name": "Jade",
        "author_age": 18,
        "boo": "boo"
    }) == [{"username": "Jade", "age": 18}], "Rearranges the key-value pairs"

Conversion Can Be Applied To Array

assert parse("$[{a:b}]").find([{"b": 1}, {"c": 1}]) == [{"a": 1}, {"a": None}]
assert parse("$[{a:b}][a != null]").find([{"b": 1}, {"c": 1}]) == [{"a": 1}]

Nested Conversion

assert parse("${author: {name: author_name}}") \
    .find({"author_name": "Jade"}) == [{"author": {"name": "Jade"}}]

Or the key of the key-value pair may be chained path which components are name only, e.g. boo.bar

assert parse("${author.name: author_name}") \
    .find({"author_name": "Jade"}) == [{"author": {"name": "Jade"}}]

The Value Of The Key-Value Pair May Be An Expression

assert parse("${name: author.name}") \
    .find({"author": {"name": "Jade"}}) == [{"name": "Jade"}]

WIP Update key-value pairs

@linw1995 linw1995 added the enhancement New feature or request label Jul 30, 2020
@linw1995 linw1995 self-assigned this Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant