1.0.0-Beta • Published 1 year ago

path-copilot v1.0.0-Beta

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

NameTypeDescription
pathstringThe path string to be determined.

Returns

boolean

True if it's an absolute path, false otherwise.

Defined in

isAbsolute.ts:18


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

NameTypeDescription
...pathsstring[]An array of path segments to join.

Returns

string

A combined path string.

Defined in

join.ts:13


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

NameTypeDescription
pathstringThe file system path to be normalized.

Returns

string

The normalized path.

Defined in

normalize.ts:17


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

NameTypeDescription
urlstringThe URL string to parse.

Returns

Object

An object containing the query and hash parameters of the URL.

NameType
hashRecord<string, string | string[]>
queryRecord<string, string | string[]>

Defined in

parseUrl.ts:64