@turndown/library 0.0.18 → 0.0.20

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,45 @@
1
+ {
2
+ "name": "@turndown/library",
3
+ "version": "0.0.20",
4
+ "description": "Shared TypeScript library for the Turndown suite.",
5
+ "keywords": [
6
+ "types",
7
+ "typescript",
8
+ "turndown"
9
+ ],
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git@github.com:Turndown-App/turndown-library.git"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "type": "module",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist",
30
+ "LICENSE",
31
+ "README.md"
32
+ ],
33
+ "scripts": {
34
+ "clean": "rimraf dist",
35
+ "build": "npm run clean && tsc -p .",
36
+ "dev": "tsc -w -p .",
37
+ "release": "npm run clean && changeset version && npm install --no-frozen-lockfile && npm run build",
38
+ "publish:ci": "npm run release && changeset publish"
39
+ },
40
+ "devDependencies": {
41
+ "@changesets/cli": "^2.29.7",
42
+ "rimraf": "^6.0.1",
43
+ "typescript": "^5.9.3"
44
+ }
45
+ }
@@ -1,13 +1,3 @@
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
1
  /**
12
2
  * Safely parse a JSON string into a value.
13
3
  *
@@ -19,14 +9,14 @@ export type VersionInput = string | Version;
19
9
  * parseJSON('{"a":1}') // => { a: 1 }
20
10
  * parseJSON('not json') // => {}
21
11
  */
