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 1.2.2 to 1.3.0

src/formatTrim.js

125

build/d3-format.js

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

// https://d3js.org/d3-format/ Version 1.2.2. Copyright 2018 Mike Bostock.
// https://d3js.org/d3-format/ Version 1.3.0. Copyright 2018 Mike Bostock.
(function (global, factory) {

@@ -54,15 +54,49 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

var formatDefault = function(x, p) {
x = x.toPrecision(p);
// [[fill]align][sign][symbol][0][width][,][.precision][~][type]
var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
switch (x[i]) {
function formatSpecifier(specifier) {
return new FormatSpecifier(specifier);
}
formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
function FormatSpecifier(specifier) {
if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
var match;
this.fill = match[1] || " ";
this.align = match[2] || ">";
this.sign = match[3] || "-";
this.symbol = match[4] || "";
this.zero = !!match[5];
this.width = match[6] && +match[6];
this.comma = !!match[7];
this.precision = match[8] && +match[8].slice(1);
this.trim = !!match[9];
this.type = match[10] || "";
}
FormatSpecifier.prototype.toString = function() {
return this.fill
+ this.align
+ this.sign
+ this.symbol
+ (this.zero ? "0" : "")
+ (this.width == null ? "" : Math.max(1, this.width | 0))
+ (this.comma ? "," : "")
+ (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
+ (this.trim ? "~" : "")
+ this.type;
};
// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
var formatTrim = function(s) {
out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
switch (s[i]) {
case ".": i0 = i1 = i; break;
case "0": if (i0 === 0) i0 = i; i1 = i; break;
case "e": break out;
default: if (i0 > 0) i0 = 0; break;
default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
}
}
return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
};

@@ -96,3 +130,2 @@

var formatTypes = {
"": formatDefault,
"%": function(x, p) { return (x * 100).toFixed(p); },

@@ -113,57 +146,2 @@ "b": function(x) { return Math.round(x).toString(2); },

// [[fill]align][sign][symbol][0][width][,][.precision][type]
var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
function formatSpecifier(specifier) {
return new FormatSpecifier(specifier);
}
formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
function FormatSpecifier(specifier) {
if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
var match,
fill = match[1] || " ",
align = match[2] || ">",
sign = match[3] || "-",
symbol = match[4] || "",
zero = !!match[5],
width = match[6] && +match[6],
comma = !!match[7],
precision = match[8] && +match[8].slice(1),
type = match[9] || "";
// The "n" type is an alias for ",g".
if (type === "n") comma = true, type = "g";
// Map invalid types to the default format.
else if (!formatTypes[type]) type = "";
// If zero fill is specified, padding goes after sign and before digits.
if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
this.fill = fill;
this.align = align;
this.sign = sign;
this.symbol = symbol;
this.zero = zero;
this.width = width;
this.comma = comma;
this.precision = precision;
this.type = type;
}
FormatSpecifier.prototype.toString = function() {
return this.fill
+ this.align
+ this.sign
+ this.symbol
+ (this.zero ? "0" : "")
+ (this.width == null ? "" : Math.max(1, this.width | 0))
+ (this.comma ? "," : "")
+ (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
+ this.type;
};
var identity = function(x) {

@@ -193,4 +171,14 @@ return x;

precision = specifier.precision,
trim = specifier.trim,
type = specifier.type;
// The "n" type is an alias for ",g".
if (type === "n") comma = true, type = "g";
// The "" type, and any invalid type, is an alias for ".12~g".
else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
// If zero fill is specified, padding goes after sign and before digits.
if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
// Compute the prefix and suffix.

@@ -205,3 +193,3 @@ // For SI-prefix, the suffix is lazily computed.

var formatType = formatTypes[type],
maybeSuffix = !type || /[defgprs%]/.test(type);
maybeSuffix = /[defgprs%]/.test(type);

@@ -212,3 +200,3 @@ // Set the default precision if not specified,

// For fixed precision, it must be in [0, 20].
precision = precision == null ? (type ? 6 : 12)
precision = precision == null ? 6
: /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))

@@ -232,2 +220,5 @@ : Math.max(0, Math.min(20, precision));

// Trim insignificant zeros.
if (trim) value = formatTrim(value);
// If a negative value rounds to zero during formatting, treat as positive.

@@ -234,0 +225,0 @@ if (valueNegative && +value === 0) valueNegative = false;

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

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

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

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

```
[​[fill]align][sign][symbol][0][width][,][.precision][type]
[​[fill]align][sign][symbol][0][width][,][.precision][~][type]
```

@@ -139,2 +139,9 @@

The `~` option trims insignificant trailing zeros across all format types. This is most commonly used in conjunction with types `r`, `e`, `s` and `%`. For example:
```js
d3.format("s")(1500); // "1.50000k"
d3.format("~s")(1500); // "1.5k"
```
The available *type* values are:

@@ -155,5 +162,4 @@

* `c` - converts the integer to the corresponding unicode character before printing.
* `​` (none) - like `g`, but trim insignificant trailing zeros.
The type `n` is also supported as shorthand for `,g`. For the `g`, `n` and `​` (none) types, decimal notation is used if the resulting string would have *precision* or fewer digits; otherwise, exponent notation is used. For example:
The type `​` (none) is also supported as shorthand for `~g` (with a default precision of 12 instead of 6), and the type `n` is shorthand for `,g`. For the `g`, `n` and `​` (none) types, decimal notation is used if the resulting string would have *precision* or fewer digits; otherwise, exponent notation is used. For example:

@@ -213,2 +219,3 @@ ```js

"precision": 6,
"trim": false,
"type": "s"

@@ -222,3 +229,3 @@ }

var s = d3.formatSpecifier("f");
s.precision = precisionFixed(0.01);
s.precision = d3.precisionFixed(0.01);
var f = d3.format(s);

@@ -225,0 +232,0 @@ f(42); // "42.00";

@@ -1,6 +0,4 @@

import formatTypes from "./formatTypes";
// [[fill]align][sign][symbol][0][width][,][.precision][~][type]
var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
// [[fill]align][sign][symbol][0][width][,][.precision][type]
var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
export default function formatSpecifier(specifier) {

@@ -14,32 +12,13 @@ return new FormatSpecifier(specifier);

if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
var match,
fill = match[1] || " ",
align = match[2] || ">",
sign = match[3] || "-",
symbol = match[4] || "",
zero = !!match[5],
width = match[6] && +match[6],
comma = !!match[7],
precision = match[8] && +match[8].slice(1),
type = match[9] || "";
// The "n" type is an alias for ",g".
if (type === "n") comma = true, type = "g";
// Map invalid types to the default format.
else if (!formatTypes[type]) type = "";
// If zero fill is specified, padding goes after sign and before digits.
if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
this.fill = fill;
this.align = align;
this.sign = sign;
this.symbol = symbol;
this.zero = zero;
this.width = width;
this.comma = comma;
this.precision = precision;
this.type = type;
var match;
this.fill = match[1] || " ";
this.align = match[2] || ">";
this.sign = match[3] || "-";
this.symbol = match[4] || "";
this.zero = !!match[5];
this.width = match[6] && +match[6];
this.comma = !!match[7];
this.precision = match[8] && +match[8].slice(1);
this.trim = !!match[9];
this.type = match[10] || "";
}

@@ -56,3 +35,4 @@

+ (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
+ (this.trim ? "~" : "")
+ this.type;
};

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

import formatDefault from "./formatDefault";
import formatPrefixAuto from "./formatPrefixAuto";

@@ -6,3 +5,2 @@ import formatRounded from "./formatRounded";

export default {
"": formatDefault,
"%": function(x, p) { return (x * 100).toFixed(p); },

@@ -9,0 +7,0 @@ "b": function(x) { return Math.round(x).toString(2); },

@@ -5,2 +5,3 @@ import exponent from "./exponent";

import formatSpecifier from "./formatSpecifier";
import formatTrim from "./formatTrim";
import formatTypes from "./formatTypes";

@@ -30,4 +31,14 @@ import {prefixExponent} from "./formatPrefixAuto";

precision = specifier.precision,
trim = specifier.trim,
type = specifier.type;
// The "n" type is an alias for ",g".
if (type === "n") comma = true, type = "g";
// The "" type, and any invalid type, is an alias for ".12~g".
else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
// If zero fill is specified, padding goes after sign and before digits.
if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
// Compute the prefix and suffix.

@@ -42,3 +53,3 @@ // For SI-prefix, the suffix is lazily computed.

var formatType = formatTypes[type],
maybeSuffix = !type || /[defgprs%]/.test(type);
maybeSuffix = /[defgprs%]/.test(type);

@@ -49,3 +60,3 @@ // Set the default precision if not specified,

// For fixed precision, it must be in [0, 20].
precision = precision == null ? (type ? 6 : 12)
precision = precision == null ? 6
: /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))

@@ -69,2 +80,5 @@ : Math.max(0, Math.min(20, precision));

// Trim insignificant zeros.
if (trim) value = formatTrim(value);
// If a negative value rounds to zero during formatting, treat as positive.

@@ -71,0 +85,0 @@ if (valueNegative && +value === 0) valueNegative = false;

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