url-extension-validator
v1.2.1
Published
Methods for validating URL webpage extensions (.aspx, .htm ...)
Downloads
5
Maintainers
Readme
url-extension-validator
Methods for validating URL web page extensions (ending in .aspx, .php, .htm, .html ...)
Check if the supplied URL ends in a known web page extension or not. The valid extensions list can be overridden for custom use cases.
Table of Contents
Install
npm install --save url-extension-validator
Usage
const UrlExtensionValidator = require('url-extension-validator');
const validator = new UrlExtensionValidator();
To check if a URL ends in a valid web page extension
const validUrl = validator.matchValidExtension('https://example.com/index.php'); // => true
To check if a web page extension is valid or not
const validExtension = validator.validateExtension('.html'); // => true
const alsoValid = validator.validateExtension('html'); // => true
To return an array of valid web page extensions for any use case (i.e. custom map, filter or reduce functions)
const validExtensions = UrlExtensionValidator.extensions(); // => ['.asp', '.aspx', ...]
To return a simple map of valid web page extensions
const validExtensionMap = validator.extensionMap(); // => { '.asp': true, '.aspx': true, ... }
To wrap any method in a promise
validator.chain( validator.validateExtension('.cgi') )
.then(result // => true)
.then(...) // do something async
To override the valid extensions list
const validator = new UrlExtensionsValidator({ extensionsList: ['.htm', '.html', '.btc'] });
const validExtension = validator.validateExtension('.php'); // => false
Maintainers
Contributing
Small note: If editing the README, please conform to the standard-readme specification.
License
MIT © 2019 njhoran