regex-extname

1.0.0 • Public • Published

Filename Extension

NPM version Build Status Coverage Status Dependencies

Regular expression to capture a filename extension.

Installation

$ npm install regex-extname

Usage

var re = require( 'regex-extname' );

re

Regular expression to capture a filename extension.

var ext;
 
// On a POSIX platform...
ext = re.exec( '/foo/bar/index.js' )[ 1 ];
// returns '.js'
 
// On a Windows platform...
ext = re.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
// returns '.js'

re.posix

Regular expression to capture a POSIX filename extension.

re.win32

Regular expression to capture a Windows filename extension.

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-extname' );
 
var ext;
 
// Assuming a POSIX platform...
ext = re.exec( '/foo/bar/index.js' )[ 1 ];
console.log( ext );
// returns '.js'
 
ext = re.posix.exec( '/foo/bar/home.html' )[ 1 ];
console.log( ext );
// returns '.html'
 
ext = re.win32.exec( 'C:\\foo\\bar\\home.html' )[ 1 ];
console.log( ext );
// returns '.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

MIT license.

Copyright

Copyright © 2015. Athan Reines.

Package Sidebar

Install

npm i regex-extname

Weekly Downloads

58

Version

1.0.0

License

MIT

Last publish

Collaborators

  • kgryte