Comparing version 0.0.36 to 0.0.37
import { CurrencyCode } from "./CurrencyCode"; | ||
export declare type Currency = "AED" | "AFN" | "ALL" | "AMD" | "ANG" | "AOA" | "ARS" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BOV" | "BRL" | "BSD" | "BTN" | "BWP" | "BYN" | "BZD" | "CAD" | "CDF" | "CHE" | "CHF" | "CHW" | "CLF" | "CLP" | "CNY" | "COP" | "COU" | "CRC" | "CUC" | "CUP" | "CVE" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "ERN" | "ETB" | "EUR" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MAD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRU" | "MUR" | "MVR" | "MWK" | "MXN" | "MXV" | "MYR" | "MZN" | "NAD" | "NGN" | "NIO" | "NOK" | "NPR" | "NZD" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STN" | "SVC" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "USD" | "USN" | "UYI" | "UYU" | "UYW" | "UZS" | "VES" | "VND" | "VUV" | "WST" | "XAF" | "XAG" | "XAU" | "XBA" | "XBB" | "XBC" | "XBD" | "XCD" | "XDR" | "XOF" | "XPD" | "XPF" | "XPT" | "XSU" | "XTS" | "XUA" | "XXX" | "YER" | "ZAR" | "ZMW" | "ZWL"; | ||
declare const currencies: readonly ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "UYI", "UYU", "UYW", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX", "YER", "ZAR", "ZMW", "ZWL"]; | ||
export declare type Currency = typeof currencies[number]; | ||
export declare namespace Currency { | ||
@@ -8,3 +9,8 @@ const types: Currency[]; | ||
function round(value: number, currency: Currency): number; | ||
function add(currency: Currency, value1: number, value2: number): number; | ||
function divide(currency: Currency, amount: number, denominator: number): number; | ||
function multiply(currency: Currency, amount: number, multiplicand: number, outputCurrency?: Currency): number; | ||
function subtract(currency: Currency, minuend: number, subtrahend: number): number; | ||
function decimalDigits(currency: Currency): number | undefined; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Currency = void 0; | ||
const currencies = [ | ||
"AED", | ||
"AFN", | ||
"ALL", | ||
"AMD", | ||
"ANG", | ||
"AOA", | ||
"ARS", | ||
"AUD", | ||
"AWG", | ||
"AZN", | ||
"BAM", | ||
"BBD", | ||
"BDT", | ||
"BGN", | ||
"BHD", | ||
"BIF", | ||
"BMD", | ||
"BND", | ||
"BOB", | ||
"BOV", | ||
"BRL", | ||
"BSD", | ||
"BTN", | ||
"BWP", | ||
"BYN", | ||
"BZD", | ||
"CAD", | ||
"CDF", | ||
"CHE", | ||
"CHF", | ||
"CHW", | ||
"CLF", | ||
"CLP", | ||
"CNY", | ||
"COP", | ||
"COU", | ||
"CRC", | ||
"CUC", | ||
"CUP", | ||
"CVE", | ||
"CZK", | ||
"DJF", | ||
"DKK", | ||
"DOP", | ||
"DZD", | ||
"EGP", | ||
"ERN", | ||
"ETB", | ||
"EUR", | ||
"FJD", | ||
"FKP", | ||
"GBP", | ||
"GEL", | ||
"GHS", | ||
"GIP", | ||
"GMD", | ||
"GNF", | ||
"GTQ", | ||
"GYD", | ||
"HKD", | ||
"HNL", | ||
"HRK", | ||
"HTG", | ||
"HUF", | ||
"IDR", | ||
"ILS", | ||
"INR", | ||
"IQD", | ||
"IRR", | ||
"ISK", | ||
"JMD", | ||
"JOD", | ||
"JPY", | ||
"KES", | ||
"KGS", | ||
"KHR", | ||
"KMF", | ||
"KPW", | ||
"KRW", | ||
"KWD", | ||
"KYD", | ||
"KZT", | ||
"LAK", | ||
"LBP", | ||
"LKR", | ||
"LRD", | ||
"LSL", | ||
"LYD", | ||
"MAD", | ||
"MDL", | ||
"MGA", | ||
"MKD", | ||
"MMK", | ||
"MNT", | ||
"MOP", | ||
"MRU", | ||
"MUR", | ||
"MVR", | ||
"MWK", | ||
"MXN", | ||
"MXV", | ||
"MYR", | ||
"MZN", | ||
"NAD", | ||
"NGN", | ||
"NIO", | ||
"NOK", | ||
"NPR", | ||
"NZD", | ||
"OMR", | ||
"PAB", | ||
"PEN", | ||
"PGK", | ||
"PHP", | ||
"PKR", | ||
"PLN", | ||
"PYG", | ||
"QAR", | ||
"RON", | ||
"RSD", | ||
"RUB", | ||
"RWF", | ||
"SAR", | ||
"SBD", | ||
"SCR", | ||
"SDG", | ||
"SEK", | ||
"SGD", | ||
"SHP", | ||
"SLL", | ||
"SOS", | ||
"SRD", | ||
"SSP", | ||
"STN", | ||
"SVC", | ||
"SYP", | ||
"SZL", | ||
"THB", | ||
"TJS", | ||
"TMT", | ||
"TND", | ||
"TOP", | ||
"TRY", | ||
"TTD", | ||
"TWD", | ||
"TZS", | ||
"UAH", | ||
"UGX", | ||
"USD", | ||
"USN", | ||
"UYI", | ||
"UYU", | ||
"UYW", | ||
"UZS", | ||
"VES", | ||
"VND", | ||
"VUV", | ||
"WST", | ||
"XAF", | ||
"XAG", | ||
"XAU", | ||
"XBA", | ||
"XBB", | ||
"XBC", | ||
"XBD", | ||
"XCD", | ||
"XDR", | ||
"XOF", | ||
"XPD", | ||
"XPF", | ||
"XPT", | ||
"XSU", | ||
"XTS", | ||
"XUA", | ||
"XXX", | ||
"YER", | ||
"ZAR", | ||
"ZMW", | ||
"ZWL", | ||
]; | ||
var Currency; | ||
(function (Currency) { | ||
Currency.types = [ | ||
"AED", | ||
"AFN", | ||
"ALL", | ||
"AMD", | ||
"ANG", | ||
"AOA", | ||
"ARS", | ||
"AUD", | ||
"AWG", | ||
"AZN", | ||
"BAM", | ||
"BBD", | ||
"BDT", | ||
"BGN", | ||
"BHD", | ||
"BIF", | ||
"BMD", | ||
"BND", | ||
"BOB", | ||
"BOV", | ||
"BRL", | ||
"BSD", | ||
"BTN", | ||
"BWP", | ||
"BYN", | ||
"BZD", | ||
"CAD", | ||
"CDF", | ||
"CHE", | ||
"CHF", | ||
"CHW", | ||
"CLF", | ||
"CLP", | ||
"CNY", | ||
"COP", | ||
"COU", | ||
"CRC", | ||
"CUC", | ||
"CUP", | ||
"CVE", | ||
"CZK", | ||
"DJF", | ||
"DKK", | ||
"DOP", | ||
"DZD", | ||
"EGP", | ||
"ERN", | ||
"ETB", | ||
"EUR", | ||
"FJD", | ||
"FKP", | ||
"GBP", | ||
"GEL", | ||
"GHS", | ||
"GIP", | ||
"GMD", | ||
"GNF", | ||
"GTQ", | ||
"GYD", | ||
"HKD", | ||
"HNL", | ||
"HRK", | ||
"HTG", | ||
"HUF", | ||
"IDR", | ||
"ILS", | ||
"INR", | ||
"IQD", | ||
"IRR", | ||
"ISK", | ||
"JMD", | ||
"JOD", | ||
"JPY", | ||
"KES", | ||
"KGS", | ||
"KHR", | ||
"KMF", | ||
"KPW", | ||
"KRW", | ||
"KWD", | ||
"KYD", | ||
"KZT", | ||
"LAK", | ||
"LBP", | ||
"LKR", | ||
"LRD", | ||
"LSL", | ||
"LYD", | ||
"MAD", | ||
"MDL", | ||
"MGA", | ||
"MKD", | ||
"MMK", | ||
"MNT", | ||
"MOP", | ||
"MRU", | ||
"MUR", | ||
"MVR", | ||
"MWK", | ||
"MXN", | ||
"MXV", | ||
"MYR", | ||
"MZN", | ||
"NAD", | ||
"NGN", | ||
"NIO", | ||
"NOK", | ||
"NPR", | ||
"NZD", | ||
"OMR", | ||
"PAB", | ||
"PEN", | ||
"PGK", | ||
"PHP", | ||
"PKR", | ||
"PLN", | ||
"PYG", | ||
"QAR", | ||
"RON", | ||
"RSD", | ||
"RUB", | ||
"RWF", | ||
"SAR", | ||
"SBD", | ||
"SCR", | ||
"SDG", | ||
"SEK", | ||
"SGD", | ||
"SHP", | ||
"SLL", | ||
"SOS", | ||
"SRD", | ||
"SSP", | ||
"STN", | ||
"SVC", | ||
"SYP", | ||
"SZL", | ||
"THB", | ||
"TJS", | ||
"TMT", | ||
"TND", | ||
"TOP", | ||
"TRY", | ||
"TTD", | ||
"TWD", | ||
"TZS", | ||
"UAH", | ||
"UGX", | ||
"USD", | ||
"USN", | ||
"UYI", | ||
"UYU", | ||
"UYW", | ||
"UZS", | ||
"VES", | ||
"VND", | ||
"VUV", | ||
"WST", | ||
"XAF", | ||
"XAG", | ||
"XAU", | ||
"XBA", | ||
"XBB", | ||
"XBC", | ||
"XBD", | ||
"XCD", | ||
"XDR", | ||
"XOF", | ||
"XPD", | ||
"XPF", | ||
"XPT", | ||
"XSU", | ||
"XTS", | ||
"XUA", | ||
"XXX", | ||
"YER", | ||
"ZAR", | ||
"ZMW", | ||
"ZWL", | ||
]; | ||
Currency.types = [...currencies]; | ||
function is(currency) { | ||
@@ -378,5 +379,21 @@ return Currency.types.includes(currency); | ||
const factor = Math.pow(10, (_a = decimalDigits(currency)) !== null && _a !== void 0 ? _a : 2); | ||
return Math.round((value + Number.EPSILON) * factor) / factor; | ||
return Math.round(Math.round(value * factor * 10) / 10) / factor; | ||
} | ||
Currency.round = round; | ||
function add(currency, value1, value2) { | ||
return round(round(value1, currency) + round(value2, currency), currency); | ||
} | ||
Currency.add = add; | ||
function divide(currency, amount, denominator) { | ||
return round(round(amount, currency) / denominator, currency); | ||
} | ||
Currency.divide = divide; | ||
function multiply(currency, amount, multiplicand, outputCurrency) { | ||
return round(round(amount, currency) * multiplicand, outputCurrency !== null && outputCurrency !== void 0 ? outputCurrency : currency); | ||
} | ||
Currency.multiply = multiply; | ||
function subtract(currency, minuend, subtrahend) { | ||
return round(round(minuend, currency) - round(subtrahend, currency), currency); | ||
} | ||
Currency.subtract = subtract; | ||
function decimalDigits(currency) { | ||
@@ -383,0 +400,0 @@ return { |
138
package.json
{ | ||
"name": "isoly", | ||
"version": "0.0.36", | ||
"description": "Datatypes and functions specified by ISO-standards.", | ||
"author": "PayFunc", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/payfunc/isoly" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/payfunc/isoly/issues" | ||
}, | ||
"homepage": "https://payfunc.com/open-source/isoly", | ||
"private": false, | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"git": { | ||
"tagName": "v${version}" | ||
}, | ||
"github": { | ||
"release": true | ||
}, | ||
"jest": { | ||
"globals": { | ||
"ts-jest": { | ||
"tsConfig": "tsconfig.test.json" | ||
} | ||
}, | ||
"testEnvironment": "node", | ||
"testRegex": "((\\.|/)(test|spec))(\\.|\\/.+)(jsx?|tsx?)$", | ||
"testPathIgnorePatterns": [ | ||
"node_modules/", | ||
"dist/" | ||
], | ||
"collectCoverageFrom": [ | ||
"**/*.{ts,tsx,js,jsx}", | ||
"!**/node_modules/**", | ||
"!**/dist/**" | ||
], | ||
"preset": "ts-jest", | ||
"testMatch": null | ||
}, | ||
"scripts": { | ||
"dev": "watch 'npm run build' .", | ||
"lint": "eslint '**/*.{js,ts,tsx}'", | ||
"fix": "eslint '**/*.{js,ts,tsx}' --fix", | ||
"build": "tsc -p .", | ||
"test": "jest", | ||
"test:watch": "watch jest", | ||
"prepare": "npm run build", | ||
"clean": "rm -rf dist node_modules coverage" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.14", | ||
"@types/node": "^14.11.10", | ||
"@typescript-eslint/eslint-plugin": "^4.4.1", | ||
"@typescript-eslint/parser": "^4.4.1", | ||
"babel-core": "^6.26.3", | ||
"babel-jest": "^26.6.0", | ||
"eslint": "^7.11.0", | ||
"eslint-config-standardize": "^0.7.1", | ||
"eslint-plugin-prettierx": "github:nilssonemma/eslint-plugin-prettierx#master", | ||
"eslint-plugin-simple-import-sort": "^7.0.0", | ||
"jest": "^26", | ||
"prettierx": "github:simonmika/prettierx#newline-before-clause", | ||
"ts-jest": "^26.4.1", | ||
"typescript": "^4.0.3", | ||
"watch": "^1.0.2" | ||
} | ||
"name": "isoly", | ||
"version": "0.0.37", | ||
"description": "Datatypes and functions specified by ISO-standards.", | ||
"author": "PayFunc", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/payfunc/isoly" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/payfunc/isoly/issues" | ||
}, | ||
"homepage": "https://payfunc.com/open-source/isoly", | ||
"private": false, | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"git": { | ||
"tagName": "v${version}" | ||
}, | ||
"github": { | ||
"release": true | ||
}, | ||
"jest": { | ||
"globals": { | ||
"ts-jest": { | ||
"tsConfig": "tsconfig.test.json" | ||
} | ||
}, | ||
"testEnvironment": "node", | ||
"testRegex": "((\\.|/)(test|spec))(\\.|\\/.+)(jsx?|tsx?)$", | ||
"testPathIgnorePatterns": [ | ||
"node_modules/", | ||
"dist/" | ||
], | ||
"collectCoverageFrom": [ | ||
"**/*.{ts,tsx,js,jsx}", | ||
"!**/node_modules/**", | ||
"!**/dist/**" | ||
], | ||
"preset": "ts-jest", | ||
"testMatch": null | ||
}, | ||
"scripts": { | ||
"dev": "watch 'npm run build' .", | ||
"lint": "eslint '**/*.{js,ts,tsx}'", | ||
"fix": "eslint '**/*.{js,ts,tsx}' --fix", | ||
"build": "tsc -p .", | ||
"test": "jest", | ||
"test:watch": "watch jest", | ||
"prepare": "npm run build", | ||
"clean": "rm -rf dist node_modules coverage" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.0.1", | ||
"@types/node": "^14.11.10", | ||
"@typescript-eslint/eslint-plugin": "^4.31.1", | ||
"@typescript-eslint/parser": "^4.31.1", | ||
"babel-core": "^6.26.3", | ||
"babel-jest": "^27.2.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-standardize": "^0.9.1", | ||
"eslint-plugin-prettierx": "github:robinnedergard/eslint-plugin-prettierx#master", | ||
"eslint-plugin-simple-import-sort": "^7.0.0", | ||
"jest": "^27", | ||
"prettierx": "github:robinnedergard/prettierx#newline-before-clause-sync", | ||
"ts-jest": "^27.0.5", | ||
"typescript": "^4.4.3", | ||
"watch": "^1.0.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
908525
18978