danholibraryjs 2.0.0 → 2.0.2

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.
Files changed (94) hide show
  1. package/README.md +1 -1
  2. package/_package.github-release.json +6 -0
  3. package/_package.npm-release.json +6 -0
  4. package/dist/Extensions/Array/index.d.ts +6 -20
  5. package/dist/Extensions/Array/index.js +8 -26
  6. package/dist/Extensions/Array/random.extension.d.ts +1 -2
  7. package/dist/Extensions/Array/random.extension.js +1 -22
  8. package/dist/Extensions/Array/string.extension.d.ts +3 -4
  9. package/dist/Extensions/Number.d.ts +2 -2
  10. package/dist/Extensions/Number.js +1 -1
  11. package/dist/Extensions/Object/arrays.extension.d.ts +14 -0
  12. package/dist/Extensions/Object/arrays.extension.js +7 -2
  13. package/dist/Extensions/Object/extracts.extension.d.ts +6 -6
  14. package/dist/Extensions/Object/extracts.extension.js +10 -7
  15. package/dist/Extensions/Object/index.d.ts +4 -10
  16. package/dist/Extensions/Object/index.js +6 -22
  17. package/dist/Extensions/Object/properties.extension.d.ts +28 -1
  18. package/dist/Extensions/Object/properties.extension.js +19 -2
  19. package/dist/Extensions/Object/properties.js +2 -1
  20. package/dist/Extensions/String/index.d.ts +2 -4
  21. package/dist/Extensions/String/index.js +4 -16
  22. package/dist/Extensions/String/string.extension.d.ts +6 -0
  23. package/dist/Extensions/String/string.extension.js +10 -0
  24. package/dist/Extensions/index.d.ts +2 -2
  25. package/dist/Extensions/index.js +2 -2
  26. package/dist/Types/Able.d.ts +1 -1
  27. package/dist/Utils/NumberUtils.d.ts +5 -0
  28. package/dist/Utils/NumberUtils.js +25 -1
  29. package/dist/Utils/StringUtils.d.ts +5 -0
  30. package/dist/Utils/StringUtils.js +6 -1
  31. package/dist/Utils/TimeUtils/index.d.ts +3 -0
  32. package/dist/Utils/TimeUtils/index.js +2 -0
  33. package/dist/Utils/TimeUtils/string.util.d.ts +3 -0
  34. package/dist/Utils/TimeUtils/string.util.js +19 -0
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.js +1 -1
  37. package/docs/Classes.md +78 -3
  38. package/docs/Extensions.md +247 -73
  39. package/docs/Types.md +202 -58
  40. package/docs/Utils.md +335 -0
  41. package/docs/index.md +1 -1
  42. package/package.json +1 -1
  43. package/src/Extensions/Array/index.ts +6 -15
  44. package/src/Extensions/Array/random.extension.ts +2 -25
  45. package/src/Extensions/Array/string.extension.ts +3 -4
  46. package/src/Extensions/Number.ts +3 -3
  47. package/src/Extensions/Object/arrays.extension.ts +23 -2
  48. package/src/Extensions/Object/extracts.extension.ts +18 -13
  49. package/src/Extensions/Object/index.ts +4 -11
  50. package/src/Extensions/Object/properties.extension.ts +50 -2
  51. package/src/Extensions/String/index.ts +2 -5
  52. package/src/Extensions/String/string.extension.ts +11 -0
  53. package/src/Extensions/index.ts +2 -2
  54. package/src/Types/Able.ts +1 -1
  55. package/src/Utils/NumberUtils.ts +27 -0
  56. package/src/Utils/StringUtils.ts +7 -1
  57. package/src/Utils/TimeUtils/index.ts +2 -0
  58. package/src/Utils/TimeUtils/string.util.ts +13 -0
  59. package/src/index.ts +2 -2
  60. package/dist/Extensions/Array.d.ts +0 -52
  61. package/dist/Extensions/Array.js +0 -51
  62. package/dist/Extensions/Document.d.ts +0 -27
  63. package/dist/Extensions/Document.js +0 -32
  64. package/dist/Extensions/String.d.ts +0 -36
  65. package/dist/Extensions/String.js +0 -25
  66. package/dist/Functions/CopyToClipboard.d.ts +0 -7
  67. package/dist/Functions/CopyToClipboard.js +0 -15
  68. package/dist/Functions/GetCSSProperty.d.ts +0 -15
  69. package/dist/Functions/GetCSSProperty.js +0 -26
  70. package/dist/Functions/GetNestedProperty.d.ts +0 -9
  71. package/dist/Functions/GetNestedProperty.js +0 -23
  72. package/dist/Functions/HTMLEvent.d.ts +0 -11
  73. package/dist/Functions/HTMLEvent.js +0 -14
  74. package/dist/Functions/SetNavigationSelected.d.ts +0 -9
  75. package/dist/Functions/SetNavigationSelected.js +0 -25
  76. package/dist/Functions/index.d.ts +0 -5
  77. package/dist/Functions/index.js +0 -21
  78. package/dist/Utils/ApiUtil/ApiTypes.d.ts +0 -15
  79. package/dist/Utils/ApiUtil/ApiTypes.js +0 -15
  80. package/dist/Utils/ApiUtil/RequestUtil.d.ts +0 -19
  81. package/dist/Utils/ApiUtil/RequestUtil.js +0 -73
  82. package/dist/Utils/ApiUtil/index.d.ts +0 -20
  83. package/dist/Utils/ApiUtil/index.js +0 -33
  84. package/dist/Utils/FormUtil.d.ts +0 -6
  85. package/dist/Utils/FormUtil.js +0 -35
  86. package/docs/Functions.md +0 -61
  87. package/src/Extensions/Document.ts +0 -58
  88. package/src/Extensions/Object/properties.ts +0 -50
  89. package/src/Functions/CopyToClipboard.ts +0 -10
  90. package/src/Functions/GetCSSProperty.ts +0 -27
  91. package/src/Functions/GetNestedProperty.ts +0 -29
  92. package/src/Functions/HTMLEvent.ts +0 -13
  93. package/src/Functions/SetNavigationSelected.ts +0 -19
  94. package/src/Functions/index.ts +0 -5
