forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchance-tests.ts
39 lines (29 loc) · 972 Bytes
/
chance-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// <reference path="chance.d.ts" />
// Instantiation
var globalInstance: Chance.Chance = chance;
var createYourOwn = new Chance(Math.random);
// Basic usage
var randBool: boolean = chance.bool();
var birthday: Date = chance.birthday();
var birthdayStr: Date|string = chance.birthday({ string: true });
var strArr: string[] = chance.n(chance.string, 42);
var uniqInts: number[] = chance.unique(chance.integer, 99);
var currencyPair = chance.currency_pair();
var firstCurrency = currencyPair[0];
var secondCurrency = currencyPair[1];
// Mixins can be used with on-the-fly type declaration
declare namespace Chance {
interface Chance {
time(): string;
}
}
chance.mixin({
time: function () {
var h = chance.hour({ twentyfour: true }),
m = chance.minute();
return `${h}:${m}`;
}
});
var timeString: string = chance.time();
var chanceConstructedWithSeed100 = new Chance(100);
var chanceCalledWithSeed100 = Chance()