google-finance-quote 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # google-finance-quote
2
2
  Node Google Finance API wrapper for free.
3
3
  No API key is required!
4
-
4
+ > Note: This results may vary by up to 20 minutes.
5
5
  ## Usage
6
6
  ### Get Started
7
7
  ```js
8
- const Finance = require("google-finance-quote");
8
+ const { Finance, symbols } = require("google-finance-quote");
9
+
10
+ console.log(symbols); // Returns available symbols.
9
11
 
10
- const finance = new Finance(); // You can use this: new Finance({ from 'usd', to: 'jpy' });
12
+ const finance = new Finance(); // You can use this: new Finance({ from 'USD', to: 'JPY' });
11
13
  // You can use http(s) proxies.
12
14
  /*
13
15
  const proxy = {
@@ -19,8 +21,8 @@ const finance = new Finance({ proxy });
19
21
  */
20
22
 
21
23
  finance
22
- .setFrom('usd');
23
- .setTo('jpy');
24
+ .setFrom('USD');
25
+ .setTo('JPY');
24
26
 
25
27
  (async () => {
26
28
  console.log(await finance.quote()); // { success: true, rate: 150.94225699999998 }
package/index.d.ts CHANGED
@@ -15,8 +15,8 @@ declare module 'google-finance-quote' {
15
15
  /**
16
16
  * @interface FinanceParams
17
17
  * @description Interface for Finance class constructor parameters.
18
- * @property {string} from - The original currency unit.
19
- * @property {string} to - The desired currency unit.
18
+ * @property {string} from - The original currency symbol.
19
+ * @property {string} to - The desired currency symbol.
20
20
  * @property {Proxy | undefined} proxy - Proxy options.
21
21
  */
22
22
  interface FinanceParams {
@@ -37,7 +37,7 @@ declare module 'google-finance-quote' {
37
37
  /**
38
38
  * @function setFrom
39
39
  * @description Set the parameter of from.
40
- * @param {string} from - The original currency unit.
40
+ * @param {string} from - The original currency symbol.
41
41
  * @returns {Finance} Returns the instance of Finance for chaining.
42
42
  */
43
43
  setFrom(from: string): Finance;
@@ -45,7 +45,7 @@ declare module 'google-finance-quote' {
45
45
  /**
46
46
  * @function setTo
47
47
  * @description Set the parameter of to.
48
- * @param {string} to - The desired currency unit.
48
+ * @param {string} to - The desired currency symbol.
49
49
  * @returns {Finance} Returns the instance of Finance for chaining.
50
50
  */
51
51
  setTo(to: string): Finance;
package/index.js CHANGED
@@ -1,25 +1,26 @@
1
1
  const axios = require('axios');
2
2
  const HttpsProxyAgent = require('https-proxy-agent');
3
3
  const { API_URL } = require('./lib/config');
4
+ const symbols = require('./lib/symbols');
4
5
 
5
6
  /**
6
7
  * @class Finance
7
8
  * @description The Finance class is designed to easily check the exchange rate.
8
9
  * @param {Object} p - The param includes p.from and p.to.
9
- * @param {string} p.from - The original currency unit.
10
- * @param {string} p.to - The desired currency unit.
10
+ * @param {string} p.from - The original currency symbol.
11
+ * @param {string} p.to - The desired currency symbol.
11
12
  * @param {object | undefined} p.proxy - Proxy options.
12
13
  */
13
14
  class Finance {
14
15
  constructor(p) {
15
16
  if (
16
17
  typeof p === 'object' &&
17
- typeof p?.from === 'string' &&
18
- typeof p?.to === 'string'
18
+ symbols.includes(from?.toUpperCase()) &&
19
+ symbols.includes(to?.toUpperCase())
19
20
  ) {
20
21
  this.param = {
21
- from: p.from,
22
- to: p.to
22
+ from: p.from.toUpperCase(),
23
+ to: p.to.toUpperCase()
23
24
  };
24
25
  } else if (typeof p === 'undefined') {
25
26
  this.param = {
@@ -47,27 +48,27 @@ class Finance {
47
48
  /**
48
49
  * @function setFrom
49
50
  * @description Set the parameter of from.
50
- * @param {string} from - The original currency unit.
51
+ * @param {string} from - The original currency symbol.
51
52
  * @returns {Finance} Returns the instance of Finance for chaining.
52
53
  */
53
54
  setFrom(from) {
54
- if (typeof from !== 'string') throw new Error('from must be string.');
55
- this.param.from = from;
55
+ if (!symbols.includes(from?.toUpperCase())) throw new Error('invalid from.');
56
+ this.param.from = from.toUpperCase();
56
57
  return this;
57
58
  }
58
59
 
59
60
  /**
60
61
  * @function setTo
61
62
  * @description Set the parameter of to.
62
- * @param {string} to - The desired currency unit.
63
+ * @param {string} to - The desired currency symbol.
63
64
  * @returns {Finance} Returns the instance of Finance for chaining.
64
65
  */
65
66
  setTo(to) {
66
- if (typeof to !== 'string') throw new Error('to must be string.');
67
- this.param.to = to;
67
+ if (!symbols.includes(to?.toUpperCase())) throw new Error('invalid to.');
68
+ this.param.to = to.toUpperCase();
68
69
  return this;
69
70
  }
70
-
71
+
71
72
  /**
72
73
  * @function getParam
73
74
  * @description Returns the current param.
@@ -88,8 +89,8 @@ class Finance {
88
89
  const result = { success: false, rate: 0 };
89
90
  try {
90
91
  if (typeof amount !== 'number') throw new Error('amount must be number.');
91
- const from = this.param.from?.toUpperCase(), to = this.param.to.toUpperCase();
92
- if (typeof from !== 'string' || typeof to !== 'string') throw new Error('from and/or to are invalid.');
92
+ const from = this.param.from, to = this.param.to;
93
+ if (!symbols?.includes(from) || !symbols?.includes(to)) throw new Error('from and/or to are invalid.');
93
94
 
94
95
  const url = `${API_URL}${from}-${to}`;
95
96
 
@@ -131,4 +132,5 @@ class Finance {
131
132
  }
132
133
  }
133
134
 
134
- module.exports = Finance;
135
+ module.exports.Finance = Finance;
136
+ module.exports.symbols = symbols;
package/lib/symbols.js ADDED
@@ -0,0 +1,209 @@
1
+ const symbols = [
2
+ // Currency Codes
3
+ 'AED',
4
+ 'AFN',
5
+ 'ALL',
6
+ 'AMD',
7
+ 'ANG',
8
+ 'ARS',
9
+ 'AUD',
10
+ 'AWG',
11
+ 'AZN',
12
+ 'BAM',
13
+ 'BDT',
14
+ 'BGN',
15
+ 'BHD',
16
+ 'BND',
17
+ 'BOB',
18
+ 'BRL',
19
+ 'BTN',
20
+ 'BWP',
21
+ 'BYN',
22
+ 'BZD',
23
+ 'CAD',
24
+ 'CHF',
25
+ 'CLP',
26
+ 'CNY',
27
+ 'COP',
28
+ 'CRC',
29
+ 'CSD',
30
+ 'CZK',
31
+ 'CVE',
32
+ 'DEM',
33
+ 'DKK',
34
+ 'DOP',
35
+ 'DZD',
36
+ 'EEK',
37
+ 'EGP',
38
+ 'EUR',
39
+ 'FJD',
40
+ 'FRF',
41
+ 'GBP',
42
+ 'GEL',
43
+ 'GHS',
44
+ 'HKD',
45
+ 'HNL',
46
+ 'HRK',
47
+ 'HUF',
48
+ 'IDR',
49
+ 'ILS',
50
+ 'INR',
51
+ 'IQD',
52
+ 'ISK',
53
+ 'JMD',
54
+ 'JOD',
55
+ 'JPY',
56
+ 'KES',
57
+ 'KGS',
58
+ 'KRW',
59
+ 'KWD',
60
+ 'KYD',
61
+ 'KZT',
62
+ 'LAK',
63
+ 'LBP',
64
+ 'LKR',
65
+ 'LTL',
66
+ 'MAD',
67
+ 'MDL',
68
+ 'MKD',
69
+ 'MMK',
70
+ 'MOP',
71
+ 'MTL',
72
+ 'MUR',
73
+ 'MVR',
74
+ 'MXN',
75
+ 'MYR',
76
+ 'NAD',
77
+ 'NGN',
78
+ 'NIO',
79
+ 'NOK',
80
+ 'NPR',
81
+ 'NZD',
82
+ 'OMR',
83
+ 'PAB',
84
+ 'PEN',
85
+ 'PHP',
86
+ 'PKR',
87
+ 'PLN',
88
+ 'PYG',
89
+ 'QAR',
90
+ 'RON',
91
+ 'ROL',
92
+ 'RSD',
93
+ 'RUB',
94
+ 'SAR',
95
+ 'SCR',
96
+ 'SEK',
97
+ 'SGD',
98
+ 'SIT',
99
+ 'SKK',
100
+ 'SVC',
101
+ 'THB',
102
+ 'TND',
103
+ 'TRL',
104
+ 'TRY',
105
+ 'TTD',
106
+ 'TWD',
107
+ 'TZS',
108
+ 'UAH',
109
+ 'UGX',
110
+ 'USD',
111
+ 'UYU',
112
+ 'UZS',
113
+ 'VEB',
114
+ 'VEF',
115
+ 'VES',
116
+ 'VND',
117
+ 'WST',
118
+ 'XCD',
119
+ 'XOF',
120
+ 'XPF',
121
+ 'YER',
122
+ 'ZAR',
123
+ // Cryptocurrency Codes
124
+ 'BTC',
125
+ 'ETH',
126
+ 'ADA',
127
+ 'BNB',
128
+ 'USDT',
129
+ 'XRP',
130
+ 'DOGE',
131
+ 'LINK',
132
+ 'LTC',
133
+ 'BCH',
134
+ 'XLM',
135
+ 'TRX',
136
+ 'ETC',
137
+ 'XMR',
138
+ 'EOS',
139
+ 'NEO',
140
+ 'WAVES',
141
+ 'DASH',
142
+ 'OMG',
143
+ 'DCR',
144
+ 'XEM',
145
+ 'MANA',
146
+ 'ICX',
147
+ 'QTUM',
148
+ 'ZIL',
149
+ 'BAT',
150
+ 'BTG',
151
+ 'BNT',
152
+ 'ZRX',
153
+ 'SC',
154
+ 'ONT',
155
+ 'DGB',
156
+ 'NANO',
157
+ 'LSK',
158
+ 'GNO',
159
+ 'XVG',
160
+ 'ARDR',
161
+ 'SNT',
162
+ 'MAID',
163
+ 'REP',
164
+ 'ARK',
165
+ 'FUN',
166
+ 'STEEM',
167
+ 'SYS',
168
+ 'BTS',
169
+ 'KMD',
170
+ 'MONA',
171
+ 'GAS',
172
+ 'RDD',
173
+ 'BTM',
174
+ 'WTC',
175
+ 'AION',
176
+ 'GRS',
177
+ 'BCN',
178
+ 'VERI',
179
+ 'DGD',
180
+ 'PIVX',
181
+ 'NXS',
182
+ 'PPT',
183
+ 'QASH',
184
+ 'NEBL',
185
+ 'SALT',
186
+ 'GAME',
187
+ 'FCT',
188
+ 'NXT',
189
+ 'PAY',
190
+ 'XDN',
191
+ 'SUB',
192
+ 'KNC',
193
+ 'GNT',
194
+ 'REQ',
195
+ 'VGX',
196
+ 'TNB',
197
+ 'ZCL',
198
+ 'HSR',
199
+ 'ICN',
200
+ 'POWR',
201
+ 'ENG',
202
+ 'SAN',
203
+ 'ELF',
204
+ 'STRAT',
205
+ 'QSP',
206
+ 'RDN'
207
+ ];
208
+
209
+ module.exports = symbols;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "google-finance-quote",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Node Google Finance API wrapper for free. No API key is required!",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "scripts": {
7
8
  "test": "echo \"Error: no test specified\" && exit 1"
8
9
  },
@@ -30,5 +31,10 @@
30
31
  "dependencies": {
31
32
  "axios": "^1.7.7",
32
33
  "https-proxy-agent": "^7.0.5"
33
- }
34
+ },
35
+ "directories": {
36
+ "lib": "lib",
37
+ "test": "tests"
38
+ },
39
+ "devDependencies": {}
34
40
  }