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.
- package/README.md +0 -1
- package/_package.github-release.json +6 -0
- package/_package.npm-release.json +6 -0
- package/dist/Extensions/Array/index.d.ts +6 -20
- package/dist/Extensions/Array/index.js +8 -26
- package/dist/Extensions/Object/index.d.ts +4 -10
- package/dist/Extensions/Object/index.js +6 -22
- package/dist/Extensions/Object/properties.extension.d.ts +28 -1
- package/dist/Extensions/Object/properties.extension.js +19 -2
- package/dist/Extensions/Object/properties.js +2 -1
- package/dist/Extensions/String/index.d.ts +1 -4
- package/dist/Extensions/String/index.js +3 -16
- package/dist/Extensions/index.d.ts +2 -2
- package/dist/Extensions/index.js +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/docs/Classes.md +78 -3
- package/docs/Extensions.md +219 -78
- package/docs/Types.md +202 -58
- package/docs/index.md +0 -1
- package/package.json +1 -1
- package/src/Extensions/Array/index.ts +6 -15
- package/src/Extensions/Object/index.ts +4 -11
- package/src/Extensions/Object/properties.extension.ts +50 -2
- package/src/Extensions/Object/properties.ts +2 -1
- package/src/Extensions/String/index.ts +1 -5
- package/src/Extensions/index.ts +2 -2
- package/src/index.ts +0 -1
- package/dist/Extensions/Array.d.ts +0 -52
- package/dist/Extensions/Array.js +0 -51
- package/dist/Extensions/Document.d.ts +0 -27
- package/dist/Extensions/Document.js +0 -32
- package/dist/Extensions/String.d.ts +0 -36
- package/dist/Extensions/String.js +0 -25
- package/dist/Functions/CopyToClipboard.d.ts +0 -7
- package/dist/Functions/CopyToClipboard.js +0 -15
- package/dist/Functions/GetCSSProperty.d.ts +0 -15
- package/dist/Functions/GetCSSProperty.js +0 -26
- package/dist/Functions/GetNestedProperty.d.ts +0 -9
- package/dist/Functions/GetNestedProperty.js +0 -23
- package/dist/Functions/HTMLEvent.d.ts +0 -11
- package/dist/Functions/HTMLEvent.js +0 -14
- package/dist/Functions/SetNavigationSelected.d.ts +0 -9
- package/dist/Functions/SetNavigationSelected.js +0 -25
- package/dist/Functions/index.d.ts +0 -5
- package/dist/Functions/index.js +0 -21
- package/dist/Utils/ApiUtil/ApiTypes.d.ts +0 -15
- package/dist/Utils/ApiUtil/ApiTypes.js +0 -15
- package/dist/Utils/ApiUtil/RequestUtil.d.ts +0 -19
- package/dist/Utils/ApiUtil/RequestUtil.js +0 -73
- package/dist/Utils/ApiUtil/index.d.ts +0 -20
- package/dist/Utils/ApiUtil/index.js +0 -33
- package/dist/Utils/FormUtil.d.ts +0 -6
- package/dist/Utils/FormUtil.js +0 -35
- package/docs/Functions.md +0 -61
- package/src/Extensions/Document.ts +0 -58
- package/src/Functions/CopyToClipboard.ts +0 -10
- package/src/Functions/GetCSSProperty.ts +0 -27
- package/src/Functions/GetNestedProperty.ts +0 -29
- package/src/Functions/HTMLEvent.ts +0 -13
- package/src/Functions/SetNavigationSelected.ts +0 -19
- package/src/Functions/index.ts +0 -5
package/docs/Extensions.md
CHANGED
|
@@ -2,72 +2,144 @@
|
|
|
2
2
|
|
|
3
3
|
## Extensions
|
|
4
4
|
|
|
5
|
-
|
|
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
|
|
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):
|
|
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
|
|
58
|
-
* @param i Index of item
|
|
49
|
+
* Returns a new array with only unique elements
|
|
59
50
|
*/
|
|
60
|
-
|
|
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
|
-
*
|
|
63
|
-
* @param
|
|
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
|
-
|
|
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
|
|
81
|
-
* @param callback
|
|
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
|
-
*
|
|
86
|
-
* @param callback
|
|
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
|
-
*
|
|
99
|
-
* @param callback
|
|
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
|
-
*
|
|
104
|
-
* @param value Value
|
|
105
|
-
* @param fromIndex Start looking
|
|
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
|
-
###
|
|
189
|
+
### Number
|
|
112
190
|
|
|
113
191
|
```ts
|
|
114
|
-
interface
|
|
192
|
+
interface Number {
|
|
115
193
|
/**
|
|
116
|
-
*
|
|
117
|
-
* @param
|
|
194
|
+
* Formats number with thousand and decimal separators
|
|
195
|
+
* @param separators Custom separators for thousand and decimal
|
|
118
196
|
*/
|
|
119
|
-
|
|
197
|
+
toSeparationString(separators: Partial<{ thousand: string; decimal: string }>): string;
|
|
198
|
+
|
|
120
199
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @param from Object to destruct
|
|
200
|
+
* Converts number to Roman numeral (1-3999)
|
|
123
201
|
*/
|
|
124
|
-
|
|
202
|
+
toRomanNumeral(): string;
|
|
125
203
|
}
|
|
126
204
|
```
|
|
127
205
|
|
|
128
|
-
###
|
|
206
|
+
### Object
|
|
207
|
+
|
|
208
|
+
#### Static Methods
|
|
129
209
|
|
|
130
210
|
```ts
|
|
131
|
-
interface
|
|
132
|
-
/**
|
|
133
|
-
* Uppercases first letter of string
|
|
134
|
-
*/
|
|
135
|
-
toPascalCase(): string
|
|
211
|
+
interface ObjectConstructor {
|
|
136
212
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @param
|
|
213
|
+
* Converts object to array of [key, value] tuples
|
|
214
|
+
* @param from Object to convert
|
|
139
215
|
*/
|
|
140
|
-
|
|
216
|
+
array<From = {}>(from: From): Array<[keyof From, ValueOf<From>]>;
|
|
217
|
+
|
|
141
218
|
/**
|
|
142
|
-
*
|
|
143
|
-
* @param
|
|
219
|
+
* Returns array of object keys with proper typing
|
|
220
|
+
* @param from Object to get keys from
|
|
144
221
|
*/
|
|
145
|
-
|
|
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
|
-
*
|
|
148
|
-
* @param
|
|
149
|
-
* @param
|
|
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
|
-
|
|
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
|
+
```
|