@pushwoosh/kit-helpers 4.8.0 → 4.8.2

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,3 @@
1
+ type NumberFormat = 'spaced' | 'short';
2
+ export declare const formatNumber: (number: number, format: NumberFormat) => string;
3
+ export {};
@@ -0,0 +1,21 @@
1
+ const getNumberAsSpacedString = number => number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
2
+ const getNumberAsShortString = num => {
3
+ if (num < 10000) {
4
+ return getNumberAsSpacedString(num);
5
+ }
6
+ const formatter = new Intl.NumberFormat('en', {
7
+ notation: 'compact',
8
+ maximumFractionDigits: 1
9
+ });
10
+ return formatter.format(num);
11
+ };
12
+ export const formatNumber = (number, format) => {
13
+ switch (format) {
14
+ case 'spaced':
15
+ return getNumberAsSpacedString(number);
16
+ case 'short':
17
+ return getNumberAsShortString(number);
18
+ default:
19
+ return number.toString();
20
+ }
21
+ };
package/grid.d.ts CHANGED
@@ -1,33 +1,47 @@
1
1
  type StrNum = string | number;
2
2
  export declare const toCssValue: (value: StrNum) => string;
3
+ type CssBoxSides<T> = {
4
+ top?: T;
5
+ right?: T;
6
+ bottom?: T;
7
+ left?: T;
8
+ } | {
9
+ horizontal: T;
10
+ top?: T;
11
+ bottom?: T;
12
+ } | {
13
+ vertical: T;
14
+ right?: T;
15
+ left?: T;
16
+ };
3
17
  export declare const GridContainer: import("styled-components").StyledComponent<"div", any, {
4
18
  $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
5
19
  $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
6
20
  $bgColor?: string | undefined;
7
- $border?: string | undefined;
21
+ $border?: string | CssBoxSides<string> | undefined;
8
22
  $borderRadius?: StrNum | undefined;
9
23
  $boxShadow?: string | undefined;
10
24
  $gap?: StrNum | undefined;
11
25
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
12
26
  $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
13
27
  $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
14
- $margin?: StrNum | undefined;
15
- $padding?: StrNum | undefined;
28
+ $margin?: StrNum | CssBoxSides<StrNum> | undefined;
29
+ $padding?: StrNum | CssBoxSides<StrNum> | undefined;
16
30
  $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
17
31
  }, never>;
18
32
  export declare const Columns: import("styled-components").StyledComponent<"div", any, {
19
33
  $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
20
34
  $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
21
35
  $bgColor?: string | undefined;
22
- $border?: string | undefined;
36
+ $border?: string | CssBoxSides<string> | undefined;
23
37
  $borderRadius?: StrNum | undefined;
24
38
  $boxShadow?: string | undefined;
25
39
  $gap?: StrNum | undefined;
26
40
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
27
41
  $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
28
42
  $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
29
- $margin?: StrNum | undefined;
30
- $padding?: StrNum | undefined;
43
+ $margin?: StrNum | CssBoxSides<StrNum> | undefined;
44
+ $padding?: StrNum | CssBoxSides<StrNum> | undefined;
31
45
  $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
32
46
  } & {
33
47
  $sizes: StrNum;
@@ -36,15 +50,15 @@ export declare const Rows: import("styled-components").StyledComponent<"div", an
36
50
  $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
37
51
  $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
38
52
  $bgColor?: string | undefined;
39
- $border?: string | undefined;
53
+ $border?: string | CssBoxSides<string> | undefined;
40
54
  $borderRadius?: StrNum | undefined;
41
55
  $boxShadow?: string | undefined;
42
56
  $gap?: StrNum | undefined;
43
57
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
44
58
  $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
45
59
  $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
46
- $margin?: StrNum | undefined;
47
- $padding?: StrNum | undefined;
60
+ $margin?: StrNum | CssBoxSides<StrNum> | undefined;
61
+ $padding?: StrNum | CssBoxSides<StrNum> | undefined;
48
62
  $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
49
63
  } & {
50
64
  $sizes: StrNum;
@@ -53,15 +67,15 @@ export declare const Horizontal: import("styled-components").StyledComponent<"di
53
67
  $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
54
68
  $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
55
69
  $bgColor?: string | undefined;
56
- $border?: string | undefined;
70
+ $border?: string | CssBoxSides<string> | undefined;
57
71
  $borderRadius?: StrNum | undefined;
58
72
  $boxShadow?: string | undefined;
59
73
  $gap?: StrNum | undefined;
60
74
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
61
75
  $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
62
76
  $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
63
- $margin?: StrNum | undefined;
64
- $padding?: StrNum | undefined;
77
+ $margin?: StrNum | CssBoxSides<StrNum> | undefined;
78
+ $padding?: StrNum | CssBoxSides<StrNum> | undefined;
65
79
  $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
66
80
  } & {
67
81
  $gridAutoFlow: string;
@@ -70,15 +84,15 @@ export declare const Vertical: import("styled-components").StyledComponent<"div"
70
84
  $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
71
85
  $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
72
86
  $bgColor?: string | undefined;
73
- $border?: string | undefined;
87
+ $border?: string | CssBoxSides<string> | undefined;
74
88
  $borderRadius?: StrNum | undefined;
75
89
  $boxShadow?: string | undefined;
76
90
  $gap?: StrNum | undefined;
77
91
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
78
92
  $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
79
93
  $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
80
- $margin?: StrNum | undefined;
81
- $padding?: StrNum | undefined;
94
+ $margin?: StrNum | CssBoxSides<StrNum> | undefined;
95
+ $padding?: StrNum | CssBoxSides<StrNum> | undefined;
82
96
  $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
83
97
  } & {
84
98
  $gridAutoFlow: string;
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './grid';
2
2
  export * from './expand';
3
3
  export * from './hooks/useClickAway';
4
+ export { formatNumber } from './formatNumber';
4
5
  export { default as usePersistentFunction } from './hooks/usePersistentFunction';
5
6
  export { default as useEffectOnce } from './hooks/useEffectOnce';
6
7
  export { default as useMountedState } from './hooks/useMountedState';
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './grid';
2
2
  export * from './expand';
3
3
  export * from './hooks/useClickAway';
4
+ export { formatNumber } from './formatNumber';
4
5
  export { default as usePersistentFunction } from './hooks/usePersistentFunction';
5
6
  export { default as useEffectOnce } from './hooks/useEffectOnce';
6
7
  export { default as useMountedState } from './hooks/useMountedState';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-helpers",
3
- "version": "4.8.0",
3
+ "version": "4.8.2",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",