@turndown/library 0.0.20 → 0.0.21

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,2 @@
1
+ export * from "./object";
2
+ export * from "./string";
@@ -0,0 +1,213 @@
1
+ import { FilterCondition, SortCondition, TurndownObject } from "@/types/base";
2
+ export interface Version {
3
+ major: number;
4
+ minor: number;
5
+ patch: number;
6
+ }
7
+ export type VersionInput = string | Version;
8
+ /**
9
+ * Safely parse a JSON string into a value.
10
+ *
11
+ * Returns `{}` if parsing fails instead of throwing.
12
+ *
13
+ * @param {TurndownObject} jsonString - The JSON string to parse.
14
+ * @returns {TurndownObject} Parsed value or `{}` on failure.
15
+ * @example
16
+ * parseJSON('{"a":1}') // => { a: 1 }
17
+ * parseJSON('not json') // => {}
18
+ */
19
+ export declare const parseJSON: (jsonString: TurndownObject) => TurndownObject;
20
+ /**
21
+ * Stringify an object to JSON while skipping circular references.
22
+ *
23
+ * Uses an internal cache to omit repeated object references that would
24
+ * normally cause `JSON.stringify` to throw.
25
+ *
26
+ * @param {TurndownObject} obj - Value to stringify.
27
+ * @returns {string} JSON string with circulars omitted.
28
+ * @example
29
+ * const a:any = {}; a.self = a;
30
+ * JSONStringify(a) // => "{}"
31
+ */
32
+ export declare const JSONStringify: (obj: TurndownObject) => string;
33
+ /**
34
+ * Deep-remove `undefined` properties by serializing & parsing.
35
+ *
36
+ * @param {TurndownObject} obj - Input object.
37
+ * @returns {TurndownObject} Cleaned clone with `undefined` removed.
38
+ */
39
+ export declare const removeUndefined: (obj: TurndownObject) => TurndownObject;
40
+ /**
41
+ * Test whether a location object's `pathname` equals a key.
42
+ *
43
+ * @param {TurndownObject} location - Object expected to have a `pathname`.
44
+ * @param {string} key - Path to compare.
45
+ * @returns {boolean}
46
+ * @example
47
+ * validPath({ pathname: "/home" }, "/home") // true
48
+ */
49
+ export declare const validPath: (location: TurndownObject, key: string) => boolean;
50
+ /**
51
+ * Return the first element if the input is an array; otherwise return the value itself.
52
+ *
53
+ * @typeParam T - Element type.
54
+ * @param {T | T[]} input - A single value or an array.
55
+ * @returns {T} First element or the input value.
56
+ * @example
57
+ * returnObject([1,2,3]) // 1
58
+ * returnObject(5) // 5
59
+ */
60
+ export declare const returnObject: <T>(input: T | T[]) => T;
61
+ /**
62
+ * Filter out items from `array1` whose `id` appears in `array2`.
63
+ *
64
+ * @typeParam T - Object type with an `id` field.
65
+ * @param {T[]} [array1] - Source array.
66
+ * @param {T[]} [array2] - Items whose `id`s should be excluded.
67
+ * @returns {T[]} Filtered array (or `[]` on errors/invalid input).
68
+ */
69
+ export declare const filterArrayById: <T extends {
70
+ id: number | string;
71
+ }>(array1?: T[], array2?: T[]) => T[];
72
+ /**
73
+ * Sort an array of objects by a given property (ascending).
74
+ *
75
+ * Mutates the original array (uses `Array.prototype.sort`).
76
+ *
77
+ * @typeParam T - Object type.
78
+ * @param {T[]} array - Array to sort.
79
+ * @param {keyof T} property - Property name to sort by.
80
+ * @returns {T[]} The same array instance, sorted (or empty array if input invalid).
81
+ */
82
+ export declare const sortArrayByProperty: <T extends Record<string, any>>(array: T[], property: keyof T) => T[];
83
+ /**
84
+ * Recursively replace `null` values with empty strings.
85
+ *
86
+ * Works on primitives, arrays, and plain objects.
87
+ *
88
+ * @param {TurndownObject} obj - Input value.
89
+ * @returns {TurndownObject} Value with all `null` replaced by `""`.
90
+ */
91
+ export declare const replaceNulls: (obj: TurndownObject) => TurndownObject;
92
+ /**
93
+ * Recursively remove object keys that contain a dot (`.`).
94
+ *
95
+ * @typeParam T - Object type.
96
+ * @param {T} obj - Input object.
97
+ * @returns {T} New object with dotted keys removed at all levels.
98
+ */
99
+ export declare const removeFormProperties: <T extends Record<string, TurndownObject>>(obj: T) => T;
100
+ /**
101
+ * Recursively convert string booleans `"true"`/`"false"` to actual booleans.
102
+ *
103
+ * Leaves all other values unchanged.
104
+ *
105
+ * @typeParam T - Object type.
106
+ * @param {T} obj - Input object or array.
107
+ * @returns {T} New value with boolean-like strings converted.
108
+ */
109
+ export declare const convertStringBooleans: <T extends Record<string, any>>(obj: T) => T;
110
+ /**
111
+ * Convenience helper to clean form-like data:
112
+ * - Removes `undefined` properties
113
+ * - Converts string booleans to booleans
114
+ * - Removes keys containing a dot ('.')
115
+ *
116
+ * @param {TurndownObject} obj - Input data.
117
+ * @returns {TurndownObject} Cleaned clone.
118
+ */
119
+ export declare const cleanFormData: (obj: TurndownObject) => any;
120
+ /**
121
+ * Return a default pagination object, allowing optional sort and filters.
122
+ *
123
+ * @param {SortCondition[]} [sort] - Optional sort conditions.
124
+ * @param {FilterCondition[]} [filters] - Optional filter conditions.
125
+ * @returns {{ page: number; size: number; sort: SortCondition[]; filters: FilterCondition[] }}
126
+ * @example
127
+ * resetPagination() // => { page:1, size:25, sort:[], filters:[] }
128
+ */
129
+ export declare const resetPagination: (sort?: SortCondition[], filters?: FilterCondition[]) => {
130
+ page: number;
131
+ size: number;
132
+ sort: SortCondition[];
133
+ filters: FilterCondition[];
134
+ };
135
+ /**
136
+ * Format a string of digits into a U.S. phone number.
137
+ *
138
+ * Strips non-numeric characters and formats as `(XXX) XXX-XXXX`.
139
+ * If fewer than 10 digits are provided, returns the input unchanged.
140
+ *
141
+ * @param {string | number} value - Phone number digits (string or number).
142
+ * @returns {string} Formatted phone number, or original input if invalid length.
143
+ * @example
144
+ * formatPhoneNumber("1234567890") // "(123) 456-7890"
145
+ * formatPhoneNumber(9876543210) // "(987) 654-3210"
146
+ * formatPhoneNumber("555") // "555"
147
+ */
148
+ export declare const formatPhoneNumber: (value: string | number) => string;
149
+ /**
150
+ * Format a number with thousands separators (commas).
151
+ *
152
+ * @param {number} value - Number to format.
153
+ * @returns {string} String with commas.
154
+ * @example
155
+ * formatNumber(1234567) // "1,234,567"
156
+ */
157
+ export declare const formatNumber: (value: number) => string;
158
+ /**
159
+ * Parse a number string (note: current implementation adds commas as well).
160
+ *
161
+ * @remarks
162
+ * This function uses the same regex as `formatNumber`, so it **does not remove**
163
+ * commas; it inserts them. If you intended to *strip* separators, consider:
164
+ * `value.toString().replace(/,/g, "")`.
165
+ *
166
+ * @param {number} value - Number to "parse".
167
+ * @returns {string} Currently returns a comma-formatted string.
168
+ */
169
+ export declare const parseNumber: (value: number) => string;
170
+ /**
171
+ * Delete a property from an object if it exists (no-op if it doesn't).
172
+ *
173
+ * @param {TurndownObject} obj - Target object (mutated).
174
+ * @param {string} propertyName - Property to delete.
175
+ * @returns {void}
176
+ */
177
+ export declare const deletePropertyIfExists: (obj: TurndownObject, propertyName: string) => void;
178
+ /**
179
+ * Split an array into chunks of a given size.
180
+ *
181
+ * @typeParam T - Element type.
182
+ * @param {T[]} array - Source array.
183
+ * @param {number} chunkSize - Size of each chunk (no validation performed).
184
+ * @returns {T[][]} Array of chunks (last one may be smaller).
185
+ * @example
186
+ * chunkArray([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
187
+ */
188
+ export declare const chunkArray: <T>(array: T[], chunkSize: number) => T[][];
189
+ /**
190
+ * Return a shallow clone of `obj` without the listed properties.
191
+ *
192
+ * @param {TurndownObject} obj - Source object.
193
+ * @param {TurndownObject} propsToOmit - Iterable of property names (expects array-like).
194
+ * @returns {TurndownObject} New object without omitted props.
195
+ * @example
196
+ * omitProperties({a:1,b:2}, ["b"]) // { a:1 }
197
+ */
198
+ export declare const omitProperties: (obj: TurndownObject, propsToOmit: TurndownObject) => any;
199
+ /**
200
+ * Safe `hasOwnProperty` check.
201
+ *
202
+ * @param {Record<string, any>} obj - Object to test.
203
+ * @param {string} key - Property name.
204
+ * @returns {boolean}
205
+ */
206
+ export declare const hasProperty: (obj: Record<string, any>, key: string) => boolean;
207
+ /**
208
+ * Determine if an object has at least one own enumerable property.
209
+ *
210
+ * @param {object} obj - Object to test.
211
+ * @returns {boolean} `true` if there is at least one key.
212
+ */
213
+ export declare const hasProperties: (obj: object) => boolean;
@@ -0,0 +1,104 @@
1
+ import { TurndownObject } from "@/types/base";
2
+ /**
3
+ * Convert a string to "Normal Case":
4
+ * - Inserts spaces between camel/pascal case boundaries
5
+ * - Capitalizes the first letter of each word, lowercases the rest
6
+ *
7
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
8
+ * @returns {string}
9
+ * @example
10
+ * normalCase("helloWorld") // "Hello World"
11
+ * normalCase("XMLHttpRequest") // "Xml Http Request"
12
+ */
13
+ export declare const normalCase: (str?: TurndownObject) => string;
14
+ /**
15
+ * Capitalize only the first character; lowercases the rest.
16
+ * Trims leading/trailing spaces before processing.
17
+ *
18
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
19
+ * @returns {string}
20
+ * @example
21
+ * sentenceCase("hELLO WORLD") // "Hello world"
22
+ */
23
+ export declare const sentenceCase: (str?: TurndownObject) => string;
24
+ /**
25
+ * Uppercase the entire string.
26
+ *
27
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
28
+ * @returns {string}
29
+ * @example
30
+ * upperCase("Hello world") // "HELLO WORLD"
31
+ */
32
+ export declare const upperCase: (str?: TurndownObject) => string;
33
+ /**
34
+ * Lowercase the entire string.
35
+ *
36
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
37
+ * @returns {string}
38
+ * @example
39
+ * lowerCase("Hello WORLD") // "hello world"
40
+ */
41
+ export declare const lowerCase: (str?: TurndownObject) => string;
42
+ /**
43
+ * Convert to camelCase.
44
+ * Splits on spaces, underscores, and hyphens; lowercases the first word,
45
+ * TitleCases the rest, then joins with no separators.
46
+ *
47
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
48
+ * @returns {string}
49
+ * @example
50
+ * camelCase("Hello world") // "helloWorld"
51
+ * camelCase("hello_world-again") // "helloWorldAgain"
52
+ */
53
+ export declare const camelCase: (str?: TurndownObject) => string;
54
+ /**
55
+ * Convert to PascalCase.
56
+ * Splits on spaces, underscores, and hyphens; TitleCases all words and joins them.
57
+ *
58
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
59
+ * @returns {string}
60
+ * @example
61
+ * pascalCase("hello world") // "HelloWorld"
62
+ * pascalCase("hello_world-again") // "HelloWorldAgain"
63
+ */
64
+ export declare const pascalCase: (str?: TurndownObject) => string;
65
+ /**
66
+ * Convert to kebab-case.
67
+ * Inserts hyphens between camelCase boundaries, then replaces spaces/underscores with hyphens.
68
+ *
69
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
70
+ * @returns {string}
71
+ * @example
72
+ * kebabCase("HelloWorld Again") // "hello-world-again"
73
+ * kebabCase("hello_world") // "hello-world"
74
+ */
75
+ export declare const kebabCase: (str?: TurndownObject) => string;
76
+ /**
77
+ * Convert to snake_case.
78
+ * Inserts underscores between camelCase boundaries, then replaces spaces/hyphens with underscores.
79
+ *
80
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
81
+ * @returns {string}
82
+ * @example
83
+ * snakeCase("HelloWorld Again") // "hello_world_again"
84
+ * snakeCase("hello-world") // "hello_world"
85
+ */
86
+ export declare const snakeCase: (str?: TurndownObject) => string;
87
+ /**
88
+ * Convert snake_case to space-delimited words.
89
+ *
90
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
91
+ * @returns {string}
92
+ * @example
93
+ * snakeCaseToSpaces("hello_world_again") // "hello world again"
94
+ */
95
+ export declare const snakeCaseToSpaces: (str?: TurndownObject) => string;
96
+ /**
97
+ * Convert kebab-case to space-delimited words.
98
+ *
99
+ * @param {TurndownObject} [str] Input value (falsy returns an empty string)
100
+ * @returns {string}
101
+ * @example
102
+ * kebabToSpaces("hello-world-again") // "hello world again"
103
+ */
104
+ export declare const kebabToSpaces: (str?: TurndownObject) => string;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./helpers";
2
+ export * from "./types";
@@ -0,0 +1,18 @@
1
+ export type GenericTurndownObject = Record<string, any> | any | undefined;
2
+ export type TurndownObject<T = GenericTurndownObject> = Record<string, T> | T | undefined;
3
+ export type ObjectValues<T> = T[keyof T];
4
+ export type ObjectKeys<T> = [keyof T];
5
+ export interface MetaData {
6
+ company_id: string;
7
+ deleted: boolean;
8
+ updated_by: string;
9
+ created_by: string;
10
+ created_at: Date;
11
+ updated_at: Date;
12
+ }
13
+ export declare const STATUS: {
14
+ readonly ACTIVE: "ACTIVE";
15
+ readonly INACTIVE: "INACTIVE";
16
+ };
17
+ export type Status = ObjectValues<typeof STATUS>;
18
+ export * from "./paging.types";
@@ -0,0 +1,30 @@
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: (page: number, size: number, sort?: SortCondition[], filters?: FilterCondition[]) => {
29
+ pagination: any;
30
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./user";
2
+ export * from "./base";
@@ -0,0 +1,37 @@
1
+ import { MetaData, ObjectValues, Status } from "@/types";
2
+ export interface User extends Omit<MetaData, "created_by" | "updated_by"> {
3
+ id: string;
4
+ firstName: string;
5
+ lastName: string;
6
+ mi: string;
7
+ username: string;
8
+ email: string;
9
+ password: string;
10
+ loginAttempts: number;
11
+ locked: boolean;
12
+ passwordLastReset: Date;
13
+ passwordResetRequired: boolean;
14
+ type: AccountType;
15
+ status: Status;
16
+ companyId: number;
17
+ phoneNumber: string;
18
+ phoneFormat: string;
19
+ language: Language;
20
+ biometrics: string;
21
+ lastLogin: Date;
22
+ }
23
+ export declare const ACCOUNT_TYPE: {
24
+ readonly TURNDOWN_ADMIN: "TURNDOWN_ADMIN";
25
+ readonly OWNER: "OWNER";
26
+ readonly ACCOUNT_ADMIN: "ACCOUNT_ADMIN";
27
+ readonly MAINTAINER: "MAINTAINER";
28
+ readonly CLEANER: "CLEANER";
29
+ };
30
+ export type AccountType = ObjectValues<typeof ACCOUNT_TYPE>;
31
+ export declare const LANGUAGE: {
32
+ readonly ENGLISH: "ENGLISH";
33
+ readonly FRENCH: "FRENCH";
34
+ readonly SPANISH: "SPANISH";
35
+ readonly GERMAN: "GERMAN";
36
+ };
37
+ export type Language = ObjectValues<typeof LANGUAGE>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turndown/library",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "Shared TypeScript library for the Turndown suite.",
5
5
  "keywords": [
6
6
  "types",
@@ -19,8 +19,8 @@
19
19
  "exports": {
20
20
  ".": {
21
21
  "types": "./dist/index.d.ts",
22
- "import": "./dist/index.js",
23
- "default": "./dist/index.js"
22
+ "import": "./dist/index.ts",
23
+ "default": "./dist/index.ts"
24
24
  },
25
25
  "./package.json": "./package.json"
26
26
  },
package/dist/package.json DELETED
@@ -1,45 +0,0 @@
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
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes