Skip to content
Myr

refactor: use `Array.prototype.at()` to look at the end (#3703)

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

authored by ryu · committed by GitHub · parent 76b7109 · Browse files · 5 files+13 added−17 removed
This commit

State

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

Diff stats

5 files+13 added−17 removed

  • other:+13 added−17 removed

5 files+13 added−17 removed

modified:src/client/client.ts+7 added-7 removed
125 unmodified lines
126 createProxy(function proxyCallback(opts) {127 const parts = [...opts.path]128129 // allow calling .toString() and .valueOf() on the proxy130 if (parts[parts.length - 1] === 'toString') {131 if (parts[parts.length - 2] === 'name') {130 if (parts.at(-1) === 'toString') {131 if (parts.at(-2) === 'name') {132 // e.g. hc().somePath.name.toString() -> "somePath"133 return parts[parts.length - 3] || ''133 return parts.at(-3) || ''134 }135 // e.g. hc().somePath.toString()136 return proxyCallback.toString()137 }138139 if (parts[parts.length - 1] === 'valueOf') {140 if (parts[parts.length - 2] === 'name') {139 if (parts.at(-1) === 'valueOf') {140 if (parts.at(-2) === 'name') {141 // e.g. hc().somePath.name.valueOf() -> "somePath"142 return parts[parts.length - 3] || ''142 return parts.at(-3) || ''143 }144 // e.g. hc().somePath.valueOf()145 return proxyCallback146 }147148 let method = ''149 if (/^\$/.test(parts[parts.length - 1])) {149 if (/^\$/.test(parts.at(-1) as string)) {150 const last = parts.pop()151 if (last) {152 method = last.replace(/^\$/, '')153 }
51 unmodified lines
modified:src/helper/html/index.ts+1 added-1 removed
modified:src/middleware/trailing-slash/index.ts+2 added-6 removed
modified:src/router/pattern-router/router.ts+1 added-1 removed
modified:src/utils/url.ts+2 added-2 removed
128 unmodified lines
129export const getPathNoStrict = (request: Request): string => {130 const result = getPath(request)131132 // if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same133 return result.length > 1 && result[result.length - 1] === '/' ? result.slice(0, -1) : result133 return result.length > 1 && result.at(-1) === '/' ? result.slice(0, -1) : result134}135136export const mergePath = (...paths: string[]): string => {137 let p: string = ''138 let endsWithSlash = false139140 for (let path of paths) {141 /* ['/hey/','/say'] => ['/hey', '/say'] */142 if (p[p.length - 1] === '/') {142 if (p.at(-1) === '/') {143 p = p.slice(0, -1)144 endsWithSlash = true145 }146
167 unmodified lines