UNPKG

upath

Version:

A drop-in replacement / proxy to Node.js path, replacing \\ with / for all results & adding file extension functions.

83 lines (78 loc) 3.65 kB
import * as path from 'node:path'; export { FormatInputPathObject, ParsedPath, PlatformPath } from 'node:path'; /** * Convert all backslashes to forward slashes and collapse duplicate slashes * (except a leading double-slash for UNC paths). */ declare function toUnix(p: string): string; /** * Normalize a path, preserving a leading `./` if the original had one, * and preserving UNC `//` or `//./' prefixes. */ declare function normalizeSafe(p: string): string; /** * Like `normalizeSafe` but also trims a trailing slash (unless the path is * root `/`). */ declare function normalizeTrim(p: string): string; /** * Like `path.join` but preserves a leading `./` from the first segment and * preserves UNC `//` or `//./' prefixes. */ declare function joinSafe(...segments: string[]): string; /** * Add an extension to `file` if it doesn't already end with it. */ declare function addExt(file: string, ext: string): string; /** * Trim the extension from `filename` if it's a valid extension (not in * `ignoreExts` and not longer than `maxSize`). */ declare function trimExt(filename: string, ignoreExts?: string[], maxSize?: number): string; /** * Remove a specific extension from `filename`. If the file doesn't have * that extension, return it unchanged. */ declare function removeExt(filename: string, ext: string): string; /** * Change the extension of `filename`. The old extension is trimmed first * (subject to `ignoreExts` / `maxSize`), then `ext` is appended. */ declare function changeExt(filename: string, ext: string, ignoreExts?: string[], maxSize?: number): string; /** * Add `ext` to `filename` only when it doesn't already have a valid * extension (not in `ignoreExts` and not longer than `maxSize`). */ declare function defaultExt(filename: string, ext: string, ignoreExts?: string[], maxSize?: number): string; declare const resolve: (...paths: string[]) => string; declare const normalize: (p: string) => string; declare const isAbsolute: (p: string) => boolean; declare const join: (...paths: string[]) => string; declare const relative: (from: string, to: string) => string; declare const dirname: (p: string) => string; declare const basename: (p: string, suffix?: string) => string; declare const extname: (p: string) => string; declare const format: (pathObject: path.FormatInputPathObject) => string; declare const parse: (p: string) => path.ParsedPath; declare const toNamespacedPath: (p: string) => string; declare const matchesGlob: ((p: string, pattern: string) => boolean) | undefined; declare const sep: "/"; declare const delimiter: string; declare const posix: path.PlatformPath; declare const win32: path.PlatformPath; declare const VERSION: string; interface UPath extends path.PlatformPath { VERSION: string; sep: '/'; toUnix(p: string): string; normalizeSafe(p: string): string; normalizeTrim(p: string): string; joinSafe(...paths: string[]): string; addExt(file: string, ext: string): string; trimExt(filename: string, ignoreExts?: string[], maxSize?: number): string; removeExt(filename: string, ext: string): string; changeExt(filename: string, ext: string, ignoreExts?: string[], maxSize?: number): string; defaultExt(filename: string, ext: string, ignoreExts?: string[], maxSize?: number): string; } declare const _default: UPath; export { type UPath, VERSION, addExt, basename, changeExt, _default as default, defaultExt, delimiter, dirname, extname, format, isAbsolute, join, joinSafe, matchesGlob, normalize, normalizeSafe, normalizeTrim, parse, posix, relative, removeExt, resolve, sep, toNamespacedPath, toUnix, trimExt, win32 };