upath
- Version 2.0.1
- Published
- 36.7 kB
- No dependencies
- MIT license
Install
npm i upath
yarn add upath
pnpm add upath
Overview
A proxy to `path`, replacing `\` with `/` for all results (supports UNC paths) & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.
Index
Namespaces
Namespaces
namespace upath
module 'upath' {}
variable delimiter
var delimiter: string;
The platform-specific file delimiter. ';' or ':'.
variable sep
var sep: string;
The platform-specific file separator. '\' or '/'.
variable VERSION
var VERSION: string;
Version of the library
function addExt
addExt: (file: string, ext: string) => string;
Adds .ext to filename, but only if it doesn't already have the exact extension.
Parameter file
string filename to add extension to
Parameter ext
string extension to add
function basename
basename: (p: string, ext?: string) => string;
Return the last portion of a path. Similar to the Unix basename command. Often used to extract the file name from a fully qualified path.
Parameter p
the path to evaluate.
Parameter ext
optionally, an extension to remove from the result.
function changeExt
changeExt: ( filename: string, ext: string, ignoreExts?: string[], maxSize?: number) => string;
Changes a filename's extension to ext. If it has no (valid) extension, it adds it.
Valid extensions are considered to be up to maxSize chars long, counting the dot (defaults to 7).
An Array of ignoreExts (eg ['.min']) prevents these from being considered as extension, thus are not changed - the new extension is added instead.
Parameter filename
string filename to change it's extension
Parameter ext
string extension to change to
Parameter ignoreExts
array extensions to ignore
Parameter maxSize
number max length of the extension
function defaultExt
defaultExt: ( filename: string, ext: string, ignoreExts?: string[], maxSize?: number) => string;
Adds .ext to filename, only if it doesn't already have any old extension.
(Old) extensions are considered to be up to maxSize chars long, counting the dot (defaults to 7).
An Array of ignoreExts (eg ['.min']) will force adding default .ext even if one of these is present.
Parameter filename
string filename to default to it's extension
Parameter ext
string extension to default to
Parameter ignoreExts
array extensions to ignore
Parameter maxSize
number max length of the extension
function dirname
dirname: (p: string) => string;
Return the directory name of a path. Similar to the Unix dirname command.
Parameter p
the path to evaluate.
function extname
extname: (p: string) => string;
Return the extension of the path, from the last '.' to end of string in the last portion of the path. If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
Parameter p
the path to evaluate.
function format
format: (pathObject: ParsedPath) => string;
Returns a path string from an object - the opposite of parse().
Parameter pathString
path to evaluate.
function isAbsolute
isAbsolute: (path: string) => boolean;
Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
Parameter path
path to test.
function join
join: { (...paths: any[]): string; (...paths: string[]): string };
Join all arguments together and normalize the resulting path. Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
Parameter paths
string paths to join.
function joinSafe
joinSafe: (...p: any[]) => string;
Exactly like path.join(), but it keeps the first meaningful ./.
Note that the unix / is returned everywhere, so windows \ is always converted to unix /.
Parameter paths
string paths to join
function normalize
normalize: (p: string) => string;
Normalize a string path, reducing '..' and '.' parts. When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
Parameter p
string path to normalize.
function normalizeSafe
normalizeSafe: (p: string) => string;
Exactly like path.normalize(path), but it keeps the first meaningful ./.
Note that the unix / is returned everywhere, so windows \ is always converted to unix /.
Parameter p
string path to normalize.
function normalizeTrim
normalizeTrim: (p: string) => string;
Exactly like path.normalizeSafe(path), but it trims any useless ending /.
Parameter p
string path to normalize
function parse
parse: (pathString: string) => ParsedPath;
Returns an object from a path string - the opposite of format().
Parameter pathString
path to evaluate.
function relative
relative: (from: string, to: string) => string;
Solve the relative path from {from} to {to}. At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
Parameter from
Parameter to
function removeExt
removeExt: (filename: string, ext: string) => string;
Removes the specific ext extension from filename, if it has it. Otherwise it leaves it as is. As in all upath functions, it be .ext or ext.
Parameter file
string filename to remove extension to
Parameter ext
string extension to remove
function resolve
resolve: (...pathSegments: any[]) => string;
The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
Starting from leftmost {from} parameter, resolves {to} to an absolute path.
If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.
Parameter pathSegments
string paths to join. Non-string arguments are ignored.
function toUnix
toUnix: (p: string) => string;
Just converts all
to/
and consolidates duplicates, without performing any normalization.Parameter p
string path to convert to unix.
function trimExt
trimExt: (filename: string, ignoreExts?: string[], maxSize?: number) => string;
Trims a filename's extension.
Extensions are considered to be up to maxSize chars long, counting the dot (defaults to 7).
An Array of ignoreExts (eg ['.min']) prevents these from being considered as extension, thus are not trimmed.
Parameter filename
string filename to trim it's extension
Parameter ignoreExts
array extensions to ignore
Parameter maxSize
number max length of the extension
interface ParsedPath
interface ParsedPath {}
A parsed path object generated by path.parse() or consumed by path.format().
property base
base: string;
The file name including extension (if any) such as 'index.html'
property dir
dir: string;
The full directory path such as '/home/user/dir' or 'c:\path\dir'
property ext
ext: string;
The file extension (if any) such as '.html'
property name
name: string;
The file name without extension (if any) such as 'index'
property root
root: string;
The root of the path such as '/' or 'c:'
namespace upath.posix
namespace upath.posix {}
variable delimiter
var delimiter: string;
variable sep
var sep: string;
function basename
basename: (p: string, ext?: string) => string;
function dirname
dirname: (p: string) => string;
function extname
extname: (p: string) => string;
function format
format: (pP: ParsedPath) => string;
function isAbsolute
isAbsolute: (p: string) => boolean;
function join
join: (...paths: any[]) => string;
function normalize
normalize: (p: string) => string;
function parse
parse: (p: string) => ParsedPath;
function relative
relative: (from: string, to: string) => string;
function resolve
resolve: (...pathSegments: any[]) => string;
namespace upath.win32
namespace upath.win32 {}
variable delimiter
var delimiter: string;
variable sep
var sep: string;
function basename
basename: (p: string, ext?: string) => string;
function dirname
dirname: (p: string) => string;
function extname
extname: (p: string) => string;
function format
format: (pP: ParsedPath) => string;
function isAbsolute
isAbsolute: (p: string) => boolean;
function join
join: (...paths: any[]) => string;
function normalize
normalize: (p: string) => string;
function parse
parse: (p: string) => ParsedPath;
function relative
relative: (from: string, to: string) => string;
function resolve
resolve: (...pathSegments: any[]) => string;
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (12)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/upath
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/upath)
- HTML<a href="https://www.jsdocs.io/package/upath"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2852 ms. - Missing or incorrect documentation? Open an issue for this package.