License Header Regular Expression

Generate a license header regular expression provided a license SPDX identifier and file type.

Usage

var headerRegExp = require( '@stdlib/_tools/licenses/header-regexp' );

headerRegExp( license, type )

Returns a license header regular expression provided a license SPDX identifier and file type.

var re = headerRegExp( 'Apache-2.0', 'Julia' );
// returns <RegExp>

If provided an unsupported file type, the function returns null.

var re = headerRegExp( 'Apache-2.0', 'beepboopbop' );
// returns null

Examples

var join = require( 'path' ).join;
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
var headerRegExp = require( '@stdlib/_tools/licenses/header-regexp' );

// Read a JavaScript file:
var fopts = {
    'encoding': 'utf8'
};
var file = readFileSync( join( __dirname, 'examples', 'index.js' ), fopts );

// Generate a license header regular expression:
var re = headerRegExp( 'Apache-2.0', 'js' );

// Test if the file has a license header:
var bool = re.test( file );
// returns <boolean>