22
- export const parseJSON = (jsonString: TurndownObject): TurndownObject => {
23
- try {
24
- return JSON.parse(jsonString);
25
- } catch (error) {
26
- return {};
27
- }
12
+ export const parseJSON = (jsonString) => {
13
+ try {
14
+ return JSON.parse(jsonString);
15
+ }
16
+ catch (error) {
17
+ return {};
18
+ }
28
19
  };
29
-
30
20
  /**
31
21
  * Stringify an object to JSON while skipping circular references.
32
22
  *
@@ -39,31 +29,29 @@ export const parseJSON = (jsonString: TurndownObject): TurndownObject => {
39
29
  * const a:any = {}; a.self = a;
40
30
  * JSONStringify(a) // => "{}"
41
31
  */
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;
32
+ export const JSONStringify = (obj) => {
33
+ let cache = [];
34
+ let str = JSON.stringify(obj, function (_key, value) {
35
+ if (typeof value === "object" && value !== null) {
36
+ if (cache.indexOf(value) !== -1) {
37
+ return;
38
+ }
39
+ cache.push(value);
40
+ }
41
+ return value;
42
+ });
43
+ cache = null;
44
+ return str;
55
45
  };
56
-
57
46
  /**
58
47
  * Deep-remove `undefined` properties by serializing & parsing.
59
48
  *
60
49
  * @param {TurndownObject} obj - Input object.
61
50
  * @returns {TurndownObject} Cleaned clone with `undefined` removed.
62
51
  */
63
- export const removeUndefined = (obj: TurndownObject): TurndownObject => {
64
- return JSON.parse(JSONStringify(obj));
52
+ export const removeUndefined = (obj) => {
53
+ return JSON.parse(JSONStringify(obj));
65
54
  };
66
-
67
55
  /**
68
56
  * Test whether a location object's `pathname` equals a key.
69
57
  *
@@ -73,10 +61,9 @@ export const removeUndefined = (obj: TurndownObject): TurndownObject => {
73
61
  * @example
74
62
  * validPath({ pathname: "/home" }, "/home") // true
75
63
  */
76
- export const validPath = (location: TurndownObject, key: string): boolean => {
77
- return location?.pathname === key;
64
+ export const validPath = (location, key) => {
65
+ return location?.pathname === key;
78
66
  };
79
-
80
67
  /**
81
68
  * Return the first element if the input is an array; otherwise return the value itself.
82
69
  *
@@ -87,10 +74,9 @@ export const validPath = (location: TurndownObject, key: string): boolean => {
87
74
  * returnObject([1,2,3]) // 1
88
75
  * returnObject(5) // 5
89
76
  */
90
- export const returnObject = <T>(input: T | T[]): T => {
91
- return Array.isArray(input) ? input[0] : input;
77
+ export const returnObject = (input) => {
78
+ return Array.isArray(input) ? input[0] : input;
92
79
  };
93
-
94
80
  /**
95
81
  * Filter out items from `array1` whose `id` appears in `array2`.
96
82
  *
@@ -99,21 +85,18 @@ export const returnObject = <T>(input: T | T[]): T => {
99
85
  * @param {T[]} [array2] - Items whose `id`s should be excluded.
100
86
  * @returns {T[]} Filtered array (or `[]` on errors/invalid input).
101
87
  */
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
- }
88
+ export const filterArrayById = (array1, array2) => {
89
+ try {
90
+ if (!array1 || !array2)
91
+ return [];
92
+ const idsToExclude = new Set(array2.map((item) => item.id));
93
+ return array1.filter((item) => !idsToExclude.has(item.id));
94
+ }
95
+ catch (error) {
96
+ console.error("An error occurred:", error);
97
+ return [];
98
+ }
115
99
  };
116
-
117
100
  /**
118
101
  * Sort an array of objects by a given property (ascending).
119
102
  *
@@ -124,19 +107,17 @@ export const filterArrayById = <T extends { id: number | string }>(
124
107
  * @param {keyof T} property - Property name to sort by.
125
108
  * @returns {T[]} The same array instance, sorted (or empty array if input invalid).
126
109
  */
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
- });
110
+ export const sortArrayByProperty = (array, property) => {
111
+ if (!array || array.length === 0)
112
+ return [];
113
+ return array.sort((a, b) => {
114
+ if (a[property] < b[property])
115
+ return -1;
116
+ if (a[property] > b[property])
117
+ return 1;
118
+ return 0;
119
+ });
138
120
  };
139
-
140
121
  /**
141
122
  * Recursively replace `null` values with empty strings.
142
123
  *
@@ -145,23 +126,24 @@ export const sortArrayByProperty = <T extends Record<string, any>>(
145
126
  * @param {TurndownObject} obj - Input value.
146
127
  * @returns {TurndownObject} Value with all `null` replaced by `""`.
147
128
  */
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
- }
129
+ export const replaceNulls = (obj) => {
130
+ if (obj === null) {
131
+ return "";
159
132
  }
160
- return newObj;
161
- }
162
- return obj;
133
+ else if (Array.isArray(obj)) {
134
+ return obj.map(replaceNulls);
135
+ }
136
+ else if (typeof obj === "object" && obj !== null) {
137
+ const newObj = {};
138
+ for (const key in obj) {
139
+ if (obj.hasOwnProperty(key)) {
140
+ newObj[key] = replaceNulls(obj[key]);
141
+ }
142
+ }
143
+ return newObj;
144
+ }
145
+ return obj;
163
146
  };
164
-
165
147
  /**
166
148
  * Recursively remove object keys that contain a dot (`.`).
167
149
  *
@@ -169,30 +151,27 @@ export const replaceNulls = (obj: TurndownObject): TurndownObject => {
169
151
  * @param {T} obj - Input object.
170
152
  * @returns {T} New object with dotted keys removed at all levels.
171
153
  */
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]);
154
+ export const removeFormProperties = (obj) => {
155
+ const recursiveRemove = (input) => {
156
+ if (Array.isArray(input)) {
157
+ return input.map((item) => recursiveRemove(item));
186
158
  }
187
- });
188
- return newObj;
189
- }
190
- return input;
191
- };
192
-
193
- return recursiveRemove(obj);
159
+ else if (typeof input === "object" && input !== null) {
160
+ const newObj = { ...input };
161
+ Object.keys(newObj).forEach((key) => {
162
+ if (key.includes(".")) {
163
+ delete newObj[key];
164
+ }
165
+ else {
166
+ newObj[key] = recursiveRemove(newObj[key]);
167
+ }
168
+ });
169
+ return newObj;
170
+ }
171
+ return input;
172
+ };
173
+ return recursiveRemove(obj);
194
174
  };
