feat(chance): add missing string/character options (#36548)

This commit is contained in:
Colby M. White 2019-07-01 12:23:10 -05:00 committed by Ryan Cavanaugh
parent 7797cfdd1a
commit 3db0acafb2
2 changed files with 30 additions and 6 deletions

View File

@ -105,9 +105,28 @@ word = chance.word({length: 10});
word = chance.word({capitalize: true});
let randomString: string = chance.string();
randomString = chance.string({pool: 'abcdef', length: 10});
randomString = chance.string({pool: 'abcdef'});
randomString = chance.string({length: 10});
randomString = chance.string({ pool: 'abcdef' });
randomString = chance.string({ length: 10 });
randomString = chance.string({ casing: 'upper' });
randomString = chance.string({ alpha: true });
randomString = chance.string({ numeric: true });
randomString = chance.string({ symbols: '!@#$' });
randomString = chance.string({
pool: 'abcdef',
length: 10,
casing: 'lower',
alpha: true,
numeric: true,
symbols: ')(*&',
});
let char: string = chance.character();
char = chance.character({ pool: 'abcdef' });
char = chance.character({ casing: 'upper' });
char = chance.character({ alpha: true });
char = chance.character({ numeric: true });
char = chance.character({ symbols: '!@#$' });
char = chance.character({ pool: 'abcdef', casing: 'lower', alpha: true, numeric: true, symbols: ')(*&' });
let url: string = chance.url();
url = chance.url({protocol: 'http'});

View File

@ -31,7 +31,7 @@ declare namespace Chance {
interface Chance extends Seeded {
// Basics
bool(opts?: {likelihood: number}): boolean;
character(opts?: Options): string;
character(opts?: AtLeastOneKey<CharacterOptions>): string;
floating(opts?: Options): number;
integer(opts?: AtLeastOneKey<IntegerOptions>): number;
letter(opts?: Options): string;
@ -197,11 +197,16 @@ declare namespace Chance {
capitalize: boolean;
}
interface StringOptions {
length: number;
interface CharacterOptions {
casing: 'upper' | 'lower';
pool: string;
alpha: boolean;
numeric: boolean;
symbols: string;
}
type StringOptions = CharacterOptions & { length: number } ;
interface UrlOptions {
protocol: string;
domain: string;