read-excel-file
Version:
Read small to medium `*.xlsx` files in a browser or Node.js. Parse to JSON with a strict schema.
73 lines (70 loc) • 1.67 kB
JavaScript
import InvalidError from './InvalidError.js';
export default function URL(value) {
if (typeof value === 'string') {
if (isURL(value)) {
return value;
}
throw new InvalidError('not_a_url');
}
throw new InvalidError('not_a_string');
}
// URL regexp explanation:
//
// /^
//
// (?:
// // Matches optional "http(s):" or "ftp:":
// (?:
// (?:https?|ftp):
// )?
//
// // Matches "//" (required):
// \/\/
// )
//
// // Matches a valid non-local IP address:
// (?:
// (?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])
// (?:
// \.
// (?:1?\d{1,2}|2[0-4]\d|25[0-5])
// ){2}
// (?:
// \.
// (?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4])
// )
//
// // Or,
// |
//
// // Matches an alpha-numeric domain name.
// (?:
// (?:
// [a-z0-9\u00a1-\uffff]
// [a-z0-9\u00a1-\uffff_-]{0,62}
// )?
// [a-z0-9\u00a1-\uffff]
// \.
// )*
// (?:
// // Domain zone: "com", "net", etc (required):
// [a-z\u00a1-\uffff]{2,}
// )
// )
//
// // Matches a colon and a port number:
// (?::\d{2,5})?
//
// // Matches everything after the "origin":
// // * pathname
// // * query
// // * hash
// (?:[/?#]\S*)?
//
// $/i
var regexp = /^(?:(?:(?:https?|ftp):)?\/\/)(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)*(?:[a-z\u00a1-\uffff]{2,}))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
// https://stackoverflow.com/questions/8667070/javascript-regular-expression-to-validate-url
export function isURL(value) {
return regexp.test(value);
}
//# sourceMappingURL=URL.js.map