195
-
196
175
  /**
197
176
  * Recursively convert string booleans `"true"`/`"false"` to actual booleans.
198
177
  *
@@ -202,36 +181,31 @@ export const removeFormProperties = <T extends Record<string, TurndownObject>>(
202
181
  * @param {T} obj - Input object or array.
203
182
  * @returns {T} New value with boolean-like strings converted.
204
183
  */
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);
184
+ export const convertStringBooleans = (obj) => {
185
+ const recursiveConvert = (input) => {
186
+ if (Array.isArray(input)) {
187
+ return input.map((item) => recursiveConvert(item));
223
188
  }
224
- });
225
-
226
- return newObj;
227
- }
228
-
229
- return input;
230
- };
231
-
232
- return recursiveConvert(obj);
189
+ else if (typeof input === "object" && input !== null) {
190
+ const newObj = { ...input };
191
+ Object.keys(newObj).forEach((key) => {
192
+ const value = newObj[key];
193
+ if (value === "true") {
194
+ newObj[key] = true;
195
+ }
196
+ else if (value === "false") {
197
+ newObj[key] = false;
198
+ }
199
+ else if (typeof value === "object" && value !== null) {
200
+ newObj[key] = recursiveConvert(value);
201
+ }
202
+ });
203
+ return newObj;
204
+ }
205
+ return input;
206
+ };
207
+ return recursiveConvert(obj);
233
208
  };
234
-
235
209
  /**
236
210
  * Convenience helper to clean form-like data:
237
211
  * - Removes `undefined` properties
@@ -241,10 +215,9 @@ export const convertStringBooleans = <T extends Record<string, any>>(
241
215
  * @param {TurndownObject} obj - Input data.
242
216
  * @returns {TurndownObject} Cleaned clone.
243
217
  */
244
- export const cleanFormData = (obj: TurndownObject) => {
245
- return removeFormProperties(convertStringBooleans(removeUndefined(obj)));
218
+ export const cleanFormData = (obj) => {
219
+ return removeFormProperties(convertStringBooleans(removeUndefined(obj)));
246
220
  };
247
-
248
221
  /**
249
222
  * Return a default pagination object, allowing optional sort and filters.
250
223
  *
@@ -254,18 +227,14 @@ export const cleanFormData = (obj: TurndownObject) => {
254
227
  * @example
255
228
  * resetPagination() // => { page:1, size:25, sort:[], filters:[] }
256
229
  */
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
- };
230
+ export const resetPagination = (sort, filters) => {
231
+ return {
232
+ page: 1,
233
+ size: 25,
234
+ sort: sort || [],
235
+ filters: filters || [],
236
+ };
267
237
  };
