danholibraryjs 2.0.0 → 2.0.1

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 (62) hide show
  1. package/README.md +0 -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/Object/index.d.ts +4 -10
  7. package/dist/Extensions/Object/index.js +6 -22
  8. package/dist/Extensions/Object/properties.extension.d.ts +28 -1
  9. package/dist/Extensions/Object/properties.extension.js +19 -2
  10. package/dist/Extensions/Object/properties.js +2 -1
  11. package/dist/Extensions/String/index.d.ts +1 -4
  12. package/dist/Extensions/String/index.js +3 -16
  13. package/dist/Extensions/index.d.ts +2 -2
  14. package/dist/Extensions/index.js +2 -2
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.js +0 -1
  17. package/docs/Classes.md +78 -3
  18. package/docs/Extensions.md +219 -78
  19. package/docs/Types.md +202 -58
  20. package/docs/index.md +0 -1
  21. package/package.json +1 -1
  22. package/src/Extensions/Array/index.ts +6 -15
  23. package/src/Extensions/Object/index.ts +4 -11
  24. package/src/Extensions/Object/properties.extension.ts +50 -2
  25. package/src/Extensions/Object/properties.ts +2 -1
  26. package/src/Extensions/String/index.ts +1 -5
  27. package/src/Extensions/index.ts +2 -2
  28. package/src/index.ts +0 -1
  29. package/dist/Extensions/Array.d.ts +0 -52
  30. package/dist/Extensions/Array.js +0 -51
  31. package/dist/Extensions/Document.d.ts +0 -27
  32. package/dist/Extensions/Document.js +0 -32
  33. package/dist/Extensions/String.d.ts +0 -36
  34. package/dist/Extensions/String.js +0 -25
  35. package/dist/Functions/CopyToClipboard.d.ts +0 -7
  36. package/dist/Functions/CopyToClipboard.js +0 -15
  37. package/dist/Functions/GetCSSProperty.d.ts +0 -15
  38. package/dist/Functions/GetCSSProperty.js +0 -26
  39. package/dist/Functions/GetNestedProperty.d.ts +0 -9
  40. package/dist/Functions/GetNestedProperty.js +0 -23
  41. package/dist/Functions/HTMLEvent.d.ts +0 -11
  42. package/dist/Functions/HTMLEvent.js +0 -14
  43. package/dist/Functions/SetNavigationSelected.d.ts +0 -9
  44. package/dist/Functions/SetNavigationSelected.js +0 -25
  45. package/dist/Functions/index.d.ts +0 -5
  46. package/dist/Functions/index.js +0 -21
  47. package/dist/Utils/ApiUtil/ApiTypes.d.ts +0 -15
  48. package/dist/Utils/ApiUtil/ApiTypes.js +0 -15
  49. package/dist/Utils/ApiUtil/RequestUtil.d.ts +0 -19
  50. package/dist/Utils/ApiUtil/RequestUtil.js +0 -73
  51. package/dist/Utils/ApiUtil/index.d.ts +0 -20
  52. package/dist/Utils/ApiUtil/index.js +0 -33
  53. package/dist/Utils/FormUtil.d.ts +0 -6
  54. package/dist/Utils/FormUtil.js +0 -35
  55. package/docs/Functions.md +0 -61
  56. package/src/Extensions/Document.ts +0 -58
  57. package/src/Functions/CopyToClipboard.ts +0 -10
  58. package/src/Functions/GetCSSProperty.ts +0 -27
  59. package/src/Functions/GetNestedProperty.ts +0 -29
  60. package/src/Functions/HTMLEvent.ts +0 -13
  61. package/src/Functions/SetNavigationSelected.ts +0 -19
  62. package/src/Functions/index.ts +0 -5
@@ -2,72 +2,144 @@
2
2
 
3
3
  ## Extensions
4
4
 
