@cloudflare/util-formatters 2.6.12 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [2.6.12](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.10...@cloudflare/util-formatters@2.6.12) (2021-10-22)
6
+ # [2.7.0](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.15...@cloudflare/util-formatters@2.7.0) (2021-11-29)
7
+
8
+
9
+ ### Features
10
+
11
+ * **stratus:** EW-5929 Integrate percentage view for chart legend ([7fecfd9](http://stash.cfops.it:7999/fe/stratus/commits/7fecfd9))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.6.15](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.14...@cloudflare/util-formatters@2.6.15) (2021-11-23)
7
18
 
8
19
  **Note:** Version bump only for package @cloudflare/util-formatters
9
20
 
@@ -11,6 +22,25 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
22
 
12
23
 
13
24
 
25
+ ## [2.6.14](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.13...@cloudflare/util-formatters@2.6.14) (2021-11-22)
26
+
27
+ **Note:** Version bump only for package @cloudflare/util-formatters
28
+
29
+
30
+
31
+
32
+
33
+ ## [2.6.13](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.10...@cloudflare/util-formatters@2.6.13) (2021-10-28)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * **stratus:** UI-000: Ran yarn run v1.18.0 ([54f1c7e](http://stash.cfops.it:7999/fe/stratus/commits/54f1c7e))
39
+
40
+
41
+
42
+
43
+
14
44
  ## [2.6.10](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-formatters@2.6.9...@cloudflare/util-formatters@2.6.10) (2021-06-03)
15
45
 
16
46
  **Note:** Version bump only for package @cloudflare/util-formatters
@@ -41,7 +41,7 @@ export declare type CurrencyValue = number | string | undefined;
41
41
  export declare type CurrencyOptions = {
42
42
  locale: SupportedLocales;
43
43
  };
44
- export declare const formatCurrency: (value?: CurrencyValue, options?: CurrencyOptions) => string;
44
+ export declare const formatCurrency: (value?: CurrencyValue, options?: CurrencyOptions, minimumFractionDigits?: number, maximumFractionDigits?: number) => string;
45
45
  /**
46
46
  * @param {Number} number
47
47
  * @param {String} locale
@@ -67,3 +67,4 @@ export declare const formatBits: (number: number, locale: SupportedLocales | und
67
67
  */
68
68
  export declare const formatNumberForAnalytics: (number: number, locale?: SupportedLocales, useSI?: boolean, decimalPlaces?: number, trimInsignificantZeros?: boolean) => string;
69
69
  export declare const capitalizeStr: (str: string) => string | undefined;
70
+ export declare const formatPercentage: (value: number, total: number) => string;
package/es/formatters.js CHANGED
@@ -99,14 +99,13 @@ export const formatNumber = (number, locale = DEFAULT_LOCALE, abbreviate = false
99
99
  };
100
100
  export const formatCurrency = (value = 0, options = {
101
101
  locale: DEFAULT_LOCALE
102
- }) => {
102
+ }, minimumFractionDigits = 2, maximumFractionDigits = 2) => {
103
103
  return Number(value).toLocaleString(options.locale, {
104
104
  style: 'currency',
105
105
  // We should *always* display the currency that was billed in (USD).
106
106
  currency: DEFAULT_CURRENCY,
107
- // In the future—we can make these properties configurable.
108
- minimumFractionDigits: 2,
109
- maximumFractionDigits: 2
107
+ minimumFractionDigits,
108
+ maximumFractionDigits
110
109
  })
111
110
  /**
112
111
  * `Number.toLocaleString` with `style: 'currency'` behaves differently
@@ -164,4 +163,5 @@ export const formatBits = (number, locale = DEFAULT_LOCALE, includeDecimals, use
164
163
  export const formatNumberForAnalytics = (number, locale = DEFAULT_LOCALE, useSI = false, decimalPlaces = 2, trimInsignificantZeros = true) => {
165
164
  return formatNumber(number, locale, useSI, decimalPlaces, trimInsignificantZeros);
166
165
  };
167
- export const capitalizeStr = str => str && str.charAt(0).toUpperCase() + str.slice(1);
166
+ export const capitalizeStr = str => str && str.charAt(0).toUpperCase() + str.slice(1);
167
+ export const formatPercentage = (value, total) => `${Math.round(value * 100 / total * 100) / 100}%`;
package/lib/formatters.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.capitalizeStr = exports.formatNumberForAnalytics = exports.formatBits = exports.formatBytes = exports.formatCurrency = exports.formatNumber = exports.localizeNumberWithPrecision = exports.formatDate = exports.DateFormatters = void 0;
6
+ exports.formatPercentage = exports.capitalizeStr = exports.formatNumberForAnalytics = exports.formatBits = exports.formatBytes = exports.formatCurrency = exports.formatNumber = exports.localizeNumberWithPrecision = exports.formatDate = exports.DateFormatters = void 0;
7
7
 
8
8
  var _d3Format = require("d3-format");
9
9
 
@@ -131,13 +131,14 @@ var formatCurrency = function formatCurrency() {
131
131
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
132
132
  locale: DEFAULT_LOCALE
133
133
  };
134
+ var minimumFractionDigits = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
135
+ var maximumFractionDigits = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
134
136
  return Number(value).toLocaleString(options.locale, {
135
137
  style: 'currency',
136
138
  // We should *always* display the currency that was billed in (USD).
137
139
  currency: DEFAULT_CURRENCY,
138
- // In the future—we can make these properties configurable.
139
- minimumFractionDigits: 2,
140
- maximumFractionDigits: 2
140
+ minimumFractionDigits: minimumFractionDigits,
141
+ maximumFractionDigits: maximumFractionDigits
141
142
  })
142
143
  /**
143
144
  * `Number.toLocaleString` with `style: 'currency'` behaves differently
@@ -220,4 +221,10 @@ var capitalizeStr = function capitalizeStr(str) {
220
221
  return str && str.charAt(0).toUpperCase() + str.slice(1);
221
222
  };
222
223
 
223
- exports.capitalizeStr = capitalizeStr;
224
+ exports.capitalizeStr = capitalizeStr;
225
+
226
+ var formatPercentage = function formatPercentage(value, total) {
227
+ return "".concat(Math.round(value * 100 / total * 100) / 100, "%");
228
+ };
229
+
230
+ exports.formatPercentage = formatPercentage;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudflare/util-formatters",
3
3
  "description": "",
4
- "version": "2.6.12",
4
+ "version": "2.7.0",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -17,9 +17,9 @@
17
17
  "autoGeneratedReadme": true
18
18
  },
19
19
  "dependencies": {
20
- "@cloudflare/intl-core": "^1.10.2",
20
+ "@cloudflare/intl-core": "^1.10.3",
21
21
  "d3-format": "^1.3.2",
22
22
  "moment": "^2.22.1"
23
23
  },
24
- "gitHead": "89a3ba424d607c36db302c7304f9edad02242164"
24
+ "gitHead": "46e16cc7018fe9cf0cde631e409f4d06b4441af7"
25
25
  }