⁘ utils

PATH

PATH is a wrapper class that contains a bunch of utilitary static methods to manipulate paths. It also indexes global paths the like of node's __dirname, or system's PATH variable. This allow to use shorter paths & strings inside the application.

This is especially useful when working with project with lots of external references, or even different environments (such as dev vs production); but can very well be used with user-set paths too.

go to → Members

Members

staticread-onlyextras :object

Return all registered paths that aren't 'system' one, or in other words, any path registered after the app initilization.

Methods

staticFULL(p_path) → {string}

Expand a path, replacing the %SHORTCUT% variables with their full value.
Opposite of SHORT.

Parameters:
Name Type Description
p_path string
Examples:
PATH.FULL('%STYLE%/main.css'); == './style/default/main.css'

staticSHORT(p_path) → {string}

Shrink a path, replacing expanded environment path with their %SHORTCUT%
Opposite of FULL.

Parameters:
Name Type Description
p_path string
Examples:
PATH.FULL('./style/default/main.css') == '%STYLE%/main.css'

staticSET(p_envShortcut, p_path)

Registers a shortcut/path pair to PATH.

Parameters:
Name Type Description
p_envShortcut string

%MY_SHORTCUT%

p_path string

path/to/foo

staticUNSET(p_envShortcut)

Removes a shortcut from PATH.

Parameters:
Name Type Description
p_envShortcut string

staticdir(p_path) → {string}

Get the parent directory path

Parameters:
Name Type Description
p_path string

staticext(p_path) → {string}

Attempts to isolate and return the extension from a given path

Parameters:
Name Type Description
p_path string
Examples:
PATH.name('./style/default/main.css')  === '.css'
PATH.name('./style/default/main.css?value=none')  === '.css'

staticname(p_path) → {string}

Attempt to isolate the last name inside a path.

Parameters:
Name Type Description
p_path string
Examples:
PATH.name('./style/default/main.css')  === 'main'
PATH.name('./style/default/main')  === 'main'
PATH.name('./style/default/main/')  === 'main'

staticSanitize(p_string) → {string}

Replaces \ with /

Parameters:
Name Type Description
p_string string

The string to sanitize

staticstripExt(p_path) → {string}

Remove the extension of a filename string.

Parameters:
Name Type Description
p_path string
Examples:
stripExt('file.ext') === 'file'