@zxcvbn-ts/core
Advanced tools
Comparing version 2.2.0 to 2.2.1
export type Procedure = (...args: any[]) => void; | ||
/** | ||
* @link https://davidwalsh.name/javascript-debounce-function | ||
* @param func needs to implement a function which is debounced | ||
* @param wait how long do you want to wait till the previous declared function is executed | ||
* @param isImmediate defines if you want to execute the function on the first execution or the last execution inside the time window. `true` for first and `false` for last. | ||
*/ | ||
declare const _default: <F extends Procedure>(func: F, wait: number, isImmediate: boolean) => (this: ThisParameterType<F>, ...args: Parameters<F>) => void; | ||
declare const _default: <F extends Procedure>(func: F, wait: number, isImmediate?: boolean) => (this: ThisParameterType<F>, ...args: Parameters<F>) => void; | ||
export default _default; |
/** | ||
* @link https://davidwalsh.name/javascript-debounce-function | ||
* @param func needs to implement a function which is debounced | ||
* @param wait how long do you want to wait till the previous declared function is executed | ||
* @param isImmediate defines if you want to execute the function on the first execution or the last execution inside the time window. `true` for first and `false` for last. | ||
*/ | ||
@@ -4,0 +7,0 @@ var debounce = ((func, wait, isImmediate) => { |
@@ -5,2 +5,5 @@ 'use strict'; | ||
* @link https://davidwalsh.name/javascript-debounce-function | ||
* @param func needs to implement a function which is debounced | ||
* @param wait how long do you want to wait till the previous declared function is executed | ||
* @param isImmediate defines if you want to execute the function on the first execution or the last execution inside the time window. `true` for first and `false` for last. | ||
*/ | ||
@@ -7,0 +10,0 @@ var debounce = ((func, wait, isImmediate) => { |
@@ -39,5 +39,6 @@ import Matching from './Matching.esm.js'; | ||
const zxcvbnAsync = async (password, userInputs) => { | ||
const usedPassword = password.substring(0, zxcvbnOptions.maxLength); | ||
const start = time(); | ||
const matches = await main(password, userInputs); | ||
return createReturnValue(matches, password, start); | ||
const matches = await main(usedPassword, userInputs); | ||
return createReturnValue(matches, usedPassword, start); | ||
}; | ||
@@ -44,0 +45,0 @@ |
@@ -40,5 +40,6 @@ 'use strict'; | ||
const zxcvbnAsync = async (password, userInputs) => { | ||
const usedPassword = password.substring(0, Options.default.maxLength); | ||
const start = time(); | ||
const matches = await main(password, userInputs); | ||
return createReturnValue(matches, password, start); | ||
const matches = await main(usedPassword, userInputs); | ||
return createReturnValue(matches, usedPassword, start); | ||
}; | ||
@@ -45,0 +46,0 @@ |
@@ -10,6 +10,6 @@ import { TranslationKeys, OptionsType, OptionsDictionary, OptionsL33tTable, OptionsGraph, RankedDictionaries, Matchers, Matcher } from './types'; | ||
graphs: OptionsGraph; | ||
availableGraphs: string[]; | ||
useLevenshteinDistance: boolean; | ||
levenshteinThreshold: number; | ||
l33tMaxSubstitutions: number; | ||
maxLength: number; | ||
constructor(); | ||
@@ -16,0 +16,0 @@ setOptions(options?: OptionsType): void; |
@@ -16,9 +16,9 @@ import { buildRankedDictionary } from './helper.esm.js'; | ||
this.graphs = {}; | ||
this.availableGraphs = []; | ||
this.useLevenshteinDistance = false; | ||
this.levenshteinThreshold = 2; | ||
this.l33tMaxSubstitutions = 100; | ||
this.maxLength = 256; | ||
this.setRankedDictionaries(); | ||
} | ||
// eslint-disable-next-line max-statements | ||
// eslint-disable-next-line max-statements,complexity | ||
setOptions(options = {}) { | ||
@@ -47,2 +47,5 @@ if (options.l33tTable) { | ||
} | ||
if (options.maxLength !== undefined) { | ||
this.maxLength = options.maxLength; | ||
} | ||
} | ||
@@ -89,4 +92,7 @@ setTranslations(translations) { | ||
}); | ||
const result = data.length === 0 ? 0 : Math.max(...data); | ||
return result; | ||
// do not use Math.max(...data) because it can result in max stack size error because every entry will be used as an argument | ||
if (data.length === 0) { | ||
return 0; | ||
} | ||
return data.reduce((a, b) => Math.max(a, b), -Infinity); | ||
} | ||
@@ -93,0 +99,0 @@ getRankedDictionary(name) { |
@@ -20,9 +20,9 @@ 'use strict'; | ||
this.graphs = {}; | ||
this.availableGraphs = []; | ||
this.useLevenshteinDistance = false; | ||
this.levenshteinThreshold = 2; | ||
this.l33tMaxSubstitutions = 100; | ||
this.maxLength = 256; | ||
this.setRankedDictionaries(); | ||
} | ||
// eslint-disable-next-line max-statements | ||
// eslint-disable-next-line max-statements,complexity | ||
setOptions(options = {}) { | ||
@@ -51,2 +51,5 @@ if (options.l33tTable) { | ||
} | ||
if (options.maxLength !== undefined) { | ||
this.maxLength = options.maxLength; | ||
} | ||
} | ||
@@ -93,4 +96,7 @@ setTranslations(translations) { | ||
}); | ||
const result = data.length === 0 ? 0 : Math.max(...data); | ||
return result; | ||
// do not use Math.max(...data) because it can result in max stack size error because every entry will be used as an argument | ||
if (data.length === 0) { | ||
return 0; | ||
} | ||
return data.reduce((a, b) => Math.max(a, b), -Infinity); | ||
} | ||
@@ -97,0 +103,0 @@ getRankedDictionary(name) { |
@@ -14,5 +14,17 @@ import translationKeys from './data/translationKeys'; | ||
export interface Match { | ||
/** | ||
* @description The name of the matcher | ||
*/ | ||
pattern: Pattern; | ||
/** | ||
* @description The start index of the token found in the password | ||
*/ | ||
i: number; | ||
/** | ||
@description The end index of the token found in the password | ||
*/ | ||
j: number; | ||
/** | ||
* @description The token found in the password | ||
*/ | ||
token: string; | ||
@@ -109,9 +121,38 @@ [key: string]: any; | ||
export interface OptionsType { | ||
/** | ||
* @description Defines an object with a key value match to translate the feedback given by this library. The default values are plain keys so that you can use your own i18n library. Already implemented language can be found with something like @zxcvbn-ts/language-en. | ||
*/ | ||
translations?: TranslationKeys; | ||
/** | ||
* @description Defines keyboard layouts as an object which are used to find sequences. Already implemented layouts can be found in @zxcvbn-ts/language-common | ||
*/ | ||
graphs?: OptionsGraph; | ||
/** | ||
* @description Define an object with l33t substitutions. For example that an "a" can be exchanged with a "4" or a "@". | ||
*/ | ||
l33tTable?: OptionsL33tTable; | ||
/** | ||
* @description Define dictionary that should be used to check against. The matcher will search the dictionaries for similar password with l33t speak and reversed words. The recommended sets are found in @zxcvbn-ts/language-common and @zxcvbn-ts/language-en. | ||
*/ | ||
dictionary?: OptionsDictionary; | ||
/** | ||
* @description Defines if the levenshtein algorithm should be used. This will be only used on the complete password and not on parts of it. This will decrease the calcTime a bit but will significantly improve the password check. The recommended sets are found in @zxcvbn-ts/language-common and @zxcvbn-ts/language-en. | ||
* @default false | ||
*/ | ||
useLevenshteinDistance?: boolean; | ||
/** | ||
* @description Defines how many characters can be different to match a dictionary word with the levenshtein algorithm. | ||
* @default 2 | ||
*/ | ||
levenshteinThreshold?: number; | ||
/** | ||
* @description The l33t matcher will check how many characters can be exchanged with the l33t table. If they are to many it will decrease the calcTime significantly. So we cap it at a reasonable value by default which will probably already seems like a strong password anyway. | ||
* @default 100 | ||
*/ | ||
l33tMaxSubstitutions?: number; | ||
/** | ||
* @description Defines how many character of the password are checked. A password longer than the default are considered strong anyway, but it can be increased as pleased. Be aware that this could open some attack vectors. | ||
* @default 256 | ||
*/ | ||
maxLength?: number; | ||
} | ||
@@ -128,2 +169,5 @@ export interface RankedDictionary { | ||
password: string; | ||
/** | ||
* @description This is the original Matcher so that one can use other matchers to define a baseGuess. An usage example is the repeat matcher | ||
*/ | ||
omniMatch: Matching; | ||
@@ -130,0 +174,0 @@ } |
{ | ||
"name": "@zxcvbn-ts/core", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"main": "dist/index.js", | ||
@@ -40,3 +40,3 @@ "module": "dist/index.esm.js", | ||
], | ||
"gitHead": "a0315646a0e1f82771d9ac26ad0cac21f48ac0fe" | ||
"gitHead": "3d2936a12566a349c1cdf895365c6f9ed8572f7a" | ||
} |
@@ -5,2 +5,5 @@ export type Procedure = (...args: any[]) => void | ||
* @link https://davidwalsh.name/javascript-debounce-function | ||
* @param func needs to implement a function which is debounced | ||
* @param wait how long do you want to wait till the previous declared function is executed | ||
* @param isImmediate defines if you want to execute the function on the first execution or the last execution inside the time window. `true` for first and `false` for last. | ||
*/ | ||
@@ -10,3 +13,3 @@ export default <F extends Procedure>( | ||
wait: number, | ||
isImmediate: boolean, | ||
isImmediate?: boolean, | ||
): ((this: ThisParameterType<F>, ...args: Parameters<F>) => void) => { | ||
@@ -13,0 +16,0 @@ let timeout: ReturnType<typeof setTimeout> | undefined |
@@ -59,6 +59,7 @@ import Matching from './Matching' | ||
): Promise<ZxcvbnResult> => { | ||
const usedPassword = password.substring(0, zxcvbnOptions.maxLength) | ||
const start = time() | ||
const matches = await main(password, userInputs) | ||
const matches = await main(usedPassword, userInputs) | ||
return createReturnValue(matches, password, start) | ||
return createReturnValue(matches, usedPassword, start) | ||
} | ||
@@ -65,0 +66,0 @@ |
@@ -32,4 +32,2 @@ import { buildRankedDictionary } from './helper' | ||
availableGraphs: string[] = [] | ||
useLevenshteinDistance: boolean = false | ||
@@ -41,2 +39,4 @@ | ||
maxLength: number = 256 | ||
constructor() { | ||
@@ -46,3 +46,3 @@ this.setRankedDictionaries() | ||
// eslint-disable-next-line max-statements | ||
// eslint-disable-next-line max-statements,complexity | ||
setOptions(options: OptionsType = {}) { | ||
@@ -78,2 +78,6 @@ if (options.l33tTable) { | ||
} | ||
if (options.maxLength !== undefined) { | ||
this.maxLength = options.maxLength | ||
} | ||
} | ||
@@ -125,5 +129,8 @@ | ||
}) | ||
const result = data.length === 0 ? 0 : Math.max(...data) | ||
return result | ||
// do not use Math.max(...data) because it can result in max stack size error because every entry will be used as an argument | ||
if (data.length === 0) { | ||
return 0 | ||
} | ||
return data.reduce((a, b) => Math.max(a, b), -Infinity) | ||
} | ||
@@ -130,0 +137,0 @@ |
@@ -33,5 +33,17 @@ import translationKeys from './data/translationKeys' | ||
export interface Match { | ||
/** | ||
* @description The name of the matcher | ||
*/ | ||
pattern: Pattern | ||
/** | ||
* @description The start index of the token found in the password | ||
*/ | ||
i: number | ||
/** | ||
@description The end index of the token found in the password | ||
*/ | ||
j: number | ||
/** | ||
* @description The token found in the password | ||
*/ | ||
token: string | ||
@@ -158,9 +170,38 @@ [key: string]: any | ||
export interface OptionsType { | ||
/** | ||
* @description Defines an object with a key value match to translate the feedback given by this library. The default values are plain keys so that you can use your own i18n library. Already implemented language can be found with something like @zxcvbn-ts/language-en. | ||
*/ | ||
translations?: TranslationKeys | ||
/** | ||
* @description Defines keyboard layouts as an object which are used to find sequences. Already implemented layouts can be found in @zxcvbn-ts/language-common | ||
*/ | ||
graphs?: OptionsGraph | ||
/** | ||
* @description Define an object with l33t substitutions. For example that an "a" can be exchanged with a "4" or a "@". | ||
*/ | ||
l33tTable?: OptionsL33tTable | ||
/** | ||
* @description Define dictionary that should be used to check against. The matcher will search the dictionaries for similar password with l33t speak and reversed words. The recommended sets are found in @zxcvbn-ts/language-common and @zxcvbn-ts/language-en. | ||
*/ | ||
dictionary?: OptionsDictionary | ||
/** | ||
* @description Defines if the levenshtein algorithm should be used. This will be only used on the complete password and not on parts of it. This will decrease the calcTime a bit but will significantly improve the password check. The recommended sets are found in @zxcvbn-ts/language-common and @zxcvbn-ts/language-en. | ||
* @default false | ||
*/ | ||
useLevenshteinDistance?: boolean | ||
/** | ||
* @description Defines how many characters can be different to match a dictionary word with the levenshtein algorithm. | ||
* @default 2 | ||
*/ | ||
levenshteinThreshold?: number | ||
/** | ||
* @description The l33t matcher will check how many characters can be exchanged with the l33t table. If they are to many it will decrease the calcTime significantly. So we cap it at a reasonable value by default which will probably already seems like a strong password anyway. | ||
* @default 100 | ||
*/ | ||
l33tMaxSubstitutions?: number | ||
/** | ||
* @description Defines how many character of the password are checked. A password longer than the default are considered strong anyway, but it can be increased as pleased. Be aware that this could open some attack vectors. | ||
* @default 256 | ||
*/ | ||
maxLength?: number | ||
} | ||
@@ -187,2 +228,5 @@ | ||
password: string | ||
/** | ||
* @description This is the original Matcher so that one can use other matchers to define a baseGuess. An usage example is the repeat matcher | ||
*/ | ||
omniMatch: Matching | ||
@@ -189,0 +233,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
589013
9816