path.ts
This file
Path
src/middleware/serve-static/path.ts
25 lines · 775 bytes · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–25why, one step back1/**2 * `defaultJoin` does not support Windows paths and always uses `/` separators.3 * If you need Windows path support, please use `join` exported from `node:path` etc. instead.4 */5export const defaultJoin = (...paths: string[]): string => {6 // Join non-empty paths with '/'7 let result = paths.filter((p) => p !== '').join('/')89 // Normalize multiple slashes to single slash10 result = result.replace(/(?<=\/)\/+/g, '')1112 // Handle path resolution (. and ..)13 const segments = result.split('/')14 const resolved = []1516 for (const segment of segments) {17 if (segment === '..' && resolved.length > 0 && resolved.at(-1) !== '..') {18 resolved.pop()19 } else if (segment !== '.') {20 resolved.push(segment)21 }22 }2324 return resolved.join('/') || '.'25}