@turndown/library 0.0.9 → 0.0.16
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.
- package/package.json +11 -9
- package/src/helpers/index.ts +2 -0
- package/src/helpers/object/index.ts +395 -0
- package/src/helpers/string/index.ts +171 -0
- package/src/index.ts +2 -0
- package/src/types/base/index.ts +26 -0
- package/src/types/base/paging.types.ts +35 -0
- package/src/types/index.ts +2 -0
- package/src/types/user/index.ts +42 -0
- package/dist/helpers/index.js +0 -18
- package/dist/helpers/object/index.js +0 -194
- package/dist/helpers/string/index.js +0 -81
- package/dist/index.js +0 -23
- package/dist/types/base/index.js +0 -22
- package/dist/types/base/paging.types.js +0 -2
- package/dist/types/index.js +0 -18
- package/dist/types/user/index.js +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turndown/library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Shared TypeScript library for the Turndown suite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"types",
|
|
@@ -16,20 +16,22 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"module": "dist/index.js",
|
|
21
|
+
"source": "./index.ts",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
19
27
|
"exports": {
|
|
20
28
|
".": {
|
|
21
29
|
"types": "./dist/index.d.ts",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
30
|
+
"browser": "./dist/index.js",
|
|
31
|
+
"import": "./dist/index.js"
|
|
24
32
|
},
|
|
25
33
|
"./package.json": "./package.json"
|
|
26
34
|
},
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"files": [
|
|
29
|
-
"dist",
|
|
30
|
-
"LICENSE",
|
|
31
|
-
"README.md"
|
|
32
|
-
],
|
|
33
35
|
"scripts": {
|
|
34
36
|
"clean": "rimraf dist",
|
|
35
37
|
"build": "npm run clean && tsc -p .",
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { FilterCondition, SortCondition, TurndownObject } from "@/types/base";
|
|
2
|
+
|
|
3
|
+
export interface Version {
|
|
4
|
+
major: number;
|
|
5
|
+
minor: number;
|
|
6
|
+
patch: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type VersionInput = string | Version;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Safely parse a JSON string into a value.
|
|
13
|
+
*
|
|
14
|
+
* Returns `{}` if parsing fails instead of throwing.
|
|
15
|
+
*
|
|
16
|
+
* @param {TurndownObject} jsonString - The JSON string to parse.
|
|
17
|
+
* @returns {TurndownObject} Parsed value or `{}` on failure.
|
|
18
|
+
* @example
|
|
19
|
+
* parseJSON('{"a":1}') // => { a: 1 }
|
|
20
|
+
* parseJSON('not json') // => {}
|
|
21
|
+
*/
|
|
22
|
+
export const parseJSON = (jsonString: TurndownObject): TurndownObject => {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(jsonString);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Stringify an object to JSON while skipping circular references.
|
|
32
|
+
*
|
|
33
|
+
* Uses an internal cache to omit repeated object references that would
|
|
34
|
+
* normally cause `JSON.stringify` to throw.
|
|
35
|
+
*
|
|
36
|
+
* @param {TurndownObject} obj - Value to stringify.
|
|
37
|
+
* @returns {string} JSON string with circulars omitted.
|
|
38
|
+
* @example
|
|
39
|
+
* const a:any = {}; a.self = a;
|
|
40
|
+
* JSONStringify(a) // => "{}"
|
|
41
|
+
*/
|
|
42
|
+
export const JSONStringify = (obj: TurndownObject): string => {
|
|
43
|
+
let cache: TurndownObject = [];
|
|
44
|
+
let str = JSON.stringify(obj, function (_key, value) {
|
|
45
|
+
if (typeof value === "object" && value !== null) {
|
|
46
|
+
if (cache.indexOf(value) !== -1) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
cache.push(value);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
});
|
|
53
|
+
cache = null;
|
|
54
|
+
return str;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Deep-remove `undefined` properties by serializing & parsing.
|
|
59
|
+
*
|
|
60
|
+
* @param {TurndownObject} obj - Input object.
|
|
61
|
+
* @returns {TurndownObject} Cleaned clone with `undefined` removed.
|
|
62
|
+
*/
|
|
63
|
+
export const removeUndefined = (obj: TurndownObject): TurndownObject => {
|
|
64
|
+
return JSON.parse(JSONStringify(obj));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Test whether a location object's `pathname` equals a key.
|
|
69
|
+
*
|
|
70
|
+
* @param {TurndownObject} location - Object expected to have a `pathname`.
|
|
71
|
+
* @param {string} key - Path to compare.
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
* @example
|
|
74
|
+
* validPath({ pathname: "/home" }, "/home") // true
|
|
75
|
+
*/
|
|
76
|
+
export const validPath = (location: TurndownObject, key: string): boolean => {
|
|
77
|
+
return location?.pathname === key;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Return the first element if the input is an array; otherwise return the value itself.
|
|
82
|
+
*
|
|
83
|
+
* @typeParam T - Element type.
|
|
84
|
+
* @param {T | T[]} input - A single value or an array.
|
|
85
|
+
* @returns {T} First element or the input value.
|
|
86
|
+
* @example
|
|
87
|
+
* returnObject([1,2,3]) // 1
|
|
88
|
+
* returnObject(5) // 5
|
|
89
|
+
*/
|
|
90
|
+
export const returnObject = <T>(input: T | T[]): T => {
|
|
91
|
+
return Array.isArray(input) ? input[0] : input;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Filter out items from `array1` whose `id` appears in `array2`.
|
|
96
|
+
*
|
|
97
|
+
* @typeParam T - Object type with an `id` field.
|
|
98
|
+
* @param {T[]} [array1] - Source array.
|
|
99
|
+
* @param {T[]} [array2] - Items whose `id`s should be excluded.
|
|
100
|
+
* @returns {T[]} Filtered array (or `[]` on errors/invalid input).
|
|
101
|
+
*/
|
|
102
|
+
export const filterArrayById = <T extends { id: number | string }>(
|
|
103
|
+
array1?: T[],
|
|
104
|
+
array2?: T[]
|
|
105
|
+
): T[] => {
|
|
106
|
+
try {
|
|
107
|
+
if (!array1 || !array2) return [];
|
|
108
|
+
|
|
109
|
+
const idsToExclude = new Set(array2.map((item) => item.id));
|
|
110
|
+
return array1.filter((item) => !idsToExclude.has(item.id));
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error("An error occurred:", error);
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Sort an array of objects by a given property (ascending).
|
|
119
|
+
*
|
|
120
|
+
* Mutates the original array (uses `Array.prototype.sort`).
|
|
121
|
+
*
|
|
122
|
+
* @typeParam T - Object type.
|
|
123
|
+
* @param {T[]} array - Array to sort.
|
|
124
|
+
* @param {keyof T} property - Property name to sort by.
|
|
125
|
+
* @returns {T[]} The same array instance, sorted (or empty array if input invalid).
|
|
126
|
+
*/
|
|
127
|
+
export const sortArrayByProperty = <T extends Record<string, any>>(
|
|
128
|
+
array: T[],
|
|
129
|
+
property: keyof T
|
|
130
|
+
): T[] => {
|
|
131
|
+
if (!array || array.length === 0) return [];
|
|
132
|
+
|
|
133
|
+
return array.sort((a, b) => {
|
|
134
|
+
if (a[property] < b[property]) return -1;
|
|
135
|
+
if (a[property] > b[property]) return 1;
|
|
136
|
+
return 0;
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Recursively replace `null` values with empty strings.
|
|
142
|
+
*
|
|
143
|
+
* Works on primitives, arrays, and plain objects.
|
|
144
|
+
*
|
|
145
|
+
* @param {TurndownObject} obj - Input value.
|
|
146
|
+
* @returns {TurndownObject} Value with all `null` replaced by `""`.
|
|
147
|
+
*/
|
|
148
|
+
export const replaceNulls = (obj: TurndownObject): TurndownObject => {
|
|
149
|
+
if (obj === null) {
|
|
150
|
+
return "";
|
|
151
|
+
} else if (Array.isArray(obj)) {
|
|
152
|
+
return obj.map(replaceNulls);
|
|
153
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
154
|
+
const newObj: any = {};
|
|
155
|
+
for (const key in obj) {
|
|
156
|
+
if (obj.hasOwnProperty(key)) {
|
|
157
|
+
newObj[key] = replaceNulls(obj[key]);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return newObj;
|
|
161
|
+
}
|
|
162
|
+
return obj;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Recursively remove object keys that contain a dot (`.`).
|
|
167
|
+
*
|
|
168
|
+
* @typeParam T - Object type.
|
|
169
|
+
* @param {T} obj - Input object.
|
|
170
|
+
* @returns {T} New object with dotted keys removed at all levels.
|
|
171
|
+
*/
|
|
172
|
+
export const removeFormProperties = <T extends Record<string, TurndownObject>>(
|
|
173
|
+
obj: T
|
|
174
|
+
): T => {
|
|
175
|
+
const recursiveRemove = (input: TurndownObject): TurndownObject => {
|
|
176
|
+
if (Array.isArray(input)) {
|
|
177
|
+
return input.map((item) => recursiveRemove(item));
|
|
178
|
+
} else if (typeof input === "object" && input !== null) {
|
|
179
|
+
const newObj: Record<string, TurndownObject> = { ...input };
|
|
180
|
+
|
|
181
|
+
Object.keys(newObj).forEach((key) => {
|
|
182
|
+
if (key.includes(".")) {
|
|
183
|
+
delete newObj[key];
|
|
184
|
+
} else {
|
|
185
|
+
newObj[key] = recursiveRemove(newObj[key]);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return newObj;
|
|
189
|
+
}
|
|
190
|
+
return input;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
return recursiveRemove(obj);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Recursively convert string booleans `"true"`/`"false"` to actual booleans.
|
|
198
|
+
*
|
|
199
|
+
* Leaves all other values unchanged.
|
|
200
|
+
*
|
|
201
|
+
* @typeParam T - Object type.
|
|
202
|
+
* @param {T} obj - Input object or array.
|
|
203
|
+
* @returns {T} New value with boolean-like strings converted.
|
|
204
|
+
*/
|
|
205
|
+
export const convertStringBooleans = <T extends Record<string, any>>(
|
|
206
|
+
obj: T
|
|
207
|
+
): T => {
|
|
208
|
+
const recursiveConvert = (input: any): any => {
|
|
209
|
+
if (Array.isArray(input)) {
|
|
210
|
+
return input.map((item) => recursiveConvert(item));
|
|
211
|
+
} else if (typeof input === "object" && input !== null) {
|
|
212
|
+
const newObj: Record<string, any> = { ...input };
|
|
213
|
+
|
|
214
|
+
Object.keys(newObj).forEach((key) => {
|
|
215
|
+
const value = newObj[key];
|
|
216
|
+
|
|
217
|
+
if (value === "true") {
|
|
218
|
+
newObj[key] = true;
|
|
219
|
+
} else if (value === "false") {
|
|
220
|
+
newObj[key] = false;
|
|
221
|
+
} else if (typeof value === "object" && value !== null) {
|
|
222
|
+
newObj[key] = recursiveConvert(value);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
return newObj;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return input;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
return recursiveConvert(obj);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Convenience helper to clean form-like data:
|
|
237
|
+
* - Removes `undefined` properties
|
|
238
|
+
* - Converts string booleans to booleans
|
|
239
|
+
* - Removes keys containing a dot ('.')
|
|
240
|
+
*
|
|
241
|
+
* @param {TurndownObject} obj - Input data.
|
|
242
|
+
* @returns {TurndownObject} Cleaned clone.
|
|
243
|
+
*/
|
|
244
|
+
export const cleanFormData = (obj: TurndownObject) => {
|
|
245
|
+
return removeFormProperties(convertStringBooleans(removeUndefined(obj)));
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Return a default pagination object, allowing optional sort and filters.
|
|
250
|
+
*
|
|
251
|
+
* @param {SortCondition[]} [sort] - Optional sort conditions.
|
|
252
|
+
* @param {FilterCondition[]} [filters] - Optional filter conditions.
|
|
253
|
+
* @returns {{ page: number; size: number; sort: SortCondition[]; filters: FilterCondition[] }}
|
|
254
|
+
* @example
|
|
255
|
+
* resetPagination() // => { page:1, size:25, sort:[], filters:[] }
|
|
256
|
+
*/
|
|
257
|
+
export const resetPagination = (
|
|
258
|
+
sort?: SortCondition[],
|
|
259
|
+
filters?: FilterCondition[]
|
|
260
|
+
) => {
|
|
261
|
+
return {
|
|
262
|
+
page: 1,
|
|
263
|
+
size: 25,
|
|
264
|
+
sort: sort || [],
|
|
265
|
+
filters: filters || [],
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Format a string of digits into a U.S. phone number.
|
|
271
|
+
*
|
|
272
|
+
* Strips non-numeric characters and formats as `(XXX) XXX-XXXX`.
|
|
273
|
+
* If fewer than 10 digits are provided, returns the input unchanged.
|
|
274
|
+
*
|
|
275
|
+
* @param {string | number} value - Phone number digits (string or number).
|
|
276
|
+
* @returns {string} Formatted phone number, or original input if invalid length.
|
|
277
|
+
* @example
|
|
278
|
+
* formatPhoneNumber("1234567890") // "(123) 456-7890"
|
|
279
|
+
* formatPhoneNumber(9876543210) // "(987) 654-3210"
|
|
280
|
+
* formatPhoneNumber("555") // "555"
|
|
281
|
+
*/
|
|
282
|
+
export const formatPhoneNumber = (value: string | number): string => {
|
|
283
|
+
const digits = value.toString().replace(/\D/g, "");
|
|
284
|
+
if (digits.length !== 10) return value.toString();
|
|
285
|
+
|
|
286
|
+
const area = digits.slice(0, 3);
|
|
287
|
+
const prefix = digits.slice(3, 6);
|
|
288
|
+
const line = digits.slice(6);
|
|
289
|
+
|
|
290
|
+
return `(${area}) ${prefix}-${line}`;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Format a number with thousands separators (commas).
|
|
295
|
+
*
|
|
296
|
+
* @param {number} value - Number to format.
|
|
297
|
+
* @returns {string} String with commas.
|
|
298
|
+
* @example
|
|
299
|
+
* formatNumber(1234567) // "1,234,567"
|
|
300
|
+
*/
|
|
301
|
+
export const formatNumber = (value: number): string => {
|
|
302
|
+
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Parse a number string (note: current implementation adds commas as well).
|
|
307
|
+
*
|
|
308
|
+
* @remarks
|
|
309
|
+
* This function uses the same regex as `formatNumber`, so it **does not remove**
|
|
310
|
+
* commas; it inserts them. If you intended to *strip* separators, consider:
|
|
311
|
+
* `value.toString().replace(/,/g, "")`.
|
|
312
|
+
*
|
|
313
|
+
* @param {number} value - Number to "parse".
|
|
314
|
+
* @returns {string} Currently returns a comma-formatted string.
|
|
315
|
+
*/
|
|
316
|
+
export const parseNumber = (value: number): string => {
|
|
317
|
+
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "");
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Delete a property from an object if it exists (no-op if it doesn't).
|
|
322
|
+
*
|
|
323
|
+
* @param {TurndownObject} obj - Target object (mutated).
|
|
324
|
+
* @param {string} propertyName - Property to delete.
|
|
325
|
+
* @returns {void}
|
|
326
|
+
*/
|
|
327
|
+
export const deletePropertyIfExists = (
|
|
328
|
+
obj: TurndownObject,
|
|
329
|
+
propertyName: string
|
|
330
|
+
) => {
|
|
331
|
+
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
|
332
|
+
delete obj[propertyName];
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Split an array into chunks of a given size.
|
|
338
|
+
*
|
|
339
|
+
* @typeParam T - Element type.
|
|
340
|
+
* @param {T[]} array - Source array.
|
|
341
|
+
* @param {number} chunkSize - Size of each chunk (no validation performed).
|
|
342
|
+
* @returns {T[][]} Array of chunks (last one may be smaller).
|
|
343
|
+
* @example
|
|
344
|
+
* chunkArray([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
|
|
345
|
+
*/
|
|
346
|
+
export const chunkArray = <T>(array: T[], chunkSize: number): T[][] => {
|
|
347
|
+
const result: T[][] = [];
|
|
348
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
349
|
+
result.push(array.slice(i, i + chunkSize));
|
|
350
|
+
}
|
|
351
|
+
return result;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Return a shallow clone of `obj` without the listed properties.
|
|
356
|
+
*
|
|
357
|
+
* @param {TurndownObject} obj - Source object.
|
|
358
|
+
* @param {TurndownObject} propsToOmit - Iterable of property names (expects array-like).
|
|
359
|
+
* @returns {TurndownObject} New object without omitted props.
|
|
360
|
+
* @example
|
|
361
|
+
* omitProperties({a:1,b:2}, ["b"]) // { a:1 }
|
|
362
|
+
*/
|
|
363
|
+
export const omitProperties = (
|
|
364
|
+
obj: TurndownObject,
|
|
365
|
+
propsToOmit: TurndownObject
|
|
366
|
+
) => {
|
|
367
|
+
const newObj = { ...obj };
|
|
368
|
+
propsToOmit.forEach((prop: TurndownObject) => {
|
|
369
|
+
delete newObj[prop];
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
return newObj;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Safe `hasOwnProperty` check.
|
|
377
|
+
*
|
|
378
|
+
* @param {Record<string, any>} obj - Object to test.
|
|
379
|
+
* @param {string} key - Property name.
|
|
380
|
+
* @returns {boolean}
|
|
381
|
+
*/
|
|
382
|
+
export const hasProperty = (obj: Record<string, any>, key: string): boolean => {
|
|
383
|
+
if (!obj) return false;
|
|
384
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Determine if an object has at least one own enumerable property.
|
|
389
|
+
*
|
|
390
|
+
* @param {object} obj - Object to test.
|
|
391
|
+
* @returns {boolean} `true` if there is at least one key.
|
|
392
|
+
*/
|
|
393
|
+
export const hasProperties = (obj: object): boolean => {
|
|
394
|
+
return Object.keys(obj || {}).length > 0;
|
|
395
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { TurndownObject } from "@/types/base";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert a string to "Normal Case":
|
|
5
|
+
* - Inserts spaces between camel/pascal case boundaries
|
|
6
|
+
* - Capitalizes the first letter of each word, lowercases the rest
|
|
7
|
+
*
|
|
8
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
9
|
+
* @returns {string}
|
|
10
|
+
* @example
|
|
11
|
+
* normalCase("helloWorld") // "Hello World"
|
|
12
|
+
* normalCase("XMLHttpRequest") // "Xml Http Request"
|
|
13
|
+
*/
|
|
14
|
+
export const normalCase = (str?: TurndownObject): string => {
|
|
15
|
+
if (!str) return "";
|
|
16
|
+
|
|
17
|
+
return str
|
|
18
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
19
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1 $2")
|
|
20
|
+
.split(/\s+/)
|
|
21
|
+
.map(
|
|
22
|
+
(word: string) =>
|
|
23
|
+
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
24
|
+
)
|
|
25
|
+
.join(" ");
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Capitalize only the first character; lowercases the rest.
|
|
30
|
+
* Trims leading/trailing spaces before processing.
|
|
31
|
+
*
|
|
32
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
33
|
+
* @returns {string}
|
|
34
|
+
* @example
|
|
35
|
+
* sentenceCase("hELLO WORLD") // "Hello world"
|
|
36
|
+
*/
|
|
37
|
+
export const sentenceCase = (str?: TurndownObject): string => {
|
|
38
|
+
if (!str) return "";
|
|
39
|
+
|
|
40
|
+
const s = str.trim();
|
|
41
|
+
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Uppercase the entire string.
|
|
46
|
+
*
|
|
47
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
48
|
+
* @returns {string}
|
|
49
|
+
* @example
|
|
50
|
+
* upperCase("Hello world") // "HELLO WORLD"
|
|
51
|
+
*/
|
|
52
|
+
export const upperCase = (str?: TurndownObject): string => {
|
|
53
|
+
return str ? str.toUpperCase() : "";
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Lowercase the entire string.
|
|
58
|
+
*
|
|
59
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
60
|
+
* @returns {string}
|
|
61
|
+
* @example
|
|
62
|
+
* lowerCase("Hello WORLD") // "hello world"
|
|
63
|
+
*/
|
|
64
|
+
export const lowerCase = (str?: TurndownObject): string => {
|
|
65
|
+
return str ? str.toLowerCase() : "";
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Convert to camelCase.
|
|
70
|
+
* Splits on spaces, underscores, and hyphens; lowercases the first word,
|
|
71
|
+
* TitleCases the rest, then joins with no separators.
|
|
72
|
+
*
|
|
73
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
74
|
+
* @returns {string}
|
|
75
|
+
* @example
|
|
76
|
+
* camelCase("Hello world") // "helloWorld"
|
|
77
|
+
* camelCase("hello_world-again") // "helloWorldAgain"
|
|
78
|
+
*/
|
|
79
|
+
export const camelCase = (str?: TurndownObject): string => {
|
|
80
|
+
if (!str) return "";
|
|
81
|
+
return str
|
|
82
|
+
.toLowerCase()
|
|
83
|
+
.split(/[\s_-]+/)
|
|
84
|
+
.map((word: string, i: number) =>
|
|
85
|
+
i === 0
|
|
86
|
+
? word
|
|
87
|
+
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
88
|
+
)
|
|
89
|
+
.join("");
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Convert to PascalCase.
|
|
94
|
+
* Splits on spaces, underscores, and hyphens; TitleCases all words and joins them.
|
|
95
|
+
*
|
|
96
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
97
|
+
* @returns {string}
|
|
98
|
+
* @example
|
|
99
|
+
* pascalCase("hello world") // "HelloWorld"
|
|
100
|
+
* pascalCase("hello_world-again") // "HelloWorldAgain"
|
|
101
|
+
*/
|
|
102
|
+
export const pascalCase = (str?: TurndownObject): string => {
|
|
103
|
+
if (!str) return "";
|
|
104
|
+
return str
|
|
105
|
+
.toLowerCase()
|
|
106
|
+
.split(/[\s_-]+/)
|
|
107
|
+
.map((word: string) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
108
|
+
.join("");
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Convert to kebab-case.
|
|
113
|
+
* Inserts hyphens between camelCase boundaries, then replaces spaces/underscores with hyphens.
|
|
114
|
+
*
|
|
115
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
116
|
+
* @returns {string}
|
|
117
|
+
* @example
|
|
118
|
+
* kebabCase("HelloWorld Again") // "hello-world-again"
|
|
119
|
+
* kebabCase("hello_world") // "hello-world"
|
|
120
|
+
*/
|
|
121
|
+
export const kebabCase = (str?: TurndownObject): string => {
|
|
122
|
+
if (!str) return "";
|
|
123
|
+
return str
|
|
124
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
125
|
+
.replace(/[\s_]+/g, "-")
|
|
126
|
+
.toLowerCase();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Convert to snake_case.
|
|
131
|
+
* Inserts underscores between camelCase boundaries, then replaces spaces/hyphens with underscores.
|
|
132
|
+
*
|
|
133
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
134
|
+
* @returns {string}
|
|
135
|
+
* @example
|
|
136
|
+
* snakeCase("HelloWorld Again") // "hello_world_again"
|
|
137
|
+
* snakeCase("hello-world") // "hello_world"
|
|
138
|
+
*/
|
|
139
|
+
export const snakeCase = (str?: TurndownObject): string => {
|
|
140
|
+
if (!str) return "";
|
|
141
|
+
return str
|
|
142
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
143
|
+
.replace(/[\s-]+/g, "_")
|
|
144
|
+
.toLowerCase();
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Convert snake_case to space-delimited words.
|
|
149
|
+
*
|
|
150
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
151
|
+
* @returns {string}
|
|
152
|
+
* @example
|
|
153
|
+
* snakeCaseToSpaces("hello_world_again") // "hello world again"
|
|
154
|
+
*/
|
|
155
|
+
export const snakeCaseToSpaces = (str?: TurndownObject): string => {
|
|
156
|
+
if (!str) return "";
|
|
157
|
+
return str.split("_").join(" ");
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Convert kebab-case to space-delimited words.
|
|
162
|
+
*
|
|
163
|
+
* @param {TurndownObject} [str] Input value (falsy returns an empty string)
|
|
164
|
+
* @returns {string}
|
|
165
|
+
* @example
|
|
166
|
+
* kebabToSpaces("hello-world-again") // "hello world again"
|
|
167
|
+
*/
|
|
168
|
+
export const kebabToSpaces = (str?: TurndownObject): string => {
|
|
169
|
+
if (!str) return "";
|
|
170
|
+
return str.split("-").join(" ");
|
|
171
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type GenericTurndownObject = Record<string, any> | any | undefined;
|
|
2
|
+
export type TurndownObject<T = GenericTurndownObject> =
|
|
3
|
+
| Record<string, T>
|
|
4
|
+
| T
|
|
5
|
+
| undefined;
|
|
6
|
+
|
|
7
|
+
export type ObjectValues<T> = T[keyof T];
|
|
8
|
+
export type ObjectKeys<T> = [keyof T];
|
|
9
|
+
|
|
10
|
+
export interface MetaData {
|
|
11
|
+
company_id: string;
|
|
12
|
+
deleted: boolean;
|
|
13
|
+
updated_by: string;
|
|
14
|
+
created_by: string;
|
|
15
|
+
created_at: Date;
|
|
16
|
+
updated_at: Date;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const STATUS = {
|
|
20
|
+
ACTIVE: "ACTIVE",
|
|
21
|
+
INACTIVE: "INACTIVE",
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
export type Status = ObjectValues<typeof STATUS>;
|
|
25
|
+
|
|
26
|
+
export * from "./paging.types";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface PagingResult {
|
|
2
|
+
hasNextPage: boolean;
|
|
3
|
+
totalPages: number;
|
|
4
|
+
totalRecords: number;
|
|
5
|
+
}
|
|
6
|
+
export interface DataWithPagingResult<T> {
|
|
7
|
+
data: T;
|
|
8
|
+
pagination: PagingResult;
|
|
9
|
+
}
|
|
10
|
+
export interface SortCondition {
|
|
11
|
+
name: string;
|
|
12
|
+
direction: "ASC" | "DESC";
|
|
13
|
+
}
|
|
14
|
+
export interface FilterCondition {
|
|
15
|
+
name: string;
|
|
16
|
+
condition: "=" | ">" | "<" | "!=" | "LIKE" | "IN" | ">=" | "<=";
|
|
17
|
+
valueString?: string;
|
|
18
|
+
valueNumber?: number;
|
|
19
|
+
valueBoolean?: boolean;
|
|
20
|
+
useAnd?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface PaginationRequest {
|
|
23
|
+
page: number;
|
|
24
|
+
size: number;
|
|
25
|
+
sort?: SortCondition[];
|
|
26
|
+
filters?: FilterCondition[];
|
|
27
|
+
}
|
|
28
|
+
export declare const createPagingObject: (
|
|
29
|
+
page: number,
|
|
30
|
+
size: number,
|
|
31
|
+
sort?: SortCondition[],
|
|
32
|
+
filters?: FilterCondition[]
|
|
33
|
+
) => {
|
|
34
|
+
pagination: any;
|
|
35
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MetaData, ObjectValues, Status } from "@/types";
|
|
2
|
+
|
|
3
|
+
export interface User extends Omit<MetaData, "created_by" | "updated_by"> {
|
|
4
|
+
id: string;
|
|
5
|
+
firstName: string;
|
|
6
|
+
lastName: string;
|
|
7
|
+
mi: string;
|
|
8
|
+
username: string;
|
|
9
|
+
email: string;
|
|
10
|
+
password: string;
|
|
11
|
+
loginAttempts: number;
|
|
12
|
+
locked: boolean;
|
|
13
|
+
passwordLastReset: Date;
|
|
14
|
+
passwordResetRequired: boolean;
|
|
15
|
+
type: AccountType;
|
|
16
|
+
status: Status;
|
|
17
|
+
companyId: number;
|
|
18
|
+
phoneNumber: string;
|
|
19
|
+
phoneFormat: string;
|
|
20
|
+
language: Language;
|
|
21
|
+
biometrics: string;
|
|
22
|
+
lastLogin: Date;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const ACCOUNT_TYPE = {
|
|
26
|
+
TURNDOWN_ADMIN: "TURNDOWN_ADMIN",
|
|
27
|
+
OWNER: "OWNER",
|
|
28
|
+
ACCOUNT_ADMIN: "ACCOUNT_ADMIN",
|
|
29
|
+
MAINTAINER: "MAINTAINER",
|
|
30
|
+
CLEANER: "CLEANER",
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
export type AccountType = ObjectValues<typeof ACCOUNT_TYPE>;
|
|
34
|
+
|
|
35
|
+
export const LANGUAGE = {
|
|
36
|
+
ENGLISH: "ENGLISH",
|
|
37
|
+
FRENCH: "FRENCH",
|
|
38
|
+
SPANISH: "SPANISH",
|
|
39
|
+
GERMAN: "GERMAN",
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
export type Language = ObjectValues<typeof LANGUAGE>;
|
package/dist/helpers/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./object"), exports);
|
|
18
|
-
__exportStar(require("./string"), exports);
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasProperties = exports.hasProperty = exports.omitProperties = exports.chunkArray = exports.deletePropertyIfExists = exports.parseNumber = exports.formatNumber = exports.formatPhoneNumber = exports.resetPagination = exports.cleanFormData = exports.convertStringBooleans = exports.removeFormProperties = exports.replaceNulls = exports.sortArrayByProperty = exports.filterArrayById = exports.returnObject = exports.validPath = exports.removeUndefined = exports.JSONStringify = exports.parseJSON = void 0;
|
|
4
|
-
const parseJSON = (jsonString) => {
|
|
5
|
-
try {
|
|
6
|
-
return JSON.parse(jsonString);
|
|
7
|
-
}
|
|
8
|
-
catch (error) {
|
|
9
|
-
return {};
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
exports.parseJSON = parseJSON;
|
|
13
|
-
const JSONStringify = (obj) => {
|
|
14
|
-
let cache = [];
|
|
15
|
-
let str = JSON.stringify(obj, function (_key, value) {
|
|
16
|
-
if (typeof value === "object" && value !== null) {
|
|
17
|
-
if (cache.indexOf(value) !== -1) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
cache.push(value);
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
23
|
-
});
|
|
24
|
-
cache = null;
|
|
25
|
-
return str;
|
|
26
|
-
};
|
|
27
|
-
exports.JSONStringify = JSONStringify;
|
|
28
|
-
const removeUndefined = (obj) => {
|
|
29
|
-
return JSON.parse((0, exports.JSONStringify)(obj));
|
|
30
|
-
};
|
|
31
|
-
exports.removeUndefined = removeUndefined;
|
|
32
|
-
const validPath = (location, key) => {
|
|
33
|
-
return location?.pathname === key;
|
|
34
|
-
};
|
|
35
|
-
exports.validPath = validPath;
|
|
36
|
-
const returnObject = (input) => {
|
|
37
|
-
return Array.isArray(input) ? input[0] : input;
|
|
38
|
-
};
|
|
39
|
-
exports.returnObject = returnObject;
|
|
40
|
-
const filterArrayById = (array1, array2) => {
|
|
41
|
-
try {
|
|
42
|
-
if (!array1 || !array2)
|
|
43
|
-
return [];
|
|
44
|
-
const idsToExclude = new Set(array2.map((item) => item.id));
|
|
45
|
-
return array1.filter((item) => !idsToExclude.has(item.id));
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error("An error occurred:", error);
|
|
49
|
-
return [];
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
exports.filterArrayById = filterArrayById;
|
|
53
|
-
const sortArrayByProperty = (array, property) => {
|
|
54
|
-
if (!array || array.length === 0)
|
|
55
|
-
return [];
|
|
56
|
-
return array.sort((a, b) => {
|
|
57
|
-
if (a[property] < b[property])
|
|
58
|
-
return -1;
|
|
59
|
-
if (a[property] > b[property])
|
|
60
|
-
return 1;
|
|
61
|
-
return 0;
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
exports.sortArrayByProperty = sortArrayByProperty;
|
|
65
|
-
const replaceNulls = (obj) => {
|
|
66
|
-
if (obj === null) {
|
|
67
|
-
return "";
|
|
68
|
-
}
|
|
69
|
-
else if (Array.isArray(obj)) {
|
|
70
|
-
return obj.map(exports.replaceNulls);
|
|
71
|
-
}
|
|
72
|
-
else if (typeof obj === "object" && obj !== null) {
|
|
73
|
-
const newObj = {};
|
|
74
|
-
for (const key in obj) {
|
|
75
|
-
if (obj.hasOwnProperty(key)) {
|
|
76
|
-
newObj[key] = (0, exports.replaceNulls)(obj[key]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return newObj;
|
|
80
|
-
}
|
|
81
|
-
return obj;
|
|
82
|
-
};
|
|
83
|
-
exports.replaceNulls = replaceNulls;
|
|
84
|
-
const removeFormProperties = (obj) => {
|
|
85
|
-
const recursiveRemove = (input) => {
|
|
86
|
-
if (Array.isArray(input)) {
|
|
87
|
-
return input.map((item) => recursiveRemove(item));
|
|
88
|
-
}
|
|
89
|
-
else if (typeof input === "object" && input !== null) {
|
|
90
|
-
const newObj = { ...input };
|
|
91
|
-
Object.keys(newObj).forEach((key) => {
|
|
92
|
-
if (key.includes(".")) {
|
|
93
|
-
delete newObj[key];
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
newObj[key] = recursiveRemove(newObj[key]);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return newObj;
|
|
100
|
-
}
|
|
101
|
-
return input;
|
|
102
|
-
};
|
|
103
|
-
return recursiveRemove(obj);
|
|
104
|
-
};
|
|
105
|
-
exports.removeFormProperties = removeFormProperties;
|
|
106
|
-
const convertStringBooleans = (obj) => {
|
|
107
|
-
const recursiveConvert = (input) => {
|
|
108
|
-
if (Array.isArray(input)) {
|
|
109
|
-
return input.map((item) => recursiveConvert(item));
|
|
110
|
-
}
|
|
111
|
-
else if (typeof input === "object" && input !== null) {
|
|
112
|
-
const newObj = { ...input };
|
|
113
|
-
Object.keys(newObj).forEach((key) => {
|
|
114
|
-
const value = newObj[key];
|
|
115
|
-
if (value === "true") {
|
|
116
|
-
newObj[key] = true;
|
|
117
|
-
}
|
|
118
|
-
else if (value === "false") {
|
|
119
|
-
newObj[key] = false;
|
|
120
|
-
}
|
|
121
|
-
else if (typeof value === "object" && value !== null) {
|
|
122
|
-
newObj[key] = recursiveConvert(value);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return newObj;
|
|
126
|
-
}
|
|
127
|
-
return input;
|
|
128
|
-
};
|
|
129
|
-
return recursiveConvert(obj);
|
|
130
|
-
};
|
|
131
|
-
exports.convertStringBooleans = convertStringBooleans;
|
|
132
|
-
const cleanFormData = (obj) => {
|
|
133
|
-
return (0, exports.removeFormProperties)((0, exports.convertStringBooleans)((0, exports.removeUndefined)(obj)));
|
|
134
|
-
};
|
|
135
|
-
exports.cleanFormData = cleanFormData;
|
|
136
|
-
const resetPagination = (sort, filters) => {
|
|
137
|
-
return {
|
|
138
|
-
page: 1,
|
|
139
|
-
size: 25,
|
|
140
|
-
sort: sort || [],
|
|
141
|
-
filters: filters || [],
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
exports.resetPagination = resetPagination;
|
|
145
|
-
const formatPhoneNumber = (value) => {
|
|
146
|
-
const digits = value.toString().replace(/\D/g, "");
|
|
147
|
-
if (digits.length !== 10)
|
|
148
|
-
return value.toString();
|
|
149
|
-
const area = digits.slice(0, 3);
|
|
150
|
-
const prefix = digits.slice(3, 6);
|
|
151
|
-
const line = digits.slice(6);
|
|
152
|
-
return `(${area}) ${prefix}-${line}`;
|
|
153
|
-
};
|
|
154
|
-
exports.formatPhoneNumber = formatPhoneNumber;
|
|
155
|
-
const formatNumber = (value) => {
|
|
156
|
-
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
157
|
-
};
|
|
158
|
-
exports.formatNumber = formatNumber;
|
|
159
|
-
const parseNumber = (value) => {
|
|
160
|
-
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "");
|
|
161
|
-
};
|
|
162
|
-
exports.parseNumber = parseNumber;
|
|
163
|
-
const deletePropertyIfExists = (obj, propertyName) => {
|
|
164
|
-
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
|
165
|
-
delete obj[propertyName];
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
exports.deletePropertyIfExists = deletePropertyIfExists;
|
|
169
|
-
const chunkArray = (array, chunkSize) => {
|
|
170
|
-
const result = [];
|
|
171
|
-
for (let i = 0; i < array.length; i += chunkSize) {
|
|
172
|
-
result.push(array.slice(i, i + chunkSize));
|
|
173
|
-
}
|
|
174
|
-
return result;
|
|
175
|
-
};
|
|
176
|
-
exports.chunkArray = chunkArray;
|
|
177
|
-
const omitProperties = (obj, propsToOmit) => {
|
|
178
|
-
const newObj = { ...obj };
|
|
179
|
-
propsToOmit.forEach((prop) => {
|
|
180
|
-
delete newObj[prop];
|
|
181
|
-
});
|
|
182
|
-
return newObj;
|
|
183
|
-
};
|
|
184
|
-
exports.omitProperties = omitProperties;
|
|
185
|
-
const hasProperty = (obj, key) => {
|
|
186
|
-
if (!obj)
|
|
187
|
-
return false;
|
|
188
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
189
|
-
};
|
|
190
|
-
exports.hasProperty = hasProperty;
|
|
191
|
-
const hasProperties = (obj) => {
|
|
192
|
-
return Object.keys(obj || {}).length > 0;
|
|
193
|
-
};
|
|
194
|
-
exports.hasProperties = hasProperties;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.kebabToSpaces = exports.snakeCaseToSpaces = exports.snakeCase = exports.kebabCase = exports.pascalCase = exports.camelCase = exports.lowerCase = exports.upperCase = exports.sentenceCase = exports.normalCase = void 0;
|
|
4
|
-
const normalCase = (str) => {
|
|
5
|
-
if (!str)
|
|
6
|
-
return "";
|
|
7
|
-
return str
|
|
8
|
-
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
9
|
-
.replace(/([A-Z])([A-Z][a-z])/g, "$1 $2")
|
|
10
|
-
.split(/\s+/)
|
|
11
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
12
|
-
.join(" ");
|
|
13
|
-
};
|
|
14
|
-
exports.normalCase = normalCase;
|
|
15
|
-
const sentenceCase = (str) => {
|
|
16
|
-
if (!str)
|
|
17
|
-
return "";
|
|
18
|
-
const s = str.trim();
|
|
19
|
-
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
20
|
-
};
|
|
21
|
-
exports.sentenceCase = sentenceCase;
|
|
22
|
-
const upperCase = (str) => {
|
|
23
|
-
return str ? str.toUpperCase() : "";
|
|
24
|
-
};
|
|
25
|
-
exports.upperCase = upperCase;
|
|
26
|
-
const lowerCase = (str) => {
|
|
27
|
-
return str ? str.toLowerCase() : "";
|
|
28
|
-
};
|
|
29
|
-
exports.lowerCase = lowerCase;
|
|
30
|
-
const camelCase = (str) => {
|
|
31
|
-
if (!str)
|
|
32
|
-
return "";
|
|
33
|
-
return str
|
|
34
|
-
.toLowerCase()
|
|
35
|
-
.split(/[\s_-]+/)
|
|
36
|
-
.map((word, i) => i === 0
|
|
37
|
-
? word
|
|
38
|
-
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
39
|
-
.join("");
|
|
40
|
-
};
|
|
41
|
-
exports.camelCase = camelCase;
|
|
42
|
-
const pascalCase = (str) => {
|
|
43
|
-
if (!str)
|
|
44
|
-
return "";
|
|
45
|
-
return str
|
|
46
|
-
.toLowerCase()
|
|
47
|
-
.split(/[\s_-]+/)
|
|
48
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
49
|
-
.join("");
|
|
50
|
-
};
|
|
51
|
-
exports.pascalCase = pascalCase;
|
|
52
|
-
const kebabCase = (str) => {
|
|
53
|
-
if (!str)
|
|
54
|
-
return "";
|
|
55
|
-
return str
|
|
56
|
-
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
57
|
-
.replace(/[\s_]+/g, "-")
|
|
58
|
-
.toLowerCase();
|
|
59
|
-
};
|
|
60
|
-
exports.kebabCase = kebabCase;
|
|
61
|
-
const snakeCase = (str) => {
|
|
62
|
-
if (!str)
|
|
63
|
-
return "";
|
|
64
|
-
return str
|
|
65
|
-
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
66
|
-
.replace(/[\s-]+/g, "_")
|
|
67
|
-
.toLowerCase();
|
|
68
|
-
};
|
|
69
|
-
exports.snakeCase = snakeCase;
|
|
70
|
-
const snakeCaseToSpaces = (str) => {
|
|
71
|
-
if (!str)
|
|
72
|
-
return "";
|
|
73
|
-
return str.split("_").join(" ");
|
|
74
|
-
};
|
|
75
|
-
exports.snakeCaseToSpaces = snakeCaseToSpaces;
|
|
76
|
-
const kebabToSpaces = (str) => {
|
|
77
|
-
if (!str)
|
|
78
|
-
return "";
|
|
79
|
-
return str.split("-").join(" ");
|
|
80
|
-
};
|
|
81
|
-
exports.kebabToSpaces = kebabToSpaces;
|
package/dist/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.test = void 0;
|
|
18
|
-
__exportStar(require("./helpers"), exports);
|
|
19
|
-
__exportStar(require("./types"), exports);
|
|
20
|
-
const test = () => {
|
|
21
|
-
console.log("working");
|
|
22
|
-
};
|
|
23
|
-
exports.test = test;
|
package/dist/types/base/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.STATUS = void 0;
|
|
18
|
-
exports.STATUS = {
|
|
19
|
-
ACTIVE: "ACTIVE",
|
|
20
|
-
INACTIVE: "INACTIVE",
|
|
21
|
-
};
|
|
22
|
-
__exportStar(require("./paging.types"), exports);
|
package/dist/types/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./user"), exports);
|
|
18
|
-
__exportStar(require("./base"), exports);
|
package/dist/types/user/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LANGUAGE = exports.ACCOUNT_TYPE = void 0;
|
|
4
|
-
exports.ACCOUNT_TYPE = {
|
|
5
|
-
TURNDOWN_ADMIN: "TURNDOWN_ADMIN",
|
|
6
|
-
OWNER: "OWNER",
|
|
7
|
-
ACCOUNT_ADMIN: "ACCOUNT_ADMIN",
|
|
8
|
-
MAINTAINER: "MAINTAINER",
|
|
9
|
-
CLEANER: "CLEANER",
|
|
10
|
-
};
|
|
11
|
-
exports.LANGUAGE = {
|
|
12
|
-
ENGLISH: "ENGLISH",
|
|
13
|
-
FRENCH: "FRENCH",
|
|
14
|
-
SPANISH: "SPANISH",
|
|
15
|
-
GERMAN: "GERMAN",
|
|
16
|
-
};
|