stringman
Version:
Stringman does string manipulation and other string operations. Do anything from lightening color codes to swapping email address in a string!
44 lines (43 loc) • 1.45 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.pwd = void 0;
const common_1 = require("./utility/common");
function buildRegex(options) {
return new RegExp(`^[${options.lc ? 'a-z' : ''}${options.capital ? 'A-Z' : ''}${options.num ? '0-9' : ''}${options.special || ''}]{${options.min},${options.max}}$`);
}
function isValid(str, options) {
const re = buildRegex(options);
return common_1.common.isValid(str, re);
}
function isValidAdvanced(str, options, advOptions) {
if (isValid(str, options)) {
if (advOptions) {
const checkerObj = {
capital: advOptions.capital ? '[A-Z]' : undefined,
lc: advOptions.lc ? '[a-z]' : undefined,
num: advOptions.num ? '[0-9]' : undefined,
special: options.special && advOptions.special ? `[${options.special}]` : undefined
};
return (Object.keys(advOptions)
.map((key) => {
const ex = checkerObj[key];
const re = new RegExp(ex, 'g');
const matched = str.match(re);
return matched && matched.length >= advOptions[key];
})
.filter((c) => !c).length < 1);
}
else {
return true;
}
}
else {
return false;
}
}
const pwd = {
buildRegex,
isValid,
isValidAdvanced
};
exports.pwd = pwd;
;