norm-join-path
v1.0.0
Published
Join and normalize path segments. Accepts arrays.
Downloads
2
Readme
norm-join-path
Join and normalize path segments. Accepts arrays.
API
This module exports one function:
normJoinPath(pathSegments[, …morePathSegments])
Expects one or more arguments. Each of them must be either
- a path segment given as non-empty string,
- a false-y value, which will be ignored,
- or a (potentially empty) array of any of the above.
They are flattened (up to one level deep),
join()
ed as path segments,
and the resulting path is normalize()
d
using the path
module's methods.
Usage
from test.usage.js:
var join = require('norm-join-path'),
want = 'foo/bar/qux';
equal(join('./foo/bar/baz/../qux'), want);
equal(join('./foo/bar', 'baz/../qux'), want);
equal(join('./foo/bar', 'baz/../', '', 'qux'), want);
equal(join('./foo/bar', 'baz', '../qux'), want);
equal(join('./foo/bar', ['baz/../', '/qux']), want);
equal(join('./foo/bar', ['baz', '../qux']), want);
equal(join('./foo/bar', false, ['baz', false, '../qux']), want);
equal(join(['./foo/bar'], ['baz', '../qux']), want);
equal(join(['./foo/bar', 'baz', '../qux']), want);
equal(join(['./foo/bar', 'baz', '..', 'qux']), want);
equal(join(['./foo/bar'], [], ['baz', '../qux']), want);
equal(join(['./foo/bar'], [], 'baz', '../qux'), want);
equal(join(['./foo/bar'], [], 'baz', ['../qux']), want);
Known issues
- Needs more/better tests and docs.
License
ISC