5
- ### General
6
-
7
- ```ts
8
- interface BooleanConstructor {
9
- /**
10
- * Parses string to boolean. Will only return true if value === "true" otherwise false
11
- */
12
- parseBoolean(value: string): boolean
13
- }
14
-
15
- interface Document {
16
- /**
17
- * Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
18
- * @param tagName HTMLElement tag name
19
- * @param options Construction options, instead of assigning values after construction
20
- */
21
- createProperElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementOptions): HTMLElementTagNameMap[K];
22
- }
23
-
24
- interface HTMLCollection {
25
- /**
26
- * Converts HTMLCollection to Element[]
27
- */
28
- array(): Element[];
29
- }
30
- ```
5
+ Extensions add new methods to native JavaScript types and interfaces.
31
6
 
32
7
  ### Array
33
8
 
9
+ #### Instance Methods
10
+
34
11
  ```ts
35
12
  interface Array<T> {
36
13
  /**
37
14
  * Pushes items to array and returns self with new items
38
15
  * @param items Items to add to array
39
16
  */
40
- add(...items: Array<T>): this
17
+ add(...items: Array<T>): this;
18
+
41
19
  /**
42
20
  * Update an item in array
43
- * @param old The old value or index to update
21
+ * @param old The old value, index, or finder function to locate item to update
44
22
  * @param updated Updated value
45
23
  */
46
- update(old: T | number, updated: T): T
24
+ update(old: T | number | ((item: T, index: number, self: Array<T>) => boolean), updated: T): T;
25
+
47
26
  /**
48
27
  * Removes item from array and returns self without item
49
28
  * @param item Item or index to remove
50
29
  */
51
- remove(item: T | number): this
30
+ remove(item: T | number): Array<T>;
31
+
52
32
  /**
53
33
  * Returns a random element from array
54
34
  */
55
- random(): T
35
+ random(): T;
36
+
37
+ /**
38
+ * Shuffles array in random order
39
+ */
40
+ shuffle(): Array<T>;
41
+
42
+ /**
43
+ * Returns the first `count` elements from the array
44
+ * @param count Number of elements to take
45
+ */
46
+ take(count: number): Array<T>;
47
+
56
48
  /**
57
- * Returns item matching index. If negative number, subtracts number from length
58
- * @param i Index of item
49
+ * Returns a new array with only unique elements
59
50
  */
60
- index(i: number): T
51
+ unique(): Array<T>;
52
+
53
+ /**
54
+ * Splits the array into chunks of a specified size or by a splitter function
55
+ * @param chunkSizeOrSplitter The size of each chunk or a function that determines where to split
56
+ */
57
+ splitBy(chunkSizeOrSplitter: number | ((value: T, index: number, array: Array<T>) => boolean)): Array<Array<T>>;
58
+
59
+ /**
60
+ * Groups elements based on a key selector function
61
+ * @param keySelector A function that selects a key for each element
62
+ */
63
+ groupBy<K>(keySelector: (value: T, index: number, array: Array<T>) => K): Map<K, Array<T>>;
64
+
65
+ /**
66
+ * For every nth element in array, execute callback
67
+ * @param every Execute callback every nth element
68
+ * @param callback Function to execute
69
+ */
70
+ nth<U>(every: number, callback: (collection: Array<T>, index: number, self: this) => U): Array<U>;
71
+
72
+ /**
73
+ * Joins array elements with a separator, and a different separator before the last element
74
+ * @param separator Separator between elements (default: ',')
75
+ * @param endSeparator Separator before last element (default: '&')
76
+ */
77
+ join(separator?: string, endSeparator?: string): string;
78
+
79
+ /**
80
+ * Orders array by comparators in ascending order
81
+ * @param comparators Comparison functions
82
+ */
83
+ orderBy(...comparators: Array<(a: T, b: T) => number>): Array<T>;
84
+
85
+ /**
86
+ * Orders array by comparators in descending order
87
+ * @param comparators Comparison functions
88
+ */
89
+ orderByDescending(...comparators: Array<(a: T, b: T) => number>): Array<T>;
90
+
91
+ /**
92
+ * Sorts array by object properties
93
+ * @param properties Properties to sort by
94
+ */
95
+ sortByProperty(...properties: Array<keyof T>): Array<T>;
96
+ }
97
+ ```
98
+
99
+ #### Static Methods
100
+
101
+ ```ts
102
+ interface ArrayConstructor {
61
103
  /**
62
- * For every number in array, do callback
63
- * @param every For every x in array
64
- * @param callback Do this for every x in array
65
- * @returns Mapped array
104
+ * Forces an arrayable object into an array
105
+ * @param arrayable The value or array to normalize
66
106
  */
67
- nth<U>(every: number, callback: (collection: Array<T>, index: number, self: this) => U): Array<U>
107
+ forceArray<T>(arrayable: T | Array<T>): Array<T>;
68
108
  }
69
109
  ```
