Socket
Socket
Sign inDemoInstall

strip-dirs

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strip-dirs

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


Version published
Weekly downloads
3.2M
increased by5.56%
Maintainers
1
Weekly downloads
 
Created
Source

strip-dirs

NPM version Build Status Dependency Status devDependency Status

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

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

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

Installation

Install with npm. (Make sure you have installed Node)

npm install --save strip-dirs

API

var 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.

var 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
option.narrow

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 such case.

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

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

CLI

You can use this module as strip-dirs command by installing it globally.

npm install -g strip-dirs

Usage

strip-dirs <string> --count(or -c) <number> [--narrow(or -n)]

Or, use with pipe(|):

echo <string> | strip-dirs --count(or -c) <number> [--narrow(or -n)]

Flags

--count,  -c: Number of directories to strip from the path
--narrow, -n: Disallow surplus count of directory level

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT LIcense.

Keywords

FAQs

Package last updated on 20 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc