@@ -8,17 +8,13 @@ export const convert = async (
88) => {
99 fromCurrency = fromCurrency . trim ( ) . toLowerCase ( ) ;
1010 toCurrency = toCurrency . trim ( ) . toLowerCase ( ) ;
11- const url = [
12- 'https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies' ,
13- fromCurrency ,
14- toCurrency ,
15- ] . join ( '/' ) ;
1611
17- return await fetch ( url + '.json' )
12+ return await fetch (
13+ `https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/${ fromCurrency } .json` ,
14+ )
1815 . then ( ( res ) => res . json ( ) )
19- . then ( ( data ) => value * data [ toCurrency ] ) ;
16+ . then ( ( data ) => value * data [ fromCurrency ] [ toCurrency ] ) ;
2017} ;
21- // https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@{apiVersion}/{date}/{endpoint}
2218
2319export const convertWithDate = async (
2420 value : number ,
@@ -33,18 +29,15 @@ export const convertWithDate = async (
3329 fromCurrency = fromCurrency . trim ( ) . toLowerCase ( ) ;
3430 toCurrency = toCurrency . trim ( ) . toLowerCase ( ) ;
3531
36- // Format date to YYYY-MM-DD
37- const formattedDate = date . toJSON ( ) . substring ( 0 , 10 ) ;
38-
39- const url = [
40- 'https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1' ,
41- formattedDate ,
42- 'currencies' ,
43- fromCurrency ,
44- toCurrency ,
45- ] . join ( '/' ) ;
32+ // https://github.com/fawazahmed0/exchange-api
33+ // Format date to YYYY.M.D
34+ // const formattedDate = date.toJSON().substring(0, 10).replaceAll('-', '.');
35+ // TODO: Migrated API does not work with historical API yet, so we use latest for now.
36+ const formattedDate = 'latest' ;
4637
47- return await fetch ( url + '.json' )
38+ return await fetch (
39+ `https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@${ formattedDate } /v1/${ fromCurrency } .json` ,
40+ )
4841 . then ( ( res ) => res . json ( ) )
4942 . then ( ( data ) => value * data [ toCurrency ] ) ;
5043} ;
0 commit comments