npath () documon/src/npath.js 15
xpath documon.npath
file documon/src/npath.js

A drop-in replacement for path, that provides cross-playform normalization. Easing the development of cross-platform modules.

Essentially what we're doing is pre-processing all methods with a path normalization -- always enforcing forward slashes.

Properties
delimiter
documon/src/npath.js45
string

Platform environment PATH delimiter.

Example of how PATH appears on Windows:

    'C:\Windows\system32;C:\Windows;C:\Program Files\node\'

Example of how PATH appears on POSIX systems (Mac Unix):

    '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'

Read the PATH with Node:

    console.log(process.env.PATH)

    Windows     = ;
  POSIX   = : 
Methods
addTrailingSlash (path) documon/src/npath.js 321

Adds a trailing slash from path (if doesn't exist).

Parameters
path
string

path

Returns string
basename (path, ext) documon/src/npath.js 108

npath.basename("/foo/bar/bob.txt") --> "bob.txt"
npath.basename("/foo/bar/bob.txt", ".txt") --> "bob"

Parameters
path
string

The full path

ext
string

Lops off the extension if it matches.

Returns string

The last portion of a path, generally the "filename".

clean (arg) documon/src/npath.js 59

Normalizes slashes by converting double \ to single \ and / to \ or \ tp / based on the current platform requirements.

Parameters
arg
string | array

arg

Returns string
dirname (Vpath) documon/src/npath.js 123

Returns the path to the parent folder that the item resides within.

    npath.dirname("/foo/bar/bob.txt") --> "/foo/bar"
  npath.dirname("/foo/sally/yoyo/boob") --> "/foo/sally/yoyo"
Parameters
Vpath
string

The path to parse.

Returns string

The path to the file/folder.

extname (Vpath) documon/src/npath.js 137

Yes, this includes the dot.

    npath.extname("/foo/bar/bob.txt") --> ".txt"
  npath.extname("/foo/sally/yoyo/boob") --> ""
Parameters
Vpath
string

The path to parse.

Returns string

The extension (if exists), including the dot.

format (obj) documon/src/npath.js 247

The opposite of path.parse().

Combines the elements of an object into a string.

Example:

    {
        root : "/",
        dir : "/home/user/dir",
        base : "file.txt",
        ext : ".txt",
        name : "file"
    }

Is converted to

    /home/user/dir/file.txt
Parameters
obj
object

The object containing some of the required keys to formulate a path.

Returns type

The string representaiton of the object.

isAbsolute (Vpath) documon/src/npath.js 149

Determines if path is an absolute path.

Parameters
Vpath
string

The path to parse.

Returns Boolean
join (paths...) documon/src/npath.js 263

Joins path segments and resolves relativity.

    path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
    Returns: '/foo/bar/baz/asdf'
Parameters
paths...
string

All arguments are evaluated as paths for construction

Returns type

description description

normalize (Vpath) documon/src/npath.js 168

Resolves ".." and "." portions of a path.
Reduces double slashes to single (e.g. // -> / )
Forces back-slashes to forward slashes (e.g. \ -> / )

Retains trailing slash if exists.

  npath.normalize("/foo/////bar") --> "/foo/bar"
  npath.normalize("/foo/bar/../boob") --> "/foo/boob"
  npath.normalize("./foo/") --> "/current/working/dir/foo/"
Parameters
Vpath
string

The path to parse.

Returns string
parse (Vpath) documon/src/npath.js 200

Extracts basic path and file parts.

path.parse('/home/user/dir/file.txt')

// Yeilds
{
    root : "/",
    dir : "/home/user/dir",
    base : "file.txt",
    ext : ".txt",
    name : "file"
}
Parameters
Vpath
string

The path to parse.

Returns object

An object containing the following properties:

{
    root : "/",
    dir : "/home/user/dir",
    base : "file.txt",
    ext : ".txt",
    name : "file"
}
relative (from, to) documon/src/npath.js 218

Creates a relative path between from adn to.

    path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')
    // Returns: '../../impl/bbb'
Parameters
from
string optional

When null, the cwd is used for this value.

to
string optional

When null, the cwd is used for this value.

Returns string

The relative path between from and to

removeTrailingSlash (path) documon/src/npath.js 306

Removes a trailing slash from path (if exists).

Parameters
path
string

path

Returns string
resolve (path...) documon/src/npath.js 294

Generates an absolute path based on thenprovided arguments.

Path construction occurs from right < to < left

    resolve("/a", "b", "c"); // yields: "/a/b/c"

If an absolute path is resolved during construction, the items to the left are ignored.

    resolve("a", "/b", "c"); // yields: "/b/c" ("a" is ignored)

If an absolute path is not resolved after constructing all arguments, the CWD is inserted.

    resolve("a", "b", "c"); // yields: "/current/working/dir/a/b/c"

Relative paths are automatically resolved:

    resolve("/a", "../b", "c"); // yields "/a/c"
Parameters
path...
string optional

All arguments are evaluated as paths for construction.

Returns string