@pushwoosh/kit-helpers 4.8.1 → 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/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.1",
3
+ "version": "4.8.2",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",