Skip to content
Myr

fix(client): Support browsers without Array.prototype.at (#4057)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Anton Kuznetsov · committed by GitHub · parent 882e75a · Browse files · 1 file+8 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−7 removed

  • other:+8 added−7 removed

1 file+8 added−7 removed

modified:src/client/client.ts+8 added-7 removed
123 unmodified lines
124 options?: ClientRequestOptions125) =>126 createProxy(function proxyCallback(opts) {127 const parts = [...opts.path]128 const lastParts = parts.slice(-3).reverse()129130 // allow calling .toString() and .valueOf() on the proxy130 if (parts.at(-1) === 'toString') {131 if (parts.at(-2) === 'name') {131 if (lastParts[0] === 'toString') {132 if (lastParts[1] === 'name') {133 // e.g. hc().somePath.name.toString() -> "somePath"133 return parts.at(-3) || ''134 return lastParts[2] || ''135 }136 // e.g. hc().somePath.toString()137 return proxyCallback.toString()138 }139139 if (parts.at(-1) === 'valueOf') {140 if (parts.at(-2) === 'name') {140 if (lastParts[0] === 'valueOf') {141 if (lastParts[1] === 'name') {142 // e.g. hc().somePath.name.valueOf() -> "somePath"142 return parts.at(-3) || ''143 return lastParts[2] || ''144 }145 // e.g. hc().somePath.valueOf()146 return proxyCallback147 }148149 let method = ''149 if (/^\$/.test(parts.at(-1) as string)) {150 if (/^\$/.test(lastParts[0] as string)) {151 const last = parts.pop()152 if (last) {153 method = last.replace(/^\$/, '')154 }
51 unmodified lines