1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 07:41:56 +00:00
musix-oss/node_modules/strip-dirs
MatteZ02 5eb0264906 fix
2019-05-30 12:06:47 +03:00
..
index.js fix 2019-05-30 12:06:47 +03:00
LICENSE fix 2019-05-30 12:06:47 +03:00
package.json fix 2019-05-30 12:06:47 +03:00
README.md fix 2019-05-30 12:06:47 +03:00

strip-dirs

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

Remove leading directory components from a path, like tar(1)'s --strip-components option

const stripDirs = require('strip-dirs');

stripDirs('foo/bar/baz', 1); //=> 'bar/baz'
stripDirs('foo/bar/baz', 2); //=> 'baz'
stripDirs('foo/bar/baz', 999); //=> 'baz'

Installation

Use npm.

npm install --save strip-dirs

API

const stripDirs = require('strip-dirs');

stripDirs(path, count [, option])

path: String (A relative path)
count: Number (0, 1, 2, ...)
option: Object
Return: String

It removes directory components from the beginning of the path by count.

const stripDirs = require('strip-dirs');

stripDirs('foo/bar', 1); //=> 'bar'
stripDirs('foo/bar/baz', 2); //=> 'bar'
stripDirs('foo/././/bar/./', 1); //=> 'bar'
stripDirs('foo/bar', 0); //=> 'foo/bar'

stripDirs('/foo/bar', 1) // throw an error because the path is an absolute path

If you want to remove all directory components certainly, use path.basename instead of this module.

option.disallowOverflow

Type: Boolean
Default: false

By default, it keeps the last path component when path components are fewer than the count.

If this option is enabled, it throws an error in this situation.

stripDirs('foo/bar/baz', 9999); //=> 'baz'

stripDirs('foo/bar/baz', 9999, {disallowOverflow: true}); // throws an range error

License

Copyright (c) 2014 - 2016 Shinnosuke Watanabe

Licensed under the MIT License.