Package Exports
- path-segments
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (path-segments) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
path-segments 
Get specific segments of a file path. First, last, last two, first two, etc.
Install
Install with npm:
npm i path-segments --save-dev
Usage
var segements = require('path-segments');
Tests
In the command line, run npm test
or mocha
.
first
Get the first n
segments of a path:
segments('a/b/c', {first: 1});
//=> 'a'
segments('./a/b/c', {first: 1});
//=> 'a'
segments('/a/b/c.js', {first: 1});
//=> 'a'
segments('/a/b/c/', {first: 1});
//=> 'a'
segments('a\\b\\c', {first: 1});
//=> 'a'
segments('.\\a\\b\\c.js', {first: 1});
//=> 'a'
segments('.\\a\\b\\c\\', {first: 2});
//=> 'a/b'
segments('.\\a\\b\\c.js', {first: 2});
//=> 'a/b'
segments('/a/b/c.js', {first: 3});
//=> 'a/b/c.js'
segments('/a/b/c/', {first: 3});
//=> 'a/b/c'
segments('a\\b\\c', {first: 3});
//=> 'a/b/c'
segments('a\\b\\c\\', {first: 3});
//=> 'a/b/c'
segments('.\\a\\b\\c.js', {first: 3});
//=> 'a/b/c.js'
last
Get the last n
segments of a path:
segments('a/b/c');
//=> 'c'
segments('./a/b/c');
//=> 'c'
segments('./a/b/c.js');
//=> 'c.js'
segments('/a/b/c.js');
//=> 'c.js'
segments('/a/b/c/');
//=> 'c'
segments('.\\a\\b\\c\\');
//=> 'c'
segments('.\\a\\b\\c.js');
//=> 'c.js'
segments('/a/b/c.js', {last: 2});
//=> 'b/c.js'
segments('/a/b/c/', {last: 2});
//=> 'b/c'
segments('a\\b\\c', {last: 2});
//=> 'b/c'
segments('.\\a\\b\\c.js', {last: 2});
//=> 'b/c.js'
segments('./a/b/c/', {last: 3});
//=> 'a/b/c'
segments('a/b/c.js', {last: 3});
//=> 'a/b/c.js'
segments('.\\a\\b\\c\\', {last: 3});
//=> 'a/b/c'
segments('.\\a\\b\\c.js', {last: 3});
//=> 'a/b/c.js'
See the tests for more examples.
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on June 26, 2014.