mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
[PM-7290] replace legacy abstraction with generation algorithms (#9435)
* replace legacy abstraction with generation algorithms * delete mv2-based generator services
This commit is contained in:
39
libs/common/src/tools/generator/abstractions/randomizer.ts
Normal file
39
libs/common/src/tools/generator/abstractions/randomizer.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { WordOptions } from "../word-options";
|
||||
|
||||
/** Entropy source for credential generation. */
|
||||
export interface Randomizer {
|
||||
/** picks a random entry from a list.
|
||||
* @param list random entry source. This must have at least one entry.
|
||||
* @returns a promise that resolves with a random entry from the list.
|
||||
*/
|
||||
pick<Entry>(list: Array<Entry>): Promise<Entry>;
|
||||
|
||||
/** picks a random word from a list.
|
||||
* @param list random entry source. This must have at least one entry.
|
||||
* @param options customizes the output word
|
||||
* @returns a promise that resolves with a random word from the list.
|
||||
*/
|
||||
pickWord(list: Array<string>, options?: WordOptions): Promise<string>;
|
||||
|
||||
/** Shuffles a list of items
|
||||
* @param list random entry source. This must have at least two entries.
|
||||
* @param options.copy shuffles a copy of the input when this is true.
|
||||
* Defaults to true.
|
||||
* @returns a promise that resolves with the randomized list.
|
||||
*/
|
||||
shuffle<Entry>(items: Array<Entry>): Promise<Array<Entry>>;
|
||||
|
||||
/** Generates a string containing random lowercase ASCII characters and numbers.
|
||||
* @param length the number of characters to generate
|
||||
* @returns a promise that resolves with the randomized string.
|
||||
*/
|
||||
chars(length: number): Promise<string>;
|
||||
|
||||
/** Selects an integer value from a range by randomly choosing it from
|
||||
* a uniform distribution.
|
||||
* @param min the minimum value in the range, inclusive.
|
||||
* @param max the minimum value in the range, inclusive.
|
||||
* @returns a promise that resolves with the randomized string.
|
||||
*/
|
||||
uniform(min: number, max: number): Promise<number>;
|
||||
}
|
||||
Reference in New Issue
Block a user