-
Notifications
You must be signed in to change notification settings - Fork 1
/
Asset.gs
110 lines (87 loc) · 2.03 KB
/
Asset.gs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Represents an asset.
*/
var Asset = class Asset {
/**
* Initializes the class with the properties set to the parameters.
* @param {string} ticker - The ticker of the asset.
* @param {string} assetType - The asset type of the asset.
* @param {boolean} isFiatBase - Whether the asset is fiat base.
* @param {number} decimalPlaces - The number of decimal places of the asset.
*/
constructor(ticker, assetType, isFiatBase, decimalPlaces) {
/**
* The ticker of the asset.
* @type {string}
*/
this.ticker = ticker;
/**
* The asset type of the asset.
* @type {string}
*/
this.assetType = assetType;
/**
* Whether the asset is fiat base.
* @type {boolean}
*/
this.isFiatBase = isFiatBase;
/**
* The number of decimal places of the asset.
* @type {number}
*/
this.decimalPlaces = decimalPlaces;
}
/**
* Regular expression to loosly validate asset ticker format.
* @type {RegExp}
* @static
*/
static get tickerRegExp() {
return /^(\w{1,15}:)?[\w$@]{1,10}$/;
}
/**
* Regular expression to validate asset types.
* @type {RegExp}
* @static
*/
static get assetTypeRegExp() {
return /^[\w\-][\w\-\s]{0,18}[\w\-]$|^[\w\-]$/;
}
/**
* Regular expression to validate decimal places.
* @type {RegExp}
* @static
*/
static get decimalPlacesRegExp() {
return /^[0-8]$/;
}
/**
* Array of default asset types.
* @type {Array<string>}
* @static
*/
static get defaultAssetTypes() {
return ['Crypto', 'Fiat', 'Fiat Base', 'Forex', 'Stablecoin', 'Stock'];
}
/**
* Whether the asset is fiat.
* @type {boolean}
*/
get isFiat() {
return this.assetType === 'Fiat';
}
/**
* The number of subunits in a unit of the asset.
* @type {number}
*/
get subunits() {
return 10 ** this.decimalPlaces;
}
/**
* Override toString() to return the asset ticker.
* @return {string} The asset ticker.
*/
toString() {
return this.ticker;
}
};