Socket
Socket
Sign inDemoInstall

d3-format

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-format - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

build/format.js

@@ -14,3 +14,3 @@ (function (global, factory) {

function formatDecimal(x, p) {
if ((i = (x = x.toExponential(p && p - 1)).indexOf("e")) < 0) return null; // NaN, ±Infinity
if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
var i, coefficient = x.slice(0, i);

@@ -17,0 +17,0 @@

@@ -1,1 +0,1 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.format={})}(this,function(t){"use strict";function n(t,n){if((r=(t=t.toExponential(n&&n-1)).indexOf("e"))<0)return null;var r,e=t.slice(0,r);return[e.length>1?e[0]+e.slice(2):e,+t.slice(r+1)]}function r(t){return t=n(Math.abs(t)),t?t[1]:0/0}function e(t,r){var e=n(t,r);if(!e)return t+"";var i=e[0],o=e[1],a=o-(g=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,u=i.length;return a===u?i:a>u?i+new Array(a-u+1).join("0"):a>0?i.slice(0,a)+"."+i.slice(a):"0."+new Array(1-a).join("0")+n(t,r+a-1)[0]}function i(t,r){var e=n(t,r);if(!e)return t+"";var i=e[0],o=e[1];return 0>o?"0."+new Array(-o).join("0")+i:i.length>o+1?i.slice(0,o+1)+"."+i.slice(o+1):i+new Array(o-i.length+2).join("0")}function o(t,n){t=t.toPrecision(n);t:for(var r,e=t.length,i=1,o=-1;e>i;++i)switch(t[i]){case".":o=r=i;break;case"0":0===o&&(o=i),r=i;break;case"e":break t;default:o>0&&(o=0)}return o>0?t.slice(0,o)+t.slice(r+1):t}function a(t){if(!(n=M.exec(t)))throw new Error("invalid format: "+t);var n,r=n[1]||" ",e=n[2]||">",i=n[3]||"-",o=n[4]||"",a=!!n[5],u=n[6]&&+n[6],s=!!n[7],c=n[8]&&+n[8].slice(1),h=n[9]||"";"n"===h?(s=!0,h="g"):d[h]||(h=""),(a||"0"===r&&"="===e)&&(a=!0,r="0",e="="),this.fill=r,this.align=e,this.sign=i,this.symbol=o,this.zero=a,this.width=u,this.comma=s,this.precision=c,this.type=h}function u(t){return new a(t)}function s(t){return t}function c(t,n){return function(r,e){for(var i=r.length,o=[],a=0,u=t[0],s=0;i>0&&u>0&&(s+u+1>e&&(u=Math.max(1,e-s)),o.push(r.substring(i-=u,i+u)),!((s+=u+1)>e));)u=t[a=(a+1)%t.length];return o.reverse().join(n)}}function h(t){function n(t){t=u(t);var n=t.fill,r=t.align,e=t.sign,s=t.symbol,c=t.zero,h=t.width,f=t.comma,l=t.precision,m=t.type,M="$"===s?o[0]:"#"===s&&/[boxX]/.test(m)?"0"+m.toLowerCase():"",x="$"===s?o[1]:/[%p]/.test(m)?"%":"",v=d[m],y=!m||/[defgprs%]/.test(m);return l=null==l?m?6:12:/[gprs]/.test(m)?Math.max(1,Math.min(21,l)):Math.max(0,Math.min(20,l)),function(t){var o=M,u=x;if("c"===m)u=v(t)+u,t="";else{t=+t;var s=(0>t||0>1/t)&&(t*=-1,!0);if(t=v(t,l),o=(s?"("===e?e:"-":"-"===e||"("===e?"":e)+o,u=u+("s"===m?p[8+g/3]:"")+(s&&"("===e?")":""),y)for(var d,b=-1,w=t.length;++b<w;)if(d=t.charCodeAt(b),48>d||d>57){u=(46===d?a+t.slice(b+1):t.slice(b))+u,t=t.slice(0,b);break}}f&&!c&&(t=i(t,1/0));var j=o.length+t.length+u.length,P=h>j?new Array(h-j+1).join(n):"";switch(f&&c&&(t=i(P+t,P.length?h-u.length:1/0),P=""),r){case"<":return o+t+u+P;case"=":return o+P+t+u;case"^":return P.slice(0,j=P.length>>1)+o+t+u+P.slice(j)}return P+o+t+u}}function e(t,e){var i=n((t=u(t),t.type="f",t)),o=3*Math.max(-8,Math.min(8,Math.floor(r(e)/3))),a=Math.pow(10,-o),s=p[8+o/3];return function(t){return i(a*t)+s}}var i=t.grouping&&t.thousands?c(t.grouping,t.thousands):s,o=t.currency,a=t.decimal;return{format:n,formatPrefix:e}}function f(t,n){return Math.max(0,r(Math.abs(n))-r(Math.abs(t)))+1}function l(t,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(r(n)/3)))-r(Math.abs(t)))}function m(t){return Math.max(0,-r(Math.abs(t)))}var g,p=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],d={"":o,"%":function(t,n){return(100*t).toFixed(n)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.round(t).toString(10)},e:function(t,n){return t.toExponential(n)},f:function(t,n){return t.toFixed(n)},g:function(t,n){return t.toPrecision(n)},o:function(t){return Math.round(t).toString(8)},p:function(t,n){return i(100*t,n)},r:i,s:e,X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}},M=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;a.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(null==this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(null==this.precision?"":"."+Math.max(0,0|this.precision))+this.type};var x=h({decimal:".",thousands:",",grouping:[3],currency:["$",""]});t.format=x.format,t.formatPrefix=x.formatPrefix,t.formatSpecifier=u,t.localeFormat=h,t.precisionFixed=m,t.precisionPrefix=l,t.precisionRound=f});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.format={})}(this,function(t){"use strict";function n(t,n){if((r=(t=n?t.toExponential(n-1):t.toExponential()).indexOf("e"))<0)return null;var r,e=t.slice(0,r);return[e.length>1?e[0]+e.slice(2):e,+t.slice(r+1)]}function r(t){return t=n(Math.abs(t)),t?t[1]:0/0}function e(t,r){var e=n(t,r);if(!e)return t+"";var i=e[0],o=e[1],a=o-(g=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,u=i.length;return a===u?i:a>u?i+new Array(a-u+1).join("0"):a>0?i.slice(0,a)+"."+i.slice(a):"0."+new Array(1-a).join("0")+n(t,r+a-1)[0]}function i(t,r){var e=n(t,r);if(!e)return t+"";var i=e[0],o=e[1];return 0>o?"0."+new Array(-o).join("0")+i:i.length>o+1?i.slice(0,o+1)+"."+i.slice(o+1):i+new Array(o-i.length+2).join("0")}function o(t,n){t=t.toPrecision(n);t:for(var r,e=t.length,i=1,o=-1;e>i;++i)switch(t[i]){case".":o=r=i;break;case"0":0===o&&(o=i),r=i;break;case"e":break t;default:o>0&&(o=0)}return o>0?t.slice(0,o)+t.slice(r+1):t}function a(t){if(!(n=M.exec(t)))throw new Error("invalid format: "+t);var n,r=n[1]||" ",e=n[2]||">",i=n[3]||"-",o=n[4]||"",a=!!n[5],u=n[6]&&+n[6],s=!!n[7],c=n[8]&&+n[8].slice(1),h=n[9]||"";"n"===h?(s=!0,h="g"):d[h]||(h=""),(a||"0"===r&&"="===e)&&(a=!0,r="0",e="="),this.fill=r,this.align=e,this.sign=i,this.symbol=o,this.zero=a,this.width=u,this.comma=s,this.precision=c,this.type=h}function u(t){return new a(t)}function s(t){return t}function c(t,n){return function(r,e){for(var i=r.length,o=[],a=0,u=t[0],s=0;i>0&&u>0&&(s+u+1>e&&(u=Math.max(1,e-s)),o.push(r.substring(i-=u,i+u)),!((s+=u+1)>e));)u=t[a=(a+1)%t.length];return o.reverse().join(n)}}function h(t){function n(t){t=u(t);var n=t.fill,r=t.align,e=t.sign,s=t.symbol,c=t.zero,h=t.width,f=t.comma,l=t.precision,m=t.type,M="$"===s?o[0]:"#"===s&&/[boxX]/.test(m)?"0"+m.toLowerCase():"",x="$"===s?o[1]:/[%p]/.test(m)?"%":"",v=d[m],y=!m||/[defgprs%]/.test(m);return l=null==l?m?6:12:/[gprs]/.test(m)?Math.max(1,Math.min(21,l)):Math.max(0,Math.min(20,l)),function(t){var o=M,u=x;if("c"===m)u=v(t)+u,t="";else{t=+t;var s=(0>t||0>1/t)&&(t*=-1,!0);if(t=v(t,l),o=(s?"("===e?e:"-":"-"===e||"("===e?"":e)+o,u=u+("s"===m?p[8+g/3]:"")+(s&&"("===e?")":""),y)for(var d,b=-1,w=t.length;++b<w;)if(d=t.charCodeAt(b),48>d||d>57){u=(46===d?a+t.slice(b+1):t.slice(b))+u,t=t.slice(0,b);break}}f&&!c&&(t=i(t,1/0));var j=o.length+t.length+u.length,P=h>j?new Array(h-j+1).join(n):"";switch(f&&c&&(t=i(P+t,P.length?h-u.length:1/0),P=""),r){case"<":return o+t+u+P;case"=":return o+P+t+u;case"^":return P.slice(0,j=P.length>>1)+o+t+u+P.slice(j)}return P+o+t+u}}function e(t,e){var i=n((t=u(t),t.type="f",t)),o=3*Math.max(-8,Math.min(8,Math.floor(r(e)/3))),a=Math.pow(10,-o),s=p[8+o/3];return function(t){return i(a*t)+s}}var i=t.grouping&&t.thousands?c(t.grouping,t.thousands):s,o=t.currency,a=t.decimal;return{format:n,formatPrefix:e}}function f(t,n){return Math.max(0,r(Math.abs(n))-r(Math.abs(t)))+1}function l(t,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(r(n)/3)))-r(Math.abs(t)))}function m(t){return Math.max(0,-r(Math.abs(t)))}var g,p=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],d={"":o,"%":function(t,n){return(100*t).toFixed(n)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.round(t).toString(10)},e:function(t,n){return t.toExponential(n)},f:function(t,n){return t.toFixed(n)},g:function(t,n){return t.toPrecision(n)},o:function(t){return Math.round(t).toString(8)},p:function(t,n){return i(100*t,n)},r:i,s:e,X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}},M=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;a.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(null==this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(null==this.precision?"":"."+Math.max(0,0|this.precision))+this.type};var x=h({decimal:".",thousands:",",grouping:[3],currency:["$",""]});t.format=x.format,t.formatPrefix=x.formatPrefix,t.formatSpecifier=u,t.localeFormat=h,t.precisionFixed=m,t.precisionPrefix=l,t.precisionRound=f});
{
"name": "d3-format",
"version": "0.2.2",
"version": "0.2.3",
"description": "Format numbers for human consumption.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -169,3 +169,3 @@ # d3-format

This method is useful when formatting multiple numbers in the same units for easy comparison. See [precisionPrefix](#precisionPrefix) for help picking an appropriate precision.
This method is useful when formatting multiple numbers in the same units for easy comparison. See [precisionPrefix](#precisionPrefix) for help picking an appropriate precision, and [bl.ocks.org/9764126](http://bl.ocks.org/mbostock/9764126) for an example.

@@ -172,0 +172,0 @@ <a name="localeFormat" href="#localeFormat">#</a> <b>localeFormat</b>(<i>definition</i>)

@@ -5,3 +5,3 @@ // Computes the decimal coefficient and exponent of the specified number x with

export default function(x, p) {
if ((i = (x = x.toExponential(p && p - 1)).indexOf("e")) < 0) return null; // NaN, ±Infinity
if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
var i, coefficient = x.slice(0, i);

@@ -8,0 +8,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc