From b0839e0bf066f8b91138bfc3b382b8b247cddfd0 Mon Sep 17 00:00:00 2001 From: cafesanu Date: Mon, 19 Feb 2018 13:49:24 -0500 Subject: [PATCH] Feat - Update chance.js library definitions --- types/chance/chance-tests.ts | 59 +++++++++++++++++++++++++++--------- types/chance/index.d.ts | 37 +++++++++++++++------- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/types/chance/chance-tests.ts b/types/chance/chance-tests.ts index 8e89d8227e..00d8752118 100644 --- a/types/chance/chance-tests.ts +++ b/types/chance/chance-tests.ts @@ -1,24 +1,25 @@ +import { Chance } from 'chance'; // Instantiation -let globalInstance: Chance.Chance = chance; -let createYourOwn = new Chance(Math.random); +const chance = new Chance(); +const createYourOwn = new Chance(Math.random); // Basic usage -let randBool: boolean = chance.bool(); +const randBool: boolean = chance.bool(); -let birthday: Date = chance.birthday(); -let birthdayStr: Date | string = chance.birthday({ string: true }); +const birthday: Date = chance.birthday(); +const birthdayStr: Date | string = chance.birthday({ string: true }); let guid = chance.guid(); guid = chance.guid({ version: 4 }); guid = chance.guid({ version: 5 }); -let strArr: string[] = chance.n(chance.string, 42); +const strArr: string[] = chance.n(chance.string, 42); -let uniqInts: number[] = chance.unique(chance.integer, 99); +const uniqInts: number[] = chance.unique(chance.integer, 99); -let currencyPair = chance.currency_pair(); -let firstCurrency = currencyPair[0]; -let secondCurrency = currencyPair[1]; +const currencyPair = chance.currency_pair(); +const firstCurrency = currencyPair[0]; +const secondCurrency = currencyPair[1]; // Mixins can be used with on-the-fly type declaration declare namespace Chance { @@ -35,8 +36,38 @@ chance.mixin({ }, }); -let timeString: string = chance.time(); +const chanceConstructedWithSeed100 = new Chance(100); +const chanceCalledWithSeed100 = Chance(); +const chanceConstructedWithStringSeed = new Chance("test"); -let chanceConstructedWithSeed100 = new Chance(100); -let chanceCalledWithSeed100 = Chance(); -let chanceConstructedWithStringSeed = new Chance("test"); +// Test new added typed functions + +let letter = chance.letter(); +letter = chance.letter({opt: 'abc'}); + +let cf = chance.cf(); +cf = chance.cf({opt: 'abc'}); + +let animal = chance.animal(); +animal = chance.animal({opt: 'abc'}); + +let avatar = chance.avatar(); +avatar = chance.avatar({opt: 'abc'}); + +let company = chance.company(); +company = chance.company(); + +let profession = chance.profession(); +profession = chance.profession({opt: 'abc'}); + +let timezone = chance.timezone(); +timezone = chance.timezone(); + +let weekday = chance.weekday({opt: 'abc'}); +weekday = chance.weekday({opt: 'abc'}); + +let euro = chance.euro(); +euro = chance.euro({opt: 'abc'}); + +let coin = chance.coin(); +coin = chance.coin(); diff --git a/types/chance/index.d.ts b/types/chance/index.d.ts index 212e90dfe2..07418e45be 100644 --- a/types/chance/index.d.ts +++ b/types/chance/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for Chance 0.7.4 +// Type definitions for Chance 1.0.13 // Project: http://chancejs.com // Definitions by: Chris Bowdon // Brice BERNARD +// Carlos Sanchez // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Chance { @@ -11,24 +12,23 @@ declare namespace Chance { seed: Seed; } - type SeededChance = Chance & Seeded; - interface ChanceStatic { (): Chance; - (seed: Seed): SeededChance; + (seed: Seed): Chance; (generator: () => any): Chance; new (): Chance; - new (seed: Seed): SeededChance; + new (seed: Seed): Chance; new (generator: () => any): Chance; } - interface Chance { + interface Chance extends Seeded { // Basics bool(opts?: Options): boolean; character(opts?: Options): string; floating(opts?: Options): number; integer(opts?: Options): number; + letter(opts?: Options): string; natural(opts?: Options): number; string(opts?: Options): string; @@ -43,6 +43,7 @@ declare namespace Chance { gender(): string; birthday(): Date; birthday(opts?: Options): Date | string; + cf(opts?: Options): string; cpf(): string; first(opts?: Options): string; last(opts?: Options): string; @@ -53,6 +54,9 @@ declare namespace Chance { ssn(opts?: Options): string; suffix(opts?: Options): string; + // Mobile + animal(opts?: Options): string; + // Mobile android_id(): string; apple_token(): string; @@ -61,7 +65,9 @@ declare namespace Chance { wp8_anid2(): string; // Web + avatar(opts?: Options): string; color(opts?: Options): string; + company(): string; domain(opts?: Options): string; email(opts?: Options): string; fbid(): string; @@ -70,6 +76,7 @@ declare namespace Chance { ip(): string; ipv6(): string; klout(): string; + profession(opts?: Options): string; tld(): string; twitter(): string; url(opts?: Options): string; @@ -104,6 +111,8 @@ declare namespace Chance { month(opts: Options): Month; second(): number; timestamp(): number; + timezone(): Timezone; + weekday(opts: Options): 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday'; year(opts?: Options): string; // Finance @@ -113,6 +122,7 @@ declare namespace Chance { currency(): Currency; currency_pair(): [Currency, Currency]; dollar(opts?: Options): string; + euro(opts?: Options): string; exp(): string; exp(opts: Options): string | CreditCardExpiration; exp_month(opts?: Options): string; @@ -136,6 +146,7 @@ declare namespace Chance { shuffle(arr: T[]): T[]; // Miscellaneous + coin(): string; d4(): number; d6(): number; d8(): number; @@ -225,13 +236,17 @@ declare namespace Chance { name: string; abbreviation: string; } + + interface Timezone { + name: string; + abbr: string; + offset: number; + isdst: boolean; + text: string; + utc: string[]; + } } -// window.chance -declare var chance: Chance.Chance; -declare var Chance: Chance.ChanceStatic; - -// import Chance = require('chance'); declare module "chance" { interface ExportedChance extends Chance.ChanceStatic { Chance: ExportedChance;