danholibraryjs 1.11.0 → 2.0.0

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 (204) hide show
  1. package/dist/Classes/DanhoLogger.d.ts +23 -0
  2. package/dist/Classes/DanhoLogger.js +65 -0
  3. package/dist/Classes/Events/Event.d.ts +66 -66
  4. package/dist/Classes/Events/Event.js +114 -114
  5. package/dist/Classes/Events/EventCollection.d.ts +57 -57
  6. package/dist/Classes/Events/EventCollection.js +109 -109
  7. package/dist/Classes/Events/EventEmitter.d.ts +74 -74
  8. package/dist/Classes/Events/EventEmitter.js +97 -97
  9. package/dist/Classes/Events/index.d.ts +3 -3
  10. package/dist/Classes/Events/index.js +19 -19
  11. package/dist/Classes/Time/Date.d.ts +148 -147
  12. package/dist/Classes/Time/Date.js +241 -238
  13. package/dist/Classes/Time/Time.d.ts +66 -65
  14. package/dist/Classes/Time/Time.js +120 -117
  15. package/dist/Classes/Time/TimeProperties.d.ts +3 -3
  16. package/dist/Classes/Time/TimeProperties.js +2 -2
  17. package/dist/Classes/Time/TimeSpan.d.ts +123 -123
  18. package/dist/Classes/Time/TimeSpan.js +179 -179
  19. package/dist/Classes/Time/index.d.ts +4 -4
  20. package/dist/Classes/Time/index.js +20 -20
  21. package/dist/Classes/index.d.ts +4 -3
  22. package/dist/Classes/index.js +20 -19
  23. package/dist/Classes/store.d.ts +75 -75
  24. package/dist/Classes/store.js +84 -84
  25. package/dist/Extensions/Array/array.extension.d.ts +42 -0
  26. package/dist/Extensions/Array/array.extension.js +57 -0
  27. package/dist/Extensions/Array/crud.extension.d.ts +24 -0
  28. package/dist/Extensions/Array/crud.extension.js +28 -0
  29. package/dist/Extensions/Array/index.d.ts +20 -0
  30. package/dist/Extensions/Array/index.js +40 -0
  31. package/dist/Extensions/Array/loop.extension.d.ts +18 -0
  32. package/dist/Extensions/Array/loop.extension.js +23 -0
  33. package/dist/Extensions/Array/random.extension.d.ts +23 -0
  34. package/dist/Extensions/Array/random.extension.js +35 -0
  35. package/dist/Extensions/Array/sort.extension.d.ts +27 -0
  36. package/dist/Extensions/Array/sort.extension.js +31 -0
  37. package/dist/Extensions/Array/string.extension.d.ts +13 -0
  38. package/dist/Extensions/Array/string.extension.js +14 -0
  39. package/dist/Extensions/Array.d.ts +52 -52
  40. package/dist/Extensions/Array.js +51 -51
  41. package/dist/Extensions/Document.d.ts +27 -27
  42. package/dist/Extensions/Document.js +32 -32
  43. package/dist/Extensions/Function.d.ts +29 -14
  44. package/dist/Extensions/Function.js +23 -10
  45. package/dist/Extensions/Map.d.ts +54 -54
  46. package/dist/Extensions/Map.js +42 -42
  47. package/dist/Extensions/Number.d.ts +13 -0
  48. package/dist/Extensions/Number.js +40 -0
  49. package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
  50. package/dist/Extensions/Object/arrays.extension.js +13 -0
  51. package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
  52. package/dist/Extensions/Object/booleans.extension.js +37 -0
  53. package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
  54. package/dist/Extensions/Object/extracts.extension.js +72 -0
  55. package/dist/Extensions/Object/index.d.ts +10 -49
  56. package/dist/Extensions/Object/index.js +36 -38
  57. package/dist/Extensions/Object/properties.d.ts +28 -28
  58. package/dist/Extensions/Object/properties.extension.d.ts +6 -0
  59. package/dist/Extensions/Object/properties.extension.js +4 -0
  60. package/dist/Extensions/Object/properties.js +19 -20
  61. package/dist/Extensions/String/case.extension.d.ts +12 -0
  62. package/dist/Extensions/String/case.extension.js +55 -0
  63. package/dist/Extensions/String/index.d.ts +4 -0
  64. package/dist/Extensions/String/index.js +30 -0
  65. package/dist/Extensions/String.d.ts +36 -36
  66. package/dist/Extensions/String.js +25 -25
  67. package/dist/Extensions/index.d.ts +6 -17
  68. package/dist/Extensions/index.js +22 -30
  69. package/dist/Functions/CopyToClipboard.d.ts +7 -7
  70. package/dist/Functions/CopyToClipboard.js +15 -15
  71. package/dist/Functions/GetCSSProperty.d.ts +15 -15
  72. package/dist/Functions/GetCSSProperty.js +26 -26
  73. package/dist/Functions/GetNestedProperty.d.ts +9 -9
  74. package/dist/Functions/GetNestedProperty.js +23 -23
  75. package/dist/Functions/HTMLEvent.d.ts +11 -11
  76. package/dist/Functions/HTMLEvent.js +14 -14
  77. package/dist/Functions/SetNavigationSelected.d.ts +9 -9
  78. package/dist/Functions/SetNavigationSelected.js +25 -25
  79. package/dist/Functions/index.d.ts +5 -5
  80. package/dist/Functions/index.js +21 -21
  81. package/dist/Interfaces/ElementOptions.d.ts +15 -15
  82. package/dist/Interfaces/ElementOptions.js +2 -2
  83. package/dist/Interfaces/IReplacement.d.ts +12 -12
  84. package/dist/Interfaces/IReplacement.js +2 -2
  85. package/dist/Interfaces/index.d.ts +2 -2
  86. package/dist/Interfaces/index.js +18 -18
  87. package/dist/Types/Able.d.ts +16 -0
  88. package/dist/Types/Able.js +2 -0
  89. package/dist/Types/Array.d.ts +6 -0
  90. package/dist/Types/Array.js +2 -0
  91. package/dist/Types/BetterTypes.d.ts +9 -9
  92. package/dist/Types/BetterTypes.js +2 -2
  93. package/dist/Types/C#.d.ts +8 -0
  94. package/dist/Types/C#.js +2 -0
  95. package/dist/Types/Date.d.ts +6 -6
  96. package/dist/Types/Date.js +2 -2
  97. package/dist/Types/Events.d.ts +10 -10
  98. package/dist/Types/Events.js +2 -2
  99. package/dist/Types/Function.d.ts +5 -0
  100. package/dist/Types/Function.js +2 -0
  101. package/dist/Types/Object.d.ts +4 -0
  102. package/dist/Types/Object.js +2 -0
  103. package/dist/Types/PropertiesWith.d.ts +34 -13
  104. package/dist/Types/PropertiesWith.js +2 -2
  105. package/dist/Types/String.d.ts +1 -0
  106. package/dist/Types/String.js +2 -0
  107. package/dist/Types/TransformTypes.d.ts +22 -16
  108. package/dist/Types/TransformTypes.js +2 -2
  109. package/dist/Types/index.d.ts +24 -65
  110. package/dist/Types/index.js +27 -21
  111. package/dist/Utils/ApiUtil/ApiTypes.d.ts +15 -15
  112. package/dist/Utils/ApiUtil/ApiTypes.js +15 -15
  113. package/dist/Utils/ApiUtil/RequestUtil.d.ts +19 -19
  114. package/dist/Utils/ApiUtil/RequestUtil.js +73 -73
  115. package/dist/Utils/ApiUtil/index.d.ts +20 -20
  116. package/dist/Utils/ApiUtil/index.js +33 -33
  117. package/dist/Utils/ApiUtils/ApiTypes.d.ts +15 -0
  118. package/dist/Utils/ApiUtils/ApiTypes.js +15 -0
  119. package/dist/Utils/ApiUtils/RequestUtil.d.ts +19 -0
  120. package/dist/Utils/ApiUtils/RequestUtil.js +73 -0
  121. package/dist/Utils/ApiUtils/index.d.ts +20 -0
  122. package/dist/Utils/ApiUtils/index.js +33 -0
  123. package/dist/Utils/ColorUtils.d.ts +11 -0
  124. package/dist/Utils/ColorUtils.js +93 -0
  125. package/dist/Utils/FormUtil.d.ts +6 -6
  126. package/dist/Utils/FormUtil.js +35 -35
  127. package/dist/Utils/FormUtils.d.ts +6 -0
  128. package/dist/Utils/FormUtils.js +35 -0
  129. package/dist/Utils/NumberUtils.d.ts +1 -0
  130. package/dist/Utils/NumberUtils.js +7 -0
  131. package/dist/Utils/PatcherUtils.d.ts +6 -0
  132. package/dist/Utils/PatcherUtils.js +80 -0
  133. package/dist/Utils/StringUtils.d.ts +3 -0
  134. package/dist/Utils/StringUtils.js +47 -0
  135. package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
  136. package/dist/Utils/TimeUtils/debounce.util.js +78 -0
  137. package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
  138. package/dist/Utils/TimeUtils/functions.util.js +21 -0
  139. package/dist/Utils/TimeUtils/index.d.ts +15 -0
  140. package/dist/Utils/TimeUtils/index.js +34 -0
  141. package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
  142. package/dist/Utils/TimeUtils/throttle.util.js +43 -0
  143. package/dist/Utils/index.d.ts +7 -2
  144. package/dist/Utils/index.js +23 -18
  145. package/dist/index.d.ts +5 -5
  146. package/dist/index.js +21 -21
  147. package/package.json +4 -2
  148. package/src/Classes/DanhoLogger.ts +78 -0
  149. package/src/Classes/Events/Event.ts +96 -96
  150. package/src/Classes/Events/EventCollection.ts +90 -90
  151. package/src/Classes/Events/EventEmitter.ts +68 -68
  152. package/src/Classes/Time/Date.ts +219 -216
  153. package/src/Classes/Time/Time.ts +109 -104
  154. package/src/Classes/Time/TimeSpan.ts +171 -171
  155. package/src/Classes/index.ts +1 -0
  156. package/src/Classes/store.ts +22 -22
  157. package/src/Extensions/Array/array.extension.ts +103 -0
  158. package/src/Extensions/Array/crud.extension.ts +46 -0
  159. package/src/Extensions/Array/index.ts +15 -0
  160. package/src/Extensions/Array/loop.extension.ts +38 -0
  161. package/src/Extensions/Array/random.extension.ts +56 -0
  162. package/src/Extensions/Array/sort.extension.ts +52 -0
  163. package/src/Extensions/Array/string.extension.ts +22 -0
  164. package/src/Extensions/Document.ts +39 -39
  165. package/src/Extensions/Function.ts +37 -10
  166. package/src/Extensions/Map.ts +56 -56
  167. package/src/Extensions/Number.ts +50 -0
  168. package/src/Extensions/Object/arrays.extension.ts +27 -0
  169. package/src/Extensions/Object/booleans.extension.ts +46 -0
  170. package/src/Extensions/Object/extracts.extension.ts +102 -0
  171. package/src/Extensions/Object/index.ts +9 -80
  172. package/src/Extensions/Object/properties.extension.ts +11 -0
  173. package/src/Extensions/Object/properties.ts +35 -36
  174. package/src/Extensions/String/case.extension.ts +95 -0
  175. package/src/Extensions/String/index.ts +5 -0
  176. package/src/Extensions/index.ts +2 -20
  177. package/src/Interfaces/ElementOptions.ts +7 -7
  178. package/src/Interfaces/IReplacement.ts +2 -2
  179. package/src/Types/Able.ts +22 -0
  180. package/src/Types/Array.ts +7 -0
  181. package/src/Types/C#.ts +9 -0
  182. package/src/Types/Date.ts +1 -1
  183. package/src/Types/Events.ts +12 -12
  184. package/src/Types/Function.ts +10 -0
  185. package/src/Types/Object.ts +4 -0
  186. package/src/Types/PropertiesWith.ts +35 -4
  187. package/src/Types/String.ts +1 -0
  188. package/src/Types/TransformTypes.ts +21 -13
  189. package/src/Types/index.ts +7 -69
  190. package/src/Utils/{ApiUtil → ApiUtils}/ApiTypes.ts +2 -1
  191. package/src/Utils/{ApiUtil → ApiUtils}/index.ts +1 -1
  192. package/src/Utils/ColorUtils.ts +102 -0
  193. package/src/Utils/{FormUtil.ts → FormUtils.ts} +2 -2
  194. package/src/Utils/NumberUtils.ts +3 -0
  195. package/src/Utils/PatcherUtils.ts +111 -0
  196. package/src/Utils/StringUtils.ts +44 -0
  197. package/src/Utils/TimeUtils/debounce.util.ts +85 -0
  198. package/src/Utils/TimeUtils/functions.util.ts +18 -0
  199. package/src/Utils/TimeUtils/index.ts +9 -0
  200. package/src/Utils/TimeUtils/throttle.util.ts +44 -0
  201. package/src/Utils/index.ts +8 -2
  202. package/src/Extensions/Array.ts +0 -95
  203. package/src/Extensions/String.ts +0 -54
  204. /package/src/Utils/{ApiUtil → ApiUtils}/RequestUtil.ts +0 -0
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Item is single or multiple
3
+ */
4
+ export type Arrayable<T> = T | Array<T>;
5
+ export type SingleArrayable<T> = T | [T];
6
+ export type TFromArray<T> = T extends Array<infer U> ? U : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,9 @@
1
- /**
2
- * Construct a type with the properties of Type except for those in type Properties.
3
- */
4
- export type BetterOmit<Type, Properties extends keyof Type> = Omit<Type, Properties>;
5
- /**
6
- * Extract from From those types that are assignable to Properties
7
- */
8
- export type BetterExtract<From, Properties extends From> = Extract<From, Properties>;
9
- export type PartialExcept<From, Properties extends keyof From> = Partial<From> & Required<Pick<From, Properties>>;
1
+ /**
2
+ * Construct a type with the properties of Type except for those in type Properties.
3
+ */
4
+ export type BetterOmit<Type, Properties extends keyof Type> = Omit<Type, Properties>;
5
+ /**
6
+ * Extract from From those types that are assignable to Properties
7
+ */
8
+ export type BetterExtract<From, Properties extends From> = Extract<From, Properties>;
9
+ export type PartialExcept<From, Properties extends keyof From> = Partial<From> & Required<Pick<From, Properties>>;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * C# Guid representation
3
+ */
4
+ export type Guid = string;
5
+ /**
6
+ * C# TimeSpan representation from JSON
7
+ */
8
+ export type TimeSpanType = string;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
- export type LongMonth = 'Janurary' | 'February' | 'March' | 'April' | 'May' | 'June' | 'July' | 'August' | 'September' | 'October' | 'November' | 'December';
2
- export type ShortMonth = 'Jan' | 'Feb' | 'Mar' | 'Apr' | 'May' | 'Jun' | 'Jul' | 'Aug' | 'Sep' | 'Oct' | 'Nov' | 'Dec';
3
- export type Month = LongMonth | ShortMonth;
4
- export type ShortDay = 'Mon' | 'Tue' | 'Wed' | 'Thu' | 'Fri' | 'Sat' | 'Sun';
5
- export type LongDay = `${'Mon' | 'Tues' | 'Wednes' | 'Thurs' | 'Fri' | 'Satur' | 'Sun'}day`;
6
- export type Day = ShortDay | LongDay;
1
+ export type LongMonth = 'January' | 'February' | 'March' | 'April' | 'May' | 'June' | 'July' | 'August' | 'September' | 'October' | 'November' | 'December';
2
+ export type ShortMonth = 'Jan' | 'Feb' | 'Mar' | 'Apr' | 'May' | 'Jun' | 'Jul' | 'Aug' | 'Sep' | 'Oct' | 'Nov' | 'Dec';
3
+ export type Month = LongMonth | ShortMonth;
4
+ export type ShortDay = 'Mon' | 'Tue' | 'Wed' | 'Thu' | 'Fri' | 'Sat' | 'Sun';
5
+ export type LongDay = `${'Mon' | 'Tues' | 'Wednes' | 'Thurs' | 'Fri' | 'Satur' | 'Sun'}day`;
6
+ export type Day = ShortDay | LongDay;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +1,10 @@
1
- /**
2
- * Default eventhandler mapper. Object with properties that are arrays
3
- */
4
- export type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Types>;
5
- /**
6
- * Eventhandler type for:
7
- * @see EventCollection
8
- * @borrows BaseEvent
9
- */
10
- export type EventHandler<Events extends BaseEvent<string, Array<any>> = BaseEvent<string, Array<any>>, Event extends keyof Events = keyof Events, ReturnType = any> = (...args: Events[Event]) => ReturnType;
1
+ /**
2
+ * Default event-handler mapper. Object with properties that are arrays
3
+ */
4
+ export type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Types>;
5
+ /**
6
+ * Event-handler type for:
7
+ * @see EventCollection
8
+ * @borrows BaseEvent
9
+ */
10
+ export type EventHandler<Events extends BaseEvent<string, Array<any>> = BaseEvent<string, Array<any>>, Event extends keyof Events = keyof Events, ReturnType = any> = (...args: Events[Event]) => ReturnType;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export type NewReturnType<Function extends (...args: any[]) => any, NewReturnType extends any> = (...args: Parameters<Function>) => NewReturnType;
2
+ export type PromisedReturn<Function extends (...args: any[]) => any> = NewReturnType<Function, Promise<ReturnType<Function>>>;
3
+ export type NoFunctions<T> = {
4
+ [K in keyof T]: T[K] extends Function ? never : T[K];
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Return types of T
3
+ */
4
+ export type ValueOf<T> = T[keyof T];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,13 +1,34 @@
1
- /**
2
- * Filters all properties from From that has the return type of Type
3
- */
4
- export type PropertiesWith<Type, From> = {
5
- [Key in keyof From as From[Key] extends Type ? Key : never]: From[Key];
6
- };
7
- export default PropertiesWith;
8
- /**
9
- * Fitlers all properties from From that don't have the return type of Type
10
- */
11
- export type PropertiesWithout<Type, From> = {
12
- [Key in keyof From as From[Key] extends Type ? never : Key]: From[Key];
13
- };
1
+ /**
2
+ * Filters all properties from From that has the return type of Type
3
+ */
4
+ export type PropertiesWith<Type, From> = {
5
+ [Key in keyof From as From[Key] extends Type ? Key : never]: From[Key];
6
+ };
7
+ export default PropertiesWith;
8
+ /**
9
+ * Fitlers all properties from From that don't have the return type of Type
10
+ */
11
+ export type PropertiesWithout<Type, From> = {
12
+ [Key in keyof From as From[Key] extends Type ? never : Key]: From[Key];
13
+ };
14
+ /**
15
+ * GetRepeatedKeys<[
16
+ * { username: string, password: string },
17
+ * { username: number, email: string },
18
+ * ]> // { username: string | number }
19
+ */
20
+ export type GetRepeatedKeys<Types extends Array<any>> = (Types extends [infer First, infer Second, ...infer Rest] ? First extends object ? Second extends object ? {
21
+ [Key in Extract<keyof First, keyof Second>]: First[Key] | Second[Key];
22
+ } & GetRepeatedKeys<Rest> : {} : {} : {});
23
+ /**
24
+ * Situation: Model = Character | Artifact | Domain
25
+ * Type must include generic type T, which is the Model type
26
+ * Type must also include generic type TProps, which is the properties of the Model type. Selected properties of TProps must extract the types of Model whose properties has been selected.
27
+ *
28
+ * Example:
29
+ * type Model = Character | Artifact | Domain
30
+ * Properties<Model, 'name' | 'rarity'>
31
+ *
32
+ * Result: Character | Artifact, because only Character and Artifact have 'name' and 'rarity' properties
33
+ */
34
+ export type ModelWithProps<T, TProps extends (keyof T | string)> = T extends Record<TProps, any> ? T : never;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type Autocomplete<T> = T | (string & {});
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +1,22 @@
1
- /**
2
- * Converts Start types to Switch types in From type
3
- */
4
- export type TransformType<From, Start, Switch> = {
5
- [Key in keyof From]: From[Key] extends Start ? Switch : From[Key];
6
- };
7
- /**
8
- * Returns object with properties matching BaseType with types of NewType
9
- */
10
- export type TransformTypes<From, BaseType, NewType> = Record<keyof {
11
- [Key in keyof From as From[Key] extends BaseType ? Key : never]: Key;
12
- }, NewType>;
13
- export type Json<T> = {
14
- [Key in keyof T]: T[Key] extends object ? Json<T[Key]> : T[Key] extends Array<infer U> ? Array<Json<U>> : T[Key] extends number | string | boolean | null ? T[Key] : string;
15
- };
16
- export default TransformTypes;
1
+ /**
2
+ * Converts Start types to Switch types in From type
3
+ */
4
+ export type TransformType<From, Start, Switch> = {
5
+ [Key in keyof From]: From[Key] extends Start ? Switch : From[Key];
6
+ };
7
+ /**
8
+ * Returns object with properties matching BaseType with types of NewType
9
+ */
10
+ export type TransformTypes<From, BaseType, NewType> = Record<keyof {
11
+ [Key in keyof From as From[Key] extends BaseType ? Key : never]: Key;
12
+ }, NewType>;
13
+ export type Json<T> = {
14
+ [Key in keyof T]: T[Key] extends object ? Json<T[Key]> : T[Key] extends Array<infer U> ? Array<Json<U>> : T[Key] extends number | string | boolean | null ? T[Key] : string;
15
+ };
16
+ /**
17
+ * Type's properties are ReturnType
18
+ */
19
+ export type AllPropsAre<ReturnType> = {
20
+ [key: string]: ReturnType;
21
+ };
22
+ export default TransformTypes;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,65 +1,24 @@
1
- export * from './BetterTypes';
2
- export * from './Date';
3
- export * from './Events';
4
- export * from './TransformTypes';
5
- export * from './PropertiesWith';
6
- /**
7
- * Item is single or multiple
8
- */
9
- export type Arrayable<T> = T | Array<T>;
10
- /**
11
- * Item is function or T
12
- */
13
- export type Functionable<T> = T | (() => T);
14
- /**
15
- * Item is Promise<T> or T
16
- */
17
- export type Promisable<T> = T | Promise<T>;
18
- /**
19
- * Item is T or null
20
- */
21
- export type Nullable<T> = T | null;
22
- /**
23
- * Item cannot be null or undefined
24
- */
25
- export type NonNullable<T> = T extends null ? never : T extends undefined ? never : T;
26
- /**
27
- * C# Guid representation
28
- */
29
- export type Guid = string;
30
- /**
31
- * C# TimeSpan representation from JSON
32
- */
33
- export type TimeSpanType = string;
34
- /**
35
- * Used for HTMLElement.append in ElementOptions, Document.createProperElement.
36
- * IElement accepts HTML Elements or HTMl-like strings.
37
- *
38
- * @see HTMLElement.append
39
- * @see Document.createElement
40
- */
41
- export type IElement = HTMLElement | string;
42
- /**
43
- * Return types of T
44
- */
45
- export type ValueOf<T> = T[keyof T];
46
- /**
47
- * Type's properties are ReturnType
48
- */
49
- export type AllPropsAre<ReturnType> = {
50
- [key: string]: ReturnType;
51
- };
52
- /**
53
- * string or RegExp.. pretty self-explanatory
54
- */
55
- export type StringRegex = string | RegExp;
56
- export type If<Boolean extends boolean, True, False> = Boolean extends true ? True : False;
57
- /**
58
- * GetRepeatedKeys<[
59
- * { username: string, password: string },
60
- * { username: number, email: string },
61
- * ]> // { username: string | number }
62
- */
63
- export type GetRepeatedKeys<Types extends Array<any>> = (Types extends [infer First, infer Second, ...infer Rest] ? First extends object ? Second extends object ? {
64
- [Key in Extract<keyof First, keyof Second>]: First[Key] | Second[Key];
65
- } & GetRepeatedKeys<Rest> : {} : {} : {});
1
+ export * from './Able';
2
+ export * from './Array';
3
+ export * from './BetterTypes';
4
+ export * from './C#';
5
+ export * from './Date';
6
+ export * from './Events';
7
+ export * from './Function';
8
+ export * from './TransformTypes';
9
+ export * from './Object';
10
+ export * from './PropertiesWith';
11
+ export * from './String';
12
+ /**
13
+ * Used for HTMLElement.append in ElementOptions, Document.createProperElement.
14
+ * IElement accepts HTML Elements or HTMl-like strings.
15
+ *
16
+ * @see HTMLElement.append
17
+ * @see Document.createElement
18
+ */
19
+ export type IElement = HTMLElement | string;
20
+ /**
21
+ * string or RegExp.. pretty self-explanatory
22
+ */
23
+ export type StringRegex = string | RegExp;
24
+ export type If<Boolean extends boolean, True, False> = Boolean extends true ? True : False;
@@ -1,21 +1,27 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./BetterTypes"), exports);
18
- __exportStar(require("./Date"), exports);
19
- __exportStar(require("./Events"), exports);
20
- __exportStar(require("./TransformTypes"), exports);
21
- __exportStar(require("./PropertiesWith"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Able"), exports);
18
+ __exportStar(require("./Array"), exports);
19
+ __exportStar(require("./BetterTypes"), exports);
20
+ __exportStar(require("./C#"), exports);
21
+ __exportStar(require("./Date"), exports);
22
+ __exportStar(require("./Events"), exports);
23
+ __exportStar(require("./Function"), exports);
24
+ __exportStar(require("./TransformTypes"), exports);
25
+ __exportStar(require("./Object"), exports);
26
+ __exportStar(require("./PropertiesWith"), exports);
27
+ __exportStar(require("./String"), exports);
@@ -1,15 +1,15 @@
1
- export type TParam = string | undefined;
2
- export type HttpMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
3
- export type RequestOptions<TBody = any> = Omit<RequestInit, 'method' | 'body'> & {
4
- method?: HttpMethods;
5
- body?: TBody;
6
- noHeaders?: boolean;
7
- controller?: AbortController;
8
- query?: Record<string, string | undefined>;
9
- baseEndpoint?: string;
10
- };
11
- export type ApiUtilOptions = {
12
- baseEndpointDev: string;
13
- baseEndpoint?: string;
14
- log?: boolean;
15
- };
1
+ export type TParam = string | undefined;
2
+ export type HttpMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
3
+ export type RequestOptions<TBody = any> = Omit<RequestInit, 'method' | 'body'> & {
4
+ method?: HttpMethods;
5
+ body?: TBody;
6
+ noHeaders?: boolean;
7
+ controller?: AbortController;
8
+ query?: Record<string, string | undefined>;
9
+ baseEndpoint?: string;
10
+ };
11
+ export type ApiUtilOptions = {
12
+ baseEndpointDev: string;
13
+ baseEndpoint?: string;
14
+ log?: boolean;
15
+ };
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // All possible endpoints for the API. This will generate autocomplete when using the Request function
4
- // The commented code below is an example from my previous "CitizenTaxi" project to illustrate how this works
5
- // export type ApiEndpoints<Param extends TParam = undefined> =
6
- // | `bookings` // [GET, POST]
7
- // | `bookings?citizenId=${Param}` // [GET] Guid
8
- // | `bookings/${Param}` // [GET, PUT, DELETE] Guid bookingId
9
- // | `notes` // [GET, POST]
10
- // | `notes?citizenId=${Param}` // [GET] Guid
11
- // | `notes/${Param}` // [GET, PUT, DELETE] Guid noteId
12
- // | `users` // [GET, POST]
13
- // | `users?role=${Param}` // [GET] enum Role
14
- // | `users/${Param}` // [GET, PUT, DELETE] Guid userId
15
- // | `users/authenticate`; // [POST, DELETE]
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // All possible endpoints for the API. This will generate autocomplete when using the Request function
4
+ // The commented code below is an example from my previous "CitizenTaxi" project to illustrate how this works
5
+ // export type ApiEndpoints<Param extends TParam = undefined> =
6
+ // | `bookings` // [GET, POST]
7
+ // | `bookings?citizenId=${Param}` // [GET] Guid
8
+ // | `bookings/${Param}` // [GET, PUT, DELETE] Guid bookingId
9
+ // | `notes` // [GET, POST]
10
+ // | `notes?citizenId=${Param}` // [GET] Guid
11
+ // | `notes/${Param}` // [GET, PUT, DELETE] Guid noteId
12
+ // | `users` // [GET, POST]
13
+ // | `users?role=${Param}` // [GET] enum Role
14
+ // | `users/${Param}` // [GET, PUT, DELETE] Guid userId
15
+ // | `users/authenticate`; // [POST, DELETE]
@@ -1,19 +1,19 @@
1
- import { RequestOptions } from "./ApiTypes";
2
- /**
3
- * Makes a request to the API
4
- * @param path Api endpoint to request
5
- * @param options Additional options for the request
6
- * @returns The response from the API
7
- */
8
- export declare function Request<TData, ApiEndpoints extends string>(path: ApiEndpoints, { method, body, noHeaders, controller, query, baseEndpoint }?: RequestOptions | undefined, log?: boolean): Promise<{
9
- success: boolean;
10
- status: number;
11
- data: TData;
12
- text: string;
13
- }>;
14
- /**
15
- * Ensures that the path starts with a /
16
- * @param path Path string
17
- * @returns Path that starts with a /
18
- */
19
- export declare function ensureSlash(path: string): string;
1
+ import { RequestOptions } from "./ApiTypes";
2
+ /**
3
+ * Makes a request to the API
4
+ * @param path Api endpoint to request
5
+ * @param options Additional options for the request
6
+ * @returns The response from the API
7
+ */
8
+ export declare function Request<TData, ApiEndpoints extends string>(path: ApiEndpoints, { method, body, noHeaders, controller, query, baseEndpoint }?: RequestOptions | undefined, log?: boolean): Promise<{
9
+ success: boolean;
10
+ status: number;
11
+ data: TData;
12
+ text: string;
13
+ }>;
14
+ /**
15
+ * Ensures that the path starts with a /
16
+ * @param path Path string
17
+ * @returns Path that starts with a /
18
+ */
19
+ export declare function ensureSlash(path: string): string;
@@ -1,73 +1,73 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureSlash = exports.Request = void 0;
4
- /**
5
- * Makes a request to the API
6
- * @param path Api endpoint to request
7
- * @param options Additional options for the request
8
- * @returns The response from the API
9
- */
10
- async function Request(path,
11
- // Destructor the options object, if it's undefined then set it to an empty object
12
- { method = 'GET', body, noHeaders = false, controller = new AbortController(), query, baseEndpoint } = {}, log = false) {
13
- // console.log(`Requesting ${path} with method ${method}`);
14
- // Construct the endpoint for the request
15
- const endpoint = (() => {
16
- const result = baseEndpoint + ensureSlash(path);
17
- if (path.includes('?') || !query)
18
- return result;
19
- // If the query object is defined, then construct a query string from it
20
- const queryString = Object.entries(query)
21
- .map(([key, value]) => value ? `${key}=${value}` : '')
22
- .join('&');
23
- return path.includes('?') ? `${result}&${queryString}` : `${result}?${queryString}`;
24
- })();
25
- // Construct the request init object to pass to the fetch function
26
- const init = {
27
- method,
28
- body: body ? !noHeaders ? JSON.stringify(body) : body : undefined,
29
- headers: !noHeaders ? { 'Content-Type': 'application/json' } : undefined,
30
- signal: controller.signal,
31
- credentials: 'include',
32
- mode: 'cors'
33
- };
34
- // Make the request, log any errors, and throw them again
35
- const res = await fetch(endpoint, init).catch(err => {
36
- console.error(`Failed to [${method}] ${path}`, err);
37
- throw err;
38
- });
39
- if (log)
40
- console.log(`[${method}] ${path} responded with ${res.status}`, res);
41
- // Clone the response so that it can be converted to JSON and text
42
- const clone = res.clone();
43
- // All successful responses are in the 200s, so check if the status code starts with 2
44
- const isSuccessful = res.status.toString().startsWith('2');
45
- // This try-catch block is used to catch any errors when converting the response to JSON
46
- // If the response is not jsonable, then the catch will return null for the data
47
- try {
48
- return {
49
- success: isSuccessful,
50
- status: res.status,
51
- data: await res.json(),
52
- text: await clone.text(),
53
- };
54
- }
55
- catch {
56
- return {
57
- success: isSuccessful,
58
- status: res.status,
59
- data: null,
60
- text: await clone.text(),
61
- };
62
- }
63
- }
64
- exports.Request = Request;
65
- /**
66
- * Ensures that the path starts with a /
67
- * @param path Path string
68
- * @returns Path that starts with a /
69
- */
70
- function ensureSlash(path) {
71
- return path.startsWith('/') ? path : '/' + path;
72
- }
73
- exports.ensureSlash = ensureSlash;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureSlash = exports.Request = void 0;
4
+ /**
5
+ * Makes a request to the API
6
+ * @param path Api endpoint to request
7
+ * @param options Additional options for the request
8
+ * @returns The response from the API
9
+ */
10
+ async function Request(path,
11
+ // Destructor the options object, if it's undefined then set it to an empty object
12
+ { method = 'GET', body, noHeaders = false, controller = new AbortController(), query, baseEndpoint } = {}, log = false) {
13
+ // console.log(`Requesting ${path} with method ${method}`);
14
+ // Construct the endpoint for the request
15
+ const endpoint = (() => {
16
+ const result = baseEndpoint + ensureSlash(path);
17
+ if (path.includes('?') || !query)
18
+ return result;
19
+ // If the query object is defined, then construct a query string from it
20
+ const queryString = Object.entries(query)
21
+ .map(([key, value]) => value ? `${key}=${value}` : '')
22
+ .join('&');
23
+ return path.includes('?') ? `${result}&${queryString}` : `${result}?${queryString}`;
24
+ })();
25
+ // Construct the request init object to pass to the fetch function
26
+ const init = {
27
+ method,
28
+ body: body ? !noHeaders ? JSON.stringify(body) : body : undefined,
29
+ headers: !noHeaders ? { 'Content-Type': 'application/json' } : undefined,
30
+ signal: controller.signal,
31
+ credentials: 'include',
32
+ mode: 'cors'
33
+ };
34
+ // Make the request, log any errors, and throw them again
35
+ const res = await fetch(endpoint, init).catch(err => {
36
+ console.error(`Failed to [${method}] ${path}`, err);
37
+ throw err;
38
+ });
39
+ if (log)
40
+ console.log(`[${method}] ${path} responded with ${res.status}`, res);
41
+ // Clone the response so that it can be converted to JSON and text
42
+ const clone = res.clone();
43
+ // All successful responses are in the 200s, so check if the status code starts with 2
44
+ const isSuccessful = res.status.toString().startsWith('2');
45
+ // This try-catch block is used to catch any errors when converting the response to JSON
46
+ // If the response is not jsonable, then the catch will return null for the data
47
+ try {
48
+ return {
49
+ success: isSuccessful,
50
+ status: res.status,
51
+ data: await res.json(),
52
+ text: await clone.text(),
53
+ };
54
+ }
55
+ catch {
56
+ return {
57
+ success: isSuccessful,
58
+ status: res.status,
59
+ data: null,
60
+ text: await clone.text(),
61
+ };
62
+ }
63
+ }
64
+ exports.Request = Request;
65
+ /**
66
+ * Ensures that the path starts with a /
67
+ * @param path Path string
68
+ * @returns Path that starts with a /
69
+ */
70
+ function ensureSlash(path) {
71
+ return path.startsWith('/') ? path : '/' + path;
72
+ }
73
+ exports.ensureSlash = ensureSlash;