kitten-format
Advanced tools
Comparing version 1.4.3 to 1.4.4
@@ -97,9 +97,2 @@ (function (global, factory) { | ||
/** | ||
* Fixed decimal part to precision | ||
* @param {Number} value | ||
* @param {Int} precision | ||
* @returns {Number} | ||
*/ | ||
var registerdFormatters = {}; | ||
@@ -173,6 +166,14 @@ | ||
var _value = 0; | ||
var _value = value; | ||
var _averagePower = 0; | ||
if (value < 1) { | ||
_value = value * Math.pow(10, 3); | ||
if (value >= 1) { | ||
var _valueStr = (value + '').split('.')[0]; | ||
var _valueLength = _valueStr.length; | ||
_averagePower = Math.trunc(_valueLength / 3) * 3; | ||
_value = value * Math.pow(10, -_averagePower); | ||
} | ||
if (_value < 1) { | ||
_value = _value * Math.pow(10, 3); | ||
_power -= 3; | ||
@@ -184,13 +185,3 @@ | ||
} | ||
else { | ||
var _valueStr = (value + '').split('.')[0]; | ||
var _valueLength = _valueStr.length; | ||
_averagePower = Math.trunc(_valueLength / 4) * 4; | ||
if (_averagePower !== 0) { | ||
_averagePower--; | ||
} | ||
_value = value * Math.pow(10, -_averagePower); | ||
} | ||
var _localeOptions = getLocale(options.locale); | ||
@@ -197,0 +188,0 @@ var _unitPrefixes = _localeOptions.unitPrefixes; |
@@ -1,1 +0,1 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r=r||self).kittenFormat=e()}(this,function(){"use strict";var r={default:{locale:"fr-FR",currency:"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"}}};function e(e){r.default=e}function n(e){return r[e]?r[e]:r.default}var t={};function a(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var a,u,i,o=n((e=e||{}).locale),l=e.precision||o.precision,f=e.locale||o.locale;return(a=f,u=l,i=a+":"+u,t[i]||(t[i]=new Intl.NumberFormat(a,{maximumFractionDigits:u})),t[i]).format(r)}function u(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var t=null===(e=e||{}).power||void 0===e.power?0:e.power,u=e.unit;if(!u)return r;var i=0,o=0;if(r<1)i=r*Math.pow(10,3),-0===(t-=3)&&(t=0);else{var l=(r+"").split(".")[0].length;0!==(o=4*Math.trunc(l/4))&&o--,i=r*Math.pow(10,-o)}var f=n(e.locale).unitPrefixes,c=a(i,e),s=f[o+t];return void 0===s?s="10^"+(o+t)+u:"string"!=typeof s?s=s[u]||s.default:s+=u,c+" "+s}function i(r){return null==r||"string"!=typeof r?r:r.toLowerCase()}var o={};o.setOptions=e,o.locale=function(n){if(n){r[n.locale]=n;var t=function(){var r=null;r=navigator.languages&&navigator.languages.length?navigator.languages[0]:navigator.userLanguage?navigator.userLanguage:navigator.language;var e={en:"en-GB",fr:"fr-FR"};return e[r]&&(r=e[r]),r}();t!==r.default.locale&&r[t]&&e(r[t])}},o.averageN=u,o.averageNumber=u,o.lowerCase=i,o.upperCase=function(r){return null==r||"string"!=typeof r?r:r.toUpperCase()},o.upperCaseFirstChar=function(r){return null!=r&&"string"==typeof r&&r.length?r[0].toUpperCase()+i(r.slice(1,r.length)):r};var l={};function f(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var t=n((e=e||{}).locale),a=e.precision||t.precision,u=e.currency||t.currency;return function(r,e,n){n<2&&(n=2);var t=r+":"+e+":"+n;return l[t]||(l[t]=new Intl.NumberFormat(r,{maximumFractionDigits:n,currency:e,style:"currency"})),l[t]}(e.locale||t.locale,u,a).format(r)}function c(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var t=n((e=e||{}).locale),a=e.source||t.currency,u=e.target,i=e.rates;return!u||!i||i&&!i[a]||i&&!i[u]?r:r/i[a]*i[u]}return o.formatC=f,o.formatCurrency=f,o.convC=c,o.convertCurrency=c,o.formatN=a,o.formatNumber=a,o.percent=function(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var n=100*r;return r>1&&(n=r),a(n,e)+"%"},o}); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r=r||self).kittenFormat=e()}(this,function(){"use strict";var r={default:{locale:"fr-FR",currency:"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"}}};function e(e){r.default=e}function n(e){return r[e]?r[e]:r.default}var t={};function a(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var a,u,i,o=n((e=e||{}).locale),l=e.precision||o.precision,f=e.locale||o.locale;return(a=f,u=l,i=a+":"+u,t[i]||(t[i]=new Intl.NumberFormat(a,{maximumFractionDigits:u})),t[i]).format(r)}function u(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var t=null===(e=e||{}).power||void 0===e.power?0:e.power,u=e.unit;if(!u)return r;var i=r,o=0;if(r>=1){var l=(r+"").split(".")[0].length;o=3*Math.trunc(l/3),i=r*Math.pow(10,-o)}i<1&&(i*=Math.pow(10,3),-0===(t-=3)&&(t=0));var f=n(e.locale).unitPrefixes,c=a(i,e),s=f[o+t];return void 0===s?s="10^"+(o+t)+u:"string"!=typeof s?s=s[u]||s.default:s+=u,c+" "+s}function i(r){return null==r||"string"!=typeof r?r:r.toLowerCase()}var o={};o.setOptions=e,o.locale=function(n){if(n){r[n.locale]=n;var t=function(){var r=null;r=navigator.languages&&navigator.languages.length?navigator.languages[0]:navigator.userLanguage?navigator.userLanguage:navigator.language;var e={en:"en-GB",fr:"fr-FR"};return e[r]&&(r=e[r]),r}();t!==r.default.locale&&r[t]&&e(r[t])}},o.averageN=u,o.averageNumber=u,o.lowerCase=i,o.upperCase=function(r){return null==r||"string"!=typeof r?r:r.toUpperCase()},o.upperCaseFirstChar=function(r){return null!=r&&"string"==typeof r&&r.length?r[0].toUpperCase()+i(r.slice(1,r.length)):r};var l={};function f(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var t=n((e=e||{}).locale),a=e.precision||t.precision,u=e.currency||t.currency;return function(r,e,n){n<2&&(n=2);var t=r+":"+e+":"+n;return l[t]||(l[t]=new Intl.NumberFormat(r,{maximumFractionDigits:n,currency:e,style:"currency"})),l[t]}(e.locale||t.locale,u,a).format(r)}function c(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var t=n((e=e||{}).locale),a=e.source||t.currency,u=e.target,i=e.rates;return!u||!i||i&&!i[a]||i&&!i[u]?r:r/i[a]*i[u]}return o.formatC=f,o.formatCurrency=f,o.convC=c,o.convertCurrency=c,o.formatN=a,o.formatNumber=a,o.percent=function(r,e){if(null==r)return r;if("string"==typeof r&&isNaN(r))return"-";var n=100*r;return r>1&&(n=r),a(n,e)+"%"},o}); |
{ | ||
"name": "kitten-format", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "Fast formatters for browsers", | ||
@@ -5,0 +5,0 @@ "main": "kittenFormat.client.js", |
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
16486
315