danholibraryjs 1.11.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/Classes/DanhoLogger.d.ts +23 -0
- package/dist/Classes/DanhoLogger.js +65 -0
- package/dist/Classes/Events/Event.d.ts +66 -66
- package/dist/Classes/Events/Event.js +114 -114
- package/dist/Classes/Events/EventCollection.d.ts +57 -57
- package/dist/Classes/Events/EventCollection.js +109 -109
- package/dist/Classes/Events/EventEmitter.d.ts +74 -74
- package/dist/Classes/Events/EventEmitter.js +97 -97
- package/dist/Classes/Events/index.d.ts +3 -3
- package/dist/Classes/Events/index.js +19 -19
- package/dist/Classes/Time/Date.d.ts +148 -147
- package/dist/Classes/Time/Date.js +241 -238
- package/dist/Classes/Time/Time.d.ts +66 -65
- package/dist/Classes/Time/Time.js +120 -117
- package/dist/Classes/Time/TimeProperties.d.ts +3 -3
- package/dist/Classes/Time/TimeProperties.js +2 -2
- package/dist/Classes/Time/TimeSpan.d.ts +123 -123
- package/dist/Classes/Time/TimeSpan.js +179 -179
- package/dist/Classes/Time/index.d.ts +4 -4
- package/dist/Classes/Time/index.js +20 -20
- package/dist/Classes/index.d.ts +4 -3
- package/dist/Classes/index.js +20 -19
- package/dist/Classes/store.d.ts +75 -75
- package/dist/Classes/store.js +84 -84
- package/dist/Extensions/Array/array.extension.d.ts +42 -0
- package/dist/Extensions/Array/array.extension.js +57 -0
- package/dist/Extensions/Array/crud.extension.d.ts +24 -0
- package/dist/Extensions/Array/crud.extension.js +28 -0
- package/dist/Extensions/Array/index.d.ts +6 -0
- package/dist/Extensions/Array/index.js +22 -0
- package/dist/Extensions/Array/loop.extension.d.ts +18 -0
- package/dist/Extensions/Array/loop.extension.js +23 -0
- package/dist/Extensions/Array/random.extension.d.ts +23 -0
- package/dist/Extensions/Array/random.extension.js +35 -0
- package/dist/Extensions/Array/sort.extension.d.ts +27 -0
- package/dist/Extensions/Array/sort.extension.js +31 -0
- package/dist/Extensions/Array/string.extension.d.ts +13 -0
- package/dist/Extensions/Array/string.extension.js +14 -0
- package/dist/Extensions/Function.d.ts +29 -14
- package/dist/Extensions/Function.js +23 -10
- package/dist/Extensions/Map.d.ts +54 -54
- package/dist/Extensions/Map.js +42 -42
- package/dist/Extensions/Number.d.ts +13 -0
- package/dist/Extensions/Number.js +40 -0
- package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
- package/dist/Extensions/Object/arrays.extension.js +13 -0
- package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
- package/dist/Extensions/Object/booleans.extension.js +37 -0
- package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
- package/dist/Extensions/Object/extracts.extension.js +72 -0
- package/dist/Extensions/Object/index.d.ts +4 -49
- package/dist/Extensions/Object/index.js +20 -38
- package/dist/Extensions/Object/properties.d.ts +28 -28
- package/dist/Extensions/Object/properties.extension.d.ts +33 -0
- package/dist/Extensions/Object/properties.extension.js +21 -0
- package/dist/Extensions/Object/properties.js +20 -20
- package/dist/Extensions/String/case.extension.d.ts +12 -0
- package/dist/Extensions/String/case.extension.js +55 -0
- package/dist/Extensions/String/index.d.ts +1 -0
- package/dist/{Functions → Extensions/String}/index.js +17 -21
- package/dist/Extensions/index.d.ts +6 -17
- package/dist/Extensions/index.js +22 -30
- package/dist/Interfaces/ElementOptions.d.ts +15 -15
- package/dist/Interfaces/ElementOptions.js +2 -2
- package/dist/Interfaces/IReplacement.d.ts +12 -12
- package/dist/Interfaces/IReplacement.js +2 -2
- package/dist/Interfaces/index.d.ts +2 -2
- package/dist/Interfaces/index.js +18 -18
- package/dist/Types/Able.d.ts +16 -0
- package/dist/Types/Able.js +2 -0
- package/dist/Types/Array.d.ts +6 -0
- package/dist/Types/Array.js +2 -0
- package/dist/Types/BetterTypes.d.ts +9 -9
- package/dist/Types/BetterTypes.js +2 -2
- package/dist/Types/C#.d.ts +8 -0
- package/dist/Types/C#.js +2 -0
- package/dist/Types/Date.d.ts +6 -6
- package/dist/Types/Date.js +2 -2
- package/dist/Types/Events.d.ts +10 -10
- package/dist/Types/Events.js +2 -2
- package/dist/Types/Function.d.ts +5 -0
- package/dist/Types/Function.js +2 -0
- package/dist/Types/Object.d.ts +4 -0
- package/dist/Types/Object.js +2 -0
- package/dist/Types/PropertiesWith.d.ts +34 -13
- package/dist/Types/PropertiesWith.js +2 -2
- package/dist/Types/String.d.ts +1 -0
- package/dist/Types/String.js +2 -0
- package/dist/Types/TransformTypes.d.ts +22 -16
- package/dist/Types/TransformTypes.js +2 -2
- package/dist/Types/index.d.ts +24 -65
- package/dist/Types/index.js +27 -21
- package/dist/Utils/{ApiUtil → ApiUtils}/ApiTypes.d.ts +15 -15
- package/dist/Utils/{ApiUtil → ApiUtils}/ApiTypes.js +15 -15
- package/dist/Utils/{ApiUtil → ApiUtils}/RequestUtil.d.ts +19 -19
- package/dist/Utils/{ApiUtil → ApiUtils}/RequestUtil.js +73 -73
- package/dist/Utils/{ApiUtil → ApiUtils}/index.d.ts +20 -20
- package/dist/Utils/{ApiUtil → ApiUtils}/index.js +33 -33
- package/dist/Utils/ColorUtils.d.ts +11 -0
- package/dist/Utils/ColorUtils.js +93 -0
- package/dist/Utils/{FormUtil.d.ts → FormUtils.d.ts} +6 -6
- package/dist/Utils/{FormUtil.js → FormUtils.js} +35 -35
- package/dist/Utils/NumberUtils.d.ts +1 -0
- package/dist/Utils/NumberUtils.js +7 -0
- package/dist/Utils/PatcherUtils.d.ts +6 -0
- package/dist/Utils/PatcherUtils.js +80 -0
- package/dist/Utils/StringUtils.d.ts +3 -0
- package/dist/Utils/StringUtils.js +47 -0
- package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
- package/dist/Utils/TimeUtils/debounce.util.js +78 -0
- package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
- package/dist/Utils/TimeUtils/functions.util.js +21 -0
- package/dist/Utils/TimeUtils/index.d.ts +15 -0
- package/dist/Utils/TimeUtils/index.js +34 -0
- package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
- package/dist/Utils/TimeUtils/throttle.util.js +43 -0
- package/dist/Utils/index.d.ts +7 -2
- package/dist/Utils/index.js +23 -18
- package/dist/index.d.ts +4 -5
- package/dist/index.js +20 -21
- 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 +4 -2
- package/src/Classes/DanhoLogger.ts +78 -0
- package/src/Classes/Events/Event.ts +96 -96
- package/src/Classes/Events/EventCollection.ts +90 -90
- package/src/Classes/Events/EventEmitter.ts +68 -68
- package/src/Classes/Time/Date.ts +219 -216
- package/src/Classes/Time/Time.ts +109 -104
- package/src/Classes/Time/TimeSpan.ts +171 -171
- package/src/Classes/index.ts +1 -0
- package/src/Classes/store.ts +22 -22
- package/src/Extensions/Array/array.extension.ts +103 -0
- package/src/Extensions/Array/crud.extension.ts +46 -0
- package/src/Extensions/Array/index.ts +6 -0
- package/src/Extensions/Array/loop.extension.ts +38 -0
- package/src/Extensions/Array/random.extension.ts +56 -0
- package/src/Extensions/Array/sort.extension.ts +52 -0
- package/src/Extensions/Array/string.extension.ts +22 -0
- package/src/Extensions/Function.ts +37 -10
- package/src/Extensions/Map.ts +56 -56
- package/src/Extensions/Number.ts +50 -0
- package/src/Extensions/Object/arrays.extension.ts +27 -0
- package/src/Extensions/Object/booleans.extension.ts +46 -0
- package/src/Extensions/Object/extracts.extension.ts +102 -0
- package/src/Extensions/Object/index.ts +4 -82
- package/src/Extensions/Object/properties.extension.ts +59 -0
- package/src/Extensions/Object/properties.ts +36 -36
- package/src/Extensions/String/case.extension.ts +95 -0
- package/src/Extensions/String/index.ts +1 -0
- package/src/Extensions/index.ts +3 -21
- package/src/Interfaces/ElementOptions.ts +7 -7
- package/src/Interfaces/IReplacement.ts +2 -2
- package/src/Types/Able.ts +22 -0
- package/src/Types/Array.ts +7 -0
- package/src/Types/C#.ts +9 -0
- package/src/Types/Date.ts +1 -1
- package/src/Types/Events.ts +12 -12
- package/src/Types/Function.ts +10 -0
- package/src/Types/Object.ts +4 -0
- package/src/Types/PropertiesWith.ts +35 -4
- package/src/Types/String.ts +1 -0
- package/src/Types/TransformTypes.ts +21 -13
- package/src/Types/index.ts +7 -69
- package/src/Utils/{ApiUtil → ApiUtils}/ApiTypes.ts +2 -1
- package/src/Utils/{ApiUtil → ApiUtils}/index.ts +1 -1
- package/src/Utils/ColorUtils.ts +102 -0
- package/src/Utils/{FormUtil.ts → FormUtils.ts} +2 -2
- package/src/Utils/NumberUtils.ts +3 -0
- package/src/Utils/PatcherUtils.ts +111 -0
- package/src/Utils/StringUtils.ts +44 -0
- package/src/Utils/TimeUtils/debounce.util.ts +85 -0
- package/src/Utils/TimeUtils/functions.util.ts +18 -0
- package/src/Utils/TimeUtils/index.ts +9 -0
- package/src/Utils/TimeUtils/throttle.util.ts +44 -0
- package/src/Utils/index.ts +8 -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/docs/Functions.md +0 -61
- package/src/Extensions/Array.ts +0 -95
- package/src/Extensions/Document.ts +0 -58
- package/src/Extensions/String.ts +0 -54
- 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/src/Utils/{ApiUtil → ApiUtils}/RequestUtil.ts +0 -0
package/docs/Types.md
CHANGED
|
@@ -4,115 +4,244 @@
|
|
|
4
4
|
|
|
5
5
|
### General
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```ts
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Used for HTMLElement.append in ElementOptions, Document.createElement.
|
|
10
|
+
* IElement accepts HTML Elements or HTML-like strings.
|
|
10
11
|
*/
|
|
11
|
-
type
|
|
12
|
-
[key: string]: ReturnType
|
|
13
|
-
}
|
|
12
|
+
type IElement = HTMLElement | string;
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
15
|
+
* string or RegExp
|
|
17
16
|
*/
|
|
18
|
-
type
|
|
17
|
+
type StringRegex = string | RegExp;
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
* If
|
|
20
|
+
* Conditional type - If Boolean is true, returns True, otherwise False
|
|
22
21
|
*/
|
|
23
|
-
type If<
|
|
22
|
+
type If<Boolean extends boolean, True, False> = Boolean extends true ? True : False;
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
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
|
|
27
|
+
type ValueOf<T> = T[keyof T];
|
|
28
|
+
```
|
|
33
29
|
|
|
30
|
+
### Able
|
|
31
|
+
|
|
32
|
+
```ts
|
|
34
33
|
/**
|
|
35
|
-
*
|
|
34
|
+
* Value can be either T or a function that returns T
|
|
36
35
|
*/
|
|
37
|
-
type
|
|
36
|
+
type Functionable<T, Args extends any[] = []> = T | ((...args: Args) => T);
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
39
|
+
* Value can be either T or a Promise that resolves to T
|
|
41
40
|
*/
|
|
42
|
-
type
|
|
41
|
+
type Promisable<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
|
|
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
|
|
159
|
+
* Default event handler mapper. Object with properties that are arrays
|
|
63
160
|
*/
|
|
64
|
-
|
|
161
|
+
type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Types>;
|
|
65
162
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
###
|
|
173
|
+
### Function
|
|
79
174
|
|
|
80
175
|
```ts
|
|
81
176
|
/**
|
|
82
|
-
*
|
|
177
|
+
* Changes return type of a function
|
|
83
178
|
*/
|
|
84
|
-
type
|
|
85
|
-
|
|
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
|
-
*
|
|
183
|
+
* Wraps function return type in Promise
|
|
91
184
|
*/
|
|
92
|
-
type
|
|
93
|
-
|
|
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
|
-
###
|
|
194
|
+
### Object
|
|
98
195
|
|
|
99
196
|
```ts
|
|
100
197
|
/**
|
|
101
|
-
* Type
|
|
102
|
-
|
|
103
|
-
|
|
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
|
|
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
|
-
*
|
|
223
|
+
* Gets keys that appear in all types in the array
|
|
109
224
|
*/
|
|
110
|
-
type
|
|
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
|
-
*
|
|
233
|
+
* Filters types that have specific properties
|
|
114
234
|
*/
|
|
115
|
-
type
|
|
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
|
|
282
|
+
* Reducer function for Store state updates
|
|
140
283
|
*/
|
|
141
|
-
type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> =
|
|
284
|
+
type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> =
|
|
285
|
+
(state: State, ...args: Types[Action]) => State;
|
|
142
286
|
```
|
package/docs/index.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
type LogOptions = {
|
|
2
|
+
name?: string;
|
|
3
|
+
color?: string;
|
|
4
|
+
preferCollapsed?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default class DanhoLogger {
|
|
8
|
+
public name: string;
|
|
9
|
+
public color?: string
|
|
10
|
+
private _preferCollapsed: boolean;
|
|
11
|
+
|
|
12
|
+
constructor(options: LogOptions = {}) {
|
|
13
|
+
this.name = options.name || 'DanhoLogger';
|
|
14
|
+
this.color = options.color;
|
|
15
|
+
this._preferCollapsed = options.preferCollapsed ?? false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private _getPrefix() {
|
|
19
|
+
return {
|
|
20
|
+
prefix: `%c[${this.name}]`,
|
|
21
|
+
style: `color: ${this.color || 'inherit'}; font-weight: bold;`
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
private _log(
|
|
25
|
+
type: 'log' | 'warn' | 'error',
|
|
26
|
+
...args: any[]
|
|
27
|
+
) {
|
|
28
|
+
const { prefix, style } = this._getPrefix();
|
|
29
|
+
console[type](prefix, style, ...args);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public log(...args: any[]) {
|
|
34
|
+
return this._log('log', ...args);
|
|
35
|
+
}
|
|
36
|
+
public warn(...args: any[]) {
|
|
37
|
+
return this._log('warn', ...args);
|
|
38
|
+
}
|
|
39
|
+
public error(...args: any[]) {
|
|
40
|
+
return this._log('error', ...args);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public group(...args: any[]) {
|
|
44
|
+
const { prefix, style } = this._getPrefix();
|
|
45
|
+
|
|
46
|
+
const groupMethod = this._preferCollapsed ? console.groupCollapsed : console.group;
|
|
47
|
+
groupMethod(prefix, style, ...args);
|
|
48
|
+
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
public groupCollapsed(...args: any[]) {
|
|
52
|
+
const { prefix, style } = this._getPrefix();
|
|
53
|
+
console.groupCollapsed(prefix, style, ...args);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
public groupEnd(...args: any[]) {
|
|
57
|
+
if (args.length) console.log(...args);
|
|
58
|
+
console.groupEnd();
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
time(label: string) {
|
|
63
|
+
const { prefix } = this._getPrefix();
|
|
64
|
+
console.time(`${prefix} ${label}`);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
timeEnd(label: string) {
|
|
68
|
+
const { prefix } = this._getPrefix();
|
|
69
|
+
console.timeEnd(`${prefix} ${label}`);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
table(data: any, columns?: string[]) {
|
|
74
|
+
this.log();
|
|
75
|
+
console.table(data, columns);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -4,111 +4,111 @@ import { BaseEvent, EventHandler } from "../../Types/Events";
|
|
|
4
4
|
* Base event for @see EventEmitter, @borrows EventHandler @borrows BaseEvent
|
|
5
5
|
*/
|
|
6
6
|
export class Event<
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Events extends BaseEvent<string, Array<any>>,
|
|
8
|
+
Name extends keyof Events = keyof Events,
|
|
9
9
|
> {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Base event for @see EventEmitter, @borrows EventHandler
|
|
12
|
+
* @param name Name of event
|
|
13
|
+
* @param listeners Listeners/Handlers to execute when emitted
|
|
14
|
+
*/
|
|
15
|
+
constructor(name: Name, ...listeners: Array<EventHandler<Events, Name>>) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
this._listeners = listeners;
|
|
18
|
+
this._lastEmitted = new Date();
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
/**Name of event*/
|
|
22
|
+
public name: Name;
|
|
23
|
+
/**Listener limit - default: 0 */
|
|
24
|
+
public limit = 0;
|
|
25
|
+
/**Number of times event was emitted - default: 0*/
|
|
26
|
+
public get runs() {
|
|
27
|
+
return this._runs;
|
|
28
|
+
}
|
|
29
|
+
/**Timestamp of last emit - default: null*/
|
|
30
|
+
public get lastEmitted() {
|
|
31
|
+
return this._lastEmitted;
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
/**@private Internal listeners array*/
|
|
35
|
+
private _listeners: Array<EventHandler<Events, Name>>;
|
|
36
|
+
/**@private Internal runs*/
|
|
37
|
+
private _runs = 0;
|
|
38
|
+
/**@private Internal lastEmitted*/
|
|
39
|
+
private _lastEmitted: Date;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Emits event and returns array of responses
|
|
43
|
+
* @param args Arguments required for event listeners
|
|
44
|
+
* @returns Return values of listeners' returns
|
|
45
|
+
*/
|
|
46
|
+
public emit(...args: Events[Name]) {
|
|
47
|
+
this._runs++;
|
|
48
|
+
this._lastEmitted = new Date();
|
|
49
|
+
return this._listeners.map(listener => (listener as any)(...args));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Adds listener to listeners array and returns self with new listener added
|
|
53
|
+
* @param listener Listener to add
|
|
54
|
+
* @param prepend Add first (true) or last (false) - default: false
|
|
55
|
+
* @returns this with listener added
|
|
56
|
+
*
|
|
57
|
+
* @throws Limit error, if limit was reached
|
|
58
|
+
*/
|
|
59
|
+
public on(listener: EventHandler<Events, Name>, prepend = false) {
|
|
60
|
+
if (this.limit > 0 && this._listeners.length + 1 > this.limit) {
|
|
61
|
+
throw new Error(`Event limit, ${this.limit}, reached for event ${this.name.toString()}!`);
|
|
50
62
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Adds listener to listeners array and returns self with new listener added
|
|
53
|
-
* @param listener Listener to add
|
|
54
|
-
* @param prepend Add first (true) or last (false) - default: false
|
|
55
|
-
* @returns this with listener added
|
|
56
|
-
*
|
|
57
|
-
* @throws Limit error, if limit was reached
|
|
58
|
-
*/
|
|
59
|
-
public on(listener: EventHandler<Events, Name>, prepend = false) {
|
|
60
|
-
if (this.limit > 0 && this._listeners.length + 1 > this.limit) {
|
|
61
|
-
throw new Error(`Event limit, ${this.limit}, reached for event ${this.name.toString()}!`);
|
|
62
|
-
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (prepend) this._listeners = [listener, ...this._listeners];
|
|
65
|
+
else this._listeners.add(listener);
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Like Event#on, adds listener to listeners array and returns self with new listener added, however removes listener once emitted
|
|
71
|
+
* @param listener Listener to add
|
|
72
|
+
* @param prepend Add first (true) or last (false) - default: false
|
|
73
|
+
* @returns this with listener added
|
|
74
|
+
*
|
|
75
|
+
* @throws Limit error, if limit was reached
|
|
76
|
+
*/
|
|
77
|
+
public once(listener: EventHandler<Events, Name>, prepend = false) {
|
|
78
|
+
const handler = (...params: Events[Name]) => {
|
|
79
|
+
const result = (listener as any)(...params);
|
|
80
|
+
this.off(handler as any);
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
this.on(handler as any, prepend);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Returns true or false, depending if event includes listener
|
|
89
|
+
* @param listener Listener to test
|
|
90
|
+
* @returns True of false, depending if event includes listener
|
|
91
|
+
*/
|
|
92
|
+
public includes(listener: EventHandler<Events, Name>) {
|
|
93
|
+
return this._listeners.includes(listener);
|
|
94
|
+
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
catch (err) { if (throwNotFoundError) throw err; }
|
|
111
|
-
return this;
|
|
96
|
+
/**
|
|
97
|
+
* Removes listener from internal listeners array
|
|
98
|
+
* @param listener Listener to remove. If none specified, all will be removed
|
|
99
|
+
* @param throwNotFoundError Throw error if listener isn't in listeners array - default: false
|
|
100
|
+
* @returns this, without listener
|
|
101
|
+
*
|
|
102
|
+
* @throws NotFound, if throwNotFoundError is true, and internal listeners array doesn't include listener provided
|
|
103
|
+
*/
|
|
104
|
+
public off(listener?: EventHandler<Events, Name>, throwNotFoundError = false) {
|
|
105
|
+
try {
|
|
106
|
+
if (!listener) this._listeners = new Array<EventHandler<Events, Name>>();
|
|
107
|
+
else if (!this._listeners.includes(listener)) return this;
|
|
108
|
+
else this._listeners.remove(listener);
|
|
112
109
|
}
|
|
110
|
+
catch (err) { if (throwNotFoundError) throw err; }
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
113
|
}
|
|
114
114
|
export default Event;
|