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

Querying keys with spaces and special separators in them #77

Open
cburatto opened this issue Dec 14, 2022 · 0 comments
Open

Querying keys with spaces and special separators in them #77

cburatto opened this issue Dec 14, 2022 · 0 comments

Comments

@cburatto
Copy link

I am reopening this issue after making comments to a closed issue

#37 (comment)

@rhalff rhalff you mention "it's better to solve it in your own code" but we don't always know the object schema.
Is it possible to implement the following?

const object = {
    foo: {
        bar: 'one'
    },
    'foo.bar': 'two',
    'some': {
        'other.node': {
            is: 'three'
        }
    }
}

let value = dot.pick('some["other.node"].is', object);

// three

let value = dot.pick('some["foo.bar"]', object);

// two 

let value = dot.pick('some.foo.bar', object);

// one

This is similar to what I would do in code, and it should cover scenarios where the property has spaces and characters that might be used as alternative separators https://github.com/rhalff/dot-object#using-a-different-separator

This could work interchangeably, even for non-dotted properties:

dot.pick('foo.bar', object) === dot.pick('["foo"]["bar"]', object)

dot.pick('["foo.bar"]', object) === object["foo.bar"]

@cburatto cburatto changed the title Querying keys with spaces in them Querying keys with spaces and special separators in them Dec 14, 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

No branches or pull requests

1 participant