@duely/core
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,2 +0,2 @@ | ||
(()=>{"use strict";var e={607:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),o=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),o(t(910),r)},672:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Currency=void 0,function(e){var r=new Set(["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"]);function t(e,t){return t=t.toUpperCase(),r.has(t)?e:e/100}e.numberToMinorCurrencyAmount=function(e,t){return t=t.toUpperCase(),r.has(t)?e:Math.floor(100*e)},e.minorCurrencyAmountToNumber=t,e.format=function(e,r,n){var o=t(e,r=r.toUpperCase());return new Intl.NumberFormat(n,{currency:r,style:"currency"}).format(o)}}(r.Currency||(r.Currency={}))},910:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),o=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),o(t(672),r)}},r={};!function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{}};return e[n].call(o.exports,o,o.exports,t),o.exports}(607)})(); | ||
(()=>{"use strict";var e={607:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),o=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),o(t(910),r)},672:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Currency=void 0,r.Currency={numberToMinorCurrencyAmount:function(e,r){return r=r.toUpperCase(),t.has(r)?e:Math.floor(100*e)},minorCurrencyAmountToNumber:n,format:function(e,r,t){var o=n(e,r=r.toUpperCase());return new Intl.NumberFormat(t,{currency:r,style:"currency"}).format(o)}};var t=new Set(["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"]);function n(e,r){return r=r.toUpperCase(),t.has(r)?e:e/100}},910:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),o=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),o(t(672),r)}},r={};!function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{}};return e[n].call(o.exports,o,o.exports,t),o.exports}(607)})(); | ||
//# sourceMappingURL=duely.js.map |
{ | ||
"name": "@duely/core", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Shared types and functions used by the Duely APIs.", | ||
@@ -5,0 +5,0 @@ "main": "dist/duely.js", |
export declare type CurrencyUppercase = 'USD' | 'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BWP' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'ISK' | 'JMD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KRW' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRO' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SEK' | 'SGD' | 'SHP' | 'SLL' | 'SOS' | 'SRD' | 'STD' | 'SZL' | 'THB' | 'TJS' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'UYU' | 'UZS' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW'; | ||
export declare type CurrencyLowercase = Lowercase<CurrencyUppercase>; | ||
export declare type Currency = CurrencyUppercase | CurrencyLowercase; | ||
export declare namespace Currency { | ||
function numberToMinorCurrencyAmount(number: number, currency: Currency): number; | ||
function minorCurrencyAmountToNumber(amount: number, currency: Currency): number; | ||
function format(amount: number, currency: Currency, locales?: string): string; | ||
} | ||
export declare const Currency: { | ||
numberToMinorCurrencyAmount: typeof numberToMinorCurrencyAmount; | ||
minorCurrencyAmountToNumber: typeof minorCurrencyAmountToNumber; | ||
format: typeof format; | ||
}; | ||
declare function numberToMinorCurrencyAmount(number: number, currency: Currency): number; | ||
declare function minorCurrencyAmountToNumber(amount: number, currency: Currency): number; | ||
declare function format(amount: number, currency: Currency, locales?: string): string; | ||
export {}; |
@@ -7,21 +7,25 @@ | ||
export namespace Currency { | ||
// see: https://stripe.com/docs/currencies#zero-decimal | ||
const zeroDecimalCurrencies = new Set<CurrencyUppercase>(['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']); | ||
export const Currency = { | ||
numberToMinorCurrencyAmount, | ||
minorCurrencyAmountToNumber, | ||
format | ||
} | ||
export function numberToMinorCurrencyAmount(number: number, currency: Currency) : number { | ||
currency = currency.toUpperCase() as CurrencyUppercase; | ||
return zeroDecimalCurrencies.has(currency) ? number : Math.floor(number * 100); | ||
} | ||
// see: https://stripe.com/docs/currencies#zero-decimal | ||
const zeroDecimalCurrencies = new Set<CurrencyUppercase>(['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']); | ||
export function minorCurrencyAmountToNumber(amount: number, currency: Currency) : number { | ||
currency = currency.toUpperCase() as CurrencyUppercase; | ||
return zeroDecimalCurrencies.has(currency) ? amount : amount / 100; | ||
} | ||
function numberToMinorCurrencyAmount(number: number, currency: Currency): number { | ||
currency = currency.toUpperCase() as CurrencyUppercase; | ||
return zeroDecimalCurrencies.has(currency) ? number : Math.floor(number * 100); | ||
} | ||
export function format(amount: number, currency: Currency, locales?: string) : string { | ||
currency = currency.toUpperCase() as CurrencyUppercase; | ||
const number = minorCurrencyAmountToNumber(amount, currency); | ||
return new Intl.NumberFormat(locales, { currency, style: 'currency' }).format(number); | ||
} | ||
function minorCurrencyAmountToNumber(amount: number, currency: Currency): number { | ||
currency = currency.toUpperCase() as CurrencyUppercase; | ||
return zeroDecimalCurrencies.has(currency) ? amount : amount / 100; | ||
} | ||
function format(amount: number, currency: Currency, locales?: string): string { | ||
currency = currency.toUpperCase() as CurrencyUppercase; | ||
const number = minorCurrencyAmountToNumber(amount, currency); | ||
return new Intl.NumberFormat(locales, { currency, style: 'currency' }).format(number); | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19449
177