-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathfunctions.ts
More file actions
33 lines (29 loc) · 997 Bytes
/
functions.ts
File metadata and controls
33 lines (29 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { IndexField } from './providers';
export const isNullOrWhiteSpace = (str?: string) => !str?.trim();
export const parseManageIndexFields = (fieldsString?: string): IndexField[] => {
const fields = fieldsString
?.split(/\s*,\s*/) // Split by commas with spaces
?.map(field => {
const [name, ...orderParts] = field.trim().split(/\s+/); // Split by one or more spaces
return { name, orderMethod: orderParts.join(' ') }; // Handle multi-word order methods
});
return fields?.filter(x => !isNullOrWhiteSpace(x.name)) as IndexField[];
};
export const clonify = <T>(input: object): T => {
const str = JSON.stringify(input);
const obj = JSON.parse(str);
return obj as T;
};
export const isEqual = (
a?: string,
b?: string,
ignoreCaseSensivity?: boolean
): boolean => {
ignoreCaseSensivity = ignoreCaseSensivity ?? true;
if (ignoreCaseSensivity) {
a = a?.toLowerCase();
b = b?.toLowerCase();
}
if (a === b) return true;
return false;
};