joi-password-complexity
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -0,0 +0,0 @@ import Joi from 'joi'; |
import Joi from 'joi'; | ||
// pluralize | ||
var p = function (word, num) { | ||
if (num === void 0) { num = 0; } | ||
return (num === 1 ? word : word + "s"); | ||
}; | ||
var isPositive = function (num) { | ||
if (num === void 0) { num = 0; } | ||
return Number(num > 0); | ||
}; | ||
var clamp = function (value, min, max) { return (value < min ? min : value > max ? max : value); }; | ||
var defaultOptions = { | ||
const p = (word, num = 0) => (num === 1 ? word : `${word}s`); | ||
const isPositive = (num = 0) => Number(num > 0); | ||
const clamp = (value, min, max) => (value < min ? min : value > max ? max : value); | ||
const defaultOptions = { | ||
min: 8, | ||
@@ -22,55 +16,52 @@ max: 26, | ||
}; | ||
var index = (function (_a, label) { | ||
var _b = _a === void 0 ? defaultOptions : _a, _c = _b.min, min = _c === void 0 ? 0 : _c, _d = _b.max, max = _d === void 0 ? 0 : _d, _e = _b.lowerCase, lowerCase = _e === void 0 ? 0 : _e, _f = _b.upperCase, upperCase = _f === void 0 ? 0 : _f, _g = _b.numeric, numeric = _g === void 0 ? 0 : _g, _h = _b.symbol, symbol = _h === void 0 ? 0 : _h, _j = _b.requirementCount, requirementCount = _j === void 0 ? 0 : _j; | ||
if (label === void 0) { label = '{{#label}}'; } | ||
var joiPasswordComplexity = { | ||
var index = ({ min = 0, max = 0, lowerCase = 0, upperCase = 0, numeric = 0, symbol = 0, requirementCount = 0, } = defaultOptions, label = '{{#label}}') => { | ||
const joiPasswordComplexity = { | ||
type: 'passwordComplexity', | ||
base: Joi.string(), | ||
messages: { | ||
'passwordComplexity.tooShort': label + " should be at least " + min + " " + p('character', min) + " long", | ||
'passwordComplexity.tooLong': label + " should not be longer than " + max + " " + p('character', max), | ||
'passwordComplexity.lowercase': label + " should contain at least " + lowerCase + " lower-cased " + p('letter', lowerCase), | ||
'passwordComplexity.uppercase': label + " should contain at least " + upperCase + " upper-cased " + p('letter', upperCase), | ||
'passwordComplexity.numeric': label + " should contain at least " + numeric + " " + p('number', numeric), | ||
'passwordComplexity.symbol': label + " should contain at least " + symbol + " " + p('symbol', symbol), | ||
'passwordComplexity.requirementCount': label + " must meet at least " + requirementCount + " of the complexity requirements", | ||
'passwordComplexity.tooShort': `${label} should be at least ${min} ${p('character', min)} long`, | ||
'passwordComplexity.tooLong': `${label} should not be longer than ${max} ${p('character', max)}`, | ||
'passwordComplexity.lowercase': `${label} should contain at least ${lowerCase} lower-cased ${p('letter', lowerCase)}`, | ||
'passwordComplexity.uppercase': `${label} should contain at least ${upperCase} upper-cased ${p('letter', upperCase)}`, | ||
'passwordComplexity.numeric': `${label} should contain at least ${numeric} ${p('number', numeric)}`, | ||
'passwordComplexity.symbol': `${label} should contain at least ${symbol} ${p('symbol', symbol)}`, | ||
'passwordComplexity.requirementCount': `${label} must meet at least ${requirementCount} of the complexity requirements`, | ||
}, | ||
validate: function (value, helpers) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var errors = []; | ||
validate: (value, helpers) => { | ||
const errors = []; | ||
if (typeof value === 'string') { | ||
var lowercaseCount = (_b = (_a = value.match(/[a-z]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0; | ||
var upperCaseCount = (_d = (_c = value.match(/[A-Z]/g)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; | ||
var numericCount = (_f = (_e = value.match(/[0-9]/g)) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0; | ||
var symbolCount = (_h = (_g = value.match(/[^a-zA-Z0-9]/g)) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0; | ||
var meetsMin = min && value.length >= min; | ||
var meetsMax = max && value.length <= max; | ||
var meetsLowercase = lowercaseCount >= (lowerCase); | ||
var meetsUppercase = upperCaseCount >= (upperCase); | ||
var meetsNumeric = numericCount >= (numeric); | ||
var meetsSymbol = symbolCount >= (symbol); | ||
var maxRequirement = isPositive(lowerCase) + isPositive(upperCase) + | ||
const lowercaseCount = value.match(/[a-z]/g)?.length ?? 0; | ||
const upperCaseCount = value.match(/[A-Z]/g)?.length ?? 0; | ||
const numericCount = value.match(/[0-9]/g)?.length ?? 0; | ||
const symbolCount = value.match(/[^a-zA-Z0-9]/g)?.length ?? 0; | ||
const meetsMin = min && value.length >= min; | ||
const meetsMax = max && value.length <= max; | ||
const meetsLowercase = lowercaseCount >= (lowerCase); | ||
const meetsUppercase = upperCaseCount >= (upperCase); | ||
const meetsNumeric = numericCount >= (numeric); | ||
const meetsSymbol = symbolCount >= (symbol); | ||
const maxRequirement = isPositive(lowerCase) + isPositive(upperCase) + | ||
isPositive(numeric) + isPositive(symbol); | ||
var requirement = clamp(requirementCount || maxRequirement, 1, maxRequirement); | ||
var requirementErrors = []; | ||
const requirement = clamp(requirementCount || maxRequirement, 1, maxRequirement); | ||
const requirementErrors = []; | ||
if (!meetsMin) | ||
errors.push(helpers.error('passwordComplexity.tooShort', { value: value })); | ||
errors.push(helpers.error('passwordComplexity.tooShort', { value })); | ||
if (!meetsMax) | ||
errors.push(helpers.error('passwordComplexity.tooLong', { value: value })); | ||
errors.push(helpers.error('passwordComplexity.tooLong', { value })); | ||
if (!meetsLowercase) { | ||
requirementErrors.push(helpers.error('passwordComplexity.lowercase', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.lowercase', { value })); | ||
} | ||
if (!meetsUppercase) { | ||
requirementErrors.push(helpers.error('passwordComplexity.uppercase', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.uppercase', { value })); | ||
} | ||
if (!meetsNumeric) { | ||
requirementErrors.push(helpers.error('passwordComplexity.numeric', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.numeric', { value })); | ||
} | ||
if (!meetsSymbol) { | ||
requirementErrors.push(helpers.error('passwordComplexity.symbol', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.symbol', { value })); | ||
} | ||
if (maxRequirement - requirementErrors.length < requirement) { | ||
errors.push.apply(errors, requirementErrors); | ||
errors.push(...requirementErrors); | ||
if (requirement < maxRequirement) { | ||
errors.push(helpers.error('passwordComplexity.requirementCount', { value: value })); | ||
errors.push(helpers.error('passwordComplexity.requirementCount', { value })); | ||
} | ||
@@ -80,3 +71,3 @@ } | ||
return { | ||
value: value, | ||
value, | ||
errors: errors.length ? errors : null, | ||
@@ -87,5 +78,4 @@ }; | ||
return Joi.extend(joiPasswordComplexity).passwordComplexity(); | ||
}); | ||
}; | ||
export default index; | ||
//# sourceMappingURL=index.es.js.map | ||
export { index as default }; |
@@ -5,17 +5,7 @@ 'use strict'; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var Joi__default = /*#__PURE__*/_interopDefaultLegacy(Joi); | ||
// pluralize | ||
var p = function (word, num) { | ||
if (num === void 0) { num = 0; } | ||
return (num === 1 ? word : word + "s"); | ||
}; | ||
var isPositive = function (num) { | ||
if (num === void 0) { num = 0; } | ||
return Number(num > 0); | ||
}; | ||
var clamp = function (value, min, max) { return (value < min ? min : value > max ? max : value); }; | ||
var defaultOptions = { | ||
const p = (word, num = 0) => (num === 1 ? word : `${word}s`); | ||
const isPositive = (num = 0) => Number(num > 0); | ||
const clamp = (value, min, max) => (value < min ? min : value > max ? max : value); | ||
const defaultOptions = { | ||
min: 8, | ||
@@ -29,55 +19,52 @@ max: 26, | ||
}; | ||
var index = (function (_a, label) { | ||
var _b = _a === void 0 ? defaultOptions : _a, _c = _b.min, min = _c === void 0 ? 0 : _c, _d = _b.max, max = _d === void 0 ? 0 : _d, _e = _b.lowerCase, lowerCase = _e === void 0 ? 0 : _e, _f = _b.upperCase, upperCase = _f === void 0 ? 0 : _f, _g = _b.numeric, numeric = _g === void 0 ? 0 : _g, _h = _b.symbol, symbol = _h === void 0 ? 0 : _h, _j = _b.requirementCount, requirementCount = _j === void 0 ? 0 : _j; | ||
if (label === void 0) { label = '{{#label}}'; } | ||
var joiPasswordComplexity = { | ||
var index = ({ min = 0, max = 0, lowerCase = 0, upperCase = 0, numeric = 0, symbol = 0, requirementCount = 0, } = defaultOptions, label = '{{#label}}') => { | ||
const joiPasswordComplexity = { | ||
type: 'passwordComplexity', | ||
base: Joi__default['default'].string(), | ||
base: Joi.string(), | ||
messages: { | ||
'passwordComplexity.tooShort': label + " should be at least " + min + " " + p('character', min) + " long", | ||
'passwordComplexity.tooLong': label + " should not be longer than " + max + " " + p('character', max), | ||
'passwordComplexity.lowercase': label + " should contain at least " + lowerCase + " lower-cased " + p('letter', lowerCase), | ||
'passwordComplexity.uppercase': label + " should contain at least " + upperCase + " upper-cased " + p('letter', upperCase), | ||
'passwordComplexity.numeric': label + " should contain at least " + numeric + " " + p('number', numeric), | ||
'passwordComplexity.symbol': label + " should contain at least " + symbol + " " + p('symbol', symbol), | ||
'passwordComplexity.requirementCount': label + " must meet at least " + requirementCount + " of the complexity requirements", | ||
'passwordComplexity.tooShort': `${label} should be at least ${min} ${p('character', min)} long`, | ||
'passwordComplexity.tooLong': `${label} should not be longer than ${max} ${p('character', max)}`, | ||
'passwordComplexity.lowercase': `${label} should contain at least ${lowerCase} lower-cased ${p('letter', lowerCase)}`, | ||
'passwordComplexity.uppercase': `${label} should contain at least ${upperCase} upper-cased ${p('letter', upperCase)}`, | ||
'passwordComplexity.numeric': `${label} should contain at least ${numeric} ${p('number', numeric)}`, | ||
'passwordComplexity.symbol': `${label} should contain at least ${symbol} ${p('symbol', symbol)}`, | ||
'passwordComplexity.requirementCount': `${label} must meet at least ${requirementCount} of the complexity requirements`, | ||
}, | ||
validate: function (value, helpers) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var errors = []; | ||
validate: (value, helpers) => { | ||
const errors = []; | ||
if (typeof value === 'string') { | ||
var lowercaseCount = (_b = (_a = value.match(/[a-z]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0; | ||
var upperCaseCount = (_d = (_c = value.match(/[A-Z]/g)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; | ||
var numericCount = (_f = (_e = value.match(/[0-9]/g)) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0; | ||
var symbolCount = (_h = (_g = value.match(/[^a-zA-Z0-9]/g)) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0; | ||
var meetsMin = min && value.length >= min; | ||
var meetsMax = max && value.length <= max; | ||
var meetsLowercase = lowercaseCount >= (lowerCase); | ||
var meetsUppercase = upperCaseCount >= (upperCase); | ||
var meetsNumeric = numericCount >= (numeric); | ||
var meetsSymbol = symbolCount >= (symbol); | ||
var maxRequirement = isPositive(lowerCase) + isPositive(upperCase) + | ||
const lowercaseCount = value.match(/[a-z]/g)?.length ?? 0; | ||
const upperCaseCount = value.match(/[A-Z]/g)?.length ?? 0; | ||
const numericCount = value.match(/[0-9]/g)?.length ?? 0; | ||
const symbolCount = value.match(/[^a-zA-Z0-9]/g)?.length ?? 0; | ||
const meetsMin = min && value.length >= min; | ||
const meetsMax = max && value.length <= max; | ||
const meetsLowercase = lowercaseCount >= (lowerCase); | ||
const meetsUppercase = upperCaseCount >= (upperCase); | ||
const meetsNumeric = numericCount >= (numeric); | ||
const meetsSymbol = symbolCount >= (symbol); | ||
const maxRequirement = isPositive(lowerCase) + isPositive(upperCase) + | ||
isPositive(numeric) + isPositive(symbol); | ||
var requirement = clamp(requirementCount || maxRequirement, 1, maxRequirement); | ||
var requirementErrors = []; | ||
const requirement = clamp(requirementCount || maxRequirement, 1, maxRequirement); | ||
const requirementErrors = []; | ||
if (!meetsMin) | ||
errors.push(helpers.error('passwordComplexity.tooShort', { value: value })); | ||
errors.push(helpers.error('passwordComplexity.tooShort', { value })); | ||
if (!meetsMax) | ||
errors.push(helpers.error('passwordComplexity.tooLong', { value: value })); | ||
errors.push(helpers.error('passwordComplexity.tooLong', { value })); | ||
if (!meetsLowercase) { | ||
requirementErrors.push(helpers.error('passwordComplexity.lowercase', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.lowercase', { value })); | ||
} | ||
if (!meetsUppercase) { | ||
requirementErrors.push(helpers.error('passwordComplexity.uppercase', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.uppercase', { value })); | ||
} | ||
if (!meetsNumeric) { | ||
requirementErrors.push(helpers.error('passwordComplexity.numeric', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.numeric', { value })); | ||
} | ||
if (!meetsSymbol) { | ||
requirementErrors.push(helpers.error('passwordComplexity.symbol', { value: value })); | ||
requirementErrors.push(helpers.error('passwordComplexity.symbol', { value })); | ||
} | ||
if (maxRequirement - requirementErrors.length < requirement) { | ||
errors.push.apply(errors, requirementErrors); | ||
errors.push(...requirementErrors); | ||
if (requirement < maxRequirement) { | ||
errors.push(helpers.error('passwordComplexity.requirementCount', { value: value })); | ||
errors.push(helpers.error('passwordComplexity.requirementCount', { value })); | ||
} | ||
@@ -87,3 +74,3 @@ } | ||
return { | ||
value: value, | ||
value, | ||
errors: errors.length ? errors : null, | ||
@@ -93,6 +80,5 @@ }; | ||
}; | ||
return Joi__default['default'].extend(joiPasswordComplexity).passwordComplexity(); | ||
}); | ||
return Joi.extend(joiPasswordComplexity).passwordComplexity(); | ||
}; | ||
module.exports = index; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "joi-password-complexity", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Joi validation for password complexity requirements.", | ||
@@ -24,27 +24,25 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.12.16", | ||
"@babel/preset-env": "^7.12.16", | ||
"@babel/preset-typescript": "^7.12.16", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.1.1", | ||
"@types/jest": "^26.0.20", | ||
"@babel/core": "^7.22.8", | ||
"@babel/preset-env": "^7.22.7", | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@rollup/plugin-commonjs": "^25.0.2", | ||
"@rollup/plugin-node-resolve": "^15.1.0", | ||
"@types/jest": "^29.5.3", | ||
"@types/joi": "^17.2.2", | ||
"@typescript-eslint/eslint-plugin": "^4.15.0", | ||
"@typescript-eslint/parser": "^4.15.0", | ||
"babel-jest": "^26.6.3", | ||
"eslint": "^7.19.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-config-airbnb-typescript": "^12.3.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jest": "^24.1.3", | ||
"eslint-plugin-jsx-a11y": "^6.4.1", | ||
"eslint-plugin-react": "^7.22.0", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"jest": "^26.6.3", | ||
"joi": "^17.3.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.38.5", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"babel-jest": "^29.6.1", | ||
"eslint": "^8.44.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-airbnb-typescript": "^17.0.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jest": "^27.2.2", | ||
"jest": "^29.6.1", | ||
"joi": "^17.9.2", | ||
"rimraf": "^5.0.1", | ||
"rollup": "^3.26.2", | ||
"rollup-plugin-peer-deps-external": "^2.2.4", | ||
"rollup-plugin-typescript2": "^0.29.0", | ||
"typescript": "^4.1.5" | ||
"rollup-plugin-typescript2": "^0.35.0", | ||
"tslib": "^2.6.0", | ||
"typescript": "^5.1.6" | ||
}, | ||
@@ -66,5 +64,3 @@ "files": [ | ||
"homepage": "https://github.com/kamronbatman/joi-password-complexity#readme", | ||
"jest": { | ||
"verbose": true | ||
} | ||
} | ||
"packageManager": "yarn@3.6.1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23
12877
6
168
1