package/docs/Types.md CHANGED
@@ -4,115 +4,244 @@
4
4
 
5
5
  ### General
6
6
 
7
- ``` ts
7
+ ```ts
8
8
  /**
9
- * Type's properties are ReturnType
9
+ * Used for HTMLElement.append in ElementOptions, Document.createElement.
10
+ * IElement accepts HTML Elements or HTML-like strings.
10
11
  */
11
- type AllPropsAre<ReturnType> = {
12
- [key: string]: ReturnType
13
- }
12
+ type IElement = HTMLElement | string;
14
13
 
15
14
  /**
16
- * Item is single or multiple
15
+ * string or RegExp
17
16
  */
18
- type Arrayable<T> = T | Array<T>;
17
+ type StringRegex = string | RegExp;
19
18
 
20
19
  /**
21
- * If Condition is true, Then, Else... pretty self-explanatory
20
+ * Conditional type - If Boolean is true, returns True, otherwise False
22
21
  */
23
- type If<Condition, Then, Else> = Condition extends true ? Then : Else;
22
+ type If<Boolean extends boolean, True, False> = Boolean extends true ? True : False;
24
23
 
25
24
  /**
26
- * Used for HTMLElement.append in ElementOptions, Document.createProperElement.
27
- * IElement accepts HTML Elements or HTMl-like strings.
28
- *
29
- * @see HTMLElement.append
30
- * @see Document.createProperElement
25
+ * Return types of T
31
26
  */
32
- type IElement = HTMLElement | string;
27
+ type ValueOf<T> = T[keyof T];
28
+ ```
33
29
 
30
+ ### Able
31
+
32
+ ```ts
34
33
  /**
35
- * string or RegExp.. pretty self-explanatory
34
+ * Value can be either T or a function that returns T
36
35
  */
37
- type StringRegex = string | RegExp;
36
+ type Functionable<T, Args extends any[] = []> = T | ((...args: Args) => T);
38
37
 
39
38
  /**
40
- * Return types of T
39
+ * Value can be either T or a Promise that resolves to T
41
40
  */
