-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathtest.ts
More file actions
72 lines (59 loc) · 1.84 KB
/
Copy pathtest.ts
File metadata and controls
72 lines (59 loc) · 1.84 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import currency from 'currency.js';
import * as namedCurrency from 'currency.js';
import interopCurrency = require('currency.js');
const currencyInstance: currency = currency(1.23);
const currencyInstance2: currency = namedCurrency(1.23);
const currencyInstance3: currency = interopCurrency(1.23);
// default uses
new currency(1.23);
new currency('1.23');
new currency(currencyInstance);
currency(1.23);
currency('1.23');
currency(currencyInstance);
// options
currency(1.23, {});
currency(1.23, {
symbol: '$',
separator: ',',
decimal: '.',
errorOnInvalid: true,
precision: 2,
increment: .05,
useVedic: false,
pattern: '!#',
negativePattern: '-!#',
format: (currency: currency, options: currency.Options) => '1.23'
});
// add
currencyInstance.add(1.23);
currencyInstance.add('1.23');
currencyInstance.add(currencyInstance);
// subtract
currencyInstance.subtract(1.23);
currencyInstance.subtract('1.23');
currencyInstance.subtract(currencyInstance);
// multiply
currencyInstance.multiply(1.23);
currencyInstance.multiply('1.23');
currencyInstance.multiply(currencyInstance);
// divide
currencyInstance.divide(1.23);
currencyInstance.divide('1.23');
currencyInstance.divide(currencyInstance);
// distribute
let a1: Array<currency> = currencyInstance.distribute(4);
// mapDistribute
let elements: Array<string> = ['a', 'b']
let a2: Array<[string, currency]> = currencyInstance.mapDistribute(elements, (element, c) => [element, c]);
// dollars
let d1: number = currencyInstance.dollars();
// cents
let c1: number = currencyInstance.cents();
// format
let s1: string = currencyInstance.format();
let s2: string = currencyInstance.format({ symbol: '£' });
let s3: string = currencyInstance.format((currency: currency, options: currency.Options) => '1.23');
// property values
let v1: number = currencyInstance.value;
let v2: number = currencyInstance.intValue;