xchange-rates 2025.8.16-1 → 2025.8.16-2

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,72 @@
1
+ name: Publish Exchange Rates
2
+
3
+ # Triggers: daily cron + manual trigger
4
+ on:
5
+ schedule:
6
+ - cron: '0 0 * * *' # daily at midnight UTC
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ update:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ # 1. Checkout the repository
15
+ - uses: actions/checkout@v4
16
+
17
+ # 2. Setup Node.js
18
+ - uses: actions/setup-node@v4
19
+ with:
20
+ node-version: 18
21
+ registry-url: 'https://registry.npmjs.org'
22
+
23
+ # 3. Install dependencies
24
+ - name: Install dependencies
25
+ run: npm install
26
+
27
+ # 4. Update exchange rates JSON
28
+ - name: Update exchange rates
29
+ run: npm run update
30
+ env:
31
+ XCR_KEY1: ${{ secrets.XCR_KEY1 }}
32
+ XCR_URL1: ${{ secrets.XCR_URL1 }}
33
+
34
+ # 5. Generate date-based version
35
+ - name: Set date-based version
36
+ id: version
37
+ run: |
38
+ VERSION=$(node scripts/semver-date.js)
39
+ # convert dots to dashes for npm tag
40
+ TAG=$(echo $VERSION | tr '.' '-')
41
+ echo "VERSION=$VERSION" >> "$GITHUB_ENV"
42
+ echo "TAG=$TAG" >> "$GITHUB_ENV"
43
+
44
+ # 6. Bump package.json version without git tag
45
+ - name: Bump version
46
+ run: npm version ${{ env.VERSION }} --no-git-tag-version
47
+
48
+ # 7. Prepare package folder
49
+ - name: Prepare package
50
+ run: |
51
+ rm -rf package
52
+ mkdir package
53
+ cp -r package.json index.js v1 package/
54
+ ls -la package # debug to verify files
55
+
56
+ # 8. Publish to npm
57
+ - name: Publish to npm
58
+ run: |
59
+ cd package
60
+ npm publish --access public
61
+ env:
62
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
63
+
64
+ # 9. Add date-based npm tag
65
+ - name: Add npm date tag
66
+ run: npm dist-tag add xchange-rates@${{ env.VERSION }} ${{ env.TAG }}
67
+ env:
68
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
69
+
70
+ # 10. Success message
71
+ - name: Success
72
+ run: echo "Exchange rates published successfully! Version ${{ env.VERSION }}"
package/index.js CHANGED
@@ -12,7 +12,7 @@ export async function xchangerate(baseCurrency, targetCurrency, useCDN = false)
12
12
  let data;
13
13
 
