@@ -125,28 +125,29 @@ export const hc = <T extends Hono<any, any, any>>(
125
125
) =>
126
126
createProxy ( function proxyCallback ( opts ) {
127
127
const parts = [ ...opts . path ]
128
+ const lastParts = parts . slice ( - 3 ) . reverse ( )
128
129
129
130
// allow calling .toString() and .valueOf() on the proxy
130
- if ( parts . at ( - 1 ) === 'toString' ) {
131
- if ( parts . at ( - 2 ) === 'name' ) {
131
+ if ( lastParts [ 0 ] === 'toString' ) {
132
+ if ( lastParts [ 1 ] === 'name' ) {
132
133
// e.g. hc().somePath.name.toString() -> "somePath"
133
- return parts . at ( - 3 ) || ''
134
+ return lastParts [ 2 ] || ''
134
135
}
135
136
// e.g. hc().somePath.toString()
136
137
return proxyCallback . toString ( )
137
138
}
138
139
139
- if ( parts . at ( - 1 ) === 'valueOf' ) {
140
- if ( parts . at ( - 2 ) === 'name' ) {
140
+ if ( lastParts [ 0 ] === 'valueOf' ) {
141
+ if ( lastParts [ 1 ] === 'name' ) {
141
142
// e.g. hc().somePath.name.valueOf() -> "somePath"
142
- return parts . at ( - 3 ) || ''
143
+ return lastParts [ 2 ] || ''
143
144
}
144
145
// e.g. hc().somePath.valueOf()
145
146
return proxyCallback
146
147
}
147
148
148
149
let method = ''
149
- if ( / ^ \$ / . test ( parts . at ( - 1 ) as string ) ) {
150
+ if ( / ^ \$ / . test ( lastParts [ 0 ] as string ) ) {
150
151
const last = parts . pop ( )
151
152
if ( last ) {
152
153
method = last . replace ( / ^ \$ / , '' )
0 commit comments