type-fest
type-fest copied to clipboard
Use `number` for array indexes in `ToPath`
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]
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
Seems like what is needed is in the
Get
Can this whole request be summarized into: Use number for array indexes in ToPath?
Yes and also ToPath has to be exported as well. Let me change the title and description
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?
Size isn't necessarily a problem but continuous requests may be. There are 10 open issues tagged https://github.com/sindresorhus/type-fest/labels/component%3Apaths and every related file has already received a lot of tweaks.
Cool I'm interested in working on exposing this and implementing this