@neovici/cosmoz-utils 6.3.0 → 6.5.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.
@@ -0,0 +1 @@
1
+ export declare const useStyleSheet: (css: string) => void;
@@ -0,0 +1,15 @@
1
+ import { useEffect, useMemo } from '@pionjs/pion';
2
+ import { useHost } from './use-host';
3
+ export const useStyleSheet = (css) => {
4
+ const host = useHost();
5
+ const cs = useMemo(() => new CSSStyleSheet(), []);
6
+ useEffect(() => {
7
+ host.shadowRoot.adoptedStyleSheets = [
8
+ ...host.shadowRoot.adoptedStyleSheets,
9
+ cs,
10
+ ];
11
+ }, []);
12
+ useEffect(() => {
13
+ cs.replaceSync(css);
14
+ }, [css]);
15
+ };
package/dist/money.d.ts CHANGED
@@ -13,22 +13,25 @@ isAmount: (potentialAmount: unknown) => potentialAmount is Amount,
13
13
  * Render an amount with decimal separator and currency symbol.
14
14
  * @param {object} money Money with amount property and optionally currency property.
15
15
  * @param {void|string} locale Locale to format the amount in.
16
+ * @param {number} maximumFractionDigits Maximum number of decimals to display.
16
17
  * @return {string} Formatted amount.
17
18
  */
18
- renderAmount: (money: Amount | null, locale?: string) => string | undefined,
19
+ renderAmount: (money: Amount | null, locale?: string, maximumFractionDigits?: number) => string | undefined,
19
20
  /**
20
21
  * Alias for renderAmount(money). Render an amount with decimal separator and currency symbol.
21
22
  * @param {object} money Money with amount property and optionally currency property.
22
23
  * @return {string} Formatted amount.
23
24
  */
24
- renderMoney: (money: Amount | null, locale?: string) => string | undefined,
25
+ renderMoney: (money: Amount | null, locale?: string, maximumFractionDigits?: number) => string | undefined,
25
26
  /**
26
27
  * Render an amount with decimal separator but without currency symbol.
27
28
  * @param {object} money Money with amount property and optionally currency property.
28
29
  * @param {void|string} locale Locale to format the amount in.
30
+ * @param {number} minimumFractionDigits Minimum number of decimals to display.
31
+ * @param {number} maximumFractionDigits Maximum number of decimals to display.
29
32
  * @return {string} Formatted number.
30
33
  */
31
- renderNumberAmount: (money: Amount, locale?: string) => string,
34
+ renderNumberAmount: (money: Amount, locale?: string, minimumFractionDigits?: number, maximumFractionDigits?: number) => string,
32
35
  /**
33
36
  * Round a number to a given precision.
34
37
  * @param {string} number Number with decimals to round.
package/dist/money.js CHANGED
@@ -1,4 +1,4 @@
1
- const CURRENCY_FORMATTERS = {}, NUMBER_FORMATTERS = {}, _getCurrencyFormatter = function (currency, locale, currencyDisplay = 'code') {
1
+ const CURRENCY_FORMATTERS = {}, NUMBER_FORMATTERS = {}, _getCurrencyFormatter = function (currency, locale, maximumFractionDigits = 2) {
2
2
  if (currency == null) {
3
3
  return;
4
4
  }
@@ -8,7 +8,8 @@ const CURRENCY_FORMATTERS = {}, NUMBER_FORMATTERS = {}, _getCurrencyFormatter =
8
8
  CURRENCY_FORMATTERS[key] = new Intl.NumberFormat(locale, {
9
9
  style: 'currency',
10
10
  currency,
11
- currencyDisplay,
11
+ currencyDisplay: 'code',
12
+ maximumFractionDigits,
12
13
  });
13
14
  }
14
15
  catch (e) {
@@ -33,13 +34,14 @@ isAmount = (potentialAmount) => potentialAmount != null &&
33
34
  * Render an amount with decimal separator and currency symbol.
34
35
  * @param {object} money Money with amount property and optionally currency property.
35
36
  * @param {void|string} locale Locale to format the amount in.
37
+ * @param {number} maximumFractionDigits Maximum number of decimals to display.
36
38
  * @return {string} Formatted amount.
37
39
  */
38
- renderAmount = (money, locale) => {
40
+ renderAmount = (money, locale, maximumFractionDigits) => {
39
41
  if (money?.amount == null) {
40
42
  return;
41
43
  }
42
- const formatter = _getCurrencyFormatter(money.currency, locale);
44
+ const formatter = _getCurrencyFormatter(money.currency, locale, maximumFractionDigits);
43
45
  if (formatter == null) {
44
46
  return;
45
47
  }
@@ -55,14 +57,16 @@ renderMoney = renderAmount,
55
57
  * Render an amount with decimal separator but without currency symbol.
56
58
  * @param {object} money Money with amount property and optionally currency property.
57
59
  * @param {void|string} locale Locale to format the amount in.
60
+ * @param {number} minimumFractionDigits Minimum number of decimals to display.
61
+ * @param {number} maximumFractionDigits Maximum number of decimals to display.
58
62
  * @return {string} Formatted number.
59
63
  */
60
- renderNumberAmount = (money, locale) => {
64
+ renderNumberAmount = (money, locale, minimumFractionDigits = 2, maximumFractionDigits = 2) => {
61
65
  const key = locale || '0';
62
66
  if (NUMBER_FORMATTERS[key] == null) {
63
67
  NUMBER_FORMATTERS[key] = new Intl.NumberFormat(locale, {
64
- minimumFractionDigits: 2,
65
- maximumFractionDigits: 2,
68
+ minimumFractionDigits,
69
+ maximumFractionDigits,
66
70
  });
67
71
  }
68
72
  return NUMBER_FORMATTERS[key].format(money.amount);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",