regex-basename
v1.0.0
Published
Regular expression to capture a path basename.
Downloads
8
Maintainers
Readme
Basename
Regular expression to capture a path basename.
Installation
$ npm install regex-basename
Usage
var re = require( 'regex-basename' );
re
Regular expression to capture a path basename.
var base;
// On a POSIX platform...
base = re.exec( '/foo/bar/index.js' )[ 1 ];
// returns 'index.js'
// On a Windows platform...
base = re.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
// returns 'index.js'
re.posix
Regular expression to capture a POSIX path basename.
re.win32
Regular expression to capture a Windows path basename.
Notes
- The main exported regular expression is platform-dependent. If the current process is running on Windows,
re === re.win32
; otherwise,re === re.posix
.
Examples
var re = require( 'regex-basename' );
var base;
// Assuming a POSIX platform...
base = re.exec( '/foo/bar/index.js' )[ 1 ];
console.log( base );
// returns 'index.js'
base = re.posix.exec( '/foo/bar/home.html' )[ 1 ];
console.log( base );
// returns 'home.html'
base = re.win32.exec( 'C:\\foo\\bar\\home.html' )[ 1 ];
console.log( base );
// returns 'home.html'
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Athan Reines.