|
1 | | -export const capitalizeFirstLetter = (str: string) => |
2 | | - str && str.length ? str.charAt(0).toUpperCase() + str.slice(1) : str; |
| 1 | +import { |
| 2 | + openExternalApp, |
| 3 | + openAppInAppStore, |
| 4 | + openAppInPlayStore, |
| 5 | +} from "./linking"; |
3 | 6 |
|
4 | | -export const capitalizeAllStartingWords = ( |
5 | | - str: string, |
6 | | - lower: boolean = false, |
7 | | -) => |
8 | | - (lower ? str.toLowerCase() : str).replace(/(?:^|\s|[''({])+\S/g, (match) => |
9 | | - match.toUpperCase(), |
10 | | - ); |
11 | | - |
12 | | -export const capitalize = (str: string) => |
13 | | - str.charAt(0).toUpperCase() + str.slice(1); |
14 | | - |
15 | | -export const generateRandomNumber = (min: number, max: number) => |
16 | | - Math.floor(Math.random() * (max - min + 1) + min); |
17 | | - |
18 | | -export const diffArrays = (arr1: any[], arr2: any[]): any[] => |
19 | | - arr1 && |
20 | | - arr2 && |
21 | | - arr1.filter( |
22 | | - (obj1) => !arr2.find((obj2) => obj1.id === obj2.id && obj2.isChecked), |
23 | | - ); |
24 | | - |
25 | | -export const diffArraysWithId = (arr1: any[], arr2: any[]): any[] => |
26 | | - arr1 && |
27 | | - arr2 && |
28 | | - arr1.filter((obj1) => !arr2.find((obj2) => obj1.id === obj2.id && obj2.id)); |
29 | | - |
30 | | -export const diffDates = (date: number, date2: number) => |
31 | | - Math.floor(Math.abs(date - date2) / 86400000); |
32 | | - |
33 | | -export const isBlankString = (str: string) => |
34 | | - !str || str.length === 0 || /^\s*$/.test(str); |
35 | | - |
36 | | -export const randomBoolean = () => Math.random() >= 0.5; |
37 | | -export const coinflip = () => Math.random() >= 0.5; |
38 | | - |
39 | | -export const isEven = (val: number) => val % 2 === 0; |
40 | | - |
41 | | -export const removeAllDuplicateValuesInArray = (arr: any[]) => [ |
42 | | - ...new Set(arr), |
43 | | -]; |
44 | | - |
45 | | -export const isArray = (arr: any[]) => Array.isArray(arr); |
46 | | - |
47 | | -export const generateRandomString = () => Math.random().toString(36).slice(2); |
48 | | - |
49 | | -export const mergeArrays = (a: any[], b: any[]) => [...a, ...b]; |
50 | | - |
51 | | -export const mergeArraysAndRemoveDuplicates = (a: any[], b: any[]) => [ |
52 | | - ...new Set([...a, ...b]), |
53 | | -]; |
54 | | - |
55 | | -export const getTrueType = (obj: any) => |
56 | | - Object.prototype.toString.call(obj).slice(8, -1).toLocaleLowerCase(); |
57 | | - |
58 | | -export const isNotEmptyArray = (arr: any[]) => |
59 | | - Array.isArray(arr) && arr.length > 0; |
60 | | - |
61 | | -export const safelyParseJson = (string?: string | null) => { |
62 | | - try { |
63 | | - return JSON.parse(string as string); |
64 | | - } catch { |
65 | | - return string; |
66 | | - } |
67 | | -}; |
68 | | - |
69 | | -export const isEmptyObj = (obj: any) => |
70 | | - Reflect.ownKeys(obj).length === 0 && obj.constructor === Object; |
71 | | - |
72 | | -export const shuffleArray = (arr: any[]) => arr.sort(() => 0.5 - Math.random()); |
73 | | - |
74 | | -export const convertSnakeToCamelCase = (str: string) => { |
75 | | - return str.replace(/([-_][a-z])/g, (group) => |
76 | | - group.toUpperCase().replace("-", "").replace("_", ""), |
77 | | - ); |
78 | | -}; |
79 | | - |
80 | | -export const getRandomHexColor = () => |
81 | | - `#${Math.floor(Math.random() * 0xffffff) |
82 | | - .toString(16) |
83 | | - .padEnd(6, "0")}`; |
84 | | - |
85 | | -export const convertRGBToHexColor = (r: number, g: number, b: number) => |
86 | | - "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); |
87 | | - |
88 | | -export const getMinMaxOfArray = (arr: any[]) => [ |
89 | | - Math.min(...arr), |
90 | | - Math.max(...arr), |
91 | | -]; |
92 | | - |
93 | | -export const sleep = (delay: number): Promise<void> => { |
94 | | - return new Promise((resolve) => setTimeout(resolve, delay)); |
95 | | -}; |
96 | | - |
97 | | -/** |
98 | | - * Create an object from the pairs of key and value |
99 | | - * @param arr |
100 | | - * @returns |
101 | | - */ |
102 | | -export const toObj = (arr: any[]) => Object.fromEntries(arr); |
103 | | - |
104 | | -/** |
105 | | - * Get union of arrays |
106 | | - * @param arr |
107 | | - * @returns |
108 | | - */ |
109 | | -export const getUnion = (...arr) => [...new Set(arr.flat())]; |
110 | | - |
111 | | -/** |
112 | | - * Partition an array based on the criteria/condition |
113 | | - * @param arr |
114 | | - * @param criteria |
115 | | - * @returns |
116 | | - */ |
117 | | -export const partition = (arr: any[], criteria: any) => |
118 | | - arr.reduce((acc, i) => (acc[criteria(i) ? 0 : 1].push(i), acc), [[], []]); |
| 7 | +export { openExternalApp, openAppInAppStore, openAppInPlayStore }; |
0 commit comments