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.6.0 to 1.0.0

src/defaultLocale.js

33

build/d3-format.js

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

// https://d3js.org/d3-format/ Version 0.6.0. Copyright 2016 Mike Bostock.
// https://d3js.org/d3-format/ Version 1.0.0. Copyright 2016 Mike Bostock.
(function (global, factory) {

@@ -162,12 +162,2 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

var defaultLocale = formatLocale({
decimal: ".",
thousands: ",",
grouping: [3],
currency: ["$", ""]
});
var format = defaultLocale.format;
var formatPrefix = defaultLocale.formatPrefix;
function formatLocale(locale) {

@@ -303,2 +293,20 @@ var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity,

var locale;
exports.format;
exports.formatPrefix;
defaultLocale({
decimal: ".",
thousands: ",",
grouping: [3],
currency: ["$", ""]
});
function defaultLocale(definition) {
locale = formatLocale(definition);
exports.format = locale.format;
exports.formatPrefix = locale.formatPrefix;
return locale;
}
function precisionFixed(step) {

@@ -317,5 +325,4 @@ return Math.max(0, -exponent(Math.abs(step)));

exports.formatDefaultLocale = defaultLocale;
exports.formatLocale = formatLocale;
exports.format = format;
exports.formatPrefix = formatPrefix;
exports.formatSpecifier = formatSpecifier;

@@ -322,0 +329,0 @@ exports.precisionFixed = precisionFixed;

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

// https://d3js.org/d3-format/ Version 0.6.0. Copyright 2016 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,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,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 i(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 o(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,Math.max(0,r+a-1))[0]}function a(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 u(t){return new s(t)}function s(t){if(!(n=p.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"):d[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 c(t){return t}function f(t){function n(t){function n(t){var n,a,u,c=x,d=y;if("c"===p)d=v(t)+d,t="";else{t=+t;var w=(0>t||0>1/t)&&(t*=-1,!0);if(t=v(t,m),w)for(n=-1,a=t.length,w=!1;++n<a;)if(u=t.charCodeAt(n),u>48&&58>u||"x"===p&&u>96&&103>u||"X"===p&&u>64&&71>u){w=!0;break}if(c=(w?"("===i?i:"-":"-"===i||"("===i?"":i)+c,d=d+("s"===p?M[8+g/3]:"")+(w&&"("===i?")":""),b)for(n=-1,a=t.length;++n<a;)if(u=t.charCodeAt(n),48>u||u>57){d=(46===u?s+t.slice(n+1):t.slice(n))+d,t=t.slice(0,n);break}}l&&!f&&(t=o(t,1/0));var j=c.length+t.length+d.length,P=h>j?new Array(h-j+1).join(r):"";switch(l&&f&&(t=o(P+t,P.length?h-d.length:1/0),P=""),e){case"<":return c+t+d+P;case"=":return c+P+t+d;case"^":return P.slice(0,j=P.length>>1)+c+t+d+P.slice(j)}return P+c+t+d}t=u(t);var r=t.fill,e=t.align,i=t.sign,c=t.symbol,f=t.zero,h=t.width,l=t.comma,m=t.precision,p=t.type,x="$"===c?a[0]:"#"===c&&/[boxX]/.test(p)?"0"+p.toLowerCase():"",y="$"===c?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 t+""},n}function i(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=M[8+o/3];return function(t){return i(a*t)+s}}var o=t.grouping&&t.thousands?e(t.grouping,t.thousands):c,a=t.currency,s=t.decimal;return{format:n,formatPrefix:i}}function h(t){return Math.max(0,-r(Math.abs(t)))}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,n){return t=Math.abs(t),n=Math.abs(n)-t,Math.max(0,r(n)-r(t))+1}var g,d={"":i,"%":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 a(100*t,n)},r:a,s:o,X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}},p=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;s.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 M=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],x=f({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),y=x.format,v=x.formatPrefix;t.formatLocale=f,t.format=y,t.formatPrefix=v,t.formatSpecifier=u,t.precisionFixed=h,t.precisionPrefix=l,t.precisionRound=m,Object.defineProperty(t,"__esModule",{value:!0})});
// https://d3js.org/d3-format/ Version 1.0.0. Copyright 2016 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,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,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 i(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}function o(t,r){var e=n(t,r);if(!e)return t+"";var i=e[0],o=e[1],a=o-(d=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,Math.max(0,r+a-1))[0]}function a(t,r){var e=n(t,r);if(!e)return t+"";var i=e[0],o=e[1];return o<0?"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 u(t){return new s(t)}function s(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"):p[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 c(t){return t}function f(t){function n(t){function n(t){var n,a,u,c=M,p=x;if("c"===g)p=v(t)+p,t="";else{t=+t;var w=(t<0||1/t<0)&&(t*=-1,!0);if(t=v(t,m),w)for(n=-1,a=t.length,w=!1;++n<a;)if(u=t.charCodeAt(n),48<u&&u<58||"x"===g&&96<u&&u<103||"X"===g&&64<u&&u<71){w=!0;break}if(c=(w?"("===i?i:"-":"-"===i||"("===i?"":i)+c,p=p+("s"===g?y[8+d/3]:"")+(w&&"("===i?")":""),b)for(n=-1,a=t.length;++n<a;)if(u=t.charCodeAt(n),48>u||u>57){p=(46===u?s+t.slice(n+1):t.slice(n))+p,t=t.slice(0,n);break}}l&&!f&&(t=o(t,1/0));var P=c.length+t.length+p.length,j=P<h?new Array(h-P+1).join(r):"";switch(l&&f&&(t=o(j+t,j.length?h-p.length:1/0),j=""),e){case"<":return c+t+p+j;case"=":return c+j+t+p;case"^":return j.slice(0,P=j.length>>1)+c+t+p+j.slice(P)}return j+c+t+p}t=u(t);var r=t.fill,e=t.align,i=t.sign,c=t.symbol,f=t.zero,h=t.width,l=t.comma,m=t.precision,g=t.type,M="$"===c?a[0]:"#"===c&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",x="$"===c?a[1]:/[%p]/.test(g)?"%":"",v=p[g],b=!g||/[defgprs%]/.test(g);return m=null==m?g?6:12:/[gprs]/.test(g)?Math.max(1,Math.min(21,m)):Math.max(0,Math.min(20,m)),n.toString=function(){return t+""},n}function i(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=y[8+o/3];return function(t){return i(a*t)+s}}var o=t.grouping&&t.thousands?e(t.grouping,t.thousands):c,a=t.currency,s=t.decimal;return{format:n,formatPrefix:i}}function h(n){return x=f(n),t.format=x.format,t.formatPrefix=x.formatPrefix,x}function l(t){return Math.max(0,-r(Math.abs(t)))}function m(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,n){return t=Math.abs(t),n=Math.abs(n)-t,Math.max(0,r(n)-r(t))+1}var d,p={"":i,"%":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 a(100*t,n)},r:a,s:o,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;s.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,y=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];t.format,t.formatPrefix,h({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),t.formatDefaultLocale=h,t.formatLocale=f,t.formatSpecifier=u,t.precisionFixed=l,t.precisionPrefix=m,t.precisionRound=g,Object.defineProperty(t,"__esModule",{value:!0})});

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

export {default as formatLocale, format, formatPrefix} from "./src/locale";
export {default as formatDefaultLocale, format, formatPrefix} from "./src/defaultLocale";
export {default as formatLocale} from "./src/locale";
export {default as formatSpecifier} from "./src/formatSpecifier";

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

@@ -5,3 +5,3 @@ {

"grouping": [3],
"currency": ["", "\xa0€"]
"currency": ["", "\u00a0€"]
}
{
"decimal": ",",
"thousands": "\xa0",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "\xa0Kč"]
"currency": ["", "\u00a0Kč"]
}

@@ -5,3 +5,3 @@ {

"grouping": [3],
"currency": ["", "\xa0CHF"]
"currency": ["", "\u00a0CHF"]
}

@@ -5,3 +5,3 @@ {

"grouping": [3],
"currency": ["", "\xa0€"]
"currency": ["", "\u00a0€"]
}

@@ -5,3 +5,3 @@ {

"grouping": [3],
"currency": ["", "\xa0€"]
"currency": ["", "\u00a0€"]
}
{
"decimal": ",",
"thousands": "\xa0",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "\xa0€"]
"currency": ["", "\u00a0€"]
}
{
"decimal": ",",
"thousands": "\xa0",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "$"]
}

@@ -5,3 +5,3 @@ {

"grouping": [3],
"currency": ["", "\xa0€"]
"currency": ["", "\u00a0€"]
}
{
"decimal": ",",
"thousands": "\xa0",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "\xa0Ft"]
"currency": ["", "\u00a0Ft"]
}

