google-finance-quote 3.0.0 → 4.0.0-dev.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.
@@ -0,0 +1,122 @@
1
+ export const currencyCodesSymbols = [
2
+ "AED",
3
+ "AFN",
4
+ "ALL",
5
+ "AMD",
6
+ "ANG",
7
+ "ARS",
8
+ "AUD",
9
+ "AWG",
10
+ "AZN",
11
+ "BAM",
12
+ "BDT",
13
+ "BGN",
14
+ "BHD",
15
+ "BND",
16
+ "BOB",
17
+ "BRL",
18
+ "BTN",
19
+ "BWP",
20
+ "BYN",
21
+ "BZD",
22
+ "CAD",
23
+ "CHF",
24
+ "CLP",
25
+ "CNY",
26
+ "COP",
27
+ "CRC",
28
+ "CSD",
29
+ "CZK",
30
+ "CVE",
31
+ "DEM",
32
+ "DKK",
33
+ "DOP",
34
+ "DZD",
35
+ "EEK",
36
+ "EGP",
37
+ "EUR",
38
+ "FJD",
39
+ "FRF",
40
+ "GBP",
41
+ "GEL",
42
+ "GHS",
43
+ "HKD",
44
+ "HNL",
45
+ "HRK",
46
+ "HUF",
47
+ "IDR",
48
+ "ILS",
49
+ "INR",
50
+ "IQD",
51
+ "ISK",
52
+ "JMD",
53
+ "JOD",
54
+ "JPY",
55
+ "KES",
56
+ "KGS",
57
+ "KRW",
58
+ "KWD",
59
+ "KYD",
60
+ "KZT",
61
+ "LAK",
62
+ "LBP",
63
+ "LKR",
64
+ "LTL",
65
+ "MAD",
66
+ "MDL",
67
+ "MKD",
68
+ "MMK",
69
+ "MOP",
70
+ "MTL",
71
+ "MUR",
72
+ "MVR",
73
+ "MXN",
74
+ "MYR",
75
+ "NAD",
76
+ "NGN",
77
+ "NIO",
78
+ "NOK",
79
+ "NPR",
80
+ "NZD",
81
+ "OMR",
82
+ "PAB",
83
+ "PEN",
84
+ "PHP",
85
+ "PKR",
86
+ "PLN",
87
+ "PYG",
88
+ "QAR",
89
+ "RON",
90
+ "ROL",
91
+ "RSD",
92
+ "RUB",
93
+ "SAR",
94
+ "SCR",
95
+ "SEK",
96
+ "SGD",
97
+ "SIT",
98
+ "SKK",
99
+ "SVC",
100
+ "THB",
101
+ "TND",
102
+ "TRL",
103
+ "TRY",
104
+ "TTD",
105
+ "TWD",
106
+ "TZS",
107
+ "UAH",
108
+ "UGX",
109
+ "USD",
110
+ "UYU",
111
+ "UZS",
112
+ "VEB",
113
+ "VEF",
114
+ "VES",
115
+ "VND",
116
+ "WST",
117
+ "XCD",
118
+ "XOF",
119
+ "XPF",
120
+ "YER",
121
+ "ZAR",
122
+ ];
@@ -0,0 +1,207 @@
1
+ export 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
+ ];
package/package.json CHANGED
@@ -1,11 +1,24 @@
1
1
  {
2
2
  "name": "google-finance-quote",
3
- "version": "3.0.0",
3
+ "version": "4.0.0-dev.0",
4
4
  "description": "Node Google Finance API wrapper for free. No API key is required!",
5
- "main": "index.js",
6
- "types": "index.d.ts",
5
+ "main": "dist/cjs/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/esm/index.mjs",
10
+ "require": "./dist/cjs/index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
7
14
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "build:cjs": "tsc -p tsconfig.cjs.json",
16
+ "build:esm": "tsc -p tsconfig.esm.json",
17
+ "build:post": "node ./build/copy-types.js && node ./build/rename-esm.js",
18
+ "build": "npm run build:cjs && npm run build:esm && npm run build:post",
19
+ "prepare": "npm run build",
20
+ "test": "echo \"Error: no test specified\" && exit 1",
21
+ "format": "prettier --write ./src/ ./build/"
9
22
  },
10
23
  "repository": {
11
24
  "type": "git",
@@ -33,9 +46,12 @@
33
46
  },
34
47
  "homepage": "https://github.com/otoneko1102/google-finance-quote#readme",
35
48
  "dependencies": {
36
- "axios": "^1.7.9"
49
+ "axios": "^1.13.2"
37
50
  },
38
51
  "devDependencies": {
39
- "@types/node": "^22.13.2"
52
+ "@types/axios": "^0.14.4",
53
+ "@types/node": "^25.0.8",
54
+ "prettier": "^3.8.0",
55
+ "typescript": "^5.9.3"
40
56
  }
41
57
  }
package/index.d.ts DELETED
@@ -1,57 +0,0 @@
1
- declare module 'google-finance-quote' {
2
- /**
3
- * @interface FinanceParams
4
- * @description Interface for Finance class constructor parameters.
5
- * @property {string} from - The original currency symbol.
6
- * @property {string} to - The desired currency symbol.
7
- */
8
- interface FinanceParams {
9
- from: string;
10
- to: string;
11
- }
12
-
13
- /**
14
- * @class Finance
15
- * @description The Finance class is designed to easily check the exchange rate.
16
- * @param {FinanceParams | undefined} p - The parameters, including p.from and p.to.
17
- */
18
- class Finance {
19
- private param: FinanceParams;
20
-
21
- constructor(p?: FinanceParams);
22
-
23
- /**
24
- * @function setFrom
25
- * @description Set the parameter of from.
26
- * @param {string} from - The original currency symbol.
27
- * @returns {Finance} Returns the instance of Finance for chaining.
28
- */
29
- setFrom(from: string): Finance;
30
-
31
- /**
32
- * @function setTo
33
- * @description Set the parameter of to.
34
- * @param {string} to - The desired currency symbol.
35
- * @returns {Finance} Returns the instance of Finance for chaining.
36
- */
37
- setTo(to: string): Finance;
38
-
39
- /**
40
- * @function getParam
41
- * @description Returns the current param.
42
- * @returns {FinanceParams} Returns the current param.
43
- */
44
- getParam(): FinanceParams;
45
-
46
- /**
47
- * @async
48
- * @function quote
49
- * @description Returns the current finance rate.
50
- * @param {number} [amount=1] - The amount to convert.
51
- * @returns {Promise<{ success: boolean; rate: number }>} Returns the converted amount based on the exchange rate.
52
- */
53
- quote(amount?: number): Promise<{ success: boolean; rate: number }>;
54
- }
55
-
56
- export = Finance;
57
- }
package/index.js DELETED
@@ -1,108 +0,0 @@
1
- const axios = require('axios');
2
- const HttpsProxyAgent = require('https-proxy-agent');
3
- const { API_URL } = require('./lib/config');
4
- const symbols = require('./lib/symbols');
5
-
6
- /**
7
- * @class Finance
8
- * @description The Finance class is designed to easily check the exchange rate.
9
- * @param {Object} p - The param includes p.from and p.to.
10
- * @param {string} p.from - The original currency symbol.
11
- * @param {string} p.to - The desired currency symbol.
12
- */
13
- class Finance {
14
- constructor(p) {
15
- if (
16
- typeof p === 'object' &&
17
- (
18
- symbols.includes(p.from?.toUpperCase()) ||
19
- symbols.includes(p.to?.toUpperCase())
20
- )
21
- ) {
22
- this.param = {
23
- from: p.from?.toUpperCase() || null,
24
- to: p.to?.toUpperCase() || null
25
- };
26
- } else if (typeof p === 'undefined') {
27
- this.param = {
28
- from: null,
29
- to: null
30
- };
31
- } else throw new Error('Invalid parameters.');
32
- }
33
-
34
- /**
35
- * @function setFrom
36
- * @description Set the parameter of from.
37
- * @param {string} from - The original currency symbol.
38
- * @returns {Finance} Returns the instance of Finance for chaining.
39
- */
40
- setFrom(from) {
41
- if (!symbols.includes(from?.toUpperCase())) throw new Error('invalid from.');
42
- this.param.from = from.toUpperCase();
43
- return this;
44
- }
45
-
46
- /**
47
- * @function setTo
48
- * @description Set the parameter of to.
49
- * @param {string} to - The desired currency symbol.
50
- * @returns {Finance} Returns the instance of Finance for chaining.
51
- */
52
- setTo(to) {
53
- if (!symbols.includes(to?.toUpperCase())) throw new Error('invalid to.');
54
- this.param.to = to.toUpperCase();
55
- return this;
56
- }
57
-
58
- /**
59
- * @function getParam
60
- * @description Returns the current param.
61
- * @returns Returns the current param.
62
- */
63
- getParam() {
64
- return this.param;
65
- }
66
-
67
- /**
68
- * @async
69
- * @function quote
70
- * @description Returns the current finance.
71
- * @param {number} [amount=1] - The amount to convert.
72
- * @returns Returns the current finance.
73
- */
74
- async quote(amount = 1) {
75
- const result = { success: false, rate: 0 };
76
- try {
77
- if (typeof amount !== 'number') throw new Error('amount must be number.');
78
- const from = this.param.from, to = this.param.to;
79
- if (!symbols?.includes(from) || !symbols?.includes(to)) throw new Error('from and/or to are invalid.');
80
-
81
- const url = `${API_URL}${from}-${to}`;
82
-
83
- const response = await axios.get(url);
84
- const html = response.data;
85
- const startIndex =
86
- html.indexOf(
87
- `data-source="${from}" data-target="${to}" data-last-price="`
88
- ) +
89
- `data-source="${from}" data-target="${to}" data-last-price="`.length;
90
- const endIndex = html.indexOf('"', startIndex);
91
- const rate = Number(html.substring(startIndex, endIndex));
92
- if (isNaN(rate)) throw new Error('Failed to get the current finance.');
93
-
94
- result.success = true;
95
- result.rate = rate * amount;
96
- return result;
97
- } catch {
98
- return result;
99
- }
100
- }
101
- }
102
-
103
- module.exports = {
104
- Finance,
105
- symbols,
106
- currencyCodesSymbols: require('./lib/currencyCodesSymbols'),
107
- cryptocurrencyCodesSymbols: require('./lib/cryptoCurrencyCodesSymbols')
108
- };
package/lib/config.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- API_URL: 'https://www.google.com/finance/quote/'
3
- };
@@ -1,93 +0,0 @@
1
- /**
2
- * A list of crypto currency codes.
3
- *
4
- * @type {string[]}
5
- */
6
- const cryptocurrencyCodesSymbols = [
7
- // Cryptocurrency Codes
8
- 'BTC',
9
- 'ETH',
10
- 'ADA',
11
- 'BNB',
12
- 'USDT',
13
- 'XRP',
14
- 'DOGE',
15
- 'LINK',
16
- 'LTC',
17
- 'BCH',
18
- 'XLM',
19
- 'TRX',
20
- 'ETC',
21
- 'XMR',
22
- 'EOS',
23
- 'NEO',
24
- 'WAVES',
25
- 'DASH',
26
- 'OMG',
27
- 'DCR',
28
- 'XEM',
29
- 'MANA',
30
- 'ICX',
31
- 'QTUM',
32
- 'ZIL',
33
- 'BAT',
34
- 'BTG',
35
- 'BNT',
36
- 'ZRX',
37
- 'SC',
38
- 'ONT',
39
- 'DGB',
40
- 'NANO',
41
- 'LSK',
42
- 'GNO',
43
- 'XVG',
44
- 'ARDR',
45
- 'SNT',
46
- 'MAID',
47
- 'REP',
48
- 'ARK',
49
- 'FUN',
50
- 'STEEM',
51
- 'SYS',
52
- 'BTS',
53
- 'KMD',
54
- 'MONA',
55
- 'GAS',
56
- 'RDD',
57
- 'BTM',
58
- 'WTC',
59
- 'AION',
60
- 'GRS',
61
- 'BCN',
62
- 'VERI',
63
- 'DGD',
64
- 'PIVX',
65
- 'NXS',
66
- 'PPT',
67
- 'QASH',
68
- 'NEBL',
69
- 'SALT',
70
- 'GAME',
71
- 'FCT',
72
- 'NXT',
73
- 'PAY',
74
- 'XDN',
75
- 'SUB',
76
- 'KNC',
77
- 'GNT',
78
- 'REQ',
79
- 'VGX',
80
- 'TNB',
81
- 'ZCL',
82
- 'HSR',
83
- 'ICN',
84
- 'POWR',
85
- 'ENG',
86
- 'SAN',
87
- 'ELF',
88
- 'STRAT',
89
- 'QSP',
90
- 'RDN'
91
- ];
92
-
93
- module.exports = cryptocurrencyCodesSymbols;