1.0.0 • Published 5 years ago

norm-join-path v1.0.0

Weekly downloads
7
License
ISC
Repository
github
Last release
5 years ago

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