Skip to content

Commit

Permalink
__path__
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Mar 25, 2024
1 parent 8c10612 commit a4f64b2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/common/utils/locale-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ type RetrievablePath<T, Delimiter extends string, Path extends string = ''> =
function getPathWithDelimiter<Shape extends PathAccessibleObject, Delimiter extends string>(delimiter: Delimiter, segments: string[] = []): RetrievablePath<Shape, Delimiter> {
const recursiveHandler = {
get(target: Shape, prop: string): unknown {
if (prop === 'toString') {
return () => segments.join(delimiter)
switch (prop) {
case '__path__': {
return segments.join(delimiter)
}
case 'toString': {
return () => segments.join(delimiter)
}
default: {
return getPathWithDelimiter<any, Delimiter>(delimiter, [...segments, prop])
}
}
return getPathWithDelimiter<any, Delimiter>(delimiter, [...segments, prop])
},
}
return new Proxy({} as any, recursiveHandler)
Expand Down

0 comments on commit a4f64b2

Please sign in to comment.