diff --git a/README.md b/README.md index 7c1cadb9f..3d0d688c1 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,7 @@ Sanitizer | Description **trim(input [, chars])** | trim characters (whitespace by default) from both sides of the input. **unescape(input)** | replace HTML encoded entities with `<`, `>`, `&`, `'`, `"`, `` ` ``, `\` and `/`. **whitelist(input, chars)** | remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will need to escape some chars, e.g. `whitelist(input, '\\[\\]')`. +**analyzePassword(str)** | Analyzes and returns details about the given string's composition as a password. Returns an object containing the password's length, count of unique characters, and the number of uppercase letters, lowercase letters, numbers, and symbols. ### XSS Sanitization diff --git a/src/index.js b/src/index.js index 1bc65a886..ba99ac727 100644 --- a/src/index.js +++ b/src/index.js @@ -125,7 +125,7 @@ import normalizeEmail from './lib/normalizeEmail'; import isSlug from './lib/isSlug'; import isLicensePlate from './lib/isLicensePlate'; -import isStrongPassword from './lib/isStrongPassword'; +import isStrongPassword, { analyzePassword } from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; @@ -237,6 +237,7 @@ const validator = { toString, isSlug, isStrongPassword, + analyzePassword, isTaxID, isDate, isTime, diff --git a/src/lib/isStrongPassword.js b/src/lib/isStrongPassword.js index 8fe9223b7..44932ed31 100644 --- a/src/lib/isStrongPassword.js +++ b/src/lib/isStrongPassword.js @@ -38,7 +38,7 @@ function countChars(str) { } /* Return information about a password */ -function analyzePassword(password) { +export function analyzePassword(password) { let charMap = countChars(password); let analysis = { length: password.length,