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.4.0 to 0.4.1

2

build/bundle.js

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

var version = "0.4.0"; export * from "../index"; export {version};
var version = "0.4.1"; export * from "../index"; export {version};

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

var version = "0.4.0";
var version = "0.4.1";

@@ -456,0 +456,0 @@ exports.version = version;

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

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-format",["exports"],r):r(n.d3_format={})}(this,function(n){"use strict";function r(n,r){if((t=(n=r?n.toExponential(r-1):n.toExponential()).indexOf("e"))<0)return null;var t,e=n.slice(0,t);return[e.length>1?e[0]+e.slice(2):e,+n.slice(t+1)]}function t(n){return n=r(Math.abs(n)),n?n[1]:NaN}function e(n,r){return function(t,e){for(var i=t.length,o=[],a=0,c=n[0],u=0;i>0&&c>0&&(u+c+1>e&&(c=Math.max(1,e-u)),o.push(t.substring(i-=c,i+c)),!((u+=c+1)>e));)c=n[a=(a+1)%n.length];return o.reverse().join(r)}}function i(n,t){var e=r(n,t);if(!e)return n+"";var i=e[0],o=e[1],a=o-(d=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,c=i.length;return a===c?i:a>c?i+new Array(a-c+1).join("0"):a>0?i.slice(0,a)+"."+i.slice(a):"0."+new Array(1-a).join("0")+r(n,Math.max(0,t+a-1))[0]}function o(n,t){var e=r(n,t);if(!e)return n+"";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 a(n,r){n=n.toPrecision(r);n:for(var t,e=n.length,i=1,o=-1;e>i;++i)switch(n[i]){case".":o=t=i;break;case"0":0===o&&(o=i),t=i;break;case"e":break n;default:o>0&&(o=0)}return o>0?n.slice(0,o)+n.slice(t+1):n}function c(n){return new u(n)}function u(n){if(!(r=p.exec(n)))throw new Error("invalid format: "+n);var r,t=r[1]||" ",e=r[2]||">",i=r[3]||"-",o=r[4]||"",a=!!r[5],c=r[6]&&+r[6],u=!!r[7],s=r[8]&&+r[8].slice(1),l=r[9]||"";"n"===l?(u=!0,l="g"):m[l]||(l=""),(a||"0"===t&&"="===e)&&(a=!0,t="0",e="="),this.fill=t,this.align=e,this.sign=i,this.symbol=o,this.zero=a,this.width=c,this.comma=u,this.precision=s,this.type=l}function s(n){return n}function l(n){function r(n){n=c(n);var r=n.fill,t=n.align,e=n.sign,i=n.symbol,s=n.zero,l=n.width,h=n.comma,f=n.precision,g=n.type,p="$"===i?a[0]:"#"===i&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",M="$"===i?a[1]:/[%p]/.test(g)?"%":"",x=m[g],v=!g||/[defgprs%]/.test(g);return f=null==f?g?6:12:/[gprs]/.test(g)?Math.max(1,Math.min(21,f)):Math.max(0,Math.min(20,f)),function(n){var i=p,a=M;if("c"===g)a=x(n)+a,n="";else{n=+n;var c=(0>n||0>1/n)&&(n*=-1,!0);if(n=x(n,f),c){var m,b=-1,w=n.length;for(c=!1;++b<w;)if(m=n.charCodeAt(b),m>48&&58>m||"x"===g&&m>96&&103>m||"X"===g&&m>64&&71>m){c=!0;break}}if(i=(c?"("===e?e:"-":"-"===e||"("===e?"":e)+i,a=a+("s"===g?y[8+d/3]:"")+(c&&"("===e?")":""),v)for(var m,b=-1,w=n.length;++b<w;)if(m=n.charCodeAt(b),48>m||m>57){a=(46===m?u+n.slice(b+1):n.slice(b))+a,n=n.slice(0,b);break}}h&&!s&&(n=o(n,1/0));var E=i.length+n.length+a.length,C=l>E?new Array(l-E+1).join(r):"";switch(h&&s&&(n=o(C+n,C.length?l-a.length:1/0),C=""),t){case"<":return i+n+a+C;case"=":return i+C+n+a;case"^":return C.slice(0,E=C.length>>1)+i+n+a+C.slice(E)}return C+i+n+a}}function i(n,e){var i=r((n=c(n),n.type="f",n)),o=3*Math.max(-8,Math.min(8,Math.floor(t(e)/3))),a=Math.pow(10,-o),u=y[8+o/3];return function(n){return i(a*n)+u}}var o=n.grouping&&n.thousands?e(n.grouping,n.thousands):s,a=n.currency,u=n.decimal;return{format:r,formatPrefix:i}}function h(n){return Math.max(0,-t(Math.abs(n)))}function f(n,r){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(t(r)/3)))-t(Math.abs(n)))}function g(n,r){return Math.max(0,t(Math.abs(r))-t(Math.abs(n)))+1}var d,m={"":a,"%":function(n,r){return(100*n).toFixed(r)},b:function(n){return Math.round(n).toString(2)},c:function(n){return n+""},d:function(n){return Math.round(n).toString(10)},e:function(n,r){return n.toExponential(r)},f:function(n,r){return n.toFixed(r)},g:function(n,r){return n.toPrecision(r)},o:function(n){return Math.round(n).toString(8)},p:function(n,r){return o(100*n,r)},r:o,s:i,X:function(n){return Math.round(n).toString(16).toUpperCase()},x:function(n){return Math.round(n).toString(16)}},p=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;u.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 y=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],M=l({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),x=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),v=l({decimal:",",thousands:"'",grouping:[3],currency:[""," CHF"]}),b=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),w=l({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),E=l({decimal:".",thousands:",",grouping:[3],currency:["£",""]}),C=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),F=l({decimal:",",thousands:" ",grouping:[3],currency:[""," €"]}),P=l({decimal:",",thousands:" ",grouping:[3],currency:["","$"]}),S=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),k=l({decimal:".",thousands:",",grouping:[3],currency:["₪",""]}),$=l({decimal:",",thousands:" ",grouping:[3],currency:[""," Ft"]}),j=l({decimal:",",thousands:".",grouping:[3],currency:["€",""]}),A=l({decimal:".",thousands:",",grouping:[3],currency:["","円"]}),z=l({decimal:".",thousands:",",grouping:[3],currency:["₩",""]}),H=l({decimal:",",thousands:".",grouping:[3],currency:[""," ден."]}),N=l({decimal:",",thousands:".",grouping:[3],currency:["€ ",""]}),R=l({decimal:",",thousands:".",grouping:[3],currency:["","zł"]}),D=l({decimal:",",thousands:".",grouping:[3],currency:["R$",""]}),I=l({decimal:",",thousands:" ",grouping:[3],currency:[""," руб."]}),K=l({decimal:",",thousands:" ",grouping:[3],currency:["","SEK"]}),X=l({decimal:".",thousands:",",grouping:[3],currency:["¥",""]}),G=M.format,J=M.formatPrefix,U="0.4.0";n.version=U,n.format=G,n.formatPrefix=J,n.locale=l,n.localeCaEs=x,n.localeDeCh=v,n.localeDeDe=b,n.localeEnCa=w,n.localeEnGb=E,n.localeEnUs=M,n.localeEsEs=C,n.localeFiFi=F,n.localeFrCa=P,n.localeFrFr=S,n.localeHeIl=k,n.localeHuHu=$,n.localeItIt=j,n.localeJaJp=A,n.localeKoKr=z,n.localeMkMk=H,n.localeNlNl=N,n.localePlPl=R,n.localePtBr=D,n.localeRuRu=I,n.localeSvSe=K,n.localeZhCn=X,n.formatSpecifier=c,n.precisionFixed=h,n.precisionPrefix=f,n.precisionRound=g});
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-format",["exports"],r):r(n.d3_format={})}(this,function(n){"use strict";function r(n,r){if((t=(n=r?n.toExponential(r-1):n.toExponential()).indexOf("e"))<0)return null;var t,e=n.slice(0,t);return[e.length>1?e[0]+e.slice(2):e,+n.slice(t+1)]}function t(n){return n=r(Math.abs(n)),n?n[1]:NaN}function e(n,r){return function(t,e){for(var i=t.length,o=[],a=0,c=n[0],u=0;i>0&&c>0&&(u+c+1>e&&(c=Math.max(1,e-u)),o.push(t.substring(i-=c,i+c)),!((u+=c+1)>e));)c=n[a=(a+1)%n.length];return o.reverse().join(r)}}function i(n,t){var e=r(n,t);if(!e)return n+"";var i=e[0],o=e[1],a=o-(d=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,c=i.length;return a===c?i:a>c?i+new Array(a-c+1).join("0"):a>0?i.slice(0,a)+"."+i.slice(a):"0."+new Array(1-a).join("0")+r(n,Math.max(0,t+a-1))[0]}function o(n,t){var e=r(n,t);if(!e)return n+"";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 a(n,r){n=n.toPrecision(r);n:for(var t,e=n.length,i=1,o=-1;e>i;++i)switch(n[i]){case".":o=t=i;break;case"0":0===o&&(o=i),t=i;break;case"e":break n;default:o>0&&(o=0)}return o>0?n.slice(0,o)+n.slice(t+1):n}function c(n){return new u(n)}function u(n){if(!(r=p.exec(n)))throw new Error("invalid format: "+n);var r,t=r[1]||" ",e=r[2]||">",i=r[3]||"-",o=r[4]||"",a=!!r[5],c=r[6]&&+r[6],u=!!r[7],s=r[8]&&+r[8].slice(1),l=r[9]||"";"n"===l?(u=!0,l="g"):m[l]||(l=""),(a||"0"===t&&"="===e)&&(a=!0,t="0",e="="),this.fill=t,this.align=e,this.sign=i,this.symbol=o,this.zero=a,this.width=c,this.comma=u,this.precision=s,this.type=l}function s(n){return n}function l(n){function r(n){n=c(n);var r=n.fill,t=n.align,e=n.sign,i=n.symbol,s=n.zero,l=n.width,h=n.comma,f=n.precision,g=n.type,p="$"===i?a[0]:"#"===i&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",M="$"===i?a[1]:/[%p]/.test(g)?"%":"",x=m[g],v=!g||/[defgprs%]/.test(g);return f=null==f?g?6:12:/[gprs]/.test(g)?Math.max(1,Math.min(21,f)):Math.max(0,Math.min(20,f)),function(n){var i=p,a=M;if("c"===g)a=x(n)+a,n="";else{n=+n;var c=(0>n||0>1/n)&&(n*=-1,!0);if(n=x(n,f),c){var m,b=-1,w=n.length;for(c=!1;++b<w;)if(m=n.charCodeAt(b),m>48&&58>m||"x"===g&&m>96&&103>m||"X"===g&&m>64&&71>m){c=!0;break}}if(i=(c?"("===e?e:"-":"-"===e||"("===e?"":e)+i,a=a+("s"===g?y[8+d/3]:"")+(c&&"("===e?")":""),v)for(var m,b=-1,w=n.length;++b<w;)if(m=n.charCodeAt(b),48>m||m>57){a=(46===m?u+n.slice(b+1):n.slice(b))+a,n=n.slice(0,b);break}}h&&!s&&(n=o(n,1/0));var E=i.length+n.length+a.length,C=l>E?new Array(l-E+1).join(r):"";switch(h&&s&&(n=o(C+n,C.length?l-a.length:1/0),C=""),t){case"<":return i+n+a+C;case"=":return i+C+n+a;case"^":return C.slice(0,E=C.length>>1)+i+n+a+C.slice(E)}return C+i+n+a}}function i(n,e){var i=r((n=c(n),n.type="f",n)),o=3*Math.max(-8,Math.min(8,Math.floor(t(e)/3))),a=Math.pow(10,-o),u=y[8+o/3];return function(n){return i(a*n)+u}}var o=n.grouping&&n.thousands?e(n.grouping,n.thousands):s,a=n.currency,u=n.decimal;return{format:r,formatPrefix:i}}function h(n){return Math.max(0,-t(Math.abs(n)))}function f(n,r){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(t(r)/3)))-t(Math.abs(n)))}function g(n,r){return Math.max(0,t(Math.abs(r))-t(Math.abs(n)))+1}var d,m={"":a,"%":function(n,r){return(100*n).toFixed(r)},b:function(n){return Math.round(n).toString(2)},c:function(n){return n+""},d:function(n){return Math.round(n).toString(10)},e:function(n,r){return n.toExponential(r)},f:function(n,r){return n.toFixed(r)},g:function(n,r){return n.toPrecision(r)},o:function(n){return Math.round(n).toString(8)},p:function(n,r){return o(100*n,r)},r:o,s:i,X:function(n){return Math.round(n).toString(16).toUpperCase()},x:function(n){return Math.round(n).toString(16)}},p=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;u.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 y=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],M=l({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),x=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),v=l({decimal:",",thousands:"'",grouping:[3],currency:[""," CHF"]}),b=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),w=l({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),E=l({decimal:".",thousands:",",grouping:[3],currency:["£",""]}),C=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),F=l({decimal:",",thousands:" ",grouping:[3],currency:[""," €"]}),P=l({decimal:",",thousands:" ",grouping:[3],currency:["","$"]}),S=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),k=l({decimal:".",thousands:",",grouping:[3],currency:["₪",""]}),$=l({decimal:",",thousands:" ",grouping:[3],currency:[""," Ft"]}),j=l({decimal:",",thousands:".",grouping:[3],currency:["€",""]}),A=l({decimal:".",thousands:",",grouping:[3],currency:["","円"]}),z=l({decimal:".",thousands:",",grouping:[3],currency:["₩",""]}),H=l({decimal:",",thousands:".",grouping:[3],currency:[""," ден."]}),N=l({decimal:",",thousands:".",grouping:[3],currency:["€ ",""]}),R=l({decimal:",",thousands:".",grouping:[3],currency:["","zł"]}),D=l({decimal:",",thousands:".",grouping:[3],currency:["R$",""]}),I=l({decimal:",",thousands:" ",grouping:[3],currency:[""," руб."]}),K=l({decimal:",",thousands:" ",grouping:[3],currency:["","SEK"]}),X=l({decimal:".",thousands:",",grouping:[3],currency:["¥",""]}),G=M.format,J=M.formatPrefix,U="0.4.1";n.version=U,n.format=G,n.formatPrefix=J,n.locale=l,n.localeCaEs=x,n.localeDeCh=v,n.localeDeDe=b,n.localeEnCa=w,n.localeEnGb=E,n.localeEnUs=M,n.localeEsEs=C,n.localeFiFi=F,n.localeFrCa=P,n.localeFrFr=S,n.localeHeIl=k,n.localeHuHu=$,n.localeItIt=j,n.localeJaJp=A,n.localeKoKr=z,n.localeMkMk=H,n.localeNlNl=N,n.localePlPl=R,n.localePtBr=D,n.localeRuRu=I,n.localeSvSe=K,n.localeZhCn=X,n.formatSpecifier=c,n.precisionFixed=h,n.precisionPrefix=f,n.precisionRound=g});
{
"name": "d3-format",
"version": "0.4.0",
"version": "0.4.1",
"description": "Format numbers for human consumption.",

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

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

```js
var f = format(".1f");
var f = d3_format.format(".1f");
for (var i = 0; i < 10; i++) {

@@ -58,9 +58,9 @@ console.log(f(0.1 * i));

```js
format(".0%")(0.123); // rounded percentage, "12%"
format("($.2f")(-3.5); // localized fixed-point currency, "(£3.50)"
format("+20")(42); // space-filled and signed, " +42"
format(".^20")(42); // dot-filled and centered, ".........42........."
format(".2s")(42e6); // SI-prefix with two significant digits, "42M"
format("#x")(48879); // prefixed lowercase hexadecimal, "0xbeef"
format(",.2r")(4223); // grouped thousands with two significant digits, "4,200"
d3_format.format(".0%")(0.123); // rounded percentage, "12%"
d3_format.format("($.2f")(-3.5); // localized fixed-point currency, "(£3.50)"
d3_format.format("+20")(42); // space-filled and signed, " +42"
d3_format.format(".^20")(42); // dot-filled and centered, ".........42........."
d3_format.format(".2s")(42e6); // SI-prefix with two significant digits, "42M"
d3_format.format("#x")(48879); // prefixed lowercase hexadecimal, "0xbeef"
d3_format.format(",.2r")(4223); // grouped thousands with two significant digits, "4,200"
```

@@ -72,13 +72,19 @@

If you use NPM, `npm install d3-format`. Otherwise, download the [latest release](https://github.com/d3/d3-format/releases/latest).
If you use NPM, `npm install d3-format`. Otherwise, download the [latest release](https://github.com/d3/d3-format/releases/latest). The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom build using [Rollup](https://github.com/rollup/rollup) or your preferred bundler. You can also load directly from [d3js.org](https://d3js.org):
```html
<script src="https://d3js.org/d3-format.v0.4.min.js"></script>
```
In a vanilla environment, a `d3_format` global is exported. [Try d3-format in your browser.](https://tonicdev.com/npm/d3-format)
## API Reference
<a name="format" href="#format">#</a> <b>format</b>(<i>specifier</i>)
<a name="format" href="#format">#</a> d3_format.<b>format</b>(<i>specifier</i>)
An alias for [*locale*.format](#locale_format) on the [U.S. English](#enUs) locale. See the other [locales](#locales), or use [locale](#locale) to define a new locale.
An alias for [*locale*.format](#locale_format) on the [U.S. English locale](#localeEnUs). See the other [locales](#locales), or use [locale](#locale) to define a new locale.
<a name="formatPrefix" href="#formatPrefix">#</a> <b>formatPrefix</b>(<i>specifier</i>, <i>value</i>)
<a name="formatPrefix" href="#formatPrefix">#</a> d3_format.<b>formatPrefix</b>(<i>specifier</i>, <i>value</i>)
An alias for [*locale*.formatPrefix](#locale_formatPrefix) on the [U.S. English](#enUs) locale. See the other [locales](#locales), or use [locale](#locale) to define a new locale.
An alias for [*locale*.formatPrefix](#locale_formatPrefix) on the [U.S. English locale](#localeEnUs). See the other [locales](#locales), or use [locale](#locale) to define a new locale.

@@ -136,6 +142,6 @@ <a name="locale_format" href="#locale_format">#</a> <i>locale</i>.<b>format</b>(<i>specifier</i>)

```js
format(".2")(42); // "42"
format(".2")(4.2); // "4.2"
format(".1")(42); // "4e+1"
format(".1")(4.2); // "4"
d3_format.format(".2")(42); // "42"
d3_format.format(".2")(4.2); // "4.2"
d3_format.format(".1")(42); // "4e+1"
d3_format.format(".1")(4.2); // "4"
```

@@ -168,3 +174,3 @@

```js
var f = formatPrefix(",.0", 1e-6);
var f = d3_format.formatPrefix(",.0", 1e-6);
f(0.00042); // "420µ"

@@ -176,3 +182,3 @@ f(0.0042); // "4,200µ"

<a name="formatSpecifier" href="#formatSpecifier">#</a> <b>formatSpecifier</b>(<i>specifier</i>)
<a name="formatSpecifier" href="#formatSpecifier">#</a> d3_format.<b>formatSpecifier</b>(<i>specifier</i>)

@@ -198,9 +204,9 @@ Parses the specified *specifier*, returning an object with exposed fields that correspond to the [format specification mini-language](#locale_format) and a toString method that reconstructs the specifier. For example, `formatSpecifier("s")` returns:

```js
var s = formatSpecifier("f");
var s = d3_format.formatSpecifier("f");
s.precision = precisionFixed(0.01);
var f = format(s);
var f = d3_format.format(s);
f(42); // "42.00";
```
<a name="precisionFixed" href="#precisionFixed">#</a> <b>precisionFixed</b>(<i>step</i>)
<a name="precisionFixed" href="#precisionFixed">#</a> d3_format.<b>precisionFixed</b>(<i>step</i>)

@@ -210,4 +216,4 @@ Returns a suggested decimal precision for fixed point notation given the specified numeric *step* value. The *step* represents the minimum absolute difference between values that will be formatted. (This assumes that the values to be formatted are also multiples of *step*.) For example, given the numbers 1, 1.5, and 2, the *step* should be 0.5 and the suggested precision is 1:

```js
var p = precisionFixed(0.5),
f = format("." + p + "f");
var p = d3_format.precisionFixed(0.5),
f = d3_format.format("." + p + "f");
f(1); // "1.0"

@@ -221,4 +227,4 @@ f(1.5); // "1.5"

```js
var p = precisionFixed(1),
f = format("." + p + "f");
var p = d3_format.precisionFixed(1),
f = d3_format.format("." + p + "f");
f(1); // "1"

@@ -232,4 +238,4 @@ f(2); // "2"

```js
var p = Math.max(0, precisionFixed(0.05) - 2),
f = format("." + p + "%");
var p = Math.max(0, d3_format.precisionFixed(0.05) - 2),
f = d3_format.format("." + p + "%");
f(0.45); // "45%"

@@ -240,3 +246,3 @@ f(0.50); // "50%"

<a name="precisionPrefix" href="#precisionPrefix">#</a> <b>precisionPrefix</b>(<i>step</i>, <i>value</i>)
<a name="precisionPrefix" href="#precisionPrefix">#</a> d3_format.<b>precisionPrefix</b>(<i>step</i>, <i>value</i>)

@@ -246,4 +252,4 @@ Returns a suggested decimal precision for use with [*locale*.formatPrefix](#locale_formatPrefix) given the specified numeric *step* and reference *value*. The *step* represents the minimum absolute difference between values that will be formatted, and *value* determines which SI prefix will be used. (This assumes that the values to be formatted are also multiples of *step*.) For example, given the numbers 1.1e6, 1.2e6, and 1.3e6, the *step* should be 1e5, the *value* could be 1.3e6, and the suggested precision is 1:

```js
var p = precisionPrefix(1e5, 1.3e6),
f = formatPrefix("." + p, 1.3e6);
var p = d3_format.precisionPrefix(1e5, 1.3e6),
f = d3_format.formatPrefix("." + p, 1.3e6);
f(1.1e6); // "1.1M"

@@ -254,3 +260,3 @@ f(1.2e6); // "1.2M"

<a name="precisionRound" href="#precisionRound">#</a> <b>precisionRound</b>(<i>step</i>, <i>max</i>)
<a name="precisionRound" href="#precisionRound">#</a> d3_format.<b>precisionRound</b>(<i>step</i>, <i>max</i>)

@@ -260,4 +266,4 @@ Returns a suggested decimal precision for format types that round to significant digits given the specified numeric *step* and *max* values. The *step* represents the minimum absolute difference between values that will be formatted, and the *max* represents the largest absolute value that will be formatted. (This assumes that the values to be formatted are also multiples of *step*.) For example, given the numbers 0.99, 1.0, and 1.01, the *step* should be 0.01, the *max* should be 1.01, and the suggested precision is 3:

```js
var p = precisionRound(0.01, 1.01),
f = format("." + p + "r");
var p = d3_format.precisionRound(0.01, 1.01),
f = d3_format.format("." + p + "r");
f(0.99); // "0.990"

@@ -271,4 +277,4 @@ f(1.0); // "1.00"

```js
var p = precisionRound(0.1, 1.1),
f = format("." + p + "r");
var p = d3_format.precisionRound(0.1, 1.1),
f = d3_format.format("." + p + "r");
f(0.9); // "0.90"

@@ -282,4 +288,4 @@ f(1.0); // "1.0"

```js
var p = Math.max(0, precisionRound(0.01, 1.01) - 1),
f = format("." + p + "e");
var p = Math.max(0, d3_format.precisionRound(0.01, 1.01) - 1),
f = d3_format.format("." + p + "e");
f(0.01); // "1.00e-2"

@@ -291,3 +297,3 @@ f(1.01); // "1.01e+0"

<a name="locale" href="#locale">#</a> <b>locale</b>(<i>definition</i>)
<a name="locale" href="#locale">#</a> d3_format.<b>locale</b>(<i>definition</i>)

@@ -303,89 +309,88 @@ Returns a *locale* object for the specified *definition* with [*locale*.format](#locale_format) and [*locale*.formatPrefix](#locale_formatPrefix) methods. The *definition* must include the following properties:

<a name="localeCaEs" href="#localeCaEs">#</a> <b>localeCaEs</b>
<a name="localeCaEs" href="#localeCaEs">#</a> d3_format.<b>localeCaEs</b>
[Catalan (Spain)](https://github.com/d3/d3-format/tree/master/src/locale/ca-ES.js)
<a name="localeDeCh" href="#localeDeCh">#</a> <b>localeDeCh</b>
<a name="localeDeCh" href="#localeDeCh">#</a> d3_format.<b>localeDeCh</b>
[German (Switzerland)](https://github.com/d3/d3-format/tree/master/src/locale/de-CH.js)
<a name="localeDeDe" href="#localeDeDe">#</a> <b>localeDeDe</b>
<a name="localeDeDe" href="#localeDeDe">#</a> d3_format.<b>localeDeDe</b>
[German (Germany)](https://github.com/d3/d3-format/tree/master/src/locale/de-DE.js)
<a name="localeEnCa" href="#localeEnCa">#</a> <b>localeEnCa</b>
<a name="localeEnCa" href="#localeEnCa">#</a> d3_format.<b>localeEnCa</b>
[English (Canada)](https://github.com/d3/d3-format/tree/master/src/locale/en-CA.js)
<a name="localeEnGb" href="#localeEnGb">#</a> <b>localeEnGb</b>
<a name="localeEnGb" href="#localeEnGb">#</a> d3_format.<b>localeEnGb</b>
[English (United Kingdom)](https://github.com/d3/d3-format/tree/master/src/locale/en-GB.js)
<a name="localeEnUs" href="#localeEnUs">#</a> <b>localeEnUs</b>
<a name="localeEnUs" href="#localeEnUs">#</a> d3_format.<b>localeEnUs</b>
[English (United States)](https://github.com/d3/d3-format/tree/master/src/locale/en-US.js)
<a name="localeEsEs" href="#localeEsEs">#</a> <b>localeEsEs</b>
<a name="localeEsEs" href="#localeEsEs">#</a> d3_format.<b>localeEsEs</b>
[Spanish (Spain)](https://github.com/d3/d3-format/tree/master/src/locale/es-ES.js)
<a name="localeFiFi" href="#localeFiFi">#</a> <b>localeFiFi</b>
<a name="localeFiFi" href="#localeFiFi">#</a> d3_format.<b>localeFiFi</b>
[Finnish (Finland)](https://github.com/d3/d3-format/tree/master/src/locale/fi-FI.js)
<a name="localeFrCa" href="#localeFrCa">#</a> <b>localeFrCa</b>
<a name="localeFrCa" href="#localeFrCa">#</a> d3_format.<b>localeFrCa</b>
[French (Canada)](https://github.com/d3/d3-format/tree/master/src/locale/fr-CA.js)
<a name="localeFrFr" href="#localeFrFr">#</a> <b>localeFrFr</b>
<a name="localeFrFr" href="#localeFrFr">#</a> d3_format.<b>localeFrFr</b>
[French (France)](https://github.com/d3/d3-format/tree/master/src/locale/fr-FR.js)
<a name="localeHeIl" href="#localeHeIl">#</a> <b>localeHeIl</b>
<a name="localeHeIl" href="#localeHeIl">#</a> d3_format.<b>localeHeIl</b>
[Hebrew (Israel)](https://github.com/d3/d3-format/tree/master/src/locale/he-IL.js)
<a name="localeHuHu" href="#localeHuHu">#</a> <b>localeHuHu</b>
<a name="localeHuHu" href="#localeHuHu">#</a> d3_format.<b>localeHuHu</b>
[Hungarian (Hungary)](https://github.com/d3/d3-format/tree/master/src/locale/hu-HU.js)
<a name="localeItIt" href="#localeItIt">#</a> <b>localeItIt</b>
<a name="localeItIt" href="#localeItIt">#</a> d3_format.<b>localeItIt</b>
[Italian (Italy)](https://github.com/d3/d3-format/tree/master/src/locale/it-IT.js)
<a name="localeJaJp" href="#localeJaJp">#</a> <b>localeJaJp</b>
<a name="localeJaJp" href="#localeJaJp">#</a> d3_format.<b>localeJaJp</b>
[Japanese (Japan)](https://github.com/d3/d3-format/tree/master/src/locale/ja-JP.js)
<a name="localeKoKr" href="#localeKoKr">#</a> <b>localeKoKr</b>
<a name="localeKoKr" href="#localeKoKr">#</a> d3_format.<b>localeKoKr</b>
[Korean (South Korea)](https://github.com/d3/d3-format/tree/master/src/locale/ko-KR.js)
<a name="localeMkMk" href="#localeMkMk">#</a> <b>localeMkMk</b>
<a name="localeMkMk" href="#localeMkMk">#</a> d3_format.<b>localeMkMk</b>
[Macedonian (Macedonia)](https://github.com/d3/d3-format/tree/master/src/locale/mk-MK.js)
<a name="localeNlNl" href="#localeNlNl">#</a> <b>localeNlNl</b>
<a name="localeNlNl" href="#localeNlNl">#</a> d3_format.<b>localeNlNl</b>
[Dutch (Netherlands)](https://github.com/d3/d3-format/tree/master/src/locale/nl-NL.js)
<a name="localePlPl" href="#localePlPl">#</a> <b>localePlPl</b>
<a name="localePlPl" href="#localePlPl">#</a> d3_format.<b>localePlPl</b>
[Polish (Poland)](https://github.com/d3/d3-format/tree/master/src/locale/pl-PL.js)
<a name="localePtBr" href="#localePtBr">#</a> <b>localePtBr</b>
<a name="localePtBr" href="#localePtBr">#</a> d3_format.<b>localePtBr</b>
[Portuguese (Brazil)](https://github.com/d3/d3-format/tree/master/src/locale/pt-BR.js)
<a name="localeRuRu" href="#localeRuRu">#</a> <b>localeRuRu</b>
<a name="localeRuRu" href="#localeRuRu">#</a> d3_format.<b>localeRuRu</b>
[Russian (Russia)](https://github.com/d3/d3-format/tree/master/src/locale/ru-RU.js)
<a name="localeSvSe" href="#localeSvSe">#</a> <b>localeSvSe</b>
<a name="localeSvSe" href="#localeSvSe">#</a> d3_format.<b>localeSvSe</b>
[Swedish (Sweden)](https://github.com/d3/d3-format/tree/master/src/locale/sv-SE.js)
<a name="localeZhCn" href="#localeZhCn">#</a> <b>localeZhCn</b>
<a name="localeZhCn" href="#localeZhCn">#</a> d3_format.<b>localeZhCn</b>
[Chinese (China)](https://github.com/d3/d3-format/tree/master/src/locale/zh-CN.js)
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