Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cloudflare/util-formatters

Package Overview
Dependencies
Maintainers
84
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudflare/util-formatters - npm Package Compare versions

Comparing version 2.6.4 to 2.6.5

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [2.6.5](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.4...@cloudflare/util-formatters@2.6.5) (2021-04-29)
**Note:** Version bump only for package @cloudflare/util-formatters
## [2.6.4](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.3...@cloudflare/util-formatters@2.6.4) (2021-04-23)

@@ -8,0 +16,0 @@

66

es/formatters.js
import { format as d3Format } from 'd3-format';
import { SupportedLocales } from '@cloudflare/intl-core';
import moment from 'moment';
var DEFAULT_LOCALE = SupportedLocales.en_US;
var DEFAULT_CURRENCY = 'USD';
var SI_PATTERN = /^([^a-zA-Z]*)([a-zA-Z]?$)/;
const DEFAULT_LOCALE = SupportedLocales.en_US;
const DEFAULT_CURRENCY = 'USD';
const SI_PATTERN = /^([^a-zA-Z]*)([a-zA-Z]?$)/;
/**

@@ -31,3 +31,3 @@ * Moment formatters per-locale examples.

export var DateFormatters;
export let DateFormatters;

@@ -46,6 +46,5 @@ (function (DateFormatters) {

export var formatDate = function formatDate(value, formatter) {
var utc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
export const formatDate = (value, formatter, utc = false) => {
// TODO: Implement global UTC pyarreference fetching and formatting
var formattedDate = moment(value);
let formattedDate = moment(value);

@@ -58,4 +57,3 @@ if (utc) {

};
export var localizeNumberWithPrecision = function localizeNumberWithPrecision(number) {
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE;
export const localizeNumberWithPrecision = (number, locale = DEFAULT_LOCALE) => {
return number.toLocaleString(locale, {

@@ -65,10 +63,5 @@ maximumFractionDigits: 20

};
export var formatNumber = function formatNumber(number) {
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE;
var abbreviate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var decimalPlaces = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
var trimInsignificantZeros = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
var addSpaceAfterNumber = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
var val = number;
var siSuffix = ''; // SI units = International system of units.
export const formatNumber = (number, locale = DEFAULT_LOCALE, abbreviate = false, decimalPlaces = 2, trimInsignificantZeros = true, addSpaceAfterNumber = false) => {
let val = number;
let siSuffix = ''; // SI units = International system of units.
// Don't use SI units for sub-1 numbers (milli, micro, etc)

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

// specified string. Returns a result array, or null.
var siMatch = SI_PATTERN.exec(d3Format('s')(number)); // Split value from SI unit.
const siMatch = SI_PATTERN.exec(d3Format('s')(number)); // Split value from SI unit.
// siMatch is an array that looks like:

@@ -96,5 +89,5 @@ // ["479.247M", "479.247", "M", index: 0, input: "479.247M", groups: undefined]

var formatted = d3Format(".".concat(decimalPlaces).concat(trimInsignificantZeros ? '~' : '', "f"))(val);
var formattedAsLocale = Number(formatted).toLocaleString(locale);
var siToShortScaleSuffix = {
const formatted = d3Format(`.${decimalPlaces}${trimInsignificantZeros ? '~' : ''}f`)(val);
const formattedAsLocale = Number(formatted).toLocaleString(locale);
const siToShortScaleSuffix = {
k: 'k',

@@ -110,10 +103,8 @@ M: 'M',

var out = abbreviate === true && siToShortScaleSuffix.hasOwnProperty(siSuffix) ? [formattedAsLocale, siToShortScaleSuffix[siSuffix]] : [formattedAsLocale, siSuffix];
const out = abbreviate === true && siToShortScaleSuffix.hasOwnProperty(siSuffix) ? [formattedAsLocale, siToShortScaleSuffix[siSuffix]] : [formattedAsLocale, siSuffix];
return out.join(addSpaceAfterNumber ? ' ' : '');
};
export var formatCurrency = function formatCurrency() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
locale: DEFAULT_LOCALE
};
export const formatCurrency = (value = 0, options = {
locale: DEFAULT_LOCALE
}) => {
return Number(value).toLocaleString(options.locale, {

@@ -155,5 +146,3 @@ style: 'currency',

export var formatBytes = function formatBytes(number) {
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE;
var includeDecimals = arguments.length > 2 ? arguments[2] : undefined;
export const formatBytes = (number, locale = DEFAULT_LOCALE, includeDecimals) => {
return formatNumber(number, locale, 'si', includeDecimals ? 2 : 0) // Add space between value and SI unit

@@ -170,8 +159,5 @@ .replace(/([a-zA-Z]?)$/, ' $1') + 'B';

export var formatBits = function formatBits(number) {
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE;
var includeDecimals = arguments.length > 2 ? arguments[2] : undefined;
var useBit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
export const formatBits = (number, locale = DEFAULT_LOCALE, includeDecimals, useBit = true) => {
return formatNumber(number, locale, 'si', includeDecimals ? 2 : 0) // Add space between value and SI unit
.replace(/([a-zA-Z]?)$/, ' $1') + "".concat(useBit ? 'bit' : 'b');
.replace(/([a-zA-Z]?)$/, ' $1') + `${useBit ? 'bit' : 'b'}`;
};

@@ -187,11 +173,5 @@ /**

export var formatNumberForAnalytics = function formatNumberForAnalytics(number) {
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE;
var useSI = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var decimalPlaces = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
var trimInsignificantZeros = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
export const formatNumberForAnalytics = (number, locale = DEFAULT_LOCALE, useSI = false, decimalPlaces = 2, trimInsignificantZeros = true) => {
return formatNumber(number, locale, useSI, decimalPlaces, trimInsignificantZeros);
};
export var capitalizeStr = function capitalizeStr(str) {
return str && str.charAt(0).toUpperCase() + str.slice(1);
};
export const capitalizeStr = str => str && str.charAt(0).toUpperCase() + str.slice(1);
{
"name": "@cloudflare/util-formatters",
"description": "",
"version": "2.6.4",
"version": "2.6.5",
"types": "./dist/index.d.ts",

@@ -20,7 +20,7 @@ "main": "lib/index.js",

"dependencies": {
"@cloudflare/intl-core": "^1.6.2",
"@cloudflare/intl-core": "^1.6.3",
"d3-format": "^1.3.2",
"moment": "^2.22.1"
},
"gitHead": "3b74aee5f2437d3981de017126c02cd66ffbeb2d"
"gitHead": "780d148e1865da2dd1d1a9077ceca2a9be40ee99"
}
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