diff --git a/package.json b/package.json index 129ff65..867a33a 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,11 @@ } }, "scripts": { - "build": "rm -rf dist && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && ./fixup.sh", + "build": "rm -rf dist && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && ./fixup.sh", "dev": "tsc --watch", "prepare": "npm run build" + }, + "directories": { + "test": "test" } } diff --git a/src/index.ts b/src/index.ts index d8a0139..d05f8af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ interface YFResponse { chart: { result: { meta: { regularMarketPrice: number } }[] } } -export async function getExchangeRate (from: CurrencyCode, to: CurrencyCode): Promise { +export async function getExchangeRate (from: CurrencyCode, to: CurrencyCode): Promise { let response try { const rateUrl = YF_BASE + from.toUpperCase() + to.toUpperCase() + YF_PARAMS @@ -26,8 +26,10 @@ export async function getExchangeRate (from: CurrencyCode, to: CurrencyCode): Pr const result = await response.json() as YFResponse const rate = result.chart?.result[0]?.meta?.regularMarketPrice + if (!rate) { throw new MalformedError('Service did not return correct data structure.') } + return rate } diff --git a/tsconfig-base.json b/tsconfig.base.json similarity index 100% rename from tsconfig-base.json rename to tsconfig.base.json diff --git a/tsconfig-cjs.json b/tsconfig.cjs.json similarity index 78% rename from tsconfig-cjs.json rename to tsconfig.cjs.json index 4949551..2ed8ed8 100644 --- a/tsconfig-cjs.json +++ b/tsconfig.cjs.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig-base.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "declaration": false, "module": "commonjs", diff --git a/tsconfig.json b/tsconfig.json index 3228364..df6e956 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig-base.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "module": "esnext", "outDir": "dist/esm",