70
110
 
111
+ #### Standalone Functions
112
+
113
+ ```ts
114
+ /**
115
+ * Selects random item from weighted items
116
+ * @param items Array of [item, weight] tuples where weight is probability
117
+ */
118
+ function randomWithPercentages<T>(items: [item: T, weight: number][]): T;
119
+ ```
120
+
121
+ ### Function
122
+
123
+ ```ts
124
+ /**
125
+ * Checks if a value is a function
126
+ */
127
+ function is(obj: any): obj is Function;
128
+
129
+ /**
130
+ * Resolves a functionable value (value or function that returns value)
131
+ * @param functionable Value or function
132
+ * @param args Arguments to pass if functionable is a function
133
+ */
134
+ function resolveFunctionable<T, TArgs extends any[] = any[]>(functionable: T | ((...args: TArgs) => T), ...args: TArgs): T;
135
+
136
+ /**
137
+ * Converts a functionable value into a function
138
+ * @param functionable Value or function
139
+ */
140
+ function forceFunction<T, TArgs extends any[] = any[]>(functionable: T | ((...args: TArgs) => T)): (...args: TArgs) => T;
141
+ ```
142
+
71
143
  ### Map
72
144
 
73
145
  ```ts
@@ -75,79 +147,148 @@ interface Map<K, V> {
75
147
  /**
76
148
  * Converts map into Array<[Key, Value]>
77
149
  */
78
- array(): Array<[K, V]>
150
+ array(): Array<[K, V]>;
151
+
79
152
  /**
80
- * Maps values into new types of generics
81
- * @param callback Callbacking function to map values
153
+ * Maps values into new types
154
+ * @param callback Mapping function
82
155
  */
83
- map<EK, EV>(callback: (value: V, key: K, index: number, self: this) => [EK, EV]): Map<EK, EV>
156
+ map<EK, EV>(callback: (value: V, key: K, index: number, self: this) => [EK, EV]): Map<EK, EV>;
157
+
84
158
  /**
85
- * Returns array of "accepted" values. Criteria defined in callback param
86
- * @param callback Callbacking function to filter away unwanted values
159
+ * Filters map entries
160
+ * @param callback Filter function
87
161
  */
88
- filter(callback: (value: V, key: K, index: number, self: this) => boolean): Map<K, V>
162
+ filter(callback: (value: V, key: K, index: number, self: this) => boolean): Map<K, V>;
163
+
89
164
  /**
90
165
  * Returns array of keys
91
166
  */
92
- keyArr(): Array<K>
167
+ keyArr(): Array<K>;
168
+
93
169
  /**
94
170
  * Returns array of values
95
171
  */
96
- valueArr(): Array<V>
172
+ valueArr(): Array<V>;
173
+
97
174
  /**
98
- * Returns first [key, value] match to callback param. Returns undefined if nothing found
99
- * @param callback Callbacking function to find KeyValuePair
175
+ * Finds first entry matching callback
176
+ * @param callback Find function
100
177
  */
101
- find(callback: (value: V, key: K, index: number, self: this) => boolean): [K, V] | undefined
178
+ find(callback: (value: V, key: K, index: number, self: this) => boolean): [K, V] | undefined;
179
+
102
180
  /**
103
- * Whether or not map includes a value (value version of Map#has)
104
- * @param value Value that may be includded in map
105
- * @param fromIndex Start looking for value from specific index+. Default: 0
181
+ * Checks if map includes a value
182
+ * @param value Value to search for
183
+ * @param fromIndex Start looking from specific index
106
184
  */
107
185
  includes(value: V, fromIndex?: number): boolean;
108
186
  }
109
187
  ```
110
188
 
111
- ### Object
189
+ ### Number
112
190
 