@@ -5,3 +5,3 @@ {

"grouping": [3],
"currency": ["", "\xa0ден."]
"currency": ["", "\u00a0ден."]
}

@@ -5,3 +5,3 @@ {

"grouping": [3],
"currency": ["€\xa0", ""]
"currency": ["€\u00a0", ""]
}
{
"decimal": ",",
"thousands": "\xa0",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "\xa0руб."]
"currency": ["", "\u00a0руб."]
}
{
"decimal": ",",
"thousands": "\xa0",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "SEK"]
}
{
"name": "d3-format",
"version": "0.6.0",
"version": "1.0.0",
"description": "Format numbers for human consumption.",
"keywords": [
"d3",
"d3-module",
"format",

@@ -26,8 +27,9 @@ "localization"

"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-format.js -c -m -o build/d3-format.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-format.js ../d3.github.com/d3-format.v0.6.js && cp build/d3-format.min.js ../d3.github.com/d3-format.v0.6.min.js && cd ../d3.github.com && git add d3-format.v0.6.js d3-format.v0.6.min.js && git commit -m \"d3-format ${VERSION}\" && git push && cd - && zip -j build/d3-format.zip -- LICENSE README.md build/d3-format.js build/d3-format.min.js"
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-format.js ../d3.github.com/d3-format.v1.js && cp build/d3-format.min.js ../d3.github.com/d3-format.v1.min.js && cd ../d3.github.com && git add d3-format.v1.js d3-format.v1.min.js && git commit -m \"d3-format ${VERSION}\" && git push && cd - && zip -j build/d3-format.zip -- LICENSE README.md build/d3-format.js build/d3-format.min.js"
},
"devDependencies": {
"d3-queue": "3",
"eslint": "2",
"package-preamble": "0.0",
"rollup": "0.27",
"rollup": "0.33",
"tape": "4",

@@ -34,0 +36,0 @@ "uglify-js": "2"

@@ -66,10 +66,10 @@ # d3-format

See [*locale*.format](#locale_format) for a detailed specification, and try running [formatSpecifier](#formatSpecifier) on the above formats to decode their meaning.
See [*locale*.format](#locale_format) for a detailed specification, and try running [d3.formatSpecifier](#formatSpecifier) on the above formats to decode their meaning.
## Installing
If you use NPM, `npm install d3-format`. Otherwise, download the [latest release](https://github.com/d3/d3-format/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-format.v0.6.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
If you use NPM, `npm install d3-format`. Otherwise, download the [latest release](https://github.com/d3/d3-format/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-format.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
```html
<script src="https://d3js.org/d3-format.v0.6.min.js"></script>
<script src="https://d3js.org/d3-format.v1.min.js"></script>
<script>

@@ -88,7 +88,7 @@

An alias for [*locale*.format](#locale_format) on the U.S. English locale. See [formatLocale](#formatLocale) to define a new locale.
An alias for [*locale*.format](#locale_format) on the [default locale](#formatDefaultLocale).
<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. See [formatLocale](#formatLocale) to define a new locale.
An alias for [*locale*.formatPrefix](#locale_formatPrefix) on the [default locale](#formatDefaultLocale).

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

Note that the *thousands* property is a misnomer, as the grouping definition allows groups other than thousands.
<a name="formatDefaultLocale" href="#formatDefaultLocale">#</a> d3.<b>formatDefaultLocale</b>(<i>definition</i>)
Equivalent to [d3.formatLocale](#formatLocale), except it also redefines [d3.format](#format) and [d3.formatPrefix](#formatPrefix) to the new locale’s [*locale*.format](#locale_format) and [*locale*.formatPrefix](#locale_formatPrefix). If you do not set a default locale, it defaults to [U.S. English](https://github.com/d3/d3-format/blob/master/locale/en-US.json).

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

var defaultLocale = formatLocale({
decimal: ".",
thousands: ",",
grouping: [3],
currency: ["$", ""]
});
export var format = defaultLocale.format;
export var formatPrefix = defaultLocale.formatPrefix;
export default function formatLocale(locale) {
export default function(locale) {
var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity,

@@ -26,0 +16,0 @@ currency = locale.currency,

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