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.2 to 0.5.0

2

build/bundle.js

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

var version = "0.4.2"; export * from "../index"; export {version};
var version = "0.5.0"; export * from "../index"; export {version};

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

function format(specifier) {
function newFormat(specifier) {
specifier = formatSpecifier(specifier);

@@ -199,3 +199,3 @@

return function(value) {
function format(value) {
var valuePrefix = prefix,

@@ -268,6 +268,12 @@ valueSuffix = suffix;

};
format.toString = function() {
return specifier + "";
};
return format;
}
function formatPrefix(specifier, value) {
var f = format((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,

@@ -282,3 +288,3 @@ k = Math.pow(10, -e),

return {
format: format,
format: newFormat,
formatPrefix: formatPrefix

@@ -465,3 +471,3 @@ };

var version = "0.4.2";
var version = "0.5.0";

@@ -471,26 +477,26 @@ exports.version = version;

exports.formatPrefix = formatPrefix;
exports.locale = locale;
exports.localeCaEs = caES;
exports.localeCsCz = csCZ;
exports.localeDeCh = deCH;
exports.localeDeDe = deDE;
exports.localeEnCa = enCA;
exports.localeEnGb = enGB;
exports.localeEnUs = defaultLocale;
exports.localeEsEs = esES;
exports.localeFiFi = fiFI;
exports.localeFrCa = frCA;
exports.localeFrFr = frFR;
exports.localeHeIl = heIL;
exports.localeHuHu = huHU;
exports.localeItIt = itIT;
exports.localeJaJp = jaJP;
exports.localeKoKr = koKR;
exports.localeMkMk = mkMK;
exports.localeNlNl = nlNL;
exports.localePlPl = plPL;
exports.localePtBr = ptBR;
exports.localeRuRu = ruRU;
exports.localeSvSe = svSE;
exports.localeZhCn = zhCN;
exports.formatLocale = locale;
exports.formatCaEs = caES;
exports.formatCsCz = csCZ;
exports.formatDeCh = deCH;
exports.formatDeDe = deDE;
exports.formatEnCa = enCA;
exports.formatEnGb = enGB;
exports.formatEnUs = defaultLocale;
exports.formatEsEs = esES;
exports.formatFiFi = fiFI;
exports.formatFrCa = frCA;
exports.formatFrFr = frFR;
exports.formatHeIl = heIL;
exports.formatHuHu = huHU;
exports.formatItIt = itIT;
exports.formatJaJp = jaJP;
exports.formatKoKr = koKR;
exports.formatMkMk = mkMK;
exports.formatNlNl = nlNL;
exports.formatPlPl = plPL;
exports.formatPtBr = ptBR;
exports.formatRuRu = ruRU;
exports.formatSvSe = svSE;
exports.formatZhCn = zhCN;
exports.formatSpecifier = formatSpecifier;

@@ -497,0 +503,0 @@ exports.precisionFixed = precisionFixed;

@@ -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-(f=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,g=n.precision,d=n.type,p="$"===i?a[0]:"#"===i&&/[boxX]/.test(d)?"0"+d.toLowerCase():"",M="$"===i?a[1]:/[%p]/.test(d)?"%":"",x=m[d],v=!d||/[defgprs%]/.test(d);return g=null==g?d?6:12:/[gprs]/.test(d)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),function(n){var i=p,a=M;if("c"===d)a=x(n)+a,n="";else{n=+n;var c=(0>n||0>1/n)&&(n*=-1,!0);if(n=x(n,g),c){var m,b=-1,w=n.length;for(c=!1;++b<w;)if(m=n.charCodeAt(b),m>48&&58>m||"x"===d&&m>96&&103>m||"X"===d&&m>64&&71>m){c=!0;break}}if(i=(c?"("===e?e:"-":"-"===e||"("===e?"":e)+i,a=a+("s"===d?y[8+f/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 C=i.length+n.length+a.length,E=l>C?new Array(l-C+1).join(r):"";switch(h&&s&&(n=o(E+n,E.length?l-a.length:1/0),E=""),t){case"<":return i+n+a+E;case"=":return i+E+n+a;case"^":return E.slice(0,C=E.length>>1)+i+n+a+E.slice(C)}return E+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 g(n,r){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(t(r)/3)))-t(Math.abs(n)))}function d(n,r){return n=Math.abs(n),r=Math.abs(r)-n,Math.max(0,t(r)-t(n))+1}var f,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:[""," Kč"]}),b=l({decimal:",",thousands:"'",grouping:[3],currency:[""," CHF"]}),w=l({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),C=l({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),E=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:["₪",""]}),j=l({decimal:",",thousands:" ",grouping:[3],currency:[""," Ft"]}),z=l({decimal:",",thousands:".",grouping:[3],currency:["€",""]}),A=l({decimal:".",thousands:",",grouping:[3],currency:["","円"]}),H=l({decimal:".",thousands:",",grouping:[3],currency:["₩",""]}),K=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:[""," руб."]}),X=l({decimal:",",thousands:" ",grouping:[3],currency:["","SEK"]}),G=l({decimal:".",thousands:",",grouping:[3],currency:["¥",""]}),J=M.format,U=M.formatPrefix,Z="0.4.2";n.version=Z,n.format=J,n.formatPrefix=U,n.locale=l,n.localeCaEs=x,n.localeCsCz=v,n.localeDeCh=b,n.localeDeDe=w,n.localeEnCa=C,n.localeEnGb=E,n.localeEnUs=M,n.localeEsEs=F,n.localeFiFi=P,n.localeFrCa=S,n.localeFrFr=k,n.localeHeIl=$,n.localeHuHu=j,n.localeItIt=z,n.localeJaJp=A,n.localeKoKr=H,n.localeMkMk=K,n.localeNlNl=N,n.localePlPl=R,n.localePtBr=D,n.localeRuRu=I,n.localeSvSe=X,n.localeZhCn=G,n.formatSpecifier=c,n.precisionFixed=h,n.precisionPrefix=g,n.precisionRound=d});
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define("d3-format",["exports"],n):n(r.d3_format={})}(this,function(r){"use strict";function n(r,n){if((t=(r=n?r.toExponential(n-1):r.toExponential()).indexOf("e"))<0)return null;var t,e=r.slice(0,t);return[e.length>1?e[0]+e.slice(2):e,+r.slice(t+1)]}function t(r){return r=n(Math.abs(r)),r?r[1]:NaN}function e(r,n){return function(t,e){for(var i=t.length,o=[],a=0,u=r[0],c=0;i>0&&u>0&&(c+u+1>e&&(u=Math.max(1,e-c)),o.push(t.substring(i-=u,i+u)),!((c+=u+1)>e));)u=r[a=(a+1)%r.length];return o.reverse().join(n)}}function i(r,t){var e=n(r,t);if(!e)return r+"";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(r,Math.max(0,t+a-1))[0]}function o(r,t){var e=n(r,t);if(!e)return r+"";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(r,n){r=r.toPrecision(n);r:for(var t,e=r.length,i=1,o=-1;e>i;++i)switch(r[i]){case".":o=t=i;break;case"0":0===o&&(o=i),t=i;break;case"e":break r;default:o>0&&(o=0)}return o>0?r.slice(0,o)+r.slice(t+1):r}function u(r){return new c(r)}function c(r){if(!(n=p.exec(r)))throw new Error("invalid format: "+r);var n,t=n[1]||" ",e=n[2]||">",i=n[3]||"-",o=n[4]||"",a=!!n[5],u=n[6]&&+n[6],c=!!n[7],s=n[8]&&+n[8].slice(1),f=n[9]||"";"n"===f?(c=!0,f="g"):d[f]||(f=""),(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=u,this.comma=c,this.precision=s,this.type=f}function s(r){return r}function f(r){function n(r){function n(r){var n=M,a=x;if("c"===p)a=v(r)+a,r="";else{r=+r;var u=(0>r||0>1/r)&&(r*=-1,!0);if(r=v(r,m),u){var s,d=-1,w=r.length;for(u=!1;++d<w;)if(s=r.charCodeAt(d),s>48&&58>s||"x"===p&&s>96&&103>s||"X"===p&&s>64&&71>s){u=!0;break}}if(n=(u?"("===i?i:"-":"-"===i||"("===i?"":i)+n,a=a+("s"===p?y[8+g/3]:"")+(u&&"("===i?")":""),b)for(var s,d=-1,w=r.length;++d<w;)if(s=r.charCodeAt(d),48>s||s>57){a=(46===s?c+r.slice(d+1):r.slice(d))+a,r=r.slice(0,d);break}}l&&!f&&(r=o(r,1/0));var C=n.length+r.length+a.length,E=h>C?new Array(h-C+1).join(t):"";switch(l&&f&&(r=o(E+r,E.length?h-a.length:1/0),E=""),e){case"<":return n+r+a+E;case"=":return n+E+r+a;case"^":return E.slice(0,C=E.length>>1)+n+r+a+E.slice(C)}return E+n+r+a}r=u(r);var t=r.fill,e=r.align,i=r.sign,s=r.symbol,f=r.zero,h=r.width,l=r.comma,m=r.precision,p=r.type,M="$"===s?a[0]:"#"===s&&/[boxX]/.test(p)?"0"+p.toLowerCase():"",x="$"===s?a[1]:/[%p]/.test(p)?"%":"",v=d[p],b=!p||/[defgprs%]/.test(p);return m=null==m?p?6:12:/[gprs]/.test(p)?Math.max(1,Math.min(21,m)):Math.max(0,Math.min(20,m)),n.toString=function(){return r+""},n}function i(r,e){var i=n((r=u(r),r.type="f",r)),o=3*Math.max(-8,Math.min(8,Math.floor(t(e)/3))),a=Math.pow(10,-o),c=y[8+o/3];return function(r){return i(a*r)+c}}var o=r.grouping&&r.thousands?e(r.grouping,r.thousands):s,a=r.currency,c=r.decimal;return{format:n,formatPrefix:i}}function h(r){return Math.max(0,-t(Math.abs(r)))}function l(r,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(t(n)/3)))-t(Math.abs(r)))}function m(r,n){return r=Math.abs(r),n=Math.abs(n)-r,Math.max(0,t(n)-t(r))+1}var g,d={"":a,"%":function(r,n){return(100*r).toFixed(n)},b:function(r){return Math.round(r).toString(2)},c:function(r){return r+""},d:function(r){return Math.round(r).toString(10)},e:function(r,n){return r.toExponential(n)},f:function(r,n){return r.toFixed(n)},g:function(r,n){return r.toPrecision(n)},o:function(r){return Math.round(r).toString(8)},p:function(r,n){return o(100*r,n)},r:o,s:i,X:function(r){return Math.round(r).toString(16).toUpperCase()},x:function(r){return Math.round(r).toString(16)}},p=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;c.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=f({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),x=f({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),v=f({decimal:",",thousands:" ",grouping:[3],currency:[""," Kč"]}),b=f({decimal:",",thousands:"'",grouping:[3],currency:[""," CHF"]}),w=f({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),C=f({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),E=f({decimal:".",thousands:",",grouping:[3],currency:["£",""]}),S=f({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),F=f({decimal:",",thousands:" ",grouping:[3],currency:[""," €"]}),P=f({decimal:",",thousands:" ",grouping:[3],currency:["","$"]}),k=f({decimal:",",thousands:".",grouping:[3],currency:[""," €"]}),$=f({decimal:".",thousands:",",grouping:[3],currency:["₪",""]}),j=f({decimal:",",thousands:" ",grouping:[3],currency:[""," Ft"]}),z=f({decimal:",",thousands:".",grouping:[3],currency:["€",""]}),A=f({decimal:".",thousands:",",grouping:[3],currency:["","円"]}),H=f({decimal:".",thousands:",",grouping:[3],currency:["₩",""]}),K=f({decimal:",",thousands:".",grouping:[3],currency:[""," ден."]}),N=f({decimal:",",thousands:".",grouping:[3],currency:["€ ",""]}),R=f({decimal:",",thousands:".",grouping:[3],currency:["","zł"]}),D=f({decimal:",",thousands:".",grouping:[3],currency:["R$",""]}),I=f({decimal:",",thousands:" ",grouping:[3],currency:[""," руб."]}),X=f({decimal:",",thousands:" ",grouping:[3],currency:["","SEK"]}),G=f({decimal:".",thousands:",",grouping:[3],currency:["¥",""]}),J=M.format,L=M.formatPrefix,U="0.5.0";r.version=U,r.format=J,r.formatPrefix=L,r.formatLocale=f,r.formatCaEs=x,r.formatCsCz=v,r.formatDeCh=b,r.formatDeDe=w,r.formatEnCa=C,r.formatEnGb=E,r.formatEnUs=M,r.formatEsEs=S,r.formatFiFi=F,r.formatFrCa=P,r.formatFrFr=k,r.formatHeIl=$,r.formatHuHu=j,r.formatItIt=z,r.formatJaJp=A,r.formatKoKr=H,r.formatMkMk=K,r.formatNlNl=N,r.formatPlPl=R,r.formatPtBr=D,r.formatRuRu=I,r.formatSvSe=X,r.formatZhCn=G,r.formatSpecifier=u,r.precisionFixed=h,r.precisionPrefix=l,r.precisionRound=m});
import defaultLocale from "./src/locale/en-US";
export {default as locale} from "./src/locale";
export {default as localeCaEs} from "./src/locale/ca-ES";
export {default as localeCsCz} from "./src/locale/cs-CZ";
export {default as localeDeCh} from "./src/locale/de-CH";
export {default as localeDeDe} from "./src/locale/de-DE";
export {default as localeEnCa} from "./src/locale/en-CA";
export {default as localeEnGb} from "./src/locale/en-GB";
export {default as localeEnUs} from "./src/locale/en-US";
export {default as localeEsEs} from "./src/locale/es-ES";
export {default as localeFiFi} from "./src/locale/fi-FI";
export {default as localeFrCa} from "./src/locale/fr-CA";
export {default as localeFrFr} from "./src/locale/fr-FR";
export {default as localeHeIl} from "./src/locale/he-IL";
export {default as localeHuHu} from "./src/locale/hu-HU";
export {default as localeItIt} from "./src/locale/it-IT";
export {default as localeJaJp} from "./src/locale/ja-JP";
export {default as localeKoKr} from "./src/locale/ko-KR";
export {default as localeMkMk} from "./src/locale/mk-MK";
export {default as localeNlNl} from "./src/locale/nl-NL";
export {default as localePlPl} from "./src/locale/pl-PL";
export {default as localePtBr} from "./src/locale/pt-BR";
export {default as localeRuRu} from "./src/locale/ru-RU";
export {default as localeSvSe} from "./src/locale/sv-SE";
export {default as localeZhCn} from "./src/locale/zh-CN";
export {default as formatLocale} from "./src/locale";
export {default as formatCaEs} from "./src/locale/ca-ES";
export {default as formatCsCz} from "./src/locale/cs-CZ";
export {default as formatDeCh} from "./src/locale/de-CH";
export {default as formatDeDe} from "./src/locale/de-DE";
export {default as formatEnCa} from "./src/locale/en-CA";
export {default as formatEnGb} from "./src/locale/en-GB";
export {default as formatEnUs} from "./src/locale/en-US";
export {default as formatEsEs} from "./src/locale/es-ES";
export {default as formatFiFi} from "./src/locale/fi-FI";
export {default as formatFrCa} from "./src/locale/fr-CA";
export {default as formatFrFr} from "./src/locale/fr-FR";
export {default as formatHeIl} from "./src/locale/he-IL";
export {default as formatHuHu} from "./src/locale/hu-HU";
export {default as formatItIt} from "./src/locale/it-IT";
export {default as formatJaJp} from "./src/locale/ja-JP";
export {default as formatKoKr} from "./src/locale/ko-KR";
export {default as formatMkMk} from "./src/locale/mk-MK";
export {default as formatNlNl} from "./src/locale/nl-NL";
export {default as formatPlPl} from "./src/locale/pl-PL";
export {default as formatPtBr} from "./src/locale/pt-BR";
export {default as formatRuRu} from "./src/locale/ru-RU";
export {default as formatSvSe} from "./src/locale/sv-SE";
export {default as formatZhCn} from "./src/locale/zh-CN";
export {default as formatSpecifier} from "./src/formatSpecifier";

@@ -27,0 +27,0 @@ export {default as precisionFixed} from "./src/precisionFixed";

{
"name": "d3-format",
"version": "0.4.2",
"version": "0.5.0",
"description": "Format numbers for human consumption.",

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

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

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

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

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

@@ -75,3 +75,3 @@

```html
<script src="https://d3js.org/d3-format.v0.4.min.js"></script>
<script src="https://d3js.org/d3-format.v0.5.min.js"></script>
```

@@ -83,9 +83,9 @@

<a name="format" href="#format">#</a> d3_format.<b>format</b>(<i>specifier</i>)
<a name="format" href="#format">#</a> d3.<b>format</b>(<i>specifier</i>)
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.
An alias for [*locale*.format](#locale_format) on the [U.S. English locale](#formatEnUs). See the other [locales](#locales), or use [formatLocale](#formatLocale) to define a new locale.
<a name="formatPrefix" href="#formatPrefix">#</a> d3_format.<b>formatPrefix</b>(<i>specifier</i>, <i>value</i>)
<a name="formatPrefix" href="#formatPrefix">#</a> d3.<b>formatPrefix</b>(<i>specifier</i>, <i>value</i>)
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.
An alias for [*locale*.formatPrefix](#locale_formatPrefix) on the [U.S. English locale](#formatEnUs). See the other [locales](#locales), or use [formatLocale](#formatLocale) to define a new locale.

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

```js
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"
d3.format(".2")(42); // "42"
d3.format(".2")(4.2); // "4.2"
d3.format(".1")(42); // "4e+1"
d3.format(".1")(4.2); // "4"
```

@@ -175,3 +175,3 @@

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

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

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

@@ -205,9 +205,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 = d3_format.formatSpecifier("f");
var s = d3.formatSpecifier("f");
s.precision = precisionFixed(0.01);
var f = d3_format.format(s);
var f = d3.format(s);
f(42); // "42.00";
```
<a name="precisionFixed" href="#precisionFixed">#</a> d3_format.<b>precisionFixed</b>(<i>step</i>)
<a name="precisionFixed" href="#precisionFixed">#</a> d3.<b>precisionFixed</b>(<i>step</i>)

@@ -217,4 +217,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 = d3_format.precisionFixed(0.5),
f = d3_format.format("." + p + "f");
var p = d3.precisionFixed(0.5),
f = d3.format("." + p + "f");
f(1); // "1.0"

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

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

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

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

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

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

@@ -253,4 +253,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 = d3_format.precisionPrefix(1e5, 1.3e6),
f = d3_format.formatPrefix("." + p, 1.3e6);
var p = d3.precisionPrefix(1e5, 1.3e6),
f = d3.formatPrefix("." + p, 1.3e6);
f(1.1e6); // "1.1M"

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

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

@@ -267,4 +267,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 = d3_format.precisionRound(0.01, 1.01),
f = d3_format.format("." + p + "r");
var p = d3.precisionRound(0.01, 1.01),
f = d3.format("." + p + "r");
f(0.99); // "0.990"

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

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

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

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

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

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

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

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

function format(specifier) {
function newFormat(specifier) {
specifier = formatSpecifier(specifier);

@@ -51,3 +51,3 @@

return function(value) {
function format(value) {
var valuePrefix = prefix,

@@ -120,6 +120,12 @@ valueSuffix = suffix;

};
format.toString = function() {
return specifier + "";
};
return format;
}
function formatPrefix(specifier, value) {
var f = format((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,

@@ -134,5 +140,5 @@ k = Math.pow(10, -e),

return {
format: format,
format: newFormat,
formatPrefix: formatPrefix
};
};
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