From 3db0acafb2a5fa7606ec2f64f8798639bfc898c8 Mon Sep 17 00:00:00 2001 From: "Colby M. White" Date: Mon, 1 Jul 2019 12:23:10 -0500 Subject: [PATCH] feat(chance): add missing string/character options (#36548) --- types/chance/chance-tests.ts | 25 ++++++++++++++++++++++--- types/chance/index.d.ts | 11 ++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/types/chance/chance-tests.ts b/types/chance/chance-tests.ts index 3dc20eb6d8..e8a5ba4cbd 100644 --- a/types/chance/chance-tests.ts +++ b/types/chance/chance-tests.ts @@ -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'}); diff --git a/types/chance/index.d.ts b/types/chance/index.d.ts index ea5b82f415..1ff6af8aee 100644 --- a/types/chance/index.d.ts +++ b/types/chance/index.d.ts @@ -31,7 +31,7 @@ declare namespace Chance { interface Chance extends Seeded { // Basics bool(opts?: {likelihood: number}): boolean; - character(opts?: Options): string; + character(opts?: AtLeastOneKey): string; floating(opts?: Options): number; integer(opts?: AtLeastOneKey): 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;