GithubHelp home page GithubHelp logo

strong-roots-capital / node-strip-dirs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shinnn/node-strip-dirs

0.0 2.0 0.0 93 KB

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

License: ISC License

JavaScript 100.00%

node-strip-dirs's Introduction

strip-dirs

npm version 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

node-strip-dirs's People

Contributors

shinnn avatar

Watchers

James Cloos avatar Eric Crosson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.