@zxcvbn-ts/core
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -8,3 +8,4 @@ import { RepeatMatch } from '../../types'; | ||
declare class MatchRepeat { | ||
match({ password, omniMatch }: RepeatMatchOptions): RepeatMatch[]; | ||
match({ password, omniMatch }: RepeatMatchOptions): RepeatMatch[] | Promise<RepeatMatch[]>; | ||
normalizeMatch(baseToken: string, j: number, match: RegExpExecArray, baseGuesses: number | Promise<number>): RepeatMatch | Promise<RepeatMatch>; | ||
getGreedyMatch(password: string, lastIndex: number): RegExpExecArray | null; | ||
@@ -16,4 +17,4 @@ getLazyMatch(password: string, lastIndex: number): RegExpExecArray | null; | ||
}; | ||
getBaseGuesses(baseToken: string, omniMatch: Matching): number; | ||
getBaseGuesses(baseToken: string, omniMatch: Matching): number | Promise<number>; | ||
} | ||
export default MatchRepeat; |
@@ -10,2 +10,3 @@ import scoring from '../../scoring/index.esm.js'; | ||
class MatchRepeat { | ||
// eslint-disable-next-line max-statements | ||
match({ | ||
@@ -34,11 +35,3 @@ password, | ||
const baseGuesses = this.getBaseGuesses(baseToken, omniMatch); | ||
matches.push({ | ||
pattern: 'repeat', | ||
i: match.index, | ||
j, | ||
token: match[0], | ||
baseToken, | ||
baseGuesses, | ||
repeatCount: match[0].length / baseToken.length | ||
}); | ||
matches.push(this.normalizeMatch(baseToken, j, match, baseGuesses)); | ||
lastIndex = j + 1; | ||
@@ -48,3 +41,36 @@ } | ||
const hasPromises = matches.some(match => { | ||
return match instanceof Promise; | ||
}); | ||
if (hasPromises) { | ||
return Promise.all(matches); | ||
} | ||
return matches; | ||
} // eslint-disable-next-line max-params | ||
normalizeMatch(baseToken, j, match, baseGuesses) { | ||
const baseMatch = { | ||
pattern: 'repeat', | ||
i: match.index, | ||
j, | ||
token: match[0], | ||
baseToken, | ||
baseGuesses: 0, | ||
repeatCount: match[0].length / baseToken.length | ||
}; | ||
if (baseGuesses instanceof Promise) { | ||
return baseGuesses.then(resolvedBaseGuesses => { | ||
return { ...baseMatch, | ||
baseGuesses: resolvedBaseGuesses | ||
}; | ||
}); | ||
} | ||
return { ...baseMatch, | ||
baseGuesses | ||
}; | ||
} | ||
@@ -101,3 +127,12 @@ | ||
getBaseGuesses(baseToken, omniMatch) { | ||
const baseAnalysis = scoring.mostGuessableMatchSequence(baseToken, omniMatch.match(baseToken)); | ||
const matches = omniMatch.match(baseToken); | ||
if (matches instanceof Promise) { | ||
return matches.then(resolvedMatches => { | ||
const baseAnalysis = scoring.mostGuessableMatchSequence(baseToken, resolvedMatches); | ||
return baseAnalysis.guesses; | ||
}); | ||
} | ||
const baseAnalysis = scoring.mostGuessableMatchSequence(baseToken, matches); | ||
return baseAnalysis.guesses; | ||
@@ -104,0 +139,0 @@ } |
@@ -12,2 +12,3 @@ 'use strict'; | ||
class MatchRepeat { | ||
// eslint-disable-next-line max-statements | ||
match({ | ||
@@ -36,11 +37,3 @@ password, | ||
const baseGuesses = this.getBaseGuesses(baseToken, omniMatch); | ||
matches.push({ | ||
pattern: 'repeat', | ||
i: match.index, | ||
j, | ||
token: match[0], | ||
baseToken, | ||
baseGuesses, | ||
repeatCount: match[0].length / baseToken.length | ||
}); | ||
matches.push(this.normalizeMatch(baseToken, j, match, baseGuesses)); | ||
lastIndex = j + 1; | ||
@@ -50,3 +43,36 @@ } | ||
const hasPromises = matches.some(match => { | ||
return match instanceof Promise; | ||
}); | ||
if (hasPromises) { | ||
return Promise.all(matches); | ||
} | ||
return matches; | ||
} // eslint-disable-next-line max-params | ||
normalizeMatch(baseToken, j, match, baseGuesses) { | ||
const baseMatch = { | ||
pattern: 'repeat', | ||
i: match.index, | ||
j, | ||
token: match[0], | ||
baseToken, | ||
baseGuesses: 0, | ||
repeatCount: match[0].length / baseToken.length | ||
}; | ||
if (baseGuesses instanceof Promise) { | ||
return baseGuesses.then(resolvedBaseGuesses => { | ||
return { ...baseMatch, | ||
baseGuesses: resolvedBaseGuesses | ||
}; | ||
}); | ||
} | ||
return { ...baseMatch, | ||
baseGuesses | ||
}; | ||
} | ||
@@ -103,3 +129,12 @@ | ||
getBaseGuesses(baseToken, omniMatch) { | ||
const baseAnalysis = index.mostGuessableMatchSequence(baseToken, omniMatch.match(baseToken)); | ||
const matches = omniMatch.match(baseToken); | ||
if (matches instanceof Promise) { | ||
return matches.then(resolvedMatches => { | ||
const baseAnalysis = index.mostGuessableMatchSequence(baseToken, resolvedMatches); | ||
return baseAnalysis.guesses; | ||
}); | ||
} | ||
const baseAnalysis = index.mostGuessableMatchSequence(baseToken, matches); | ||
return baseAnalysis.guesses; | ||
@@ -106,0 +141,0 @@ } |
@@ -16,2 +16,3 @@ import { extend, sorted } from './helper.esm.js'; | ||
regex: MatchRegex, | ||
// @ts-ignore => TODO resolve this type issue. This is because it is possible to be async | ||
repeat: MatchRepeat, | ||
@@ -51,3 +52,3 @@ sequence: MatchSequence, | ||
return new Promise(resolve => { | ||
return Promise.all(promises).then(() => { | ||
Promise.all(promises).then(() => { | ||
resolve(sorted(matches)); | ||
@@ -54,0 +55,0 @@ }); |
@@ -18,2 +18,3 @@ 'use strict'; | ||
regex: matching$2, | ||
// @ts-ignore => TODO resolve this type issue. This is because it is possible to be async | ||
repeat: matching$3, | ||
@@ -53,3 +54,3 @@ sequence: matching$4, | ||
return new Promise(resolve => { | ||
return Promise.all(promises).then(() => { | ||
Promise.all(promises).then(() => { | ||
resolve(helper.sorted(matches)); | ||
@@ -56,0 +57,0 @@ }); |
@@ -115,3 +115,4 @@ import utils from './utils.esm.js'; | ||
let sequenceLength = 0; | ||
let sequenceLength = 0; // eslint-disable-next-line no-loss-of-precision | ||
let g = 2e308; | ||
@@ -118,0 +119,0 @@ const temp = this.optimal.g[k]; // safety check for empty passwords |
@@ -117,3 +117,4 @@ 'use strict'; | ||
let sequenceLength = 0; | ||
let sequenceLength = 0; // eslint-disable-next-line no-loss-of-precision | ||
let g = 2e308; | ||
@@ -120,0 +121,0 @@ const temp = this.optimal.g[k]; // safety check for empty passwords |
{ | ||
"name": "@zxcvbn-ts/core", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "dist/index.js", | ||
@@ -37,3 +37,3 @@ "module": "dist/index.esm.js", | ||
], | ||
"gitHead": "90410e48548c425c6c34f8a3bb448588800c8bd3" | ||
"gitHead": "b874784758f0f1c9828c3e9d96180cf38abb4472" | ||
} |
@@ -1,2 +0,2 @@ | ||
import { MatchExtended, RepeatMatch } from '../../types' | ||
import { RepeatMatch } from '../../types' | ||
import scoring from '../../scoring' | ||
@@ -15,4 +15,5 @@ import Matching from '../../Matching' | ||
class MatchRepeat { | ||
// eslint-disable-next-line max-statements | ||
match({ password, omniMatch }: RepeatMatchOptions) { | ||
const matches: RepeatMatch[] = [] | ||
const matches: (RepeatMatch | Promise<RepeatMatch>)[] = [] | ||
let lastIndex = 0 | ||
@@ -30,18 +31,47 @@ while (lastIndex < password.length) { | ||
const baseGuesses = this.getBaseGuesses(baseToken, omniMatch) | ||
matches.push(this.normalizeMatch(baseToken, j, match, baseGuesses)) | ||
matches.push({ | ||
pattern: 'repeat', | ||
i: match.index, | ||
j, | ||
token: match[0], | ||
baseToken, | ||
baseGuesses, | ||
repeatCount: match[0].length / baseToken.length, | ||
}) | ||
lastIndex = j + 1 | ||
} | ||
} | ||
return matches | ||
const hasPromises = matches.some((match) => { | ||
return match instanceof Promise | ||
}) | ||
if (hasPromises) { | ||
return Promise.all(matches) | ||
} | ||
return matches as RepeatMatch[] | ||
} | ||
// eslint-disable-next-line max-params | ||
normalizeMatch( | ||
baseToken: string, | ||
j: number, | ||
match: RegExpExecArray, | ||
baseGuesses: number | Promise<number>, | ||
) { | ||
const baseMatch: RepeatMatch = { | ||
pattern: 'repeat', | ||
i: match.index, | ||
j, | ||
token: match[0], | ||
baseToken, | ||
baseGuesses: 0, | ||
repeatCount: match[0].length / baseToken.length, | ||
} | ||
if (baseGuesses instanceof Promise) { | ||
return baseGuesses.then((resolvedBaseGuesses) => { | ||
return { | ||
...baseMatch, | ||
baseGuesses: resolvedBaseGuesses, | ||
} as RepeatMatch | ||
}) | ||
} | ||
return { | ||
...baseMatch, | ||
baseGuesses, | ||
} as RepeatMatch | ||
} | ||
getGreedyMatch(password: string, lastIndex: number) { | ||
@@ -95,6 +125,13 @@ const greedy = /(.+)\1+/g | ||
getBaseGuesses(baseToken: string, omniMatch: Matching) { | ||
const baseAnalysis = scoring.mostGuessableMatchSequence( | ||
baseToken, | ||
omniMatch.match(baseToken) as MatchExtended[], | ||
) | ||
const matches = omniMatch.match(baseToken) | ||
if (matches instanceof Promise) { | ||
return matches.then((resolvedMatches) => { | ||
const baseAnalysis = scoring.mostGuessableMatchSequence( | ||
baseToken, | ||
resolvedMatches, | ||
) | ||
return baseAnalysis.guesses | ||
}) | ||
} | ||
const baseAnalysis = scoring.mostGuessableMatchSequence(baseToken, matches) | ||
return baseAnalysis.guesses | ||
@@ -101,0 +138,0 @@ } |
@@ -26,2 +26,3 @@ import { extend, sorted } from './helper' | ||
regex: regexMatcher, | ||
// @ts-ignore => TODO resolve this type issue. This is because it is possible to be async | ||
repeat: repeatMatcher, | ||
@@ -64,3 +65,3 @@ sequence: sequenceMatcher, | ||
return new Promise((resolve) => { | ||
return Promise.all(promises).then(() => { | ||
Promise.all(promises).then(() => { | ||
resolve(sorted(matches)) | ||
@@ -67,0 +68,0 @@ }) |
@@ -103,2 +103,3 @@ import utils from './utils' | ||
let sequenceLength = 0 | ||
// eslint-disable-next-line no-loss-of-precision | ||
let g = 2e308 | ||
@@ -105,0 +106,0 @@ const temp = this.optimal.g[k] |
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
506135
8806