check-extension
Check whether a file has a given extension.
Install
npm i check-extension
Usage
const checkExtension = ; let isJsFile = ; // => truelet isJsonFile = ; // => falselet isMarkdownFile = ; // => truelet isOtherFile = ; // => true
API
function checkExtension(file, extensions)
Checks whether a file has a given extension.
Parameters
Name | Type | Description |
---|---|---|
file | string | The path of the file to check. |
extensions | string /array |
One or more allowed extensions. Can be omitted (or set to a falsy value like null ) to check whether a file has no extension. |
Returns
true
if the extensions matched, false
otherwise.
Testing
npm test