-
Notifications
You must be signed in to change notification settings - Fork 7
/
codegen-paypal.js
77 lines (70 loc) ยท 1.7 KB
/
codegen-paypal.js
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
const fs = require('fs');
const path = require('path');
const prettier = require('prettier');
// https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
const PayPalSupportedCurrencies = `
Australian dollar AUD
Brazilian real 2 BRL
Canadian dollar CAD
Chinese Renmenbi 4 CNY
Czech koruna CZK
Danish krone DKK
Euro EUR
Hong Kong dollar HKD
Hungarian forint 1 HUF
Israeli new shekel ILS
Japanese yen 1 JPY
Malaysian ringgit 3 MYR
Mexican peso MXN
New Taiwan dollar 1 TWD
New Zealand dollar NZD
Norwegian krone NOK
Philippine peso PHP
Polish zลoty PLN
Pound sterling GBP
Singapore dollar SGD
Swedish krona SEK
Swiss franc CHF
Thai baht THB
United States dollar USD
`;
const currencyMap = PayPalSupportedCurrencies.split('\n')
.map((line) => line.trim())
.filter(Boolean)
.map((line) => line.replace(/\d/g, '').trim())
.reduce((acc, line) => {
const [currency, code] = line.split('\t');
acc[currency] = code;
return acc;
}, {});
const code = `
/**
* PayPal supported currencies
* @see https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
*/
export type PayPalSupportedCurrency =
${Object.keys(currencyMap)
.map((currency) => ` | /** ${currency} */ '${currencyMap[currency]}'`)
.join('\n')};
`;
const main = async () => {
const options = await prettier.resolveConfig(
path.resolve(__dirname, '../.prettierrc.js'),
);
const content = await prettier.format(code, {
parser: 'typescript',
...options,
});
fs.writeFileSync(
path.resolve(__dirname, '../src/paypal/PayPalSupportedCurrency.ts'),
content,
'utf-8',
);
};
main()
.then(() => {
console.log('Done โจ');
})
.catch((e) => {
console.error(e);
});