path-copilot
v1.0.0-Beta
Published
A rich and colorful toolkit about Path.
Downloads
17
Maintainers
Readme
path-copilot
A toolkit for path
Usage
npm i path-copilot
path-copilot - v1.0.0-Beta
path-copilot - v1.0.0-Beta
Table of contents
Functions
Functions
isAbsolute
▸ isAbsolute(path
): boolean
Determine whether the given path string is an absolute path.
Since
1.0.0
Example
isAbsolute('/') // true
isAbsolute('/path') // true
isAbsolute('C:\\path') // true
isAbsolute('\\path') // true
isAbsolute('https://example.com') // true
isAbsolute('ftp://example.com') // true
isAbsolute('relative/path') // false
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| path
| string
| The path string to be determined. |
Returns
boolean
True if it's an absolute path, false otherwise.
Defined in
join
▸ join(...paths
): string
Combines an array of path segments into a single path string, with forward slashes (/) as separators.
Since
1.0.0
Example
const path = join('foo', 'bar', 'baz'); // path == 'foo/bar/baz'
const path2 = join('foo/', '/bar/', '/baz/'); // path2 == 'foo/bar/baz'
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| ...paths
| string
[] | An array of path segments to join. |
Returns
string
A combined path string.
Defined in
normalize
▸ normalize(path
): string
Normalize a file system path by removing any unnecessary "." and ".." segments and resolving any directory separators to match the host operating system.
Example
const path = '/users/john/../jane/./documents/';
const normalizedPath = normalize(path); // "/users/jane/documents/"
Since
1.0.0
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| path
| string
| The file system path to be normalized. |
Returns
string
The normalized path.
Defined in
parseUrl
▸ parseUrl(url
): Object
Parses the query and hash parameters of the specified URL string.
Example
// Basic usage
const url = 'http://example.com/path/to/page?a=1&b=2#section1';
const { query, hash } = parseUrl(url);
console.log(query); // { a: '1', b: '2' }
console.log(hash); // { section1: '' }
// Query and hash without value
const url2 = 'http://example.com/path/to/page?a&b#c';
const { query: query2, hash: hash2 } = parseUrl(url2);
console.log(query2); // { a: '', b: '' }
console.log(hash2); // { c: '' }
// Query with array value
const url3 = 'http://example.com/path/to/page?color=red&color=green&color=blue';
const { query: query3, hash: hash3 } = parseUrl(url3);
console.log(query3); // { color: ['red', 'green', 'blue'] }
console.log(hash3); // {}
Since
1.0.0
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| url
| string
| The URL string to parse. |
Returns
Object
An object containing the query and hash parameters of the URL.
| Name | Type |
| :------ | :------ |
| hash
| Record
<string
, string
| string
[]> |
| query
| Record
<string
, string
| string
[]> |