42
- type ValueOf<T> = T[keyof T];
41
+ type Promiseable<T> = T | Promise<T>;
42
+
43
+ /**
44
+ * Value can be T or null
45
+ */
46
+ type Nullable<T> = T | null;
47
+
48
+ /**
49
+ * Removes null and undefined from T
50
+ */
51
+ type NonNullable<T> = T extends null | undefined ? never : T;
52
+ ```
53
+
54
+ ### Array
55
+
56
+ ```ts
57
+ /**
58
+ * Item is single or multiple (T or Array<T>)
59
+ */
60
+ type Arrayable<T> = T | Array<T>;
61
+
62
+ /**
63
+ * Item is single or wrapped in single-element array
64
+ */
65
+ type SingleArrayable<T> = T | [T];
66
+
67
+ /**
68
+ * Extracts type from Array<T>
69
+ */
70
+ type TFromArray<T> = T extends Array<infer U> ? U : never;
43
71
  ```
44
72
 
45
73
  ### BetterTypes
46
74
 
47
75
  ```ts
48
76
  /**
49
- * Construct a type with the properties of Type except for those in type Properties.
77
+ * Construct a type with the properties of Type except for those in Properties
50
78
  */
51
79
  type BetterOmit<Type, Properties extends keyof Type> = Omit<Type, Properties>;
80
+
52
81
  /**
53
82
  * Extract from From those types that are assignable to Properties
54
83
  */
55
84
  type BetterExtract<From, Properties extends From> = Extract<From, Properties>;
85
+
86
+ /**
87
+ * Partial type but with required properties
88
+ */
89
+ type PartialExcept<From, Properties extends keyof From> = Partial<From> & Required<Pick<From, Properties>>;
90
+ ```
91
+
92
+ ### C# Types
93
+
94
+ ```ts
95
+ /**
96
+ * GUID string
97
+ */
98
+ type Guid = string;
99
+
100
+ /**
101
+ * TimeSpan string format
102
+ */
103
+ type TimeSpanType = string;
104
+ ```
105
+
106
+ ### Date
107
+
108
+ ```ts
109
+ /**
110
+ * Long month names
111
+ */
112
+ type LongMonth = 'January' | 'February' | 'March' | 'April' | 'May' | 'June' | 'July' | 'August' | 'September' | 'October' | 'November' | 'December';
113
+
114
+ /**
115
+ * Short month names
116
+ */
117
+ type ShortMonth = 'Jan' | 'Feb' | 'Mar' | 'Apr' | 'May' | 'Jun' | 'Jul' | 'Aug' | 'Sep' | 'Oct' | 'Nov' | 'Dec';
118
+
119
+ /**
120
+ * Month name (long or short)
121
+ */
122
+ type Month = LongMonth | ShortMonth;
123
+
124
+ /**
125
+ * Short day names
126
+ */
127
+ type ShortDay = 'Mon' | 'Tue' | 'Wed' | 'Thu' | 'Fri' | 'Sat' | 'Sun';
128
+
129
+ /**
130
+ * Long day names
131
+ */
132
+ type LongDay = `${'Mon' | 'Tues' | 'Wednes' | 'Thurs' | 'Fri' | 'Satur' | 'Sun'}day`;
133
+
134
+ /**
135
+ * Day name (long or short)
136
+ */
137
+ type Day = ShortDay | LongDay;
138
+
139
+ /**
140
+ * Constructor type for DanhoDate
141
+ */
142
+ type DanhoDateConstructor = TimeProperties | string | number | Date;
143
+
144
+ /**
145
+ * Time properties object
146
+ */
147
+ type TimeProperties<Plural extends boolean = false> = Record<Plural extends true ? `${TimeKeys}s` : TimeKeys, number>;
148
+
149
+ /**
150
+ * What properties to include when using TimeSpan.toString()
151
+ */
152
+ type TimeSpanFormat = Partial<TransformType<TimeProperties<true>, number, boolean>>;
56
153
  ```
57
154
 
58
155
  ### Events
59
156
 
60
157
  ```ts
61
158
  /**
62
- * Default eventhandler mapper. Object with properties that are arrays
159
+ * Default event handler mapper. Object with properties that are arrays
63
160
  */
64
- type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Types>;
161
+ type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Types>;
65
162
 
66
- /**
67
- * Eventhandler type for:
68
- * @see EventCollection
69
- * @borrows BaseEvent
70
- */
71
- type EventHandler<
72
- Events extends BaseEvent<string, Array<any>> = BaseEvent<string, Array<any>>,
73
- Event extends keyof Events = keyof Events,
74
- ReturnType = any
75
- > = (...args: Events[Event]) => ReturnType;
163
+ /**
164
+ * Event handler type
165
+ */
166
+ type EventHandler<
167
+ Events extends BaseEvent<string, Array<any>> = BaseEvent<string, Array<any>>,
168
+ Event extends keyof Events = keyof Events,
169
+ ReturnType = any
170
+ > = (...args: Events[Event]) => ReturnType;
76
171
  ```
77
172
 
78
- ### PropertiesWith
173
+ ### Function
79
174
 
80
175
  ```ts
