CurrencyExchange
CurrencyExchange
安裝
npm i @brandon.yeh/currencyexchange
測試
npm test
使用方式
import Exchange from '@brandon.yeh/currencyexchange';
/**
* 兌換所實例化邏輯
*/
// 實例化一個兌換所
var currencyEXApp = new Exchange.CurrencyExchange();
// 實例化貨幣
var ntd = new Exchange.Currency('ntd','台幣',10000);
var usd = new Exchange.Currency('usd','美金',1000);
// 加入儲備庫
currencyEXApp.addCurrency(ntd);
currencyEXApp.addCurrency(usd);
/**
* 兌換邏輯
*/
// 估計6000台幣能夠換得多少美金
var amount = currencyEXApp.estimate('ntd','usd',6000);
console.log(amount);
// 以6000台幣兌換美金
currencyEXApp.trade('ntd','usd',6000);
// 第二次估計6000台幣能夠換得多少美金
var amount = currencyEXApp.estimate('ntd','usd',6000);
console.log(amount);
/**
* 更新儲備庫邏輯
*/
// 更新儲備庫中 ntd 名稱為 新台幣,並降低 1000 儲備量
currencyEXApp.updateCurrencyName('ntd','新台幣');
currencyEXApp.updateCurrencySupply('ntd',-1000);
// 取得目前 ntd 儲備狀況
currencyEXApp.getCurrency('ntd');
// 刪除 ntd 儲備
currencyEXApp.deleteCurrency('ntd');