@cloudflare/util-formatters
Advanced tools
Comparing version 2.4.0 to 2.4.2
@@ -6,2 +6,18 @@ # Change Log | ||
## [2.4.2](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.4.0...@cloudflare/util-formatters@2.4.2) (2019-11-20) | ||
**Note:** Version bump only for package @cloudflare/util-formatters | ||
## [2.4.1](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.4.0...@cloudflare/util-formatters@2.4.1) (2019-11-19) | ||
**Note:** Version bump only for package @cloudflare/util-formatters | ||
# [2.4.0](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.0.0...@cloudflare/util-formatters@2.4.0) (2019-11-13) | ||
@@ -8,0 +24,0 @@ |
import { ESupportedLocales } from '@cloudflare/intl-core'; | ||
import moment from 'moment'; | ||
/** | ||
@@ -33,6 +32,9 @@ * Moment formatters per-locale examples. | ||
LongDayMonth = "D MMMM", | ||
ShortDayMonth = "D MMM" | ||
ShortDayMonth = "D MMM", | ||
DateTimeWithSeparators = "L LT", | ||
DateTimeSecondsWithSeparators = "L LTS" | ||
} | ||
export declare const formatDate: (value: string | moment.Moment, formatter: DateFormatters) => string; | ||
export declare const formatNumber: (number: string | number, locale?: ESupportedLocales, useSI?: boolean, significantDecimals?: number, trimInsignificantZeros?: boolean) => string; | ||
export declare const formatDate: (value: any, formatter: DateFormatters) => string; | ||
export declare const localizeNumberWithPrecision: (number: number, locale?: ESupportedLocales) => string; | ||
export declare const formatNumber: (number: number, locale?: ESupportedLocales, useSI?: boolean, decimalPlaces?: number, trimInsignificantZeros?: boolean) => string; | ||
export declare type CurrencyOptions = { | ||
@@ -53,6 +55,6 @@ locale: ESupportedLocales; | ||
* @param {Boolean} [useSI] | ||
* @param {Number} [significantDecimals] | ||
* @param {Number} [decimalPlaces] | ||
* @param {Boolean} [trimInsignificantZeros] | ||
* @return {String} | ||
*/ | ||
export declare const formatNumberForAnalytics: (number: number, locale?: ESupportedLocales, useSI?: boolean, significantDecimals?: number, trimInsignificantZeros?: boolean) => string; | ||
export declare const formatNumberForAnalytics: (number: number, locale?: ESupportedLocales, useSI?: boolean, decimalPlaces?: number, trimInsignificantZeros?: boolean) => string; |
@@ -41,2 +41,4 @@ import { format as d3Format } from 'd3-format'; | ||
DateFormatters["ShortDayMonth"] = "D MMM"; | ||
DateFormatters["DateTimeWithSeparators"] = "L LT"; | ||
DateFormatters["DateTimeSecondsWithSeparators"] = "L LTS"; | ||
})(DateFormatters || (DateFormatters = {})); | ||
@@ -46,26 +48,20 @@ | ||
// TODO: Implement global UTC preference fetching and formatting | ||
return moment(value).format(formatter); | ||
var date = new Date(value); | ||
return moment(date).format(formatter); | ||
}; | ||
export var localizeNumberWithPrecision = function localizeNumberWithPrecision(number) { | ||
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE; | ||
return number.toLocaleString(locale, { | ||
maximumFractionDigits: 20 | ||
}); | ||
}; | ||
export var formatNumber = function formatNumber(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 significantDecimals = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var decimalPlaces = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var trimInsignificantZeros = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; | ||
var val = number; | ||
var suffix = ''; | ||
if (typeof val === 'string') { | ||
// Strip from the string anything that's a non-numeric character. | ||
val = val.replace(/[^\d.-]/g, ''); // If val cannot be coerced to a number, return original input so we never return NaN. | ||
if (Number.isNaN(Number(val))) { | ||
return val; | ||
} // If we've parsed a valid number from the string, localize and return it. | ||
return Number(val).toLocaleString(locale); | ||
} // SI units = International system of units. | ||
var suffix = ''; // SI units = International system of units. | ||
// Don't use SI units for sub-1 numbers (milli, micro, etc) | ||
if (useSI && number >= 1) { | ||
@@ -90,3 +86,3 @@ // d3Format notes: | ||
var formatted = d3Format(".".concat(significantDecimals).concat(trimInsignificantZeros ? '~' : '', "f"))(val); | ||
var formatted = d3Format(".".concat(decimalPlaces).concat(trimInsignificantZeros ? '~' : '', "f"))(val); | ||
return Number(formatted).toLocaleString(locale) + suffix; | ||
@@ -145,3 +141,3 @@ }; | ||
* @param {Boolean} [useSI] | ||
* @param {Number} [significantDecimals] | ||
* @param {Number} [decimalPlaces] | ||
* @param {Boolean} [trimInsignificantZeros] | ||
@@ -154,5 +150,5 @@ * @return {String} | ||
var useSI = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var significantDecimals = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var decimalPlaces = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var trimInsignificantZeros = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; | ||
return formatNumber(number, locale, useSI, significantDecimals, trimInsignificantZeros); | ||
return formatNumber(number, locale, useSI, decimalPlaces, trimInsignificantZeros); | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { formatNumberForAnalytics, formatBytes, formatNumber, formatDate, formatCurrency, DateFormatters } from './formatters'; | ||
export { formatNumberForAnalytics, formatBytes, formatNumber, formatDate, formatCurrency, DateFormatters }; | ||
import { formatNumberForAnalytics, formatBytes, formatNumber, formatDate, formatCurrency, localizeNumberWithPrecision, DateFormatters } from './formatters'; | ||
export { formatNumberForAnalytics, formatBytes, formatNumber, formatDate, formatCurrency, localizeNumberWithPrecision, DateFormatters }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.formatNumberForAnalytics = exports.formatBytes = exports.formatCurrency = exports.formatNumber = exports.formatDate = exports.DateFormatters = void 0; | ||
exports.formatNumberForAnalytics = exports.formatBytes = exports.formatCurrency = exports.formatNumber = exports.localizeNumberWithPrecision = exports.formatDate = exports.DateFormatters = void 0; | ||
@@ -55,2 +55,4 @@ var _d3Format = require("d3-format"); | ||
DateFormatters["ShortDayMonth"] = "D MMM"; | ||
DateFormatters["DateTimeWithSeparators"] = "L LT"; | ||
DateFormatters["DateTimeSecondsWithSeparators"] = "L LTS"; | ||
})(DateFormatters || (exports.DateFormatters = DateFormatters = {})); | ||
@@ -60,3 +62,4 @@ | ||
// TODO: Implement global UTC preference fetching and formatting | ||
return (0, _moment.default)(value).format(formatter); | ||
var date = new Date(value); | ||
return (0, _moment.default)(date).format(formatter); | ||
}; | ||
@@ -66,24 +69,20 @@ | ||
var localizeNumberWithPrecision = function localizeNumberWithPrecision(number) { | ||
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE; | ||
return number.toLocaleString(locale, { | ||
maximumFractionDigits: 20 | ||
}); | ||
}; | ||
exports.localizeNumberWithPrecision = localizeNumberWithPrecision; | ||
var formatNumber = function formatNumber(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 significantDecimals = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var decimalPlaces = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var trimInsignificantZeros = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; | ||
var val = number; | ||
var suffix = ''; | ||
if (typeof val === 'string') { | ||
// Strip from the string anything that's a non-numeric character. | ||
val = val.replace(/[^\d.-]/g, ''); // If val cannot be coerced to a number, return original input so we never return NaN. | ||
if (Number.isNaN(Number(val))) { | ||
return val; | ||
} // If we've parsed a valid number from the string, localize and return it. | ||
return Number(val).toLocaleString(locale); | ||
} // SI units = International system of units. | ||
var suffix = ''; // SI units = International system of units. | ||
// Don't use SI units for sub-1 numbers (milli, micro, etc) | ||
if (useSI && number >= 1) { | ||
@@ -108,3 +107,3 @@ // d3Format notes: | ||
var formatted = (0, _d3Format.format)(".".concat(significantDecimals).concat(trimInsignificantZeros ? '~' : '', "f"))(val); | ||
var formatted = (0, _d3Format.format)(".".concat(decimalPlaces).concat(trimInsignificantZeros ? '~' : '', "f"))(val); | ||
return Number(formatted).toLocaleString(locale) + suffix; | ||
@@ -169,3 +168,3 @@ }; | ||
* @param {Boolean} [useSI] | ||
* @param {Number} [significantDecimals] | ||
* @param {Number} [decimalPlaces] | ||
* @param {Boolean} [trimInsignificantZeros] | ||
@@ -181,7 +180,7 @@ * @return {String} | ||
var useSI = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var significantDecimals = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var decimalPlaces = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
var trimInsignificantZeros = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; | ||
return formatNumber(number, locale, useSI, significantDecimals, trimInsignificantZeros); | ||
return formatNumber(number, locale, useSI, decimalPlaces, trimInsignificantZeros); | ||
}; | ||
exports.formatNumberForAnalytics = formatNumberForAnalytics; |
@@ -36,2 +36,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "localizeNumberWithPrecision", { | ||
enumerable: true, | ||
get: function get() { | ||
return _formatters.localizeNumberWithPrecision; | ||
} | ||
}); | ||
Object.defineProperty(exports, "DateFormatters", { | ||
@@ -38,0 +44,0 @@ enumerable: true, |
{ | ||
"name": "@cloudflare/util-formatters", | ||
"description": "", | ||
"version": "2.4.0", | ||
"version": "2.4.2", | ||
"types": "./dist/index.d.ts", | ||
@@ -21,7 +21,7 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@cloudflare/intl-core": "^1.2.6", | ||
"@cloudflare/intl-core": "^1.4.0", | ||
"d3-format": "^1.3.2", | ||
"moment": "^2.22.1" | ||
}, | ||
"gitHead": "45bf3f03d804ca368c8cd366d5d74480bc1b993a" | ||
"gitHead": "2c7116804e9d7e6f2e005ee4d7aa37829d2624a3" | ||
} |
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
20379
396
Updated@cloudflare/intl-core@^1.4.0