validatees
Version:
✅ Validation library for ES6+ modules
30 lines (29 loc) • 1.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidPassword = void 0;
const isString_1 = __importDefault(require("../types/isString"));
function isValidPassword(value, options) {
var _a, _b, _c, _d;
const { minLength, numbers, specialChars, maxLength } = {
minLength: (_a = options === null || options === void 0 ? void 0 : options.minLength) !== null && _a !== void 0 ? _a : 8,
maxLength: (_b = options === null || options === void 0 ? void 0 : options.maxLength) !== null && _b !== void 0 ? _b : 32,
numbers: (_c = options === null || options === void 0 ? void 0 : options.numbers) !== null && _c !== void 0 ? _c : 1,
specialChars: (_d = options === null || options === void 0 ? void 0 : options.specialChars) !== null && _d !== void 0 ? _d : 1,
};
if (null === value || undefined === value || "" === value) {
return false;
}
else if (false === (0, isString_1.default)(value)) {
throw new Error("Invalid argument");
}
else if (value.length < minLength || value.length > maxLength) {
return false;
}
const regex = new RegExp(`^(?=.*[0-9]{${numbers},})(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':"\\\\|,.<>\\/?]{${specialChars},}).*$`);
return regex.test(value);
}
exports.isValidPassword = isValidPassword;
exports.default = isValidPassword;