113
191
  ```ts
114
- interface ObjectConstructor {
192
+ interface Number {
115
193
  /**
116
- * Destructures object into array of [property, value]
117
- * @param from Object to destruct
194
+ * Formats number with thousand and decimal separators
195
+ * @param separators Custom separators for thousand and decimal
118
196
  */
119
- array<From = {}>(from: From): Array<keyof From, ValueOf<From>>
197
+ toSeparationString(separators: Partial<{ thousand: string; decimal: string }>): string;
198
+
120
199
  /**
121
- * Destructures object into array of property keys
122
- * @param from Object to destruct
200
+ * Converts number to Roman numeral (1-3999)
123
201
  */
124
- keysOf<From = {}>(from: From): Array<keyof From>
202
+ toRomanNumeral(): string;
125
203
  }
126
204
  ```
127
205
 
128
- ### String
206
+ ### Object
207
+
208
+ #### Static Methods
129
209
 
130
210
  ```ts
131
- interface String {
132
- /**
133
- * Uppercases first letter of string
134
- */
135
- toPascalCase(): string
211
+ interface ObjectConstructor {
136
212
  /**
137
- * Replaces "replacer" (default: ' ') with "replacement" (default: '_')
138
- * @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
213
+ * Converts object to array of [key, value] tuples
214
+ * @param from Object to convert
139
215
  */
140
- toSnakeCase(replaceOptions?: IReplacement): string
216
+ array<From = {}>(from: From): Array<[keyof From, ValueOf<From>]>;
217
+
141
218
  /**
142
- * Replaces "replacer" (default: ' ') with "replacement" (default: '-')
143
- * @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
219
+ * Returns array of object keys with proper typing
220
+ * @param from Object to get keys from
144
221
  */
145
- toKebabCase(replaceOptions?: IReplacement): string
222
+ keysOf<From = {}>(from: From): Array<keyof From>;
223
+ }
224
+ ```
225
+
226
+ #### Standalone Functions
227
+
228
+ ```ts
229
+ /**
230
+ * Creates new object omitting specified properties
231
+ * @param from Source object
232
+ * @param props Properties to omit
233
+ */
234
+ function omit<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props>;
235
+
236
+ /**
237
+ * Creates new object with only specified properties
238
+ * @param from Source object
239
+ * @param props Properties to pick
240
+ */
241
+ function pick<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>;
242
+
243
+ /**
244
+ * Returns the difference between two objects
245
+ * @param source Source object
246
+ * @param target Target object
247
+ * @param exclude Properties to exclude from comparison
248
+ */
249
+ function difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Partial<T>;
250
+
251
+ /**
252
+ * Deeply combines multiple objects
253
+ * @param objects Objects to combine
254
+ */
255
+ function combine<T extends Record<string, any | undefined>>(...objects: Array<T | undefined>): T;
256
+
257
+ /**
258
+ * Deep equality check for objects
259
+ * @param a First object
260
+ * @param b Second object
261
+ */
262
+ function areEqual<T extends object | null>(a?: T, b?: T): boolean;
263
+
264
+ /**
265
+ * Type guard for null or undefined
266
+ * @param obj Value to check
267
+ */
268
+ function isNullOrUndefined(obj: any): obj is null | undefined;
269
+ ```
270
+
271
+ ### String
272
+
273
+ ```ts
274
+ interface String {
146
275
  /**
147
- * String.substring but accepting negative numbers to cut from length
148
- * @param start Start of string. 0 indexed, if negative number, subtracts number from length
149
- * @param end End of string. 0 indexed, if negative number, substracts number from length
276
+ * Converts string from one case to another
277
+ * @param from Case to convert from ('camel' | 'pascal' | 'snake' | 'kebab' | 'lower' | 'upper')
278
+ * @param to Cases to convert to, can chain multiple conversions
150
279
  */
151
- clip(start: number, end?: number): string
280
+ convertCase(from: Case, ...to: Array<Case>): string;
152
281
  }
153
282
  ```
283
+
284
+ #### Standalone Function
285
+
286
+ ```ts
287
+ /**
288
+ * Converts a string's case
289
+ * @param value String to convert
290
+ * @param from Source case format
291
+ * @param to Target case format(s)
292
+ */
293
+ function convertCase(value: string, from: Case, ...to: Array<Case>): string;
294
+ ```