Skip to content

Commit 0c1f978

Browse files
committed
Simplified mergePath
1 parent 565f8a6 commit 0c1f978

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib/stringPath.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export function splitPath<T extends object>(path: string) {
99

1010
export function mergePath(path: (string | number | symbol)[]) {
1111
return path.reduce((acc: string, next) => {
12-
if (typeof next === 'number' || !isNaN(parseInt(String(next), 10)))
13-
acc += `[${String(next)}]`;
14-
else if (!acc) acc += String(next);
15-
else acc += `.${String(next)}`;
12+
const key = String(next);
13+
if (typeof next === 'number' || /^\d+$/.test(key)) acc += `[${key}]`;
14+
else if (!acc) acc += key;
15+
else acc += `.${key}`;
1616

1717
return acc;
1818
}, '');

0 commit comments

Comments
 (0)