woocommerce/assets/js/accounting/accounting.min.js

11 lines
3.2 KiB
JavaScript

/*!
* accounting.js v0.4.2
* Copyright 2014 Open Exchange Rates
*
* Freely distributable under the MIT license.
* Portions of accounting.js are inspired or borrowed from underscore.js
*
* Full details and documentation:
* http://openexchangerates.github.io/accounting.js/
*/
!function(n){var f={version:"0.4.1",settings:{currency:{symbol:"$",format:"%s%v",decimal:".",thousand:",",precision:2,grouping:3},number:{precision:0,grouping:3,thousand:",",decimal:"."}}},i=Array.prototype.map,r=Array.isArray,e=Object.prototype.toString;function p(n){return""===n||n&&n.charCodeAt&&n.substr}function l(n){return r?r(n):"[object Array]"===e.call(n)}function m(n){return n&&"[object Object]"===e.call(n)}function d(n,r){for(var e in n=n||{},r=r||{})r.hasOwnProperty(e)&&null==n[e]&&(n[e]=r[e]);return n}function g(n,r,e){var t,o,a=[];if(!n)return a;if(i&&n.map===i)return n.map(r,e);for(t=0,o=n.length;t<o;t++)a[t]=r.call(e,n[t],t,n);return a}function h(n,r){return n=Math.round(Math.abs(n)),isNaN(n)?r:n}function y(n){var r=f.settings.currency.format;return"function"==typeof n&&(n=n()),p(n)&&n.match("%v")?{pos:n,neg:n.replace("-","").replace("%v","-%v"),zero:n}:n&&n.pos&&n.pos.match("%v")?n:p(r)?f.settings.currency.format={pos:r,neg:r.replace("%v","-%v"),zero:r}:r}var t,b=f.unformat=f.parse=function(n,r){if(l(n))return g(n,function(n){return b(n,r)});if("number"==typeof(n=n||0))return n;r=r||f.settings.number.decimal;var e=new RegExp("[^0-9-"+r+"]",["g"]),e=parseFloat((""+n).replace(/\((.*)\)/,"-$1").replace(e,"").replace(r,"."));return isNaN(e)?0:e},s=f.toFixed=function(n,r){r=h(r,f.settings.number.precision);var e=Math.pow(10,r);return(Math.round(f.unformat(n)*e)/e).toFixed(r)},v=f.formatNumber=f.format=function(n,r,e,t){if(l(n))return g(n,function(n){return v(n,r,e,t)});n=b(n);var o=d(m(r)?r:{precision:r,thousand:e,decimal:t},f.settings.number),a=h(o.precision),i=n<0?"-":"",u=parseInt(s(Math.abs(n||0),a),10)+"",c=3<u.length?u.length%3:0;return i+(c?u.substr(0,c)+o.thousand:"")+u.substr(c).replace(/(\d{3})(?=\d)/g,"$1"+o.thousand)+(a?o.decimal+s(Math.abs(n),a).split(".")[1]:"")},c=f.formatMoney=function(n,r,e,t,o,a){if(l(n))return g(n,function(n){return c(n,r,e,t,o,a)});n=b(n);var i=d(m(r)?r:{symbol:r,precision:e,thousand:t,decimal:o,format:a},f.settings.currency),u=y(i.format);return(0<n?u.pos:n<0?u.neg:u.zero).replace("%s",i.symbol).replace("%v",v(Math.abs(n),h(i.precision),i.thousand,i.decimal))};f.formatColumn=function(n,r,e,t,o,a){if(!n)return[];var i=d(m(r)?r:{symbol:r,precision:e,thousand:t,decimal:o,format:a},f.settings.currency),u=y(i.format),c=u.pos.indexOf("%s")<u.pos.indexOf("%v"),s=0,n=g(n,function(n,r){if(l(n))return f.formatColumn(n,i);n=(0<(n=b(n))?u.pos:n<0?u.neg:u.zero).replace("%s",i.symbol).replace("%v",v(Math.abs(n),h(i.precision),i.thousand,i.decimal));return n.length>s&&(s=n.length),n});return g(n,function(n,r){return p(n)&&n.length<s?c?n.replace(i.symbol,i.symbol+new Array(s-n.length+1).join(" ")):new Array(s-n.length+1).join(" ")+n:n})},"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=f),exports.accounting=f):"function"==typeof define&&define.amd?define([],function(){return f}):(f.noConflict=(t=n.accounting,function(){return n.accounting=t,f.noConflict=void 0,f}),n.accounting=f)}(this);