aboutsummaryrefslogtreecommitdiff
path: root/node_modules/strip-dirs
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/strip-dirs')
-rw-r--r--node_modules/strip-dirs/LICENSE20
-rw-r--r--node_modules/strip-dirs/README.md75
-rw-r--r--node_modules/strip-dirs/index.js72
-rw-r--r--node_modules/strip-dirs/package.json39
4 files changed, 206 insertions, 0 deletions
diff --git a/node_modules/strip-dirs/LICENSE b/node_modules/strip-dirs/LICENSE
new file mode 100644
index 0000000..3b7a190
--- /dev/null
+++ b/node_modules/strip-dirs/LICENSE
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 - 2016 Shinnosuke Watanabe
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/strip-dirs/README.md b/node_modules/strip-dirs/README.md
new file mode 100644
index 0000000..7449982
--- /dev/null
+++ b/node_modules/strip-dirs/README.md
@@ -0,0 +1,75 @@
+# strip-dirs
+
+[![NPM version](https://img.shields.io/npm/v/strip-dirs.svg)](https://www.npmjs.com/package/strip-dirs)
+[![Build Status](https://img.shields.io/travis/shinnn/node-strip-dirs.svg)](https://travis-ci.org/shinnn/node-strip-dirs)
+[![Build status](https://ci.appveyor.com/api/projects/status/pr5edbtg59f6xfgn?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/node-strip-dirs)
+[![Coverage Status](https://img.shields.io/coveralls/shinnn/node-strip-dirs.svg)](https://coveralls.io/r/shinnn/node-strip-dirs)
+[![Dependency Status](https://david-dm.org/shinnn/node-strip-dirs.svg)](https://david-dm.org/shinnn/node-strip-dirs)
+[![devDependency Status](https://david-dm.org/shinnn/node-strip-dirs/dev-status.svg)](https://david-dm.org/shinnn/node-strip-dirs#info=devDependencies)
+
+Remove leading directory components from a path, like [tar(1)](http://linuxcommand.org/man_pages/tar1.html)'s `--strip-components` option
+
+```javascript
+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](https://docs.npmjs.com/cli/install).
+
+```
+npm install --save strip-dirs
+```
+
+## API
+
+```javascript
+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*.
+
+```javascript
+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`](https://nodejs.org/api/path.html#path_path_basename_path_ext) 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.
+
+```javascript
+stripDirs('foo/bar/baz', 9999); //=> 'baz'
+
+stripDirs('foo/bar/baz', 9999, {disallowOverflow: true}); // throws an range error
+```
+
+## License
+
+Copyright (c) 2014 - 2016 [Shinnosuke Watanabe](https://github.com/shinnn)
+
+Licensed under [the MIT License](./LICENSE).
diff --git a/node_modules/strip-dirs/index.js b/node_modules/strip-dirs/index.js
new file mode 100644
index 0000000..974af89
--- /dev/null
+++ b/node_modules/strip-dirs/index.js
@@ -0,0 +1,72 @@
+/*!
+ * strip-dirs | MIT (c) Shinnosuke Watanabe
+ * https://github.com/shinnn/node-strip-dirs
+*/
+'use strict';
+
+const path = require('path');
+const util = require('util');
+
+const isNaturalNumber = require('is-natural-number');
+
+module.exports = function stripDirs(pathStr, count, option) {
+ if (typeof pathStr !== 'string') {
+ throw new TypeError(
+ util.inspect(pathStr) +
+ ' is not a string. First argument to strip-dirs must be a path string.'
+ );
+ }
+
+ if (path.posix.isAbsolute(pathStr) || path.win32.isAbsolute(pathStr)) {
+ throw new Error(`${pathStr} is an absolute path. strip-dirs requires a relative path.`);
+ }
+
+ if (!isNaturalNumber(count, {includeZero: true})) {
+ throw new Error(
+ 'The Second argument of strip-dirs must be a natural number or 0, but received ' +
+ util.inspect(count) +
+ '.'
+ );
+ }
+
+ if (option) {
+ if (typeof option !== 'object') {
+ throw new TypeError(
+ util.inspect(option) +
+ ' is not an object. Expected an object with a boolean `disallowOverflow` property.'
+ );
+ }
+
+ if (Array.isArray(option)) {
+ throw new TypeError(
+ util.inspect(option) +
+ ' is an array. Expected an object with a boolean `disallowOverflow` property.'
+ );
+ }
+
+ if ('disallowOverflow' in option && typeof option.disallowOverflow !== 'boolean') {
+ throw new TypeError(
+ util.inspect(option.disallowOverflow) +
+ ' is neither true nor false. `disallowOverflow` option must be a Boolean value.'
+ );
+ }
+ } else {
+ option = {disallowOverflow: false};
+ }
+
+ const pathComponents = path.normalize(pathStr).split(path.sep);
+
+ if (pathComponents.length > 1 && pathComponents[0] === '.') {
+ pathComponents.shift();
+ }
+
+ if (count > pathComponents.length - 1) {
+ if (option.disallowOverflow) {
+ throw new RangeError('Cannot strip more directories than there are.');
+ }
+
+ count = pathComponents.length - 1;
+ }
+
+ return path.join.apply(null, pathComponents.slice(count));
+};
diff --git a/node_modules/strip-dirs/package.json b/node_modules/strip-dirs/package.json
new file mode 100644
index 0000000..7f1a3db
--- /dev/null
+++ b/node_modules/strip-dirs/package.json
@@ -0,0 +1,39 @@
+{
+ "name": "strip-dirs",
+ "version": "2.1.0",
+ "description": "Remove leading directory components from a path, like tar's --strip-components option",
+ "repository": "shinnn/node-strip-dirs",
+ "author": "Shinnosuke Watanabe (https://github.com/shinnn)",
+ "files": [
+ "index.js"
+ ],
+ "scripts": {
+ "pretest": "eslint --fix --format=codeframe index.js test.js",
+ "test": "node --throw-deprecation --track-heap-objects test.js | tap-spec",
+ "coverage": "istanbul cover test.js"
+ },
+ "license": "MIT",
+ "keywords": [
+ "filepath",
+ "file-path",
+ "path",
+ "dir",
+ "directory",
+ "strip",
+ "strip-components"
+ ],
+ "dependencies": {
+ "is-natural-number": "^4.0.1"
+ },
+ "devDependencies": {
+ "@shinnn/eslint-config-node": "^3.0.0",
+ "eslint": "^3.10.0",
+ "istanbul": "^0.4.5",
+ "istanbul-coveralls": "^1.0.3",
+ "tap-spec": "^4.1.1",
+ "tape": "^4.6.2"
+ },
+ "eslintConfig": {
+ "extends": "@shinnn/node"
+ }
+}