/** * @file Shared internals for the `paths/` module — the leaf-level primitives * every other path leaf depends on. Kept as a single file so `normalize`, * `predicates`, `conversion`, and `resolve` can layer above it without * circular imports. * * - char-code constants + shared regexps * - `pathLikeToString` — `string | Buffer | URL` → `string` * - `normalizePath` and its `msysDriveToNative` / `foldPathForCompare` helpers * — they live at the leaf because `conversion` and `resolve` call * `normalizePath` and `predicates` calls `foldPathForCompare`. Hosting them * one layer up made `paths/normalize` import its own importers, and the * built CJS barrel then snapshotted those re-exports as `undefined`. * Nothing here may import a sibling `paths/*` leaf. That is the invariant * `scripts/repo/check/reexports-have-no-import-cycles.mts` enforces. */ export { CHAR_BACKWARD_SLASH, CHAR_COLON, CHAR_FORWARD_SLASH, CHAR_LOWERCASE_A, CHAR_LOWERCASE_Z, CHAR_UPPERCASE_A, CHAR_UPPERCASE_Z, } from '../constants/encoding.js'; export declare const msysDriveRegExp: RegExp; export declare const nodeModulesPathRegExp: RegExp; export declare const slashRegExp: RegExp; export declare function appendNormalizedPathSegment(state: NormalizedPathState, segment: string, prefix: string): void; export interface NormalizedPathState { collapsed: string; segmentCount: number; leadingDotDots: number; } export declare function collapsePathParent(state: NormalizedPathState, prefix: string): void; /** * Normalize a path for equality comparison — forward slashes, no trailing * separator, lowercased on Windows. * * @example * ;```typescript * foldPathForCompare('C:\\Program Files\\') // 'c:/program files' * ``` */ export declare function foldPathForCompare(pathLike: string): string; export declare function hasUncPathPrefix(filepath: string): boolean; export declare function hasUncPathShare(filepath: string): boolean; /** * Find the next path separator at or after an index. * * Scans char codes for `/` (47) and `\` (92) — the same two characters * `slashRegExp` matches — and allocates nothing. Reaching the same answer * through `search` costs a substring, an options bag, and a regex match per * lookup, which a segment walk pays once per segment. * * @example * ;```typescript * indexOfPathSeparator('a/b', 0) // 1 * indexOfPathSeparator('a/b', 2) // -1 * indexOfPathSeparator('a\\b', 0) // 1 * ``` * * @param {string} filepath - The path to scan. * @param {number} fromIndex - The index to start scanning at. * * @returns {number} The index of the first separator at or after `fromIndex`, * or -1 when there is none. */ export declare function indexOfPathSeparator(filepath: string, fromIndex: number): number; export declare function isPathSeparatorCode(code: number): boolean; export declare function msysDriveToNative(normalized: string): string; export declare function normalizedPathPrefix(filepath: string): { __proto__: null; prefix: string; start: number; }; /** * Normalize a path by converting backslashes to forward slashes and collapsing * segments. * * - Converts all backslashes (`\`) to forward slashes (`/`) * - Collapses repeated slashes * - Resolves `.` and `..` segments * - Preserves UNC path prefixes (`//server/share`) * - Preserves Windows namespace prefixes (`//./`, `//?/`) * - Returns `.` for empty or collapsed paths * - On Windows: MSYS drive letters `/c/path` become `C:/path` * * @example * ;```typescript * normalizePath('foo/bar//baz') // 'foo/bar/baz' * normalizePath('foo/./bar') // 'foo/bar' * normalizePath('foo/bar/../baz') // 'foo/baz' * normalizePath('C:\\Users\\u\\file.txt') // 'C:/Users/u/file.txt' * normalizePath('\\\\server\\share\\file') // '//server/share/file' * normalizePath('') // '.' * ``` * * @param {string | Buffer | URL} pathLike - The path to normalize. * * @returns {string} The normalized path * * @security * **WARNING**: This function resolves `..` patterns as part of normalization, which means * paths like `/../etc/passwd` become `/etc/passwd`. When processing untrusted user input * (HTTP requests, file uploads, URL parameters), you MUST validate for path traversal * attacks BEFORE calling this function. */ export declare function normalizePath(pathLike: string | Buffer | URL): string; export declare function normalizeSinglePathSegment(segment: string, prefix: string): string; /** * Convert a path-like value to a string. * * Converts various path-like types (string, Buffer, URL) into a normalized * string representation. Handles different input formats and provides * consistent string output for path operations. * * @example * ;```typescript * pathLikeToString('/home/user') // '/home/user' * pathLikeToString(Buffer.from('/tmp/file')) // '/tmp/file' * pathLikeToString(new URL('file:///home/user')) // '/home/user' * pathLikeToString(null) // '' * ``` * * @param {string | Buffer | URL | null | undefined} pathLike - The value to * convert. * * @returns {string} The string representation, or empty string for * null/undefined. */ export declare function pathLikeToString(pathLike: string | Buffer | URL | null | undefined): string; export declare function skipPathSeparators(filepath: string, start: number): number;