kitten-format
Advanced tools
Comparing version 1.8.8 to 1.8.9
@@ -164,2 +164,13 @@ (function (global, factory) { | ||
let res = ''; | ||
if (fraction[fraction.length - 1] !== '0' && options.shouldNotRound !== true) { | ||
fraction = (toFixed(Number('0.' + fraction, 10), (options.maximumFractionDigits ? options.maximumFractionDigits : locale$$1.precision)) + ''); | ||
if (Number(fraction) === 1) { | ||
decimal = Number(decimal) + 1 + ''; | ||
} | ||
fraction = fraction.slice(2); | ||
} | ||
for (let i = decimal.length - 1; i >= 0; i--) { | ||
@@ -175,12 +186,2 @@ res = decimal[i] + res; | ||
if (fraction[fraction.length - 1] !== '0' && options.shouldNotRound !== true) { | ||
fraction = (toFixed(Number('0.' + fraction, 10), (options.maximumFractionDigits ? options.maximumFractionDigits : locale$$1.precision)) + ''); | ||
if (Number(fraction) === 1) { | ||
res = Number(res) + 1 + ''; | ||
} | ||
fraction = fraction.slice(2); | ||
} | ||
if (options.minimumFractionDigits != null) { | ||
@@ -187,0 +188,0 @@ for (fraction+=''; fraction.length < options.minimumFractionDigits; fraction = fraction + '0') {} |
@@ -1,1 +0,1 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e=e||self).kittenFormat=r()}(this,function(){"use strict";function e(e){return null==e||"string"!=typeof e?e:e.toLowerCase()}var r={EUR:"€",GBP:"£",CHF:"CHF",USD:"$"},t={locale:"fr-FR",currency:"EUR",currencySymbol:r.EUR,precision:2,unitPrefixes:{15:{default:"P",g:"GT"},12:{default:"T",g:"MT"},9:{default:"G",g:"kT"},6:{default:"M",g:"T"},3:"k",0:"","-3":"m","-6":"μ","-9":"n"},thousandSeparator:" ",decimalSeparator:","},n={default:t};function i(e){e&&(n.default=e)}function o(e){return n[e]?n[e]:n.default}function u(e,r,t){e=o(e);let n=(r+="").split("."),i=n[0],u=n[1]||"",l=e.thousandSeparator||" ",c=0,a="";for(let e=i.length-1;e>=0;e--)a=i[e]+a,3===++c&&e-1>=0&&(a=l+a,c=0);if("0"!==u[u.length-1]&&!0!==t.shouldNotRound&&(u=function(e,r){var t=Math.pow(10,r);return Math.round(e*t)/t}(Number("0."+u,10),t.maximumFractionDigits?t.maximumFractionDigits:e.precision)+"",1===Number(u)&&(a=Number(a)+1+""),u=u.slice(2)),null!=t.minimumFractionDigits)for(u+="";u.length<t.minimumFractionDigits;u+="0");return!0===t.shouldNotRound&&(u=u.slice(0,t.maximumFractionDigits?t.maximumFractionDigits:u.length)),u.length&&(a+=e.decimalSeparator+u),"currency"===t.style&&(!0===e.isCurrencyFirst?a=e.currencySymbol+a:a+=" "+e.currencySymbol),a}function l(e,r){let t=function(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=o((r=r||{}).locale),n=r.shouldNotRound?r.precision:r.precision||t.precision;return{locale:r.locale||t.locale,precision:n}}(e,r);return null==t||"object"!=typeof t?t:((r=r||{}).maximumFractionDigits=t.precision,u(t.locale,e,r))}function c(e,r){let t=function(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=null===(r=r||{}).power||void 0===r.power?0:r.power,n=r.unit;if(!n)return e;var i=e,u=0,l=null;if(e>=1){var c=(e+"").split(".")[0],a=c.length;u=3*Math.trunc(a/3),null!==r.maxPower&&void 0!==r.maxPower&&u+t>r.maxPower&&(l=r.maxPower-t),i=e*Math.pow(10,-(null!==l?l:u))}i<1&&(i*=Math.pow(10,3),-0===(t-=3)&&(t=0));var s=o(r.locale).unitPrefixes[(null!==l?l:u)+t];void 0===s?s="10^"+(u+t)+n:"string"!=typeof s?s=s[n]||s.default:s+=n;return{value:i,unit:s}}(e,r);return null==t||"object"!=typeof t?t:(r=r||{},(e=l(t.value,r))+" "+t.unit)}function a(e,r){let t=function(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=o((r=r||{}).locale),n=r.shouldNotRound?r.precision:r.precision||t.precision,i=r.currency||r.source||t.currency,u=r.locale||t.locale;r.target&&r.rates&&r.rates[r.target]&&(r.source=i,i=r.target,e=s(e,r));return{locale:u,currency:i,precision:n,value:e,shouldNotRound:r.shouldNotRound}}(e,r);return null==t||"object"!=typeof t?t:(t.precision<2&&(t.precision=2),t.style="currency",t.minimumFractionDigits=t.precision,null==t.minimumFractionDigits&&(t.minimumFractionDigits=t.locale.precision),t.maximumFractionDigits=t.minimumFractionDigits,u(t.locale,t.value,t))}function s(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=o((r=r||{}).locale),n=r.source||t.currency,i=r.target,u=r.rates;return!i||!u||u&&!u[n]||u&&!u[i]?e:e/u[n]*u[i]}const f={};return f.setOptions=i,f.setOption=function(e,i){null!=e&&("currency"===e&&(n.default.currencySymbol=r[i]||t.currencySymbol),n.default[e]=i)},f.locale=function(e){e&&(n[e.locale]=e,i(n[e.locale]))},f.lowerCase=e,f.upperCase=function(e){return null==e||"string"!=typeof e?e:e.toUpperCase()},f.upperCaseFirstChar=function(r){return null!=r&&"string"==typeof r&&r.length?r[0].toUpperCase()+e(r.slice(1,r.length)):r},f.formatN=l,f.formatNumber=l,f.percent=function(e,r){let t=function(e){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var r=100*e;return e>1&&(r=e),{value:r}}(e);return null==t||"object"!=typeof t?t:l(t.value,r)+"%"},f.averageN=c,f.averageNumber=c,f.formatC=a,f.formatCurrency=a,f.convC=s,f.convertCurrency=s,f}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e=e||self).kittenFormat=r()}(this,function(){"use strict";function e(e){return null==e||"string"!=typeof e?e:e.toLowerCase()}var r={EUR:"€",GBP:"£",CHF:"CHF",USD:"$"},t={locale:"fr-FR",currency:"EUR",currencySymbol:r.EUR,precision:2,unitPrefixes:{15:{default:"P",g:"GT"},12:{default:"T",g:"MT"},9:{default:"G",g:"kT"},6:{default:"M",g:"T"},3:"k",0:"","-3":"m","-6":"μ","-9":"n"},thousandSeparator:" ",decimalSeparator:","},n={default:t};function i(e){e&&(n.default=e)}function o(e){return n[e]?n[e]:n.default}function u(e,r,t){e=o(e);let n=(r+="").split("."),i=n[0],u=n[1]||"",l=e.thousandSeparator||" ",c=0,a="";"0"!==u[u.length-1]&&!0!==t.shouldNotRound&&(u=function(e,r){var t=Math.pow(10,r);return Math.round(e*t)/t}(Number("0."+u,10),t.maximumFractionDigits?t.maximumFractionDigits:e.precision)+"",1===Number(u)&&(i=Number(i)+1+""),u=u.slice(2));for(let e=i.length-1;e>=0;e--)a=i[e]+a,3===++c&&e-1>=0&&(a=l+a,c=0);if(null!=t.minimumFractionDigits)for(u+="";u.length<t.minimumFractionDigits;u+="0");return!0===t.shouldNotRound&&(u=u.slice(0,t.maximumFractionDigits?t.maximumFractionDigits:u.length)),u.length&&(a+=e.decimalSeparator+u),"currency"===t.style&&(!0===e.isCurrencyFirst?a=e.currencySymbol+a:a+=" "+e.currencySymbol),a}function l(e,r){let t=function(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=o((r=r||{}).locale),n=r.shouldNotRound?r.precision:r.precision||t.precision;return{locale:r.locale||t.locale,precision:n}}(e,r);return null==t||"object"!=typeof t?t:((r=r||{}).maximumFractionDigits=t.precision,u(t.locale,e,r))}function c(e,r){let t=function(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=null===(r=r||{}).power||void 0===r.power?0:r.power,n=r.unit;if(!n)return e;var i=e,u=0,l=null;if(e>=1){var c=(e+"").split(".")[0],a=c.length;u=3*Math.trunc(a/3),null!==r.maxPower&&void 0!==r.maxPower&&u+t>r.maxPower&&(l=r.maxPower-t),i=e*Math.pow(10,-(null!==l?l:u))}i<1&&(i*=Math.pow(10,3),-0===(t-=3)&&(t=0));var s=o(r.locale).unitPrefixes[(null!==l?l:u)+t];void 0===s?s="10^"+(u+t)+n:"string"!=typeof s?s=s[n]||s.default:s+=n;return{value:i,unit:s}}(e,r);return null==t||"object"!=typeof t?t:(r=r||{},(e=l(t.value,r))+" "+t.unit)}function a(e,r){let t=function(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=o((r=r||{}).locale),n=r.shouldNotRound?r.precision:r.precision||t.precision,i=r.currency||r.source||t.currency,u=r.locale||t.locale;r.target&&r.rates&&r.rates[r.target]&&(r.source=i,i=r.target,e=s(e,r));return{locale:u,currency:i,precision:n,value:e,shouldNotRound:r.shouldNotRound}}(e,r);return null==t||"object"!=typeof t?t:(t.precision<2&&(t.precision=2),t.style="currency",t.minimumFractionDigits=t.precision,null==t.minimumFractionDigits&&(t.minimumFractionDigits=t.locale.precision),t.maximumFractionDigits=t.minimumFractionDigits,u(t.locale,t.value,t))}function s(e,r){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var t=o((r=r||{}).locale),n=r.source||t.currency,i=r.target,u=r.rates;return!i||!u||u&&!u[n]||u&&!u[i]?e:e/u[n]*u[i]}const f={};return f.setOptions=i,f.setOption=function(e,i){null!=e&&("currency"===e&&(n.default.currencySymbol=r[i]||t.currencySymbol),n.default[e]=i)},f.locale=function(e){e&&(n[e.locale]=e,i(n[e.locale]))},f.lowerCase=e,f.upperCase=function(e){return null==e||"string"!=typeof e?e:e.toUpperCase()},f.upperCaseFirstChar=function(r){return null!=r&&"string"==typeof r&&r.length?r[0].toUpperCase()+e(r.slice(1,r.length)):r},f.formatN=l,f.formatNumber=l,f.percent=function(e,r){let t=function(e){if(null==e)return e;if("string"==typeof e&&isNaN(e))return"-";var r=100*e;return e>1&&(r=e),{value:r}}(e);return null==t||"object"!=typeof t?t:l(t.value,r)+"%"},f.averageN=c,f.averageNumber=c,f.formatC=a,f.formatCurrency=a,f.convC=s,f.convertCurrency=s,f}); |
@@ -160,2 +160,13 @@ 'use strict'; | ||
let res = ''; | ||
if (fraction[fraction.length - 1] !== '0' && options.shouldNotRound !== true) { | ||
fraction = (toFixed(Number('0.' + fraction, 10), (options.maximumFractionDigits ? options.maximumFractionDigits : locale$$1.precision)) + ''); | ||
if (Number(fraction) === 1) { | ||
decimal = Number(decimal) + 1 + ''; | ||
} | ||
fraction = fraction.slice(2); | ||
} | ||
for (let i = decimal.length - 1; i >= 0; i--) { | ||
@@ -171,12 +182,2 @@ res = decimal[i] + res; | ||
if (fraction[fraction.length - 1] !== '0' && options.shouldNotRound !== true) { | ||
fraction = (toFixed(Number('0.' + fraction, 10), (options.maximumFractionDigits ? options.maximumFractionDigits : locale$$1.precision)) + ''); | ||
if (Number(fraction) === 1) { | ||
res = Number(res) + 1 + ''; | ||
} | ||
fraction = fraction.slice(2); | ||
} | ||
if (options.minimumFractionDigits != null) { | ||
@@ -183,0 +184,0 @@ for (fraction+=''; fraction.length < options.minimumFractionDigits; fraction = fraction + '0') {} |
@@ -25,2 +25,13 @@ import { getLocale } from './options'; | ||
let res = ''; | ||
if (fraction[fraction.length - 1] !== '0' && options.shouldNotRound !== true) { | ||
fraction = (toFixed(Number('0.' + fraction, 10), (options.maximumFractionDigits ? options.maximumFractionDigits : locale.precision)) + ''); | ||
if (Number(fraction) === 1) { | ||
decimal = Number(decimal) + 1 + ''; | ||
} | ||
fraction = fraction.slice(2); | ||
} | ||
for (let i = decimal.length - 1; i >= 0; i--) { | ||
@@ -36,12 +47,2 @@ res = decimal[i] + res; | ||
if (fraction[fraction.length - 1] !== '0' && options.shouldNotRound !== true) { | ||
fraction = (toFixed(Number('0.' + fraction, 10), (options.maximumFractionDigits ? options.maximumFractionDigits : locale.precision)) + ''); | ||
if (Number(fraction) === 1) { | ||
res = Number(res) + 1 + ''; | ||
} | ||
fraction = fraction.slice(2); | ||
} | ||
if (options.minimumFractionDigits != null) { | ||
@@ -48,0 +49,0 @@ for (fraction+=''; fraction.length < options.minimumFractionDigits; fraction = fraction + '0') {} |
{ | ||
"name": "kitten-format", | ||
"version": "1.8.8", | ||
"version": "1.8.9", | ||
"description": "Fast formatters for browsers", | ||
@@ -5,0 +5,0 @@ "main": "build/kittenFormat.server.js", |
@@ -119,2 +119,8 @@ const should = require('should'); | ||
it('should format decimal number with large decimal parts', () => { | ||
should(kittenFormat.formatN('23516.9979741', { | ||
precision : 2 | ||
})).eql('23 517'); | ||
}); | ||
it('should format a number with minimumFractionDigits', () => { | ||
@@ -121,0 +127,0 @@ should(kittenFormat.formatN('14.4596', { |
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
99486
2282