268
-
269
238
  /**
270
239
  * Format a string of digits into a U.S. phone number.
271
240
  *
@@ -279,17 +248,15 @@ export const resetPagination = (
279
248
  * formatPhoneNumber(9876543210) // "(987) 654-3210"
280
249
  * formatPhoneNumber("555") // "555"
281
250
  */
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}`;
251
+ export const formatPhoneNumber = (value) => {
252
+ const digits = value.toString().replace(/\D/g, "");
253
+ if (digits.length !== 10)
254
+ return value.toString();
255
+ const area = digits.slice(0, 3);
256
+ const prefix = digits.slice(3, 6);
257
+ const line = digits.slice(6);
258
+ return `(${area}) ${prefix}-${line}`;
291
259
  };
292
-
293
260
  /**
294
261
  * Format a number with thousands separators (commas).
295
262
  *
@@ -298,10 +265,9 @@ export const formatPhoneNumber = (value: string | number): string => {
298
265
  * @example
299
266
  * formatNumber(1234567) // "1,234,567"
300
267
  */
301
- export const formatNumber = (value: number): string => {
302
- return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
268
+ export const formatNumber = (value) => {
269
+ return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
303
270
  };
304
-
305
271
  /**
306
272
  * Parse a number string (note: current implementation adds commas as well).
307
273
  *
@@ -313,10 +279,9 @@ export const formatNumber = (value: number): string => {
313
279
  * @param {number} value - Number to "parse".
314
280
  * @returns {string} Currently returns a comma-formatted string.
315
281
  */
316
- export const parseNumber = (value: number): string => {
317
- return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "");
282
+ export const parseNumber = (value) => {
283
+ return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "");
318
284
  };
319
-
320
285
  /**
321
286
  * Delete a property from an object if it exists (no-op if it doesn't).
322
287
  *
@@ -324,15 +289,11 @@ export const parseNumber = (value: number): string => {
324
289
  * @param {string} propertyName - Property to delete.
325
290
  * @returns {void}
326
291
  */
327
- export const deletePropertyIfExists = (
328
- obj: TurndownObject,
329
- propertyName: string
330
- ) => {
331
- if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
332
- delete obj[propertyName];
333
- }
292
+ export const deletePropertyIfExists = (obj, propertyName) => {
293
+ if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
294
+ delete obj[propertyName];
295
+ }
334
296
  };
335
-
336
297
  /**
337
298
  * Split an array into chunks of a given size.
338
299
  *
@@ -343,14 +304,13 @@ export const deletePropertyIfExists = (
343
304
  * @example
344
305
  * chunkArray([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
345
306
  */
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;
307
+ export const chunkArray = (array, chunkSize) => {
308
+ const result = [];
309
+ for (let i = 0; i < array.length; i += chunkSize) {
310
+ result.push(array.slice(i, i + chunkSize));
311
+ }
312
+ return result;
352
313
  };
353
-
354
314
  /**
355
315
  * Return a shallow clone of `obj` without the listed properties.
356
316
  *
@@ -360,18 +320,13 @@ export const chunkArray = <T>(array: T[], chunkSize: number): T[][] => {
360
320
  * @example
361
321
  * omitProperties({a:1,b:2}, ["b"]) // { a:1 }
362
322
  */
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;
323
+ export const omitProperties = (obj, propsToOmit) => {
324
+ const newObj = { ...obj };
325
+ propsToOmit.forEach((prop) => {
326
+ delete newObj[prop];
327
+ });
328
+ return newObj;
373
329
  };
374
-
375
330
  /**
376
331
  * Safe `hasOwnProperty` check.
377
332
  *
@@ -379,17 +334,17 @@ export const omitProperties = (
379
334
  * @param {string} key - Property name.
380
335
  * @returns {boolean}
381
336
  */
382
- export const hasProperty = (obj: Record<string, any>, key: string): boolean => {
383
- if (!obj) return false;
384
- return Object.prototype.hasOwnProperty.call(obj, key);
337
+ export const hasProperty = (obj, key) => {
338
+ if (!obj)
339
+ return false;
340
+ return Object.prototype.hasOwnProperty.call(obj, key);
385
341
  };
386
-
387
342
  /**
388
343
  * Determine if an object has at least one own enumerable property.
389
344
  *
390
345
  * @param {object} obj - Object to test.
391
346
  * @returns {boolean} `true` if there is at least one key.
392
347
  */
393
- export const hasProperties = (obj: object): boolean => {
394
- return Object.keys(obj || {}).length > 0;
348
+ export const hasProperties = (obj) => {
349
+ return Object.keys(obj || {}).length > 0;
395
350
  };
@@ -1,5 +1,3 @@
1
- import { TurndownObject } from "@/types/base";
2
-
3
1
  /**
4
2
  * Convert a string to "Normal Case":
5
3
  * - Inserts spaces between camel/pascal case boundaries
@@ -11,20 +9,16 @@ import { TurndownObject } from "@/types/base";
11
9
  * normalCase("helloWorld") // "Hello World"
12
10
  * normalCase("XMLHttpRequest") // "Xml Http Request"
13
11
  */
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(" ");
12
+ export const normalCase = (str) => {
13
+ if (!str)
14
+ return "";
15
+ return str
16
+ .replace(/([a-z])([A-Z])/g, "$1 $2")
17
+ .replace(/([A-Z])([A-Z][a-z])/g, "$1 $2")
18
+ .split(/\s+/)
19
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
20
+ .join(" ");
26
21
  };
27
-
28
22
  /**
29
23
  * Capitalize only the first character; lowercases the rest.
30
24
  * Trims leading/trailing spaces before processing.
@@ -34,13 +28,12 @@ export const normalCase = (str?: TurndownObject): string => {
34
28
  * @example
35
29
  * sentenceCase("hELLO WORLD") // "Hello world"
36
30
  */
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();
31
+ export const sentenceCase = (str) => {
32
+ if (!str)
33
+ return "";
34
+ const s = str.trim();
35
+ return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
42
36
  };
43
-
44
37
  /**
45
38
  * Uppercase the entire string.
46
39
  *
@@ -49,10 +42,9 @@ export const sentenceCase = (str?: TurndownObject): string => {
49
42
  * @example
50
43
  * upperCase("Hello world") // "HELLO WORLD"
51
44
  */
52
- export const upperCase = (str?: TurndownObject): string => {
53
- return str ? str.toUpperCase() : "";
45
+ export const upperCase = (str) => {
46
+ return str ? str.toUpperCase() : "";
54
47
  };
55
-
56
48
  /**
57
49
  * Lowercase the entire string.
58
50
  *
@@ -61,10 +53,9 @@ export const upperCase = (str?: TurndownObject): string => {
61
53
  * @example
62
54
  * lowerCase("Hello WORLD") // "hello world"
63
55
  */
64
- export const lowerCase = (str?: TurndownObject): string => {
65
- return str ? str.toLowerCase() : "";
56
+ export const lowerCase = (str) => {
57
+ return str ? str.toLowerCase() : "";
66
58
  };
67
-
68
59
  /**
69
60
  * Convert to camelCase.
70
61
  * Splits on spaces, underscores, and hyphens; lowercases the first word,
@@ -76,19 +67,17 @@ export const lowerCase = (str?: TurndownObject): string => {
76
67
  * camelCase("Hello world") // "helloWorld"
77
68
  * camelCase("hello_world-again") // "helloWorldAgain"
78
69
  */
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
70
+ export const camelCase = (str) => {
71
+ if (!str)
72
+ return "";
73
+ return str
74
+ .toLowerCase()
75
+ .split(/[\s_-]+/)
76
+ .map((word, i) => i === 0
86
77
  ? word
87
- : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
88
- )
89
- .join("");
78
+ : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
79
+ .join("");
90
80
  };
91
-
92
81
  /**
93
82
  * Convert to PascalCase.
94
83
  * Splits on spaces, underscores, and hyphens; TitleCases all words and joins them.
@@ -99,15 +88,15 @@ export const camelCase = (str?: TurndownObject): string => {
99
88
  * pascalCase("hello world") // "HelloWorld"
100
89
  * pascalCase("hello_world-again") // "HelloWorldAgain"
101
90
  */
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("");
91
+ export const pascalCase = (str) => {
92
+ if (!str)
93
+ return "";
94
+ return str
95
+ .toLowerCase()
96
+ .split(/[\s_-]+/)
97
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
98
+ .join("");
109
99
  };
110
-
111
100
  /**
112
101
  * Convert to kebab-case.
113
102
  * Inserts hyphens between camelCase boundaries, then replaces spaces/underscores with hyphens.
@@ -118,14 +107,14 @@ export const pascalCase = (str?: TurndownObject): string => {
118
107
  * kebabCase("HelloWorld Again") // "hello-world-again"
119
108
  * kebabCase("hello_world") // "hello-world"
120
109
  */
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();
110
+ export const kebabCase = (str) => {
111
+ if (!str)
112
+ return "";
113
+ return str
114
+ .replace(/([a-z])([A-Z])/g, "$1-$2")
115
+ .replace(/[\s_]+/g, "-")
116
+ .toLowerCase();
127
117
  };
128
-
129
118
  /**
130
119
  * Convert to snake_case.
131
120
  * Inserts underscores between camelCase boundaries, then replaces spaces/hyphens with underscores.
@@ -136,14 +125,14 @@ export const kebabCase = (str?: TurndownObject): string => {
136
125
  * snakeCase("HelloWorld Again") // "hello_world_again"
137
126
  * snakeCase("hello-world") // "hello_world"
138
127
  */
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();
128
+ export const snakeCase = (str) => {
129
+ if (!str)
130
+ return "";
131
+ return str
132
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
133
+ .replace(/[\s-]+/g, "_")
134
+ .toLowerCase();
145
135
  };
146
-
147
136
  /**
148
137
  * Convert snake_case to space-delimited words.
149
138
  *
@@ -152,11 +141,11 @@ export const snakeCase = (str?: TurndownObject): string => {
152
141
  * @example
153
142
  * snakeCaseToSpaces("hello_world_again") // "hello world again"
154
143
  */
155
- export const snakeCaseToSpaces = (str?: TurndownObject): string => {
156
- if (!str) return "";
157
- return str.split("_").join(" ");
144
+ export const snakeCaseToSpaces = (str) => {
145
+ if (!str)
146
+ return "";
147
+ return str.split("_").join(" ");
158
148
  };
159
-
160
149
  /**
161
150
  * Convert kebab-case to space-delimited words.
162
151
  *
@@ -165,7 +154,8 @@ export const snakeCaseToSpaces = (str?: TurndownObject): string => {
165
154
  * @example
166
155
  * kebabToSpaces("hello-world-again") // "hello world again"
167
156
  */
168
- export const kebabToSpaces = (str?: TurndownObject): string => {
169
- if (!str) return "";
170
- return str.split("-").join(" ");
157
+ export const kebabToSpaces = (str) => {
158
+ if (!str)
159
+ return "";
160
+ return str.split("-").join(" ");
171
161
  };
@@ -0,0 +1,5 @@
1
+ export const STATUS = {
2
+ ACTIVE: "ACTIVE",
3
+ INACTIVE: "INACTIVE",
4
+ };
5
+ export * from "./paging.types";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ export const ACCOUNT_TYPE = {
2
+ TURNDOWN_ADMIN: "TURNDOWN_ADMIN",
3
+ OWNER: "OWNER",
4
+ ACCOUNT_ADMIN: "ACCOUNT_ADMIN",
5
+ MAINTAINER: "MAINTAINER",
6
+ CLEANER: "CLEANER",
7
+ };
8
+ export const LANGUAGE = {
9
+ ENGLISH: "ENGLISH",
10
+ FRENCH: "FRENCH",
11
+ SPANISH: "SPANISH",
12
+ GERMAN: "GERMAN",
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turndown/library",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Shared TypeScript library for the Turndown suite.",
5
5
  "keywords": [
6
6
  "types",
@@ -16,21 +16,20 @@
16
16
  "access": "public"
17
17
  },
18
18
  "type": "module",
19
- "main": "dist/index.ts",
20
- "module": "dist/index.ts",
21
- "types": "./dist/index.d.ts",
22
- "files": [
23
- "src",
24
- "dist"
25
- ],
26
19
  "exports": {
27
20
  ".": {
28
21
  "types": "./dist/index.d.ts",
29
- "browser": "./dist/index.ts",
30
- "import": "./dist/index.ts"
22
+ "import": "./dist/index.js",
23
+ "default": "./dist/index.js"
31
24
  },
32
25
  "./package.json": "./package.json"
33
26
  },
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist",
30
+ "LICENSE",
31
+ "README.md"
32
+ ],
34
33
  "scripts": {
35
34
  "clean": "rimraf dist",
36
35
  "build": "npm run clean && tsc -p .",
@@ -1,26 +0,0 @@
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";
@@ -1,35 +0,0 @@
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
- };
@@ -1,42 +0,0 @@
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>;
File without changes
File without changes