Socket
Socket
Sign inDemoInstall

strip-dirs

Package Overview
Dependencies
3
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

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
2.9M
decreased by-0.75%
Maintainers
1
Install size
40.1 kB
Created
Weekly downloads
 

Readme

Source

strip-dirs

npm version Build Status Build status Coverage 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 strip-dirs

API

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

stripDirs(path, count [, option])

path: string (A relative path)
count: integer (>= 0)
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

ISC License © 2017 - 2018 Shinnosuke Watanabe

Keywords

FAQs

Last updated on 14 Sep 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc