spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / is-outside-working-tree / normal-path-of.ts
25 lines · 765 BRaw
1/**
2 * An absolute path spelled one way, its names joined by `/` with no
3 * leading or trailing one: either separator splits, `.` and empty names
4 * drop, `..` drops the name before it. No disk is read, no link followed.
5 *
6 * A drive-letter path is lowercased, as its file system compares names.
7 *
8 * @param path an absolute path, POSIX or drive-letter
9 * @returns the names joined, empty for the root
10 */
11export function normalPathOf(path: string): string {
12 const names: string[] = []
13
14 for (const name of path.split(/[\\/]/)) {
15 if (name === '..') {
16 names.pop()
17 } else if (name !== '' && name !== '.') {
18 names.push(name)
19 }
20 }
21
22 const spelled = names.join('/')
23
24 return /^[A-Za-z]:/.test(spelled) ? spelled.toLowerCase() : spelled
25}