14
14
  if (useCDN) {
15
- const res = await fetch('https://cdn.jsdelivr.net/npm/@jayadevpanthaplavil/xchange-rates@latest/v1/currencies.json');
15
+ const res = await fetch('https://cdn.jsdelivr.net/npm/xchange-rates@latest/v1/currencies.json');
16
16
  data = await res.json();
17
17
  } else {
18
18
  if (!localRates) throw new Error('Local JSON not available');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xchange-rates",
3
- "version": "2025.8.16-1",
3
+ "version": "2025.8.16-2",
4
4
  "description": "A lightweight Node.js package to get real-time currency exchange rates for any base currency using a pivot currency, fetched directly from a CDN for fast and reliable access.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,41 @@
1
+ // // semver-date.js
2
+ // const today = new Date();
3
+ // const version = `${today.getFullYear()}.${today.getMonth()+1}.${today.getDate()}`;
4
+ // console.log(version);
5
+
6
+
7
+ import fetch from 'node-fetch';
8
+
9
+ async function generateVersion() {
10
+ const today = new Date();
11
+ const year = today.getFullYear();
12
+ const month = today.getMonth() + 1; // 1–12
13
+ const day = today.getDate(); // 1–31
14
+
15
+ // Ensure no leading zeros
16
+ const baseVersion = `${year}.${month}.${day}`;
17
+
18
+ try {
19
+ const res = await fetch('https://registry.npmjs.org/xchange-rates');
20
+ const data = await res.json();
21
+
22
+ const versions = new Set(Object.keys(data.versions || {}));
23
+ const timeKeys = new Set(Object.keys(data.time || {})); // includes removed versions
24
+ const allVersions = new Set([...versions, ...timeKeys]);
25
+
26
+ let finalVersion = baseVersion;
27
+ let patch = 0;
28
+
29
+ while (allVersions.has(finalVersion)) {
30
+ patch += 1;
31
+ finalVersion = `${baseVersion}-${patch}`;
32
+ }
33
+
34
+ console.log(finalVersion);
35
+ } catch (err) {
36
+ console.error("Error fetching registry:", err);
37
+ console.log(baseVersion);
38
+ }
39
+ }
40
+
41
+ generateVersion();
@@ -0,0 +1,36 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import fetch from 'node-fetch';
4
+ import dotenv from 'dotenv';
5
+ import { format } from 'date-fns';
6
+
7
+ dotenv.config();
8
+
9
+ const KEY = process.env.XCR_KEY1;
10
+ const URL = process.env.XCR_URL1;
11
+ const API_URL = `${URL}${KEY}`;
12
+ const outputDir = path.resolve('./v1');
13
+ const outputFile = path.join(outputDir, 'currencies.json');
14
+
15
+ async function updateRates() {
16
+ try {
17
+ const res = await fetch(API_URL);
18
+ const data = await res.json();
19
+
20
+ // Remove disclaimer and license
21
+ const { disclaimer, license, ...cleanData } = data;
22
+
23
+ // Add today's date
24
+ cleanData.date = format(new Date(), 'yyyy-MM-dd');
25
+
26
+ // Ensure directory exists
27
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
28
+
29
+ fs.writeFileSync(outputFile, JSON.stringify(cleanData, null, 2));
30
+ console.log('Exchange rates updated successfully!');
31
+ } catch (err) {
32
+ console.error('Error updating rates:', err);
33
+ }
34
+ }
35
+
36
+ updateRates();
@@ -1,179 +0,0 @@
1
- {
2
- "timestamp": 1755331205,
3
- "base": "USD",
4
- "rates": {
5
- "AED": 3.67295,
6
- "AFN": 69,
7
- "ALL": 83.8,
8
- "AMD": 383.1,
9
- "ANG": 1.79,
10
- "AOA": 917,
11
- "ARS": 1297.537602,
12
- "AUD": 1.537043,
13
- "AWG": 1.80075,
14
- "AZN": 1.7,
15
- "BAM": 1.673054,
16
- "BBD": 2,
17
- "BDT": 121.454217,
18
- "BGN": 1.67146,
19
- "BHD": 0.376789,
20
- "BIF": 2960,
21
- "BMD": 1,
22
- "BND": 1.281694,
23
- "BOB": 6.907525,
24
- "BRL": 5.4013,
25
- "BSD": 1,
26
- "BTC": 0.000008496902,
27
- "BTN": 87.426851,
28
- "BWP": 13.378101,
29
- "BYN": 3.323768,
30
- "BZD": 2.00793,
31
- "CAD": 1.38215,
32
- "CDF": 2895,
33
- "CHF": 0.806593,
34
- "CLF": 0.024586,
35
- "CLP": 963.17,
36
- "CNH": 7.1854,
37
- "CNY": 7.1821,
38
- "COP": 4046.904675,
39
- "CRC": 505.848441,
40
- "CUC": 1,
41
- "CUP": 25.75,
42
- "CVE": 94.9,
43
- "CZK": 20.9044,
44
- "DJF": 177.827972,
45
- "DKK": 6.37675,
46
- "DOP": 61.725,
47
- "DZD": 129.567225,
48
- "EGP": 48.265049,
49
- "ERN": 15,
50
- "ETB": 141.15,
51
- "EUR": 0.854348,
52
- "FJD": 2.2559,
53
- "FKP": 0.73749,
54
- "GBP": 0.73749,
55
- "GEL": 2.69,
56
- "GGP": 0.73749,
57
- "GHS": 10.65,
58
- "GIP": 0.73749,
59
- "GMD": 72.499999,
60
- "GNF": 8677.5,
61
- "GTQ": 7.667237,
62
- "GYD": 209.056268,
63
- "HKD": 7.82445,
64
- "HNL": 26.4,
65
- "HRK": 6.43702,
66
- "HTG": 130.80408,
67
- "HUF": 337.8,
68
- "IDR": 16203,
69
- "ILS": 3.37948,
70
- "IMP": 0.73749,
71
- "INR": 87.51385,
72
- "IQD": 1310,
73
- "IRR": 42125,
74
- "ISK": 122.38,
75
- "JEP": 0.73749,
76
- "JMD": 159.957172,
77
- "JOD": 0.709,
78
- "JPY": 147.09494849,
79
- "KES": 129.5,
80
- "KGS": 87.3788,
81
- "KHR": 4005,
82
- "KMF": 420.499968,
83
- "KPW": 900,
84
- "KRW": 1388.97,
85
- "KWD": 0.305303,
86
- "KYD": 0.83302,
87
- "KZT": 541.496827,
88
- "LAK": 21600,
89
- "LBP": 89552.5,
90
- "LKR": 300.889726,
91
- "LRD": 201.499983,
92
- "LSL": 17.59,
93
- "LYD": 5.415,
94
- "MAD": 9.0095,
95
- "MDL": 16.598984,
96
- "MGA": 4440,
97
- "MKD": 52.634726,
98
- "MMK": 2099,
99
- "MNT": 3592.646,
100
- "MOP": 8.081343,
101
- "MRU": 39.95,
102
- "MUR": 45.520003,
103
- "MVR": 15.4,
104
- "MWK": 1735,
105
- "MXN": 18.7435,
106
- "MYR": 4.213,
107
- "MZN": 63.959999,
108
- "NAD": 17.59,
109
- "NGN": 1532.72,
110
- "NIO": 36.76,
111
- "NOK": 10.19562,
112
- "NPR": 139.882797,
113
- "NZD": 1.688049,
114
- "OMR": 0.384284,
115
- "PAB": 1,
116
- "PEN": 3.56,
117
- "PGK": 4.14,
118
- "PHP": 57.107006,
119
- "PKR": 282.05,
120
- "PLN": 3.638739,
121
- "PYG": 7492.814679,
122
- "QAR": 3.6406,
123
- "RON": 4.3258,
124
- "RSD": 100.188013,
125
- "RUB": 80.100406,
126
- "RWF": 1445,
127
- "SAR": 3.752253,
128
- "SBD": 8.223773,
129
- "SCR": 14.145453,
130
- "SDG": 600.5,
131
- "SEK": 9.5588,
132
- "SGD": 1.282874,
133
- "SHP": 0.73749,
134
- "SLE": 23.225,
135
- "SLL": 20969.5,
136
- "SOS": 571.5,
137
- "SRD": 37.56,
138
- "SSP": 130.26,
139
- "STD": 22281.8,
140
- "STN": 21.3,
141
- "SVC": 8.746792,
142
- "SYP": 13002,
143
- "SZL": 17.59,
144
- "THB": 32.420657,
145
- "TJS": 9.321609,
146
- "TMT": 3.51,
147
- "TND": 2.921557,
148
- "TOP": 2.40776,
149
- "TRY": 40.799999,
150
- "TTD": 6.782633,
151
- "TWD": 30.0325,
152
- "TZS": 2611.496551,
153
- "UAH": 41.258598,
154
- "UGX": 3558.612919,
155
- "USD": 1,
156
- "UYU": 40.070284,
157
- "UZS": 12550,
158
- "VES": 135.470356,
159
- "VND": 26270.889205,
160
- "VUV": 119.1167,
161
- "WST": 2.7716,
162
- "XAF": 560.415306,
163
- "XAG": 0.02631337,
164
- "XAU": 0.00029985,
165
- "XCD": 2.70255,
166
- "XCG": 1.801625,
167
- "XDR": 0.704914,
168
- "XOF": 560.415306,
169
- "XPD": 0.00089865,
170
- "XPF": 101.950791,
171
- "XPT": 0.0007475,
172
- "YER": 240.27495,
173
- "ZAR": 17.595245,
174
- "ZMW": 23.166511,
175
- "ZWG": 26.78,
176
- "ZWL": 322
177
- },
178
- "date": "2025-08-16"
179
- }