81
176
  /**
82
- * Filters all properties from From that has the return type of Type
177
+ * Changes return type of a function
83
178
  */
84
- type PropertiesWith<Type, From> = {
85
- [Key in keyof From as From[Key] extends Type ? Key : never]: From[Key]
86
- }
87
- default PropertiesWith;
179
+ type NewReturnType<Func extends (...args: any[]) => any, NewReturn> =
180
+ Func extends (...args: infer Args) => any ? (...args: Args) => NewReturn : never;
88
181
 
89
182
  /**
90
- * Fitlers all properties from From that don't have the return type of Type
183
+ * Wraps function return type in Promise
91
184
  */
92
- type PropertiesWithout<Type, From> = {
93
- [Key in keyof From as From[Key] extends Type ? never : Key]: From[Key]
94
- }
185
+ type PromisedReturn<Func extends (...args: any[]) => any> =
186
+ Func extends (...args: infer Args) => infer Return ? (...args: Args) => Promise<Return> : never;
187
+
188
+ /**
189
+ * Removes all function properties from type
190
+ */
191
+ type NoFunctions<T> = { [K in keyof T]: T[K] extends Function ? never : T[K] };
95
192
  ```
96
193
 
97
- ### Time
194
+ ### Object
98
195
 
99
196
  ```ts
100
197
  /**
101
- * Type used to construct DanhoDate.
102
- * @Data Partial TimeProperties except years & months
103
- * @DateFormat string as dd/MM/yyyy
198
+ * Type's properties are all ReturnType
199
+ */
200
+ type AllPropsAre<ReturnType> = {
201
+ [key: string]: ReturnType;
202
+ };
203
+ ```
204
+
205
+ ### PropertiesWith
206
+
207
+ ```ts
208
+ /**
209
+ * Filters all properties from From that have the return type of Type
210
+ */
211
+ type PropertiesWith<Type, From> = {
212
+ [Key in keyof From as From[Key] extends Type ? Key : never]: From[Key];
213
+ };
214
+
215
+ /**
216
+ * Filters all properties from From that don't have the return type of Type
104
217
  */
105
- type DanhoDateConstructor = Data | DateFormat | number | Date;
218
+ type PropertiesWithout<Type, From> = {
219
+ [Key in keyof From as From[Key] extends Type ? never : Key]: From[Key];
220
+ };
106
221
 
107
222
  /**
108
- * Object interface with keys above to number values. If Plural is true, all properties ends with 's'
223
+ * Gets keys that appear in all types in the array
109
224
  */
110
- type TimeProperties<Plural extends boolean = false> = Record<Plural extends true ? `${TimeKeys}s` : TimeKeys, number>
225
+ type GetRepeatedKeys<Types extends Array<any>> =
226
+ Types extends [infer First, ...infer Rest]
227
+ ? Rest extends Array<any>
228
+ ? keyof First & GetRepeatedKeys<Rest>
229
+ : keyof First
230
+ : never;
111
231
 
112
232
  /**
113
- * What properties to include when using TimeSpan.toString(format: TimeSpanFormat): string
233
+ * Filters types that have specific properties
114
234
  */
115
- type TimeSpanFormat = Partial<TransformType<TimeProperties<true>, number, boolean>>
235
+ type ModelWithProps<T, TProps extends (keyof T | string)> = T extends Record<TProps, any> ? T : never;
236
+ ```
237
+
238
+ ### String
239
+
240
+ ```ts
241
+ /**
242
+ * Autocomplete type - allows string literal autocomplete while still accepting any string
243
+ */
244
+ type Autocomplete<T> = T | (string & {});
116
245
  ```
117
246
 
118
247
  ### TransformTypes
@@ -122,21 +251,36 @@ type TimeSpanFormat = Partial<TransformType<TimeProperties<true>, number, boolea
122
251
  * Converts Start types to Switch types in From type
123
252
  */
124
253
  type TransformType<From, Start, Switch> = {
125
- [Key in keyof From]: From[Key] extends Start ? Switch : From[Key]
126
- }
254
+ [Key in keyof From]: From[Key] extends Start ? Switch : From[Key];
255
+ };
127
256
 
128
257
  /**
129
258
  * Returns object with properties matching BaseType with types of NewType
130
259
  */
131
- type TransformTypes<From, BaseType, NewType> = Record<keyof {
132
- [Key in keyof From as From[Key] extends BaseType ? Key : never]: Key
133
- }, NewType>
260
+ type TransformTypes<From, BaseType, NewType> = Record<keyof {
261
+ [Key in keyof From as From[Key] extends BaseType ? Key : never]: Key;
262
+ }, NewType>;
263
+
264
+ /**
265
+ * Converts object to JSON-serializable type (removes functions, Date -> string, etc.)
266
+ */
267
+ type Json<T> = {
268
+ [K in keyof T]: T[K] extends Function
269
+ ? never
270
+ : T[K] extends Date
271
+ ? string
272
+ : T[K] extends object
273
+ ? Json<T[K]>
274
+ : T[K];
275
+ };
134
276
  ```
135
277
 
136
278
  ### Store
279
+
137
280
  ```ts
138
281
  /**
139
- * Reducer function to map wanted parameters when using @see Store.on(action, reducer);
282
+ * Reducer function for Store state updates
140
283
  */
141
- type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> = (state: State, ...args: Types[Action]) => State
284
+ type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> =
285
+ (state: State, ...args: Types[Action]) => State;
142
286
  ```
package/docs/Utils.md ADDED
@@ -0,0 +1,335 @@
1
+ # [DanhoLibraryJS](../README.md)
2
+
3
+ ## Utils
4
+
5
+ Utility functions and classes for common tasks.
6
+
7
+ ### ApiUtils
8
+
9
+ ```ts
10
+ /**
11
+ * API utility class for making HTTP requests
12
+ */
13
+ class ApiUtils<ApiEndpoints extends string> {
14
+ /**
15
+ * @param options Configuration options
16
+ * @param options.baseEndpointDev Base URL for development environment
17
+ * @param options.baseEndpoint Base URL for production environment (optional)
18
+ * @param options.log Enable request logging (default: false)
19
+ */
20
+ constructor(options: {
21
+ baseEndpointDev: string;
22
+ baseEndpoint?: string;
23
+ log?: boolean;
24
+ });
25
+
26
+ /**
27
+ * Make a request to the API
28
+ * @param path The path to the endpoint
29
+ * @param options Request options (method, body, headers, etc.)
30
+ * @returns The response from the API
31
+ */
32
+ public async request<TData>(
33
+ path: ApiEndpoints,
34
+ options?: RequestOptions
35
+ ): Promise<TData>;
36
+
37
+ /**
38
+ * Get the base endpoint URL based on environment
39
+ */
40
+ public get baseEndpoint(): string;
41
+ }
42
+
43
+ /**
44
+ * Request options type
45
+ */
46
+ type RequestOptions<TBody = any> = Omit<RequestInit, 'method' | 'body'> & {
47
+ method?: HttpMethods;
48
+ body?: TBody;
49
+ params?: Record<string, string | number | boolean>;
50
+ };
51
+
52
+ /**
53
+ * HTTP methods
54
+ */
55
+ type HttpMethods =
56
+ | 'GET'
57
+ | 'POST'
58
+ | 'PUT'
59
+ | 'PATCH'
60
+ | 'DELETE'
61
+ | 'HEAD'
62
+ | 'OPTIONS';
63
+ ```
64
+
65
+ ### ColorUtils
66
+
67
+ ```ts
68
+ /**
69
+ * RGB color as tuple
70
+ */
71
+ type RGB = [number, number, number];
72
+
73
+ /**
74
+ * Hex color string
75
+ */
76
+ type Hex = `#${string}`;
77
+
78
+ /**
79
+ * Color type identifier
80
+ */
81
+ type ColorType = 'hex' | 'rgb' | 'hsl';
82
+
83
+ /**
84
+ * Convert colors between different formats
85
+ * @param value Color value to convert
86
+ * @param fromOrTo Source format (for strings) or target format (for RGB)
87
+ * @param to Target format (when converting from string)
88
+ */
89
+ function convert(value: RGB, to: Exclude<ColorType, 'rgb'>): string;
90
+ function convert(value: string, from: Exclude<ColorType, 'rgb'>, to: 'rgb'): RGB;
91
+ function convert(value: string | RGB, fromOrTo: ColorType, to?: ColorType): string | RGB;
92
+
93
+ /**
94
+ * Generate a random hex color
95
+ * @returns Random hex color string
96
+ */
97
+ function generateRandomColor(): Hex;
98
+
99
+ /**
100
+ * Color utilities object
101
+ */
102
+ const ColorUtils = {
103
+ convert,
104
+ generateRandomColor
105
+ };
106
+ ```
107
+
108
+ ### FormUtils
109
+
110
+ ```ts
111
+ /**
112
+ * Serialize a form into an object
113
+ * @param form The form element to serialize
114
+ * @param log Whether to log the serialization process (default: false)
115
+ * @returns An object containing the form data
116
+ */
117
+ function serializeForm<T extends object>(form: HTMLFormElement, log?: boolean): T;
118
+ ```
119
+
120
+ ### NumberUtils
121
+
122
+ ```ts
123
+ /**
124
+ * Generate a random number between min and max (inclusive)
125
+ * @param min Minimum value
126
+ * @param max Maximum value
127
+ * @returns Random number between min and max
128
+ */
129
+ function between(min: number, max: number): number;
130
+
131
+ /**
132
+ * Select a random item from weighted items
133
+ * @param items Array of [item, weight] tuples where weight determines probability
134
+ * @returns Randomly selected item based on weights
135
+ * @throws Error if items array is empty or total weight is zero
136
+ */
137
+ function randomWithPercentages<T>(items: [item: T, weight: number][]): T;
138
+
139
+ /**
140
+ * Number utilities object
141
+ */
142
+ const NumberUtils = {
143
+ between,
144
+ randomWithPercentages,
145
+ };
146
+ ```
147
+
148
+ ### PatcherUtils
149
+
150
+ ```ts
151
+ /**
152
+ * Patch event type
153
+ */
154
+ type PatchEvent = 'before' | 'instead' | 'after';
155
+
156
+ /**
157
+ * Monkey patch a property or method on an object
158
+ * @param target Object to patch
159
+ * @param property Property or method name to patch
160
+ * @param event When to run the patch ('before', 'instead', or 'after')
161
+ * @param replacement Replacement function or value handler
162
+ * @returns Function to unpatch
163
+ */
164
+ function patch<
165
+ TTarget extends object,
166
+ TProperty extends keyof TTarget,
167
+ TPatchEvent extends PatchEvent,
168
+ TPatchReplacement extends PatcherReplacement<TTarget, TProperty, TPatchEvent>
169
+ >(
170
+ target: TTarget,
171
+ property: TProperty,
172
+ event: TPatchEvent,
173
+ replacement: TPatchReplacement
174
+ ): (() => void) | undefined;
175
+
176
+ /**
177
+ * Remove all patches from a specific property
178
+ * @param target Object with patches
179
+ * @param property Property to unpatch
180
+ */
181
+ function unpatch<TTarget extends object, TProperty extends keyof TTarget>(
182
+ target: TTarget,
183
+ property: TProperty
184
+ ): void;
185
+
186
+ /**
187
+ * Remove all patches from all objects
188
+ */
189
+ function unpatchAll(): void;
190
+ ```
191
+
192
+ ### StringUtils
193
+
194
+ ```ts
195
+ /**
196
+ * Combines class names from various input types
197
+ * Supports strings, objects (key-value where truthy values include the key),
198
+ * arrays, and nested structures
199
+ * @param args Class name arguments
200
+ * @returns Combined class name string
201
+ */
202
+ function classNames(...args: Array<any>): string;
203
+
204
+ /**
205
+ * Generate a random ID string
206
+ * @param length Length of the ID (default: 16)
207
+ * @returns Random alphanumeric string
208
+ */
209
+ function randomId(length?: number): string;
210
+
211
+ /**
212
+ * Pluralize a word based on count
213
+ * @param countable Number, array-like object, or Map to count
214
+ * @param singular Singular form of the word
215
+ * @param plural Optional custom plural form (default: adds 's' to singular)
216
+ * @returns Singular or plural form based on count
217
+ */
218
+ function pluralize(
219
+ countable: number | ArrayLike<any> | Map<any, any>,
220
+ singular: string,
221
+ plural?: string
222
+ ): string;
223
+ ```
224
+
225
+ ### TimeUtils
226
+
227
+ ```ts
228
+ /**
229
+ * Wait for a specified amount of time or execute a callback after a delay
230
+ * @param time Milliseconds to wait
231
+ */
232
+ function wait<T>(time: number): Promise<void>;
233
+ function wait<T>(callback: (...args: any[]) => T, time: number): Promise<T>;
234
+
235
+ /**
236
+ * Get Unix timestamp from various date formats
237
+ * @param date Date object or date string
238
+ */
239
+ function getUnixTime(date: Date | string): number;
240
+ function getUnixTime(timestamp: number): number;
241
+
242
+ /**
243
+ * Debounce a function call
244
+ * @param debounceId Unique identifier for this debounce
245
+ * @param callback Function to debounce
246
+ * @param delay Delay in milliseconds
247
+ * @param signal Optional AbortSignal to cancel the debounce
248
+ * @returns Promise that resolves with callback result or rejects if cancelled
249
+ */
250
+ function debounce<T>(
251
+ debounceId: string,
252
+ callback: () => T,
253
+ delay: number,
254
+ signal?: AbortSignal
255
+ ): Promise<T>;
256
+
257
+ /**
258
+ * Wrap a function in a debounce
259
+ * @param callback Function to wrap
260
+ * @param delay Delay in milliseconds
261
+ * @returns Debounced function
262
+ */
263
+ function wrapInDebounce<T>(
264
+ callback: (...args: T[]) => void,
265
+ delay: number
266
+ ): (...args: T[]) => void;
267
+
268
+ /**
269
+ * Throttle a function call
270
+ * @param throttleId Unique identifier for this throttle
271
+ * @param callback Function to throttle
272
+ * @param cooldown Cooldown period in milliseconds
273
+ * @returns Callback result or undefined if on cooldown
274
+ */
275
+ function throttle<T>(
276
+ throttleId: string,
277
+ callback: () => T,
278
+ cooldown: number
279
+ ): T | undefined;
280
+
281
+ /**
282
+ * Wrap a function in a throttle
283
+ * @param callback Function to wrap
284
+ * @param cooldown Cooldown period in milliseconds
285
+ * @returns Throttled function
286
+ */
287
+ function wrapInThrottle<T>(
288
+ callback: (...args: T[]) => void,
289
+ cooldown: number
290
+ ): (...args: T[]) => void;
291
+
292
+ /**
293
+ * Check if a throttle is currently on cooldown
294
+ * @param throttleId Throttle identifier to check
295
+ * @returns True if on cooldown, false otherwise
296
+ */
297
+ function isThrottleOnCooldown(throttleId: string): boolean;
298
+
299
+ /**
300
+ * Ensure a number is formatted with a leading zero if less than 10
301
+ * @param num Number to format
302
+ * @returns String with leading zero if needed
303
+ */
304
+ function ensureStartZero(num: number): string;
305
+
306
+ /**
307
+ * Convert 24-hour format to 12-hour format with am/pm
308
+ * @param hour Hour in 24-hour format (0-23)
309
+ * @returns Hour in 12-hour format with am/pm suffix
310
+ */
311
+ function get12HourFormat(hour: number): string;
312
+
313
+ /**
314
+ * Format hour in 24-hour format with leading zero
315
+ * @param hour Hour to format
316
+ * @returns Hour as two-digit string
317
+ */
318
+ function get24HourFormat(hour: number): string;
319
+
320
+ /**
321
+ * Time utilities object containing all time-related functions
322
+ */
323
+ const TimeUtils = {
324
+ wait,
325
+ getUnixTime,
326
+ debounce,
327
+ wrapInDebounce,
328
+ throttle,
329
+ wrapInThrottle,
330
+ isThrottleOnCooldown,
331
+ ensureStartZero,
332
+ get12HourFormat,
333
+ get24HourFormat
334
+ };
335
+ ```
package/docs/index.md CHANGED
@@ -24,6 +24,6 @@ import { ... } from 'DanhoLibraryJS';
24
24
 
25
25
  * [Classes](./Classes.md)
26
26
  * [Extensions](./Extensions.md)
27
- * [Functions](./Functions.md)
28
27
  * [Interfaces](./Interfaces.md)
29
28
  * [Types](./Types.md)
29
+ * [Utils](./Utils.md)
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "registry": "https://registry.npmjs.org/"
5
5
  },
6
- "version": "2.0.0",
6
+ "version": "2.0.2",
7
7
  "description": "Library for Javascript.",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",