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.3.4 to 0.3.5

33

build/format.cjs.js

@@ -172,3 +172,3 @@ 'use strict';

function exponent$1(x) {
function exponent(x) {
return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;

@@ -366,2 +366,17 @@ };

// If the original value was negative, it may be rounded to zero during
// formatting; treat this as (positive) zero.
if (valueNegative) {
var i = -1, n = value.length, c;
valueNegative = false;
while (++i < n) {
if (c = value.charCodeAt(i), (48 < c && c < 58)
|| (type === "x" && 96 < c && c < 103)
|| (type === "X" && 64 < c && c < 71)) {
valueNegative = true;
break;
}
}
}
// Compute the prefix and suffix.

@@ -407,3 +422,3 @@ valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;

var f = format((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
k = Math.pow(10, -e),

@@ -422,14 +437,14 @@ prefix = prefixes[8 + e / 3];

function precisionRound(step, max) {
return Math.max(0, exponent$1(Math.abs(max)) - exponent$1(Math.abs(step))) + 1;
};
function precisionFixed(step) {
return Math.max(0, -exponent$1(Math.abs(step)));
return Math.max(0, -exponent(Math.abs(step)));
};
function precisionPrefix(step, value) {
return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
};
function precisionRound(step, max) {
return Math.max(0, exponent(Math.abs(max)) - exponent(Math.abs(step))) + 1;
};
var localeDefinitions = {

@@ -478,2 +493,2 @@ "ca-ES": caEs,

exports.precisionPrefix = precisionPrefix;
exports.precisionRound = precisionRound;
exports.precisionRound = precisionRound;

@@ -1,6 +0,3 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.format = {}));
}(this, function (exports) { 'use strict';
!function(global, exports) {
"use strict";

@@ -176,3 +173,3 @@ var zhCn = {

function exponent$1(x) {
function exponent(x) {
return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;

@@ -370,2 +367,17 @@ };

// If the original value was negative, it may be rounded to zero during
// formatting; treat this as (positive) zero.
if (valueNegative) {
var i = -1, n = value.length, c;
valueNegative = false;
while (++i < n) {
if (c = value.charCodeAt(i), (48 < c && c < 58)
|| (type === "x" && 96 < c && c < 103)
|| (type === "X" && 64 < c && c < 71)) {
valueNegative = true;
break;
}
}
}
// Compute the prefix and suffix.

@@ -411,3 +423,3 @@ valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;

var f = format((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
k = Math.pow(10, -e),

@@ -426,14 +438,14 @@ prefix = prefixes[8 + e / 3];

function precisionRound(step, max) {
return Math.max(0, exponent$1(Math.abs(max)) - exponent$1(Math.abs(step))) + 1;
};
function precisionFixed(step) {
return Math.max(0, -exponent$1(Math.abs(step)));
return Math.max(0, -exponent(Math.abs(step)));
};
function precisionPrefix(step, value) {
return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
};
function precisionRound(step, max) {
return Math.max(0, exponent(Math.abs(max)) - exponent(Math.abs(step))) + 1;
};
var localeDefinitions = {

@@ -483,3 +495,7 @@ "ca-ES": caEs,

exports.precisionRound = precisionRound;
exports.version = "0.3.5";
}));
if (typeof define === "function" && define.amd) global.format = exports, define("format", [], function() { return exports; });
else if (typeof module === "object" && module.exports) module.exports = exports;
else global.format = exports;
}(this, {});

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

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.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=[],u=0,a=n[0],c=0;i>0&&a>0&&(c+a+1>e&&(a=Math.max(1,e-c)),o.push(t.substring(i-=a,i+a)),!((c+=a+1)>e));)a=n[u=(u+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],u=o-(m=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")+r(n,Math.max(0,t+u-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 u(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 a(n){return new c(n)}function c(n){if(!(r=K.exec(n)))throw new Error("invalid format: "+n);var r,t=r[1]||" ",e=r[2]||">",i=r[3]||"-",o=r[4]||"",u=!!r[5],a=r[6]&&+r[6],c=!!r[7],s=r[8]&&+r[8].slice(1),h=r[9]||"";"n"===h?(c=!0,h="g"):I[h]||(h=""),(u||"0"===t&&"="===e)&&(u=!0,t="0",e="="),this.fill=t,this.align=e,this.sign=i,this.symbol=o,this.zero=u,this.width=a,this.comma=c,this.precision=s,this.type=h}function s(n){return n}function h(n){function r(n){n=a(n);var r=n.fill,t=n.align,e=n.sign,i=n.symbol,s=n.zero,h=n.width,l=n.comma,f=n.precision,g=n.type,d="$"===i?u[0]:"#"===i&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",p="$"===i?u[1]:/[%p]/.test(g)?"%":"",y=I[g],M=!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=d,u=p;if("c"===g)u=y(n)+u,n="";else{n=+n;var a=(0>n||0>1/n)&&(n*=-1,!0);if(n=y(n,f),i=(a?"("===e?e:"-":"-"===e||"("===e?"":e)+i,u=u+("s"===g?B[8+m/3]:"")+(a&&"("===e?")":""),M)for(var x,v=-1,w=n.length;++v<w;)if(x=n.charCodeAt(v),48>x||x>57){u=(46===x?c+n.slice(v+1):n.slice(v))+u,n=n.slice(0,v);break}}l&&!s&&(n=o(n,1/0));var b=i.length+n.length+u.length,S=h>b?new Array(h-b+1).join(r):"";switch(l&&s&&(n=o(S+n,S.length?h-u.length:1/0),S=""),t){case"<":return i+n+u+S;case"=":return i+S+n+u;case"^":return S.slice(0,b=S.length>>1)+i+n+u+S.slice(b)}return S+i+n+u}}function i(n,e){var i=r((n=a(n),n.type="f",n)),o=3*Math.max(-8,Math.min(8,Math.floor(t(e)/3))),u=Math.pow(10,-o),c=B[8+o/3];return function(n){return i(u*n)+c}}var o=n.grouping&&n.thousands?e(n.grouping,n.thousands):s,u=n.currency,c=n.decimal;return{format:r,formatPrefix:i}}function l(n,r){return Math.max(0,t(Math.abs(r))-t(Math.abs(n)))+1}function f(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){if("string"==typeof n){if(!G.hasOwnProperty(n))return null;n=G[n]}return h(n)}var m,p={decimal:".",thousands:",",grouping:[3],currency:["¥",""]},y={decimal:",",thousands:" ",grouping:[3],currency:["","SEK"]},M={decimal:",",thousands:" ",grouping:[3],currency:[""," руб."]},x={decimal:",",thousands:".",grouping:[3],currency:["R$",""]},v={decimal:",",thousands:".",grouping:[3],currency:["","zł"]},w={decimal:",",thousands:".",grouping:[3],currency:["€ ",""]},b={decimal:",",thousands:".",grouping:[3],currency:[""," ден."]},S={decimal:".",thousands:",",grouping:[3],currency:["₩",""]},E={decimal:".",thousands:",",grouping:[3],currency:["","円"]},P={decimal:",",thousands:".",grouping:[3],currency:["€",""]},j={decimal:",",thousands:" ",grouping:[3],currency:[""," Ft"]},A={decimal:".",thousands:",",grouping:[3],currency:["₪",""]},C={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},F={decimal:",",thousands:" ",grouping:[3],currency:["","$"]},$={decimal:",",thousands:" ",grouping:[3],currency:[""," €"]},k={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},z={decimal:".",thousands:",",grouping:[3],currency:["$",""]},R={decimal:".",thousands:",",grouping:[3],currency:["£",""]},L={decimal:".",thousands:",",grouping:[3],currency:["$",""]},N={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},U={decimal:",",thousands:"'",grouping:[3],currency:[""," CHF"]},H={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},I={"":u,"%":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)}},K=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(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 B=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],G={"ca-ES":H,"de-CH":U,"de-DE":N,"en-CA":L,"en-GB":R,"en-US":z,"es-ES":k,"fi-FI":$,"fr-CA":F,"fr-FR":C,"he-IL":A,"hu-HU":j,"it-IT":P,"ja-JP":E,"ko-KR":S,"mk-MK":b,"nl-NL":w,"pl-PL":v,"pt-BR":x,"ru-RU":M,"sv-SE":y,"zh-CN":p},O=h(z),T=O.format,X=O.formatPrefix;n.format=T,n.formatPrefix=X,n.localeFormat=d,n.formatSpecifier=a,n.precisionFixed=f,n.precisionPrefix=g,n.precisionRound=l});
!function(n,r){"use strict";function t(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 e(n){return n=t(Math.abs(n)),n?n[1]:NaN}function i(n,r){return function(t,e){for(var i=t.length,o=[],a=0,u=n[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=n[a=(a+1)%n.length];return o.reverse().join(r)}}function o(n,r){var e=t(n,r);if(!e)return n+"";var i=e[0],o=e[1],a=o-(p=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")+t(n,Math.max(0,r+a-1))[0]}function a(n,r){var e=t(n,r);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 u(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 s(n)}function s(n){if(!(r=X.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],u=r[6]&&+r[6],c=!!r[7],s=r[8]&&+r[8].slice(1),h=r[9]||"";"n"===h?(c=!0,h="g"):K[h]||(h=""),(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=h}function h(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,h=n.width,l=n.comma,f=n.precision,g=n.type,d="$"===i?a[0]:"#"===i&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",m="$"===i?a[1]:/[%p]/.test(g)?"%":"",y=K[g],M=!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=d,a=m;if("c"===g)a=y(n)+a,n="";else{n=+n;var c=(0>n||0>1/n)&&(n*=-1,!0);if(n=y(n,f),c){var x,v=-1,b=n.length;for(c=!1;++v<b;)if(x=n.charCodeAt(v),x>48&&58>x||"x"===g&&x>96&&103>x||"X"===g&&x>64&&71>x){c=!0;break}}if(i=(c?"("===e?e:"-":"-"===e||"("===e?"":e)+i,a=a+("s"===g?B[8+p/3]:"")+(c&&"("===e?")":""),M)for(var x,v=-1,b=n.length;++v<b;)if(x=n.charCodeAt(v),48>x||x>57){a=(46===x?u+n.slice(v+1):n.slice(v))+a,n=n.slice(0,v);break}}l&&!s&&(n=o(n,1/0));var w=i.length+n.length+a.length,S=h>w?new Array(h-w+1).join(r):"";switch(l&&s&&(n=o(S+n,S.length?h-a.length:1/0),S=""),t){case"<":return i+n+a+S;case"=":return i+S+n+a;case"^":return S.slice(0,w=S.length>>1)+i+n+a+S.slice(w)}return S+i+n+a}}function t(n,t){var i=r((n=c(n),n.type="f",n)),o=3*Math.max(-8,Math.min(8,Math.floor(e(t)/3))),a=Math.pow(10,-o),u=B[8+o/3];return function(n){return i(a*n)+u}}var o=n.grouping&&n.thousands?i(n.grouping,n.thousands):h,a=n.currency,u=n.decimal;return{format:r,formatPrefix:t}}function f(n){return Math.max(0,-e(Math.abs(n)))}function g(n,r){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(e(r)/3)))-e(Math.abs(n)))}function d(n,r){return Math.max(0,e(Math.abs(r))-e(Math.abs(n)))+1}function m(n){if("string"==typeof n){if(!G.hasOwnProperty(n))return null;n=G[n]}return l(n)}var p,y={decimal:".",thousands:",",grouping:[3],currency:["¥",""]},M={decimal:",",thousands:" ",grouping:[3],currency:["","SEK"]},x={decimal:",",thousands:" ",grouping:[3],currency:[""," руб."]},v={decimal:",",thousands:".",grouping:[3],currency:["R$",""]},b={decimal:",",thousands:".",grouping:[3],currency:["","zł"]},w={decimal:",",thousands:".",grouping:[3],currency:["€ ",""]},S={decimal:",",thousands:".",grouping:[3],currency:[""," ден."]},E={decimal:".",thousands:",",grouping:[3],currency:["₩",""]},P={decimal:".",thousands:",",grouping:[3],currency:["","円"]},A={decimal:",",thousands:".",grouping:[3],currency:["€",""]},C={decimal:",",thousands:" ",grouping:[3],currency:[""," Ft"]},j={decimal:".",thousands:",",grouping:[3],currency:["₪",""]},k={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},F={decimal:",",thousands:" ",grouping:[3],currency:["","$"]},$={decimal:",",thousands:" ",grouping:[3],currency:[""," €"]},z={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},R={decimal:".",thousands:",",grouping:[3],currency:["$",""]},L={decimal:".",thousands:",",grouping:[3],currency:["£",""]},N={decimal:".",thousands:",",grouping:[3],currency:["$",""]},U={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},H={decimal:",",thousands:"'",grouping:[3],currency:[""," CHF"]},I={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},K={"":u,"%":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 a(100*n,r)},r:a,s:o,X:function(n){return Math.round(n).toString(16).toUpperCase()},x:function(n){return Math.round(n).toString(16)}},X=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(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 B=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],G={"ca-ES":I,"de-CH":H,"de-DE":U,"en-CA":N,"en-GB":L,"en-US":R,"es-ES":z,"fi-FI":$,"fr-CA":F,"fr-FR":k,"he-IL":j,"hu-HU":C,"it-IT":A,"ja-JP":P,"ko-KR":E,"mk-MK":S,"nl-NL":w,"pl-PL":b,"pt-BR":v,"ru-RU":x,"sv-SE":M,"zh-CN":y},O=l(R),T=O.format,D=O.formatPrefix;r.format=T,r.formatPrefix=D,r.localeFormat=m,r.formatSpecifier=c,r.precisionFixed=f,r.precisionPrefix=g,r.precisionRound=d,r.version="0.3.5","function"==typeof define&&define.amd?(n.format=r,define("format",[],function(){return r})):"object"==typeof module&&module.exports?module.exports=r:n.format=r}(this,{});

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

import formatSpecifier from "./src/formatSpecifier";
import locale from "./src/locale";
import precisionFixed from "./src/precisionFixed";
import precisionPrefix from "./src/precisionPrefix";
import precisionRound from "./src/precisionRound";
import caEs from "./src/locale/ca-ES";

@@ -67,7 +62,5 @@ import deCh from "./src/locale/de-CH";

export {
formatSpecifier,
precisionFixed,
precisionPrefix,
precisionRound
};
export {default as formatSpecifier} from "./src/formatSpecifier";
export {default as precisionFixed} from "./src/precisionFixed";
export {default as precisionPrefix} from "./src/precisionPrefix";
export {default as precisionRound} from "./src/precisionRound";
{
"name": "d3-format",
"version": "0.3.4",
"version": "0.3.5",
"description": "Format numbers for human consumption.",

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

@@ -67,2 +67,17 @@ import exponent from "./exponent";

// If the original value was negative, it may be rounded to zero during
// formatting; treat this as (positive) zero.
if (valueNegative) {
var i = -1, n = value.length, c;
valueNegative = false;
while (++i < n) {
if (c = value.charCodeAt(i), (48 < c && c < 58)
|| (type === "x" && 96 < c && c < 103)
|| (type === "X" && 64 < c && c < 71)) {
valueNegative = true;
break;
}
}
}
// Compute the prefix and suffix.

@@ -69,0 +84,0 @@ valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;

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