Merge pull request #23771 from cafesanu/feat-update-chance

Feat - Update chance library definitions
This commit is contained in:
Bowden Kelly
2018-03-01 11:36:10 -08:00
committed by GitHub
2 changed files with 71 additions and 25 deletions
+45 -14
View File
@@ -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();
+26 -11
View File
@@ -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 <https://github.com/cbowdon>
// Brice BERNARD <https://github.com/brikou>
// Carlos Sanchez <https://github.com/cafesanu>
// 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<T>(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;