google-finance-quote 2.1.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,85 @@
1
+ export const cryptocurrencyCodesSymbols = [
2
+ "BTC",
3
+ "ETH",
4
+ "ADA",
5
+ "BNB",
6
+ "USDT",
7
+ "XRP",
8
+ "DOGE",
9
+ "LINK",
10
+ "LTC",
11
+ "BCH",
12
+ "XLM",
13
+ "TRX",
14
+ "ETC",
15
+ "XMR",
16
+ "EOS",
17
+ "NEO",
18
+ "WAVES",
19
+ "DASH",
20
+ "OMG",
21
+ "DCR",
22
+ "XEM",
23
+ "MANA",
24
+ "ICX",
25
+ "QTUM",
26
+ "ZIL",
27
+ "BAT",
28
+ "BTG",
29
+ "BNT",
30
+ "ZRX",
31
+ "SC",
32
+ "ONT",
33
+ "DGB",
34
+ "NANO",
35
+ "LSK",
36
+ "GNO",
37
+ "XVG",
38
+ "ARDR",
39
+ "SNT",
40
+ "MAID",
41
+ "REP",
42
+ "ARK",
43
+ "FUN",
44
+ "STEEM",
45
+ "SYS",
46
+ "BTS",
47
+ "KMD",
48
+ "MONA",
49
+ "GAS",
50
+ "RDD",
51
+ "BTM",
52
+ "WTC",
53
+ "AION",
54
+ "GRS",
55
+ "BCN",
56
+ "VERI",
57
+ "DGD",
58
+ "PIVX",
59
+ "NXS",
60
+ "PPT",
61
+ "QASH",
62
+ "NEBL",
63
+ "SALT",
64
+ "GAME",
65
+ "FCT",
66
+ "NXT",
67
+ "PAY",
68
+ "XDN",
69
+ "SUB",
70
+ "KNC",
71
+ "GNT",
72
+ "REQ",
73
+ "VGX",
74
+ "TNB",
75
+ "ZCL",
76
+ "HSR",
77
+ "ICN",
78
+ "POWR",
79
+ "ENG",
80
+ "SAN",
81
+ "ELF",
82
+ "STRAT",
83
+ "QSP",
84
+ "RDN",
85
+ ];
@@ -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": "2.1.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",
@@ -24,8 +37,7 @@
24
37
  "codes",
25
38
  "data",
26
39
  "lib",
27
- "free",
28
- "proxy"
40
+ "free"
29
41
  ],
30
42
  "author": "otoneko.",
31
43
  "license": "ISC",
@@ -34,10 +46,12 @@
34
46
  },
35
47
  "homepage": "https://github.com/otoneko1102/google-finance-quote#readme",
36
48
  "dependencies": {
37
- "axios": "^1.7.9",
38
- "https-proxy-agent": "^7.0.6"
49
+ "axios": "^1.13.2"
39
50
  },
40
51
  "devDependencies": {
41
- "@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"
42
56
  }
43
57
  }
package/index.d.ts DELETED
@@ -1,72 +0,0 @@
1
- declare module 'google-finance-quote' {
2
- /**
3
- * @interface Proxy
4
- * @description Interface for proxy parameters.
5
- * @property {string} host - Proxy host name.
6
- * @property {number | undefined} - Proxy port number.
7
- * @property {'http' | 'https'} protocol - Proxy protocol type.
8
- */
9
- interface Proxy {
10
- host: string;
11
- port?: number,
12
- protocol: 'http' | 'https';
13
- }
14
-
15
- /**
16
- * @interface FinanceParams
17
- * @description Interface for Finance class constructor parameters.
18
- * @property {string} from - The original currency symbol.
19
- * @property {string} to - The desired currency symbol.
20
- * @property {Proxy | undefined} proxy - Proxy options.
21
- */
22
- interface FinanceParams {
23
- from: string;
24
- to: string;
25
- proxy?: Proxy;
26
- }
27
-
28
- /**
29
- * @class Finance
30
- * @description The Finance class is designed to easily check the exchange rate.
31
- * @param {FinanceParams | undefined} p - The parameters, including p.from and p.to.
32
- */
33
- class Finance {
34
- private param: FinanceParams;
35
-
36
- constructor(p?: FinanceParams);
37
-
38
- /**
39
- * @function setFrom
40
- * @description Set the parameter of from.
41
- * @param {string} from - The original currency symbol.
42
- * @returns {Finance} Returns the instance of Finance for chaining.
43
- */
44
- setFrom(from: string): Finance;
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: string): Finance;
53
-
54
- /**
55
- * @function getParam
56
- * @description Returns the current param.
57
- * @returns {FinanceParams} Returns the current param.
58
- */
59
- getParam(): FinanceParams;
60
-
61
- /**
62
- * @async
63
- * @function quote
64
- * @description Returns the current finance rate.
65
- * @param {number} [amount=1] - The amount to convert.
66
- * @returns {Promise<{ success: boolean; rate: number }>} Returns the converted amount based on the exchange rate.
67
- */
68
- quote(amount?: number): Promise<{ success: boolean; rate: number }>;
69
- }
70
-
71
- export = Finance;
72
- }
package/index.js DELETED
@@ -1,142 +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
- * @param {object | undefined} p.proxy - Proxy options.
13
- */
14
- class Finance {
15
- constructor(p) {
16
- if (
17
- typeof p === 'object' &&
18
- (
19
- symbols.includes(p.from?.toUpperCase()) ||
20
- symbols.includes(p.to?.toUpperCase())
21
- )
22
- ) {
23
- this.param = {
24
- from: p.from?.toUpperCase() || null,
25
- to: p.to?.toUpperCase() || null
26
- };
27
- } else if (typeof p === 'undefined') {
28
- this.param = {
29
- from: null,
30
- to: null
31
- };
32
- } else throw new Error('Invalid parameters.');
33
-
34
- this.proxy = {};
35
- if (typeof p?.proxy === 'object') {
36
- if (
37
- typeof p.proxy?.host === 'string' &&
38
- (
39
- p.proxy.protocol === 'http' ||
40
- p.proxy.protocol === 'https'
41
- )
42
- ) {
43
- this.proxy.host = p.proxy.host;
44
- if (typeof p.proxy?.port === 'number') this.proxy.port = p.proxy.port;
45
- this.proxy.protocol = p.proxy.protocol;
46
- }
47
- }
48
- }
49
-
50
- /**
51
- * @function setFrom
52
- * @description Set the parameter of from.
53
- * @param {string} from - The original currency symbol.
54
- * @returns {Finance} Returns the instance of Finance for chaining.
55
- */
56
- setFrom(from) {
57
- if (!symbols.includes(from?.toUpperCase())) throw new Error('invalid from.');
58
- this.param.from = from.toUpperCase();
59
- return this;
60
- }
61
-
62
- /**
63
- * @function setTo
64
- * @description Set the parameter of to.
65
- * @param {string} to - The desired currency symbol.
66
- * @returns {Finance} Returns the instance of Finance for chaining.
67
- */
68
- setTo(to) {
69
- if (!symbols.includes(to?.toUpperCase())) throw new Error('invalid to.');
70
- this.param.to = to.toUpperCase();
71
- return this;
72
- }
73
-
74
- /**
75
- * @function getParam
76
- * @description Returns the current param.
77
- * @returns Returns the current param.
78
- */
79
- getParam() {
80
- return this.param;
81
- }
82
-
83
- /**
84
- * @async
85
- * @function quote
86
- * @description Returns the current finance.
87
- * @param {number} [amount=1] - The amount to convert.
88
- * @returns Returns the current finance.
89
- */
90
- async quote(amount = 1) {
91
- const result = { success: false, rate: 0 };
92
- try {
93
- if (typeof amount !== 'number') throw new Error('amount must be number.');
94
- const from = this.param.from, to = this.param.to;
95
- if (!symbols?.includes(from) || !symbols?.includes(to)) throw new Error('from and/or to are invalid.');
96
-
97
- const url = `${API_URL}${from}-${to}`;
98
-
99
- let response;
100
- if (this.proxy) {
101
- const axiosConfig = {};
102
- if (this.proxy.protocol === 'http') {
103
- axiosConfig.proxy = {
104
- host: this.proxy.host,
105
- }
106
- if (this.proxy.port) axiosConfig.proxy.port = this.proxy.port;
107
- } else if (this.proxy.protocol === 'https') {
108
- const proxyUrl = `http://${this.proxy.host}${this.proxy.port ? `:${this.proxy.port}` : ''}`;
109
- const agent = new HttpsProxyAgent(proxyUrl);
110
- axiosConfig.httpsAgent = agent;
111
- axiosConfig.proxy = false;
112
- }
113
- response = await axios.get(url, axiosConfig);
114
- } else {
115
- response = await axios.get(url);
116
- }
117
-
118
- const html = response.data;
119
- const startIndex =
120
- html.indexOf(
121
- `data-source="${from}" data-target="${to}" data-last-price="`
122
- ) +
123
- `data-source="${from}" data-target="${to}" data-last-price="`.length;
124
- const endIndex = html.indexOf('"', startIndex);
125
- const rate = Number(html.substring(startIndex, endIndex));
126
- if (isNaN(rate)) throw new Error('Failed to get the current finance.');
127
-
128
- result.success = true;
129
- result.rate = rate * amount;
130
- return result;
131
- } catch {
132
- return result;
133
- }
134
- }
135
- }
136
-
137
- module.exports = {
138
- Finance,
139
- symbols,
140
- currencyCodesSymbols: require('./lib/currencyCodesSymbols'),
141
- cryptocurrencyCodesSymbols: require('./lib/cryptoCurrencyCodesSymbols')
142
- };
package/lib/config.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- API_URL: 'https://www.google.com/finance/quote/'
3
- };