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

Use number for array indexes in ToPath #979

Open
NicolasCwy opened this issue Nov 8, 2024 · 6 comments
Open

Use number for array indexes in ToPath #979

NicolasCwy opened this issue Nov 8, 2024 · 6 comments
Labels
component:paths enhancement New feature or request

Comments

@NicolasCwy
Copy link

NicolasCwy commented Nov 8, 2024

Would it be possible to add an option to make paths in array format instead of dot format
Some form item libraries e.g Antd use arrays of strings/ number to denote the path, essentially splitting them by the "." that separates them.

type Obj = {
  a: {
    b: {
      e: string;
    };
    c: {
      d: ['foo'];
    };
  };
};

// Current feature
a.c.d[0]
a.c.d.0

// New Feature - array notation
["a", "c", "d", 0] 

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@NicolasCwy NicolasCwy added the enhancement New feature or request label Nov 8, 2024
@NicolasCwy NicolasCwy changed the title Add option to ignore arrays in Path type Add option to make path an array type instead of dot notation Nov 9, 2024
@NicolasCwy NicolasCwy changed the title Add option to make path an array type instead of dot notation Add array notation for path type Nov 9, 2024
@NicolasCwy
Copy link
Author

NicolasCwy commented Nov 12, 2024

Seems like what is needed is in the Get source file, with some slight tweaks

// Current behaviour
ToPath<'foo[0].bar.baz'>
//=> ['foo', '0', 'bar', 'baz']

// Expected behaviour
ToPath<'foo[0].bar.baz'>
//=> ['foo', 0, 'bar', 'baz'] // 0 should be a number since it is an array index

@fregante
Copy link
Collaborator

fregante commented Nov 12, 2024

Seems like what is needed is in the Get

Can this whole request be summarized into: Use number for array indexes in ToPath?

@NicolasCwy
Copy link
Author

NicolasCwy commented Nov 12, 2024

Yes and also ToPath has to be exported as well. Let me change the title and description

@voxpelli
Copy link
Collaborator

Question to other maintainers: At what point are the path related helpers so large and complex that they merit extraction into a standalone project that focuses on them and just them?

@fregante fregante changed the title Add array notation for path type Use number for array indexes in ToPath Nov 13, 2024
@fregante
Copy link
Collaborator

fregante commented Nov 13, 2024

Size isn't necessarily a problem but continuous requests may be. There are 10 open issues tagged component:paths and every related file has already received a lot of tweaks.

@NicolasCwy
Copy link
Author

NicolasCwy commented Nov 13, 2024

Cool I'm interested in working on exposing this and implementing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:paths enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants