Comparing version 0.2.3 to 0.3.0
@@ -0,1 +1,20 @@ | ||
if (typeof Map === "undefined") { | ||
Map = function() { this.clear(); }; | ||
Map.prototype = { | ||
set: function(k, v) { this._[k] = v; return this; }, | ||
get: function(k) { return this._[k]; }, | ||
has: function(k) { return k in this._; }, | ||
delete: function(k) { return k in this._ && delete this._[k]; }, | ||
clear: function() { this._ = Object.create(null); }, | ||
get size() { var n = 0; for (var k in this._) ++n; return n; }, | ||
forEach: function(c) { for (var k in this._) c(this._[k], k, this); } | ||
}; | ||
} else (function() { | ||
var m = new Map; | ||
if (m.set(0, 0) !== m) { | ||
m = m.set; | ||
Map.prototype.set = function() { m.apply(this, arguments); return this; }; | ||
} | ||
})(); | ||
(function (global, factory) { | ||
@@ -7,5 +26,122 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
var prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"]; | ||
var zhCn = { | ||
decimal: ".", | ||
thousands: ",", | ||
grouping: [3], | ||
currency: ["¥", ""] | ||
}; | ||
var ruRu = { | ||
decimal: ",", | ||
thousands: "\xa0", | ||
grouping: [3], | ||
currency: ["", "\xa0руб."] | ||
}; | ||
var ptBr = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["R$", ""] | ||
}; | ||
var plPl = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["", "zł"] | ||
}; | ||
var nlNl = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["€\xa0", ""] | ||
}; | ||
var mkMk = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["", "\xa0ден."] | ||
}; | ||
var itIt = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["€", ""] | ||
}; | ||
var heIl = { | ||
decimal: ".", | ||
thousands: ",", | ||
grouping: [3], | ||
currency: ["₪", ""] | ||
}; | ||
var frFr = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["", "\xa0€"] | ||
}; | ||
var frCa = { | ||
decimal: ",", | ||
thousands: "\xa0", | ||
grouping: [3], | ||
currency: ["", "$"] | ||
}; | ||
var fiFi = { | ||
decimal: ",", | ||
thousands: "\xa0", | ||
grouping: [3], | ||
currency: ["", "\xa0€"] | ||
}; | ||
var esEs = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["", "\xa0€"] | ||
}; | ||
var enUs = { | ||
decimal: ".", | ||
thousands: ",", | ||
grouping: [3], | ||
currency: ["$", ""] | ||
}; | ||
var enGb = { | ||
decimal: ".", | ||
thousands: ",", | ||
grouping: [3], | ||
currency: ["£", ""] | ||
}; | ||
var enCa = { | ||
decimal: ".", | ||
thousands: ",", | ||
grouping: [3], | ||
currency: ["$", ""] | ||
}; | ||
var deDe = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["", "\xa0€"] | ||
}; | ||
var caEs = { | ||
decimal: ",", | ||
thousands: ".", | ||
grouping: [3], | ||
currency: ["", "\xa0€"] | ||
}; | ||
// Computes the decimal coefficient and exponent of the specified number x with | ||
@@ -91,2 +227,6 @@ // significant digits p, where x is positive and p is in [1, 21] or undefined. | ||
function formatSpecifier(specifier) { | ||
return new FormatSpecifier(specifier); | ||
} | ||
function FormatSpecifier(specifier) { | ||
@@ -138,10 +278,2 @@ if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier); | ||
function formatSpecifier(specifier) { | ||
return new FormatSpecifier(specifier); | ||
} | ||
function identity(x) { | ||
return x; | ||
} | ||
function formatGroup(grouping, thousands) { | ||
@@ -166,3 +298,9 @@ return function(value, width) { | ||
function localeFormat(locale) { | ||
var prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"]; | ||
function identity(x) { | ||
return x; | ||
} | ||
function locale(locale) { | ||
var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity, | ||
@@ -275,12 +413,2 @@ currency = locale.currency, | ||
var locale = localeFormat({ | ||
decimal: ".", | ||
thousands: ",", | ||
grouping: [3], | ||
currency: ["$", ""] | ||
}); | ||
exports.format = locale.format; | ||
exports.formatPrefix = locale.formatPrefix; | ||
function precisionRound(step, max) { | ||
@@ -298,4 +426,36 @@ return Math.max(0, exponent(Math.abs(max)) - exponent(Math.abs(step))) + 1; | ||
var localeDefinitions = (new Map) | ||
.set("ca-ES", caEs) | ||
.set("de-DE", deDe) | ||
.set("en-CA", enCa) | ||
.set("en-GB", enGb) | ||
.set("en-US", enUs) | ||
.set("es-ES", esEs) | ||
.set("fi-FI", fiFi) | ||
.set("fr-CA", frCa) | ||
.set("fr-FR", frFr) | ||
.set("he-IL", heIl) | ||
.set("it-IT", itIt) | ||
.set("mk-MK", mkMk) | ||
.set("nl-NL", nlNl) | ||
.set("pl-PL", plPl) | ||
.set("pt-BR", ptBr) | ||
.set("ru-RU", ruRu) | ||
.set("zh-CN", zhCn); | ||
var defaultLocale = locale(enUs); | ||
exports.format = defaultLocale.format; | ||
exports.formatPrefix = defaultLocale.formatPrefix; | ||
function localeFormat(definition) { | ||
if (typeof definition === "string") { | ||
definition = localeDefinitions.get(definition); | ||
if (!definition) return null; | ||
} | ||
return locale(definition); | ||
} | ||
; | ||
exports.localeFormat = localeFormat; | ||
exports.formatSpecifier = formatSpecifier; | ||
exports.localeFormat = localeFormat; | ||
exports.precisionFixed = precisionFixed; | ||
@@ -302,0 +462,0 @@ exports.precisionPrefix = precisionPrefix; |
@@ -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=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}); | ||
"undefined"==typeof Map?(Map=function(){this.clear()},Map.prototype={set:function(t,n){return this._[t]=n,this},get:function(t){return this._[t]},has:function(t){return t in this._},"delete":function(t){return t in this._&&delete this._[t]},clear:function(){this._=Object.create(null)},get size(){var t=0;for(var n in this._)++t;return t},forEach:function(t){for(var n in this._)t(this._[n],n,this)}}):function(){var t=new Map;t.set(0,0)!==t&&(t=t.set,Map.prototype.set=function(){return t.apply(this,arguments),this})}(),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]:NaN}function e(t,r){var e=n(t,r);if(!e)return t+"";var i=e[0],o=e[1],u=o-(p=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,a=i.length;return u===a?i:u>a?i+new Array(u-a+1).join("0"):u>0?i.slice(0,u)+"."+i.slice(u):"0."+new Array(1-u).join("0")+n(t,r+u-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 u(t){return new a(t)}function a(t){if(!(n=R.exec(t)))throw new Error("invalid format: "+t);var n,r=n[1]||" ",e=n[2]||">",i=n[3]||"-",o=n[4]||"",u=!!n[5],a=n[6]&&+n[6],s=!!n[7],c=n[8]&&+n[8].slice(1),h=n[9]||"";"n"===h?(s=!0,h="g"):F[h]||(h=""),(u||"0"===r&&"="===e)&&(u=!0,r="0",e="="),this.fill=r,this.align=e,this.sign=i,this.symbol=o,this.zero=u,this.width=a,this.comma=s,this.precision=c,this.type=h}function s(t,n){return function(r,e){for(var i=r.length,o=[],u=0,a=t[0],s=0;i>0&&a>0&&(s+a+1>e&&(a=Math.max(1,e-s)),o.push(r.substring(i-=a,i+a)),!((s+=a+1)>e));)a=t[u=(u+1)%t.length];return o.reverse().join(n)}}function c(t){return t}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,g=t.type,d="$"===s?o[0]:"#"===s&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",m="$"===s?o[1]:/[%p]/.test(g)?"%":"",y=F[g],M=!g||/[defgprs%]/.test(g);return l=null==l?g?6:12:/[gprs]/.test(g)?Math.max(1,Math.min(21,l)):Math.max(0,Math.min(20,l)),function(t){var o=d,u=m;if("c"===g)u=y(t)+u,t="";else{t=+t;var s=(0>t||0>1/t)&&(t*=-1,!0);if(t=y(t,l),o=(s?"("===e?e:"-":"-"===e||"("===e?"":e)+o,u=u+("s"===g?L[8+p/3]:"")+(s&&"("===e?")":""),M)for(var x,v=-1,b=t.length;++v<b;)if(x=t.charCodeAt(v),48>x||x>57){u=(46===x?a+t.slice(v+1):t.slice(v))+u,t=t.slice(0,v);break}}f&&!c&&(t=i(t,1/0));var w=o.length+t.length+u.length,j=h>w?new Array(h-w+1).join(n):"";switch(f&&c&&(t=i(j+t,j.length?h-u.length:1/0),j=""),r){case"<":return o+t+u+j;case"=":return o+j+t+u;case"^":return j.slice(0,w=j.length>>1)+o+t+u+j.slice(w)}return j+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=L[8+o/3];return function(t){return i(a*t)+s}}var i=t.grouping&&t.thousands?s(t.grouping,t.thousands):c,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 g(t){return Math.max(0,-r(Math.abs(t)))}function d(t){return"string"!=typeof t||(t=N.get(t))?h(t):null}var p,m={decimal:".",thousands:",",grouping:[3],currency:["¥",""]},y={decimal:",",thousands:" ",grouping:[3],currency:[""," руб."]},M={decimal:",",thousands:".",grouping:[3],currency:["R$",""]},x={decimal:",",thousands:".",grouping:[3],currency:["","zł"]},v={decimal:",",thousands:".",grouping:[3],currency:["€ ",""]},b={decimal:",",thousands:".",grouping:[3],currency:[""," ден."]},w={decimal:",",thousands:".",grouping:[3],currency:["€",""]},j={decimal:".",thousands:",",grouping:[3],currency:["₪",""]},S={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},E={decimal:",",thousands:" ",grouping:[3],currency:["","$"]},_={decimal:",",thousands:" ",grouping:[3],currency:[""," €"]},A={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},P={decimal:".",thousands:",",grouping:[3],currency:["$",""]},$={decimal:".",thousands:",",grouping:[3],currency:["£",""]},z={decimal:".",thousands:",",grouping:[3],currency:["$",""]},k={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},C={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},F={"":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)}},R=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(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 L=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],N=(new Map).set("ca-ES",C).set("de-DE",k).set("en-CA",z).set("en-GB",$).set("en-US",P).set("es-ES",A).set("fi-FI",_).set("fr-CA",E).set("fr-FR",S).set("he-IL",j).set("it-IT",w).set("mk-MK",b).set("nl-NL",v).set("pl-PL",x).set("pt-BR",M).set("ru-RU",y).set("zh-CN",m),I=h(P);t.format=I.format,t.formatPrefix=I.formatPrefix,t.localeFormat=d,t.formatSpecifier=u,t.precisionFixed=g,t.precisionPrefix=l,t.precisionRound=f}); |
54
index.js
import formatSpecifier from "./src/formatSpecifier"; | ||
import locale from "./src/locale/en-US"; | ||
import localeFormat from "./src/localeFormat"; | ||
import locale from "./src/locale"; | ||
import precisionFixed from "./src/precisionFixed"; | ||
@@ -8,8 +7,53 @@ import precisionPrefix from "./src/precisionPrefix"; | ||
export var format = locale.format; | ||
export var formatPrefix = locale.formatPrefix; | ||
import caEs from "./src/locale/ca-ES"; | ||
import deDe from "./src/locale/de-DE"; | ||
import enCa from "./src/locale/en-CA"; | ||
import enGb from "./src/locale/en-GB"; | ||
import enUs from "./src/locale/en-US"; | ||
import esEs from "./src/locale/es-ES"; | ||
import fiFi from "./src/locale/fi-FI"; | ||
import frCa from "./src/locale/fr-CA"; | ||
import frFr from "./src/locale/fr-FR"; | ||
import heIl from "./src/locale/he-IL"; | ||
import itIt from "./src/locale/it-IT"; | ||
import mkMk from "./src/locale/mk-MK"; | ||
import nlNl from "./src/locale/nl-NL"; | ||
import plPl from "./src/locale/pl-PL"; | ||
import ptBr from "./src/locale/pt-BR"; | ||
import ruRu from "./src/locale/ru-RU"; | ||
import zhCn from "./src/locale/zh-CN"; | ||
var localeDefinitions = (new Map) | ||
.set("ca-ES", caEs) | ||
.set("de-DE", deDe) | ||
.set("en-CA", enCa) | ||
.set("en-GB", enGb) | ||
.set("en-US", enUs) | ||
.set("es-ES", esEs) | ||
.set("fi-FI", fiFi) | ||
.set("fr-CA", frCa) | ||
.set("fr-FR", frFr) | ||
.set("he-IL", heIl) | ||
.set("it-IT", itIt) | ||
.set("mk-MK", mkMk) | ||
.set("nl-NL", nlNl) | ||
.set("pl-PL", plPl) | ||
.set("pt-BR", ptBr) | ||
.set("ru-RU", ruRu) | ||
.set("zh-CN", zhCn); | ||
var defaultLocale = locale(enUs); | ||
export var format = defaultLocale.format; | ||
export var formatPrefix = defaultLocale.formatPrefix; | ||
export function localeFormat(definition) { | ||
if (typeof definition === "string") { | ||
definition = localeDefinitions.get(definition); | ||
if (!definition) return null; | ||
} | ||
return locale(definition); | ||
}; | ||
export { | ||
formatSpecifier, | ||
localeFormat, | ||
precisionFixed, | ||
@@ -16,0 +60,0 @@ precisionPrefix, |
{ | ||
"name": "d3-format", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Format numbers for human consumption.", | ||
@@ -22,3 +22,3 @@ "keywords": [ | ||
"scripts": { | ||
"pretest": "mkdir -p build && d3-bundler --format=umd --name=format -- index.js > build/format.js", | ||
"pretest": "mkdir -p build && d3-bundler --polyfill-map --format=umd --name=format -- index.js > build/format.js", | ||
"test": "faucet `find test -name '*-test.js'`", | ||
@@ -31,4 +31,4 @@ "prepublish": "npm run test && uglifyjs build/format.js -c -m -o build/format.min.js && rm -f build/format.zip && zip -j build/format.zip -- LICENSE README.md build/format.js build/format.min.js" | ||
"tape": "4", | ||
"uglifyjs": "2" | ||
"uglify-js": "2" | ||
} | ||
} |
@@ -76,11 +76,11 @@ # d3-format | ||
An alias for [*locale*.format](#locale_format) on the default locale. While this method generates output for [U.S. English](https://github.com/d3/d3-format/tree/master/src/locale/en-US.js)-speaking humans by default, humans in other locales may be served using [localeFormat](#localeFormat) or by editing [index.js](https://github.com/d3/d3-format/tree/master/index.js) and rebuilding. | ||
An alias for [*locale*.format](#locale_format) on the default [U.S. English](https://github.com/d3/d3-format/tree/master/src/locale/en-US.js) locale. Use [localeFormat](#localeFormat) for a different built-in locale or to define a new locale. | ||
<a name="formatPrefix" href="#formatPrefix">#</a> <b>formatPrefix</b>(<i>specifier</i>, <i>value</i>) | ||
An alias for [*locale*.formatPrefix](#locale_formatPrefix) on the default locale. While this method generates output for [U.S. English](https://github.com/d3/d3-format/tree/master/src/locale/en-US.js)-speaking humans by default, humans in other locales may be served using [localeFormat](#localeFormat) or by editing [index.js](https://github.com/d3/d3-format/tree/master/index.js) and rebuilding. | ||
An alias for [*locale*.formatPrefix](#locale_formatPrefix) on the default [U.S. English](https://github.com/d3/d3-format/tree/master/src/locale/en-US.js) locale. Use [localeFormat](#localeFormat) for a different built-in locale or to define a new locale. | ||
<a name="locale_format" href="#locale_format">#</a> <i>locale</i>.<b>format</b>(<i>specifier</i>) | ||
Returns a new format function with the given string *specifier*. The returned function takes a number as the only argument, and returns a string representing the formatted number. The general form of a specifier is: | ||
Returns a new format function for the given string *specifier*. The returned function takes a number as the only argument, and returns a string representing the formatted number. The general form of a specifier is: | ||
@@ -174,4 +174,24 @@ ``` | ||
Returns a *locale* object for the specified *definition*, with [*locale*.format](#locale_format) and [*locale*.formatPrefix](#locale_formatPrefix) methods. The locale *definition* must include the following properties: | ||
Returns a *locale* object for the specified *definition* with [*locale*.format](#locale_format) and [*locale*.formatPrefix](#locale_formatPrefix) methods. If *definition* is a string, it is the name of a built-in locale: | ||
* `"ca-ES"` - [Catalan (Spain)](https://github.com/d3/d3-format/tree/master/src/locale/ca-ES.js) | ||
* `"de-DE"` - [German (Germany)](https://github.com/d3/d3-format/tree/master/src/locale/de-DE.js) | ||
* `"en-CA"` - [English (Canada)](https://github.com/d3/d3-format/tree/master/src/locale/en-CA.js) | ||
* `"en-GB"` - [English (United Kingdom)](https://github.com/d3/d3-format/tree/master/src/locale/en-GB.js) | ||
* `"en-US"` - [English (United States)](https://github.com/d3/d3-format/tree/master/src/locale/en-US.js) | ||
* `"es-ES"` - [Spanish (Spain)](https://github.com/d3/d3-format/tree/master/src/locale/es-ES.js) | ||
* `"fi-FI"` - [Finnish (Finland)](https://github.com/d3/d3-format/tree/master/src/locale/fi-FI.js) | ||
* `"fr-CA"` - [French (Canada)](https://github.com/d3/d3-format/tree/master/src/locale/fr-CA.js) | ||
* `"fr-FR"` - [French (France)](https://github.com/d3/d3-format/tree/master/src/locale/fr-FR.js) | ||
* `"he-IL"` - [Hebrew (Israel)](https://github.com/d3/d3-format/tree/master/src/locale/he-IL.js) | ||
* `"it-IT"` - [Italian (Italy)](https://github.com/d3/d3-format/tree/master/src/locale/it-IT.js) | ||
* `"mk-MK"` - [Macedonian (Macedonia)](https://github.com/d3/d3-format/tree/master/src/locale/mk-MK.js) | ||
* `"nl-NL"` - [Dutch (Netherlands)](https://github.com/d3/d3-format/tree/master/src/locale/nl-NL.js) | ||
* `"pl-PL"` - [Polish (Poland)](https://github.com/d3/d3-format/tree/master/src/locale/pl-PL.js) | ||
* `"pt-BR"` - [Portuguese (Brazil)](https://github.com/d3/d3-format/tree/master/src/locale/pt-BR.js) | ||
* `"ru-RU"` - [Russian (Russia)](https://github.com/d3/d3-format/tree/master/src/locale/ru-RU.js) | ||
* `"zh-CN"` - [Chinese (China)](https://github.com/d3/d3-format/tree/master/src/locale/zh-CN.js) | ||
Otherwise, the locale *definition* must include the following properties: | ||
* `decimal` - the decimal point (e.g., `"."`). | ||
@@ -182,24 +202,4 @@ * `thousands` - the group separator (e.g., `","`). | ||
(Note that the *thousands* property is a misnomer, as the grouping definition allows groups other than thousands.) The following locale definitions are available in the source: | ||
Note that the *thousands* property is a misnomer, as the grouping definition allows groups other than thousands. | ||
* [Catalan (Spain)](https://github.com/d3/d3-format/tree/master/src/locale/ca-ES.js) | ||
* [German (Germany)](https://github.com/d3/d3-format/tree/master/src/locale/de-DE.js) | ||
* [English (Canada)](https://github.com/d3/d3-format/tree/master/src/locale/en-CA.js) | ||
* [English (United Kingdom)](https://github.com/d3/d3-format/tree/master/src/locale/en-GB.js) | ||
* [English (United States)](https://github.com/d3/d3-format/tree/master/src/locale/en-US.js) | ||
* [Spanish (Spain)](https://github.com/d3/d3-format/tree/master/src/locale/es-ES.js) | ||
* [Finnish (Finland)](https://github.com/d3/d3-format/tree/master/src/locale/fi-FI.js) | ||
* [French (Canada)](https://github.com/d3/d3-format/tree/master/src/locale/fr-CA.js) | ||
* [French (France)](https://github.com/d3/d3-format/tree/master/src/locale/fr-FR.js) | ||
* [Hebrew (Israel)](https://github.com/d3/d3-format/tree/master/src/locale/he-IL.js) | ||
* [Italian (Italy)](https://github.com/d3/d3-format/tree/master/src/locale/it-IT.js) | ||
* [Macedonian (Macedonia)](https://github.com/d3/d3-format/tree/master/src/locale/mk-MK.js) | ||
* [Dutch (Netherlands)](https://github.com/d3/d3-format/tree/master/src/locale/nl-NL.js) | ||
* [Polish (Poland)](https://github.com/d3/d3-format/tree/master/src/locale/pl-PL.js) | ||
* [Portuguese (Brazil)](https://github.com/d3/d3-format/tree/master/src/locale/pt-BR.js) | ||
* [Russian (Russia)](https://github.com/d3/d3-format/tree/master/src/locale/ru-RU.js) | ||
* [Chinese (China)](https://github.com/d3/d3-format/tree/master/src/locale/zh-CN.js) | ||
To change the default locale, edit [index.js](https://github.com/d3/d3-format/tree/master/index.js) and run `npm run prepublish`. | ||
<a name="formatSpecifier" href="#formatSpecifier">#</a> <b>formatSpecifier</b>(<i>specifier</i>) | ||
@@ -206,0 +206,0 @@ |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["", "\xa0€"] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["", "\xa0€"] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ".", | ||
@@ -8,2 +6,2 @@ thousands: ",", | ||
currency: ["$", ""] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ".", | ||
@@ -8,2 +6,2 @@ thousands: ",", | ||
currency: ["£", ""] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ".", | ||
@@ -8,2 +6,2 @@ thousands: ",", | ||
currency: ["$", ""] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["", "\xa0€"] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: "\xa0", | ||
currency: ["", "\xa0€"] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: "\xa0", | ||
currency: ["", "$"] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["", "\xa0€"] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ".", | ||
@@ -8,2 +6,2 @@ thousands: ",", | ||
currency: ["₪", ""] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["€", ""] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["", "\xa0ден."] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["€\xa0", ""] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["", "zł"] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: ".", | ||
currency: ["R$", ""] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ",", | ||
@@ -8,2 +6,2 @@ thousands: "\xa0", | ||
currency: ["", "\xa0руб."] | ||
}); | ||
}; |
@@ -1,4 +0,2 @@ | ||
import localeFormat from "../localeFormat"; | ||
export default localeFormat({ | ||
export default { | ||
decimal: ".", | ||
@@ -8,2 +6,2 @@ thousands: ",", | ||
currency: ["¥", ""] | ||
}); | ||
}; |
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
50536
791