Initial commit
This commit is contained in:
42
node_modules/currency.js/dist/currency.d.ts
generated
vendored
Normal file
42
node_modules/currency.js/dist/currency.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
declare module 'currency.js' {
|
||||
namespace currency {
|
||||
type Any = number | string | currency;
|
||||
type Format = (currency?: currency, opts?: Options) => string;
|
||||
interface Constructor {
|
||||
(value: currency.Any, opts?: currency.Options): currency,
|
||||
new(value: currency.Any, opts?: currency.Options): currency
|
||||
}
|
||||
interface Options {
|
||||
symbol?: string,
|
||||
separator?: string,
|
||||
decimal?: string,
|
||||
errorOnInvalid?: boolean,
|
||||
precision?: number,
|
||||
increment?: number,
|
||||
useVedic?: boolean,
|
||||
pattern?: string,
|
||||
negativePattern?: string,
|
||||
format?: currency.Format,
|
||||
fromCents?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
interface currency {
|
||||
add(number: currency.Any): currency;
|
||||
subtract(number: currency.Any): currency;
|
||||
multiply(number: currency.Any): currency;
|
||||
divide(number: currency.Any): currency;
|
||||
distribute(count: number): Array<currency>;
|
||||
dollars(): number;
|
||||
cents(): number;
|
||||
format(opts?: currency.Options | currency.Format): string;
|
||||
toString(): string;
|
||||
toJSON(): number;
|
||||
readonly intValue: number;
|
||||
readonly value: number;
|
||||
}
|
||||
|
||||
const currency: currency.Constructor;
|
||||
|
||||
export = currency;
|
||||
}
|
||||
254
node_modules/currency.js/dist/currency.es.js
generated
vendored
Normal file
254
node_modules/currency.js/dist/currency.es.js
generated
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
/*!
|
||||
* currency.js - v2.0.4
|
||||
* http://scurker.github.io/currency.js
|
||||
*
|
||||
* Copyright (c) 2021 Jason Wilson
|
||||
* Released under MIT license
|
||||
*/
|
||||
|
||||
var defaults = {
|
||||
symbol: '$',
|
||||
separator: ',',
|
||||
decimal: '.',
|
||||
errorOnInvalid: false,
|
||||
precision: 2,
|
||||
pattern: '!#',
|
||||
negativePattern: '-!#',
|
||||
format: format,
|
||||
fromCents: false
|
||||
};
|
||||
|
||||
var round = function round(v) {
|
||||
return Math.round(v);
|
||||
};
|
||||
|
||||
var pow = function pow(p) {
|
||||
return Math.pow(10, p);
|
||||
};
|
||||
|
||||
var rounding = function rounding(value, increment) {
|
||||
return round(value / increment) * increment;
|
||||
};
|
||||
|
||||
var groupRegex = /(\d)(?=(\d{3})+\b)/g;
|
||||
var vedicRegex = /(\d)(?=(\d\d)+\d\b)/g;
|
||||
/**
|
||||
* Create a new instance of currency.js
|
||||
* @param {number|string|currency} value
|
||||
* @param {object} [opts]
|
||||
*/
|
||||
|
||||
function currency(value, opts) {
|
||||
var that = this;
|
||||
|
||||
if (!(that instanceof currency)) {
|
||||
return new currency(value, opts);
|
||||
}
|
||||
|
||||
var settings = Object.assign({}, defaults, opts),
|
||||
precision = pow(settings.precision),
|
||||
v = parse(value, settings);
|
||||
that.intValue = v;
|
||||
that.value = v / precision; // Set default incremental value
|
||||
|
||||
settings.increment = settings.increment || 1 / precision; // Support vedic numbering systems
|
||||
// see: https://en.wikipedia.org/wiki/Indian_numbering_system
|
||||
|
||||
if (settings.useVedic) {
|
||||
settings.groups = vedicRegex;
|
||||
} else {
|
||||
settings.groups = groupRegex;
|
||||
} // Intended for internal usage only - subject to change
|
||||
|
||||
|
||||
this.s = settings;
|
||||
this.p = precision;
|
||||
}
|
||||
|
||||
function parse(value, opts) {
|
||||
var useRounding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
var v = 0,
|
||||
decimal = opts.decimal,
|
||||
errorOnInvalid = opts.errorOnInvalid,
|
||||
decimals = opts.precision,
|
||||
fromCents = opts.fromCents,
|
||||
precision = pow(decimals),
|
||||
isNumber = typeof value === 'number',
|
||||
isCurrency = value instanceof currency;
|
||||
|
||||
if (isCurrency && fromCents) {
|
||||
return value.intValue;
|
||||
}
|
||||
|
||||
if (isNumber || isCurrency) {
|
||||
v = isCurrency ? value.value : value;
|
||||
} else if (typeof value === 'string') {
|
||||
var regex = new RegExp('[^-\\d' + decimal + ']', 'g'),
|
||||
decimalString = new RegExp('\\' + decimal, 'g');
|
||||
v = value.replace(/\((.*)\)/, '-$1') // allow negative e.g. (1.99)
|
||||
.replace(regex, '') // replace any non numeric values
|
||||
.replace(decimalString, '.'); // convert any decimal values
|
||||
|
||||
v = v || 0;
|
||||
} else {
|
||||
if (errorOnInvalid) {
|
||||
throw Error('Invalid Input');
|
||||
}
|
||||
|
||||
v = 0;
|
||||
}
|
||||
|
||||
if (!fromCents) {
|
||||
v *= precision; // scale number to integer value
|
||||
|
||||
v = v.toFixed(4); // Handle additional decimal for proper rounding.
|
||||
}
|
||||
|
||||
return useRounding ? round(v) : v;
|
||||
}
|
||||
/**
|
||||
* Formats a currency object
|
||||
* @param currency
|
||||
* @param {object} [opts]
|
||||
*/
|
||||
|
||||
|
||||
function format(currency, settings) {
|
||||
var pattern = settings.pattern,
|
||||
negativePattern = settings.negativePattern,
|
||||
symbol = settings.symbol,
|
||||
separator = settings.separator,
|
||||
decimal = settings.decimal,
|
||||
groups = settings.groups,
|
||||
split = ('' + currency).replace(/^-/, '').split('.'),
|
||||
dollars = split[0],
|
||||
cents = split[1];
|
||||
return (currency.value >= 0 ? pattern : negativePattern).replace('!', symbol).replace('#', dollars.replace(groups, '$1' + separator) + (cents ? decimal + cents : ''));
|
||||
}
|
||||
|
||||
currency.prototype = {
|
||||
/**
|
||||
* Adds values together.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
add: function add(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s,
|
||||
_precision = this.p;
|
||||
return currency((intValue += parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Subtracts value.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
subtract: function subtract(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s,
|
||||
_precision = this.p;
|
||||
return currency((intValue -= parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Multiplies values.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
multiply: function multiply(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s;
|
||||
return currency((intValue *= number) / (_settings.fromCents ? 1 : pow(_settings.precision)), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Divides value.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
divide: function divide(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s;
|
||||
return currency(intValue /= parse(number, _settings, false), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes the currency amount and distributes the values evenly. Any extra pennies
|
||||
* left over from the distribution will be stacked onto the first set of entries.
|
||||
* @param {number} count
|
||||
* @returns {array}
|
||||
*/
|
||||
distribute: function distribute(count) {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p,
|
||||
_settings = this.s,
|
||||
distribution = [],
|
||||
split = Math[intValue >= 0 ? 'floor' : 'ceil'](intValue / count),
|
||||
pennies = Math.abs(intValue - split * count),
|
||||
precision = _settings.fromCents ? 1 : _precision;
|
||||
|
||||
for (; count !== 0; count--) {
|
||||
var item = currency(split / precision, _settings); // Add any left over pennies
|
||||
|
||||
pennies-- > 0 && (item = item[intValue >= 0 ? 'add' : 'subtract'](1 / precision));
|
||||
distribution.push(item);
|
||||
}
|
||||
|
||||
return distribution;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the dollar value.
|
||||
* @returns {number}
|
||||
*/
|
||||
dollars: function dollars() {
|
||||
return ~~this.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the cent value.
|
||||
* @returns {number}
|
||||
*/
|
||||
cents: function cents() {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p;
|
||||
return ~~(intValue % _precision);
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the value as a string according to the formatting settings.
|
||||
* @param {boolean} useSymbol - format with currency symbol
|
||||
* @returns {string}
|
||||
*/
|
||||
format: function format(options) {
|
||||
var _settings = this.s;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
return options(this, _settings);
|
||||
}
|
||||
|
||||
return _settings.format(this, Object.assign({}, _settings, options));
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the value as a string according to the formatting settings.
|
||||
* @returns {string}
|
||||
*/
|
||||
toString: function toString() {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p,
|
||||
_settings = this.s;
|
||||
return rounding(intValue / _precision, _settings.increment).toFixed(_settings.precision);
|
||||
},
|
||||
|
||||
/**
|
||||
* Value for JSON serialization.
|
||||
* @returns {float}
|
||||
*/
|
||||
toJSON: function toJSON() {
|
||||
return this.value;
|
||||
}
|
||||
};
|
||||
|
||||
export default currency;
|
||||
256
node_modules/currency.js/dist/currency.js
generated
vendored
Normal file
256
node_modules/currency.js/dist/currency.js
generated
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
/*!
|
||||
* currency.js - v2.0.4
|
||||
* http://scurker.github.io/currency.js
|
||||
*
|
||||
* Copyright (c) 2021 Jason Wilson
|
||||
* Released under MIT license
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var defaults = {
|
||||
symbol: '$',
|
||||
separator: ',',
|
||||
decimal: '.',
|
||||
errorOnInvalid: false,
|
||||
precision: 2,
|
||||
pattern: '!#',
|
||||
negativePattern: '-!#',
|
||||
format: format,
|
||||
fromCents: false
|
||||
};
|
||||
|
||||
var round = function round(v) {
|
||||
return Math.round(v);
|
||||
};
|
||||
|
||||
var pow = function pow(p) {
|
||||
return Math.pow(10, p);
|
||||
};
|
||||
|
||||
var rounding = function rounding(value, increment) {
|
||||
return round(value / increment) * increment;
|
||||
};
|
||||
|
||||
var groupRegex = /(\d)(?=(\d{3})+\b)/g;
|
||||
var vedicRegex = /(\d)(?=(\d\d)+\d\b)/g;
|
||||
/**
|
||||
* Create a new instance of currency.js
|
||||
* @param {number|string|currency} value
|
||||
* @param {object} [opts]
|
||||
*/
|
||||
|
||||
function currency(value, opts) {
|
||||
var that = this;
|
||||
|
||||
if (!(that instanceof currency)) {
|
||||
return new currency(value, opts);
|
||||
}
|
||||
|
||||
var settings = Object.assign({}, defaults, opts),
|
||||
precision = pow(settings.precision),
|
||||
v = parse(value, settings);
|
||||
that.intValue = v;
|
||||
that.value = v / precision; // Set default incremental value
|
||||
|
||||
settings.increment = settings.increment || 1 / precision; // Support vedic numbering systems
|
||||
// see: https://en.wikipedia.org/wiki/Indian_numbering_system
|
||||
|
||||
if (settings.useVedic) {
|
||||
settings.groups = vedicRegex;
|
||||
} else {
|
||||
settings.groups = groupRegex;
|
||||
} // Intended for internal usage only - subject to change
|
||||
|
||||
|
||||
this.s = settings;
|
||||
this.p = precision;
|
||||
}
|
||||
|
||||
function parse(value, opts) {
|
||||
var useRounding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
var v = 0,
|
||||
decimal = opts.decimal,
|
||||
errorOnInvalid = opts.errorOnInvalid,
|
||||
decimals = opts.precision,
|
||||
fromCents = opts.fromCents,
|
||||
precision = pow(decimals),
|
||||
isNumber = typeof value === 'number',
|
||||
isCurrency = value instanceof currency;
|
||||
|
||||
if (isCurrency && fromCents) {
|
||||
return value.intValue;
|
||||
}
|
||||
|
||||
if (isNumber || isCurrency) {
|
||||
v = isCurrency ? value.value : value;
|
||||
} else if (typeof value === 'string') {
|
||||
var regex = new RegExp('[^-\\d' + decimal + ']', 'g'),
|
||||
decimalString = new RegExp('\\' + decimal, 'g');
|
||||
v = value.replace(/\((.*)\)/, '-$1') // allow negative e.g. (1.99)
|
||||
.replace(regex, '') // replace any non numeric values
|
||||
.replace(decimalString, '.'); // convert any decimal values
|
||||
|
||||
v = v || 0;
|
||||
} else {
|
||||
if (errorOnInvalid) {
|
||||
throw Error('Invalid Input');
|
||||
}
|
||||
|
||||
v = 0;
|
||||
}
|
||||
|
||||
if (!fromCents) {
|
||||
v *= precision; // scale number to integer value
|
||||
|
||||
v = v.toFixed(4); // Handle additional decimal for proper rounding.
|
||||
}
|
||||
|
||||
return useRounding ? round(v) : v;
|
||||
}
|
||||
/**
|
||||
* Formats a currency object
|
||||
* @param currency
|
||||
* @param {object} [opts]
|
||||
*/
|
||||
|
||||
|
||||
function format(currency, settings) {
|
||||
var pattern = settings.pattern,
|
||||
negativePattern = settings.negativePattern,
|
||||
symbol = settings.symbol,
|
||||
separator = settings.separator,
|
||||
decimal = settings.decimal,
|
||||
groups = settings.groups,
|
||||
split = ('' + currency).replace(/^-/, '').split('.'),
|
||||
dollars = split[0],
|
||||
cents = split[1];
|
||||
return (currency.value >= 0 ? pattern : negativePattern).replace('!', symbol).replace('#', dollars.replace(groups, '$1' + separator) + (cents ? decimal + cents : ''));
|
||||
}
|
||||
|
||||
currency.prototype = {
|
||||
/**
|
||||
* Adds values together.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
add: function add(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s,
|
||||
_precision = this.p;
|
||||
return currency((intValue += parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Subtracts value.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
subtract: function subtract(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s,
|
||||
_precision = this.p;
|
||||
return currency((intValue -= parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Multiplies values.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
multiply: function multiply(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s;
|
||||
return currency((intValue *= number) / (_settings.fromCents ? 1 : pow(_settings.precision)), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Divides value.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
divide: function divide(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s;
|
||||
return currency(intValue /= parse(number, _settings, false), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes the currency amount and distributes the values evenly. Any extra pennies
|
||||
* left over from the distribution will be stacked onto the first set of entries.
|
||||
* @param {number} count
|
||||
* @returns {array}
|
||||
*/
|
||||
distribute: function distribute(count) {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p,
|
||||
_settings = this.s,
|
||||
distribution = [],
|
||||
split = Math[intValue >= 0 ? 'floor' : 'ceil'](intValue / count),
|
||||
pennies = Math.abs(intValue - split * count),
|
||||
precision = _settings.fromCents ? 1 : _precision;
|
||||
|
||||
for (; count !== 0; count--) {
|
||||
var item = currency(split / precision, _settings); // Add any left over pennies
|
||||
|
||||
pennies-- > 0 && (item = item[intValue >= 0 ? 'add' : 'subtract'](1 / precision));
|
||||
distribution.push(item);
|
||||
}
|
||||
|
||||
return distribution;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the dollar value.
|
||||
* @returns {number}
|
||||
*/
|
||||
dollars: function dollars() {
|
||||
return ~~this.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the cent value.
|
||||
* @returns {number}
|
||||
*/
|
||||
cents: function cents() {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p;
|
||||
return ~~(intValue % _precision);
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the value as a string according to the formatting settings.
|
||||
* @param {boolean} useSymbol - format with currency symbol
|
||||
* @returns {string}
|
||||
*/
|
||||
format: function format(options) {
|
||||
var _settings = this.s;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
return options(this, _settings);
|
||||
}
|
||||
|
||||
return _settings.format(this, Object.assign({}, _settings, options));
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the value as a string according to the formatting settings.
|
||||
* @returns {string}
|
||||
*/
|
||||
toString: function toString() {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p,
|
||||
_settings = this.s;
|
||||
return rounding(intValue / _precision, _settings.increment).toFixed(_settings.precision);
|
||||
},
|
||||
|
||||
/**
|
||||
* Value for JSON serialization.
|
||||
* @returns {float}
|
||||
*/
|
||||
toJSON: function toJSON() {
|
||||
return this.value;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = currency;
|
||||
37
node_modules/currency.js/dist/currency.js.flow
generated
vendored
Normal file
37
node_modules/currency.js/dist/currency.js.flow
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// @flow
|
||||
declare type $currency$any = number | string | currency;
|
||||
|
||||
declare type formatFunction = (currency: currency, options: $currency$opts) => string;
|
||||
|
||||
declare type $currency$opts = {
|
||||
symbol?: string,
|
||||
separator?: string,
|
||||
decimal?: string,
|
||||
errorOnInvalid?: boolean,
|
||||
precision?: number,
|
||||
increment?: number,
|
||||
useVedic?: boolean,
|
||||
pattern?: string,
|
||||
negativePattern?: string,
|
||||
format?: formatFunction,
|
||||
fromCents?: boolean
|
||||
}
|
||||
|
||||
declare class currency {
|
||||
static (value: $currency$any, opts?: $currency$opts): currency,
|
||||
constructor(value: $currency$any, opts?: $currency$opts): currency,
|
||||
add(number: $currency$any): currency;
|
||||
subtract(number: $currency$any): currency;
|
||||
multiply(number: $currency$any): currency;
|
||||
divide(number: $currency$any): currency;
|
||||
distribute(count: number): Array<currency>;
|
||||
dollars(): number;
|
||||
cents(): number;
|
||||
format(options?: $currency$opts | formatFunction): string;
|
||||
toString(): string;
|
||||
toJSON(): number;
|
||||
+intValue: number;
|
||||
+value: number;
|
||||
}
|
||||
|
||||
declare module.exports: typeof currency;
|
||||
12
node_modules/currency.js/dist/currency.min.js
generated
vendored
Normal file
12
node_modules/currency.js/dist/currency.min.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
currency.js - v2.0.4
|
||||
http://scurker.github.io/currency.js
|
||||
|
||||
Copyright (c) 2021 Jason Wilson
|
||||
Released under MIT license
|
||||
*/
|
||||
(function(e,g){"object"===typeof exports&&"undefined"!==typeof module?module.exports=g():"function"===typeof define&&define.amd?define(g):(e=e||self,e.currency=g())})(this,function(){function e(b,a){if(!(this instanceof e))return new e(b,a);a=Object.assign({},m,a);var d=Math.pow(10,a.precision);this.intValue=b=g(b,a);this.value=b/d;a.increment=a.increment||1/d;a.groups=a.useVedic?n:p;this.s=a;this.p=d}function g(b,a){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:!0;var c=a.decimal;
|
||||
var h=a.errorOnInvalid,k=a.fromCents,l=Math.pow(10,a.precision),f=b instanceof e;if(f&&k)return b.intValue;if("number"===typeof b||f)c=f?b.value:b;else if("string"===typeof b)h=new RegExp("[^-\\d"+c+"]","g"),c=new RegExp("\\"+c,"g"),c=(c=b.replace(/\((.*)\)/,"-$1").replace(h,"").replace(c,"."))||0;else{if(h)throw Error("Invalid Input");c=0}k||(c=(c*l).toFixed(4));return d?Math.round(c):c}var m={symbol:"$",separator:",",decimal:".",errorOnInvalid:!1,precision:2,pattern:"!#",negativePattern:"-!#",format:function(b,
|
||||
a){var d=a.pattern,c=a.negativePattern,h=a.symbol,k=a.separator,l=a.decimal;a=a.groups;var f=(""+b).replace(/^-/,"").split("."),q=f[0];f=f[1];return(0<=b.value?d:c).replace("!",h).replace("#",q.replace(a,"$1"+k)+(f?l+f:""))},fromCents:!1},p=/(\d)(?=(\d{3})+\b)/g,n=/(\d)(?=(\d\d)+\d\b)/g;e.prototype={add:function(b){var a=this.s,d=this.p;return e((this.intValue+g(b,a))/(a.fromCents?1:d),a)},subtract:function(b){var a=this.s,d=this.p;return e((this.intValue-g(b,a))/(a.fromCents?1:d),a)},multiply:function(b){var a=
|
||||
this.s;return e(this.intValue*b/(a.fromCents?1:Math.pow(10,a.precision)),a)},divide:function(b){var a=this.s;return e(this.intValue/g(b,a,!1),a)},distribute:function(b){var a=this.intValue,d=this.p,c=this.s,h=[],k=Math[0<=a?"floor":"ceil"](a/b),l=Math.abs(a-k*b);for(d=c.fromCents?1:d;0!==b;b--){var f=e(k/d,c);0<l--&&(f=f[0<=a?"add":"subtract"](1/d));h.push(f)}return h},dollars:function(){return~~this.value},cents:function(){return~~(this.intValue%this.p)},format:function(b){var a=this.s;return"function"===
|
||||
typeof b?b(this,a):a.format(this,Object.assign({},a,b))},toString:function(){var b=this.s,a=b.increment;return(Math.round(this.intValue/this.p/a)*a).toFixed(b.precision)},toJSON:function(){return this.value}};return e});
|
||||
262
node_modules/currency.js/dist/currency.umd.js
generated
vendored
Normal file
262
node_modules/currency.js/dist/currency.umd.js
generated
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
/*!
|
||||
* currency.js - v2.0.4
|
||||
* http://scurker.github.io/currency.js
|
||||
*
|
||||
* Copyright (c) 2021 Jason Wilson
|
||||
* Released under MIT license
|
||||
*/
|
||||
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.currency = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
var defaults = {
|
||||
symbol: '$',
|
||||
separator: ',',
|
||||
decimal: '.',
|
||||
errorOnInvalid: false,
|
||||
precision: 2,
|
||||
pattern: '!#',
|
||||
negativePattern: '-!#',
|
||||
format: format,
|
||||
fromCents: false
|
||||
};
|
||||
|
||||
var round = function round(v) {
|
||||
return Math.round(v);
|
||||
};
|
||||
|
||||
var pow = function pow(p) {
|
||||
return Math.pow(10, p);
|
||||
};
|
||||
|
||||
var rounding = function rounding(value, increment) {
|
||||
return round(value / increment) * increment;
|
||||
};
|
||||
|
||||
var groupRegex = /(\d)(?=(\d{3})+\b)/g;
|
||||
var vedicRegex = /(\d)(?=(\d\d)+\d\b)/g;
|
||||
/**
|
||||
* Create a new instance of currency.js
|
||||
* @param {number|string|currency} value
|
||||
* @param {object} [opts]
|
||||
*/
|
||||
|
||||
function currency(value, opts) {
|
||||
var that = this;
|
||||
|
||||
if (!(that instanceof currency)) {
|
||||
return new currency(value, opts);
|
||||
}
|
||||
|
||||
var settings = Object.assign({}, defaults, opts),
|
||||
precision = pow(settings.precision),
|
||||
v = parse(value, settings);
|
||||
that.intValue = v;
|
||||
that.value = v / precision; // Set default incremental value
|
||||
|
||||
settings.increment = settings.increment || 1 / precision; // Support vedic numbering systems
|
||||
// see: https://en.wikipedia.org/wiki/Indian_numbering_system
|
||||
|
||||
if (settings.useVedic) {
|
||||
settings.groups = vedicRegex;
|
||||
} else {
|
||||
settings.groups = groupRegex;
|
||||
} // Intended for internal usage only - subject to change
|
||||
|
||||
|
||||
this.s = settings;
|
||||
this.p = precision;
|
||||
}
|
||||
|
||||
function parse(value, opts) {
|
||||
var useRounding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
var v = 0,
|
||||
decimal = opts.decimal,
|
||||
errorOnInvalid = opts.errorOnInvalid,
|
||||
decimals = opts.precision,
|
||||
fromCents = opts.fromCents,
|
||||
precision = pow(decimals),
|
||||
isNumber = typeof value === 'number',
|
||||
isCurrency = value instanceof currency;
|
||||
|
||||
if (isCurrency && fromCents) {
|
||||
return value.intValue;
|
||||
}
|
||||
|
||||
if (isNumber || isCurrency) {
|
||||
v = isCurrency ? value.value : value;
|
||||
} else if (typeof value === 'string') {
|
||||
var regex = new RegExp('[^-\\d' + decimal + ']', 'g'),
|
||||
decimalString = new RegExp('\\' + decimal, 'g');
|
||||
v = value.replace(/\((.*)\)/, '-$1') // allow negative e.g. (1.99)
|
||||
.replace(regex, '') // replace any non numeric values
|
||||
.replace(decimalString, '.'); // convert any decimal values
|
||||
|
||||
v = v || 0;
|
||||
} else {
|
||||
if (errorOnInvalid) {
|
||||
throw Error('Invalid Input');
|
||||
}
|
||||
|
||||
v = 0;
|
||||
}
|
||||
|
||||
if (!fromCents) {
|
||||
v *= precision; // scale number to integer value
|
||||
|
||||
v = v.toFixed(4); // Handle additional decimal for proper rounding.
|
||||
}
|
||||
|
||||
return useRounding ? round(v) : v;
|
||||
}
|
||||
/**
|
||||
* Formats a currency object
|
||||
* @param currency
|
||||
* @param {object} [opts]
|
||||
*/
|
||||
|
||||
|
||||
function format(currency, settings) {
|
||||
var pattern = settings.pattern,
|
||||
negativePattern = settings.negativePattern,
|
||||
symbol = settings.symbol,
|
||||
separator = settings.separator,
|
||||
decimal = settings.decimal,
|
||||
groups = settings.groups,
|
||||
split = ('' + currency).replace(/^-/, '').split('.'),
|
||||
dollars = split[0],
|
||||
cents = split[1];
|
||||
return (currency.value >= 0 ? pattern : negativePattern).replace('!', symbol).replace('#', dollars.replace(groups, '$1' + separator) + (cents ? decimal + cents : ''));
|
||||
}
|
||||
|
||||
currency.prototype = {
|
||||
/**
|
||||
* Adds values together.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
add: function add(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s,
|
||||
_precision = this.p;
|
||||
return currency((intValue += parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Subtracts value.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
subtract: function subtract(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s,
|
||||
_precision = this.p;
|
||||
return currency((intValue -= parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Multiplies values.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
multiply: function multiply(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s;
|
||||
return currency((intValue *= number) / (_settings.fromCents ? 1 : pow(_settings.precision)), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Divides value.
|
||||
* @param {number} number
|
||||
* @returns {currency}
|
||||
*/
|
||||
divide: function divide(number) {
|
||||
var intValue = this.intValue,
|
||||
_settings = this.s;
|
||||
return currency(intValue /= parse(number, _settings, false), _settings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes the currency amount and distributes the values evenly. Any extra pennies
|
||||
* left over from the distribution will be stacked onto the first set of entries.
|
||||
* @param {number} count
|
||||
* @returns {array}
|
||||
*/
|
||||
distribute: function distribute(count) {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p,
|
||||
_settings = this.s,
|
||||
distribution = [],
|
||||
split = Math[intValue >= 0 ? 'floor' : 'ceil'](intValue / count),
|
||||
pennies = Math.abs(intValue - split * count),
|
||||
precision = _settings.fromCents ? 1 : _precision;
|
||||
|
||||
for (; count !== 0; count--) {
|
||||
var item = currency(split / precision, _settings); // Add any left over pennies
|
||||
|
||||
pennies-- > 0 && (item = item[intValue >= 0 ? 'add' : 'subtract'](1 / precision));
|
||||
distribution.push(item);
|
||||
}
|
||||
|
||||
return distribution;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the dollar value.
|
||||
* @returns {number}
|
||||
*/
|
||||
dollars: function dollars() {
|
||||
return ~~this.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the cent value.
|
||||
* @returns {number}
|
||||
*/
|
||||
cents: function cents() {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p;
|
||||
return ~~(intValue % _precision);
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the value as a string according to the formatting settings.
|
||||
* @param {boolean} useSymbol - format with currency symbol
|
||||
* @returns {string}
|
||||
*/
|
||||
format: function format(options) {
|
||||
var _settings = this.s;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
return options(this, _settings);
|
||||
}
|
||||
|
||||
return _settings.format(this, Object.assign({}, _settings, options));
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the value as a string according to the formatting settings.
|
||||
* @returns {string}
|
||||
*/
|
||||
toString: function toString() {
|
||||
var intValue = this.intValue,
|
||||
_precision = this.p,
|
||||
_settings = this.s;
|
||||
return rounding(intValue / _precision, _settings.increment).toFixed(_settings.precision);
|
||||
},
|
||||
|
||||
/**
|
||||
* Value for JSON serialization.
|
||||
* @returns {float}
|
||||
*/
|
||||
toJSON: function toJSON() {
|
||||
return this.value;
|
||||
}
|
||||
};
|
||||
|
||||
return currency;
|
||||
|
||||
})));
|
||||
Reference in New Issue
Block a user