Compare commits

..

No commits in common. 'master' and 'master' have entirely different histories.

@ -5,9 +5,6 @@ const isURL = require("./");
console.log(validateValue("https://example.com/", [ isURL() ])); // Url { ... } console.log(validateValue("https://example.com/", [ isURL() ])); // Url { ... }
// validate without returning parsed Url {}
console.log(validateValue("https://example.com/", [ isURL({parse: false}) ]))
console.log(validateValue("bar", [ isURL() ])); /* console.log(validateValue("bar", [ isURL() ])); /*
AggregrateValidationError: One or more validation errors occurred: AggregrateValidationError: One or more validation errors occurred:
- At (root): Must be a valid URL - At (root): Must be a valid URL

@ -1,21 +1,10 @@
"use strict"; "use strict";
const defaultValue = require("default-value");
const url = require("url"); const url = require("url");
const ValidationError = require("@validatem/error"); const ValidationError = require("@validatem/error");
const isString = require("@validatem/is-string"); const isString = require("@validatem/is-string");
module.exports = function (options = {}) { module.exports = function (protocols) {
let parse = defaultValue(options.parse, true);
let protocols = options.protocols;
if (Array.isArray(options)) { // keep compatibility with <=0.2.0
protocols = options;
options = {};
}
if (protocols != null && !Array.isArray(protocols)) { if (protocols != null && !Array.isArray(protocols)) {
throw new Error(`Permitted protocol list must be an array`); throw new Error(`Permitted protocol list must be an array`);
} }
@ -46,11 +35,7 @@ module.exports = function (options = {}) {
return new ValidationError(`Must be a URL with one of the following protocols: ${validProtocolList} - but got ${parsedProtocol.toUpperCase()} instead`, { code: "validatem.is-url.wrong-protocol" }); return new ValidationError(`Must be a URL with one of the following protocols: ${validProtocolList} - but got ${parsedProtocol.toUpperCase()} instead`, { code: "validatem.is-url.wrong-protocol" });
} else { } else {
if (parse) { return parsed;
return parsed;
} else {
return value;
}
} }
} }
]; ];

@ -12,8 +12,7 @@
"license": "WTFPL OR CC0-1.0", "license": "WTFPL OR CC0-1.0",
"dependencies": { "dependencies": {
"@validatem/error": "^1.0.0", "@validatem/error": "^1.0.0",
"@validatem/is-string": "^0.1.1", "@validatem/is-string": "^0.1.1"
"default-value": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"@validatem/core": "^0.3.1" "@validatem/core": "^0.3.1"

Loading…
Cancel
Save