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.
Files changed (210) 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/Classes/DanhoLogger.d.ts +23 -0
  5. package/dist/Classes/DanhoLogger.js +65 -0
  6. package/dist/Classes/Events/Event.d.ts +66 -66
  7. package/dist/Classes/Events/Event.js +114 -114
  8. package/dist/Classes/Events/EventCollection.d.ts +57 -57
  9. package/dist/Classes/Events/EventCollection.js +109 -109
  10. package/dist/Classes/Events/EventEmitter.d.ts +74 -74
  11. package/dist/Classes/Events/EventEmitter.js +97 -97
  12. package/dist/Classes/Events/index.d.ts +3 -3
  13. package/dist/Classes/Events/index.js +19 -19
  14. package/dist/Classes/Time/Date.d.ts +148 -147
  15. package/dist/Classes/Time/Date.js +241 -238
  16. package/dist/Classes/Time/Time.d.ts +66 -65
  17. package/dist/Classes/Time/Time.js +120 -117
  18. package/dist/Classes/Time/TimeProperties.d.ts +3 -3
  19. package/dist/Classes/Time/TimeProperties.js +2 -2
  20. package/dist/Classes/Time/TimeSpan.d.ts +123 -123
  21. package/dist/Classes/Time/TimeSpan.js +179 -179
  22. package/dist/Classes/Time/index.d.ts +4 -4
  23. package/dist/Classes/Time/index.js +20 -20
  24. package/dist/Classes/index.d.ts +4 -3
  25. package/dist/Classes/index.js +20 -19
  26. package/dist/Classes/store.d.ts +75 -75
  27. package/dist/Classes/store.js +84 -84
  28. package/dist/Extensions/Array/array.extension.d.ts +42 -0
  29. package/dist/Extensions/Array/array.extension.js +57 -0
  30. package/dist/Extensions/Array/crud.extension.d.ts +24 -0
  31. package/dist/Extensions/Array/crud.extension.js +28 -0
  32. package/dist/Extensions/Array/index.d.ts +6 -0
  33. package/dist/Extensions/Array/index.js +22 -0
  34. package/dist/Extensions/Array/loop.extension.d.ts +18 -0
  35. package/dist/Extensions/Array/loop.extension.js +23 -0
  36. package/dist/Extensions/Array/random.extension.d.ts +23 -0
  37. package/dist/Extensions/Array/random.extension.js +35 -0
  38. package/dist/Extensions/Array/sort.extension.d.ts +27 -0
  39. package/dist/Extensions/Array/sort.extension.js +31 -0
  40. package/dist/Extensions/Array/string.extension.d.ts +13 -0
  41. package/dist/Extensions/Array/string.extension.js +14 -0
  42. package/dist/Extensions/Function.d.ts +29 -14
  43. package/dist/Extensions/Function.js +23 -10
  44. package/dist/Extensions/Map.d.ts +54 -54
  45. package/dist/Extensions/Map.js +42 -42
  46. package/dist/Extensions/Number.d.ts +13 -0
  47. package/dist/Extensions/Number.js +40 -0
  48. package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
  49. package/dist/Extensions/Object/arrays.extension.js +13 -0
  50. package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
  51. package/dist/Extensions/Object/booleans.extension.js +37 -0
  52. package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
  53. package/dist/Extensions/Object/extracts.extension.js +72 -0
  54. package/dist/Extensions/Object/index.d.ts +4 -49
  55. package/dist/Extensions/Object/index.js +20 -38
  56. package/dist/Extensions/Object/properties.d.ts +28 -28
  57. package/dist/Extensions/Object/properties.extension.d.ts +33 -0
  58. package/dist/Extensions/Object/properties.extension.js +21 -0
  59. package/dist/Extensions/Object/properties.js +20 -20
  60. package/dist/Extensions/String/case.extension.d.ts +12 -0
  61. package/dist/Extensions/String/case.extension.js +55 -0
  62. package/dist/Extensions/String/index.d.ts +1 -0
  63. package/dist/{Functions → Extensions/String}/index.js +17 -21
  64. package/dist/Extensions/index.d.ts +6 -17
  65. package/dist/Extensions/index.js +22 -30
  66. package/dist/Interfaces/ElementOptions.d.ts +15 -15
  67. package/dist/Interfaces/ElementOptions.js +2 -2
  68. package/dist/Interfaces/IReplacement.d.ts +12 -12
  69. package/dist/Interfaces/IReplacement.js +2 -2
  70. package/dist/Interfaces/index.d.ts +2 -2
  71. package/dist/Interfaces/index.js +18 -18
  72. package/dist/Types/Able.d.ts +16 -0
  73. package/dist/Types/Able.js +2 -0
  74. package/dist/Types/Array.d.ts +6 -0
  75. package/dist/Types/Array.js +2 -0
  76. package/dist/Types/BetterTypes.d.ts +9 -9
  77. package/dist/Types/BetterTypes.js +2 -2
  78. package/dist/Types/C#.d.ts +8 -0
  79. package/dist/Types/C#.js +2 -0
  80. package/dist/Types/Date.d.ts +6 -6
  81. package/dist/Types/Date.js +2 -2
  82. package/dist/Types/Events.d.ts +10 -10
  83. package/dist/Types/Events.js +2 -2
  84. package/dist/Types/Function.d.ts +5 -0
  85. package/dist/Types/Function.js +2 -0
  86. package/dist/Types/Object.d.ts +4 -0
  87. package/dist/Types/Object.js +2 -0
  88. package/dist/Types/PropertiesWith.d.ts +34 -13
  89. package/dist/Types/PropertiesWith.js +2 -2
  90. package/dist/Types/String.d.ts +1 -0
  91. package/dist/Types/String.js +2 -0
  92. package/dist/Types/TransformTypes.d.ts +22 -16
  93. package/dist/Types/TransformTypes.js +2 -2
  94. package/dist/Types/index.d.ts +24 -65
  95. package/dist/Types/index.js +27 -21
  96. package/dist/Utils/{ApiUtil → ApiUtils}/ApiTypes.d.ts +15 -15
  97. package/dist/Utils/{ApiUtil → ApiUtils}/ApiTypes.js +15 -15
  98. package/dist/Utils/{ApiUtil → ApiUtils}/RequestUtil.d.ts +19 -19
  99. package/dist/Utils/{ApiUtil → ApiUtils}/RequestUtil.js +73 -73
  100. package/dist/Utils/{ApiUtil → ApiUtils}/index.d.ts +20 -20
  101. package/dist/Utils/{ApiUtil → ApiUtils}/index.js +33 -33
  102. package/dist/Utils/ColorUtils.d.ts +11 -0
  103. package/dist/Utils/ColorUtils.js +93 -0
  104. package/dist/Utils/{FormUtil.d.ts → FormUtils.d.ts} +6 -6
  105. package/dist/Utils/{FormUtil.js → FormUtils.js} +35 -35
  106. package/dist/Utils/NumberUtils.d.ts +1 -0
  107. package/dist/Utils/NumberUtils.js +7 -0
  108. package/dist/Utils/PatcherUtils.d.ts +6 -0
  109. package/dist/Utils/PatcherUtils.js +80 -0
  110. package/dist/Utils/StringUtils.d.ts +3 -0
  111. package/dist/Utils/StringUtils.js +47 -0
  112. package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
  113. package/dist/Utils/TimeUtils/debounce.util.js +78 -0
  114. package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
  115. package/dist/Utils/TimeUtils/functions.util.js +21 -0
  116. package/dist/Utils/TimeUtils/index.d.ts +15 -0
  117. package/dist/Utils/TimeUtils/index.js +34 -0
  118. package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
  119. package/dist/Utils/TimeUtils/throttle.util.js +43 -0
  120. package/dist/Utils/index.d.ts +7 -2
  121. package/dist/Utils/index.js +23 -18
  122. package/dist/index.d.ts +4 -5
  123. package/dist/index.js +20 -21
  124. package/docs/Classes.md +78 -3
  125. package/docs/Extensions.md +219 -78
  126. package/docs/Types.md +202 -58
  127. package/docs/index.md +0 -1
  128. package/package.json +4 -2
  129. package/src/Classes/DanhoLogger.ts +78 -0
  130. package/src/Classes/Events/Event.ts +96 -96
  131. package/src/Classes/Events/EventCollection.ts +90 -90
  132. package/src/Classes/Events/EventEmitter.ts +68 -68
  133. package/src/Classes/Time/Date.ts +219 -216
  134. package/src/Classes/Time/Time.ts +109 -104
  135. package/src/Classes/Time/TimeSpan.ts +171 -171
  136. package/src/Classes/index.ts +1 -0
  137. package/src/Classes/store.ts +22 -22
  138. package/src/Extensions/Array/array.extension.ts +103 -0
  139. package/src/Extensions/Array/crud.extension.ts +46 -0
  140. package/src/Extensions/Array/index.ts +6 -0
  141. package/src/Extensions/Array/loop.extension.ts +38 -0
  142. package/src/Extensions/Array/random.extension.ts +56 -0
  143. package/src/Extensions/Array/sort.extension.ts +52 -0
  144. package/src/Extensions/Array/string.extension.ts +22 -0
  145. package/src/Extensions/Function.ts +37 -10
  146. package/src/Extensions/Map.ts +56 -56
  147. package/src/Extensions/Number.ts +50 -0
  148. package/src/Extensions/Object/arrays.extension.ts +27 -0
  149. package/src/Extensions/Object/booleans.extension.ts +46 -0
  150. package/src/Extensions/Object/extracts.extension.ts +102 -0
  151. package/src/Extensions/Object/index.ts +4 -82
  152. package/src/Extensions/Object/properties.extension.ts +59 -0
  153. package/src/Extensions/Object/properties.ts +36 -36
  154. package/src/Extensions/String/case.extension.ts +95 -0
  155. package/src/Extensions/String/index.ts +1 -0
  156. package/src/Extensions/index.ts +3 -21
  157. package/src/Interfaces/ElementOptions.ts +7 -7
  158. package/src/Interfaces/IReplacement.ts +2 -2
  159. package/src/Types/Able.ts +22 -0
  160. package/src/Types/Array.ts +7 -0
  161. package/src/Types/C#.ts +9 -0
  162. package/src/Types/Date.ts +1 -1
  163. package/src/Types/Events.ts +12 -12
  164. package/src/Types/Function.ts +10 -0
  165. package/src/Types/Object.ts +4 -0
  166. package/src/Types/PropertiesWith.ts +35 -4
  167. package/src/Types/String.ts +1 -0
  168. package/src/Types/TransformTypes.ts +21 -13
  169. package/src/Types/index.ts +7 -69
  170. package/src/Utils/{ApiUtil → ApiUtils}/ApiTypes.ts +2 -1
  171. package/src/Utils/{ApiUtil → ApiUtils}/index.ts +1 -1
  172. package/src/Utils/ColorUtils.ts +102 -0
  173. package/src/Utils/{FormUtil.ts → FormUtils.ts} +2 -2
  174. package/src/Utils/NumberUtils.ts +3 -0
  175. package/src/Utils/PatcherUtils.ts +111 -0
  176. package/src/Utils/StringUtils.ts +44 -0
  177. package/src/Utils/TimeUtils/debounce.util.ts +85 -0
  178. package/src/Utils/TimeUtils/functions.util.ts +18 -0
  179. package/src/Utils/TimeUtils/index.ts +9 -0
  180. package/src/Utils/TimeUtils/throttle.util.ts +44 -0
  181. package/src/Utils/index.ts +8 -2
  182. package/src/index.ts +0 -1
  183. package/dist/Extensions/Array.d.ts +0 -52
  184. package/dist/Extensions/Array.js +0 -51
  185. package/dist/Extensions/Document.d.ts +0 -27
  186. package/dist/Extensions/Document.js +0 -32
  187. package/dist/Extensions/String.d.ts +0 -36
  188. package/dist/Extensions/String.js +0 -25
  189. package/dist/Functions/CopyToClipboard.d.ts +0 -7
  190. package/dist/Functions/CopyToClipboard.js +0 -15
  191. package/dist/Functions/GetCSSProperty.d.ts +0 -15
  192. package/dist/Functions/GetCSSProperty.js +0 -26
  193. package/dist/Functions/GetNestedProperty.d.ts +0 -9
  194. package/dist/Functions/GetNestedProperty.js +0 -23
  195. package/dist/Functions/HTMLEvent.d.ts +0 -11
  196. package/dist/Functions/HTMLEvent.js +0 -14
  197. package/dist/Functions/SetNavigationSelected.d.ts +0 -9
  198. package/dist/Functions/SetNavigationSelected.js +0 -25
  199. package/dist/Functions/index.d.ts +0 -5
  200. package/docs/Functions.md +0 -61
  201. package/src/Extensions/Array.ts +0 -95
  202. package/src/Extensions/Document.ts +0 -58
  203. package/src/Extensions/String.ts +0 -54
  204. package/src/Functions/CopyToClipboard.ts +0 -10
  205. package/src/Functions/GetCSSProperty.ts +0 -27
  206. package/src/Functions/GetNestedProperty.ts +0 -29
  207. package/src/Functions/HTMLEvent.ts +0 -13
  208. package/src/Functions/SetNavigationSelected.ts +0 -19
  209. package/src/Functions/index.ts +0 -5
  210. /package/src/Utils/{ApiUtil → ApiUtils}/RequestUtil.ts +0 -0
@@ -0,0 +1,46 @@
1
+ declare global {
2
+ interface ObjectConstructor {
3
+ /**
4
+ * Returns true if objects are equal by comparing their properties and values recursively. Does not compare functions.
5
+ * @param a First object
6
+ * @param b Second object
7
+ * @returns true if objects are equal, false otherwise
8
+ */
9
+ areEqual<T extends object | null>(a?: T, b?: T): boolean;
10
+
11
+ /**
12
+ * Returns true if object is empty
13
+ * @param obj Object to check
14
+ */
15
+ isNullOrUndefined(obj: any): obj is null | undefined;
16
+ }
17
+ }
18
+
19
+ export function areEqual<T extends object | null>(a?: T, b?: T): boolean {
20
+ if (a === b) return true;
21
+ if (typeof a !== typeof b) return false;
22
+ if (isNullOrUndefined(a) && isNullOrUndefined(b)) return true;
23
+
24
+ const keysA = Object.keys(a ?? {});
25
+ const keysB = Object.keys(b ?? {});
26
+ if (keysA.length !== keysB.length) return false;
27
+
28
+ try {
29
+ const jsonA = JSON.stringify(a);
30
+ const jsonB = JSON.stringify(b);
31
+ if (jsonA === jsonB) return true;
32
+ } catch {
33
+ for (const key of keysA) {
34
+ if (!keysB.includes(key)) return false;
35
+ if (!areEqual((a as any)[key], (b as any)[key])) return false;
36
+ }
37
+ }
38
+
39
+ return true;
40
+ }
41
+ Object.areEqual = areEqual;
42
+
43
+ export function isNullOrUndefined(obj: any): obj is null | undefined {
44
+ return obj === null || obj === undefined;
45
+ }
46
+ Object.isNullOrUndefined = isNullOrUndefined;
@@ -0,0 +1,102 @@
1
+ declare global {
2
+ interface ObjectConstructor {
3
+ /**
4
+ * Get a copy of object without specified properties or partial versions.
5
+ * @param from Object to extract properties from
6
+ * @param props Properties to extract/Omit
7
+ */
8
+ omit<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props>;
9
+
10
+ /**
11
+ * Get a copy of object with only specified properties or partial versions.
12
+ * @param from Object to extract properties from
13
+ * @param props Properties to extract/Pick
14
+ */
15
+ pick<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>;
16
+
17
+ /**
18
+ * Receive an object with properties that are not in union of source and target objects
19
+ * @param source Source object
20
+ * @param target Target object
21
+ * @param exclude Properties to exclude from difference
22
+ * @returns Object with properties that are not in union of source and target objects, excluding specified properties
23
+ */
24
+ difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Omit<T, keyof T>;
25
+
26
+ /**
27
+ * Deeply combines objects, with later objects in parameters taking precedence over earlier ones. Does not combine arrays.
28
+ * @param objects Objects to combine
29
+ * @returns Combined object
30
+ */
31
+ combine<T extends Record<string, any | undefined>>(...objects: Array<Partial<T> | undefined>): T;
32
+ }
33
+ }
34
+
35
+
36
+ export function omit<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props> {
37
+ return props.reduce((result, prop) => {
38
+ if (typeof prop === "object") {
39
+ const keys = Object.keysOf(prop);
40
+ keys.forEach(key => delete (result as Partial<From>)[key]);
41
+ } else {
42
+ delete (result as Partial<From>)[prop];
43
+ }
44
+
45
+ return result;
46
+ }, { ...from } as Omit<From, Props>);
47
+ }
48
+ Object.omit = omit;
49
+
50
+ export function pick<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props> {
51
+ return props.reduce((result, prop) => {
52
+ if (typeof prop === "object") {
53
+ const keys = Object.keysOf(prop);
54
+ keys.forEach(key => (result as Partial<From>)[key] = from[key]);
55
+ } else {
56
+ (result as Partial<From>)[prop] = from[prop];
57
+ }
58
+ return result;
59
+ }, {} as Pick<From, Props>);
60
+ }
61
+ Object.pick = pick;
62
+
63
+ export function difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Omit<T, keyof T> {
64
+ const diffKeys = new Set([...Object.keysOf(source), ...Object.keysOf(target)]);
65
+ exclude?.forEach(key => diffKeys.delete(key));
66
+
67
+ return [...diffKeys.values()].reduce((acc, key, i, arr) => {
68
+ const sourceValue = JSON.stringify(source[key]);
69
+ const targetValue = JSON.stringify(target[key]);
70
+ if (sourceValue !== targetValue) acc[key] = target[key];
71
+ return acc;
72
+ }, {} as T);
73
+ }
74
+ Object.difference = difference;
75
+
76
+ type Combinable<T extends Record<string, any>> = {
77
+ [key in keyof T]?: T[key] extends Record<string, any> ? Combinable<T[key]> : T[key];
78
+ };
79
+
80
+ export function combine<T extends Record<string, any | undefined>>(...objects: Array<Combinable<T> | undefined>): T {
81
+ return objects.reduce((acc: T, obj) => {
82
+ if (!obj) return acc;
83
+
84
+ for (const key in obj) {
85
+ if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
86
+ try {
87
+ acc[key] = combine(acc[key] as T, obj[key] as T) as any;
88
+ } catch (err) {
89
+ const error = err as Error;
90
+ if (error.message.includes('Maximum call stack size exceeded')) {
91
+ acc[key] = obj[key] as any;
92
+ } else throw err;
93
+ }
94
+ } else if (obj[key] !== undefined && obj[key] !== null && obj[key] !== '') {
95
+ // @ts-ignore
96
+ (acc[key] as Combinable<T>) = obj[key];
97
+ }
98
+ }
99
+ return acc;
100
+ }, {} as T) as T;
101
+ }
102
+ Object.combine = combine;
@@ -1,82 +1,4 @@
1
- import { ValueOf } from "../../Types";
2
- import { Properties, properties } from "./properties";
3
-
4
- declare global {
5
- interface ObjectConstructor {
6
- /**
7
- * Destructures object into array of [property, value]
8
- * @param from Object to destruct
9
- */
10
- array<From extends {} = {}>(from: From): Array<[keyof From, ValueOf<From>]>
11
-
12
- /**
13
- * Omits properties from object, but for some reason the correct term is "extract"
14
- * @param from Object to extract properties from
15
- * @param props Properties to extract/Omit
16
- */
17
- extract<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props>
18
-
19
- /**
20
- * Pick properties from object, but for some reason the correct term is "exclude"
21
- * @param from Object to exclude properties from
22
- * @param props Properties to exclude/pick
23
- */
24
- exclude<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>
25
-
26
- /**
27
- * Returns true if object is empty
28
- * @param obj Object to check
29
- */
30
- isNullOrUndefined(obj: any): obj is null | undefined
31
-
32
- /**
33
- * Destructures object into array of property keys
34
- * @param from Object to destruct
35
- */
36
- keysOf<From extends {} = {}>(from: From): Array<keyof From>
37
-
38
- omit<From extends {}, Exclude extends keyof From>(from: From, ...exclude: Exclude[]): Omit<From, Exclude>;
39
-
40
- properties: Properties
41
- }
42
- }
43
-
44
- function array<From extends {} = {}>(this: object, from: From): Array<[keyof From, ValueOf<From>]> {
45
- return Object.keysOf(from).map(prop => [prop, from[prop]]) as Array<[keyof From, ValueOf<From>]>;
46
- }
47
- Object.array = array;
48
-
49
- function extract<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props> {
50
- // If props are Array<keyof From>, Array<Partial<From>>, or Array<keyof From | Partial<From>>, ensure _props as Array<keyof From>
51
- const _props = props.map(prop => typeof prop === "object" ? Object.keysOf(prop) : prop).flat();
52
- _props.forEach(prop => delete from[prop as keyof From]);
53
- return from;
54
- }
55
- Object.extract = extract;
56
-
57
- function exclude<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props> {
58
- // If props are Array<keyof From>, Array<Partial<From>>, or Array<keyof From | Partial<From>>, ensure _props as Array<keyof From>
59
- const _props = props.map(prop => typeof prop === "object" ? Object.keysOf(prop) : prop).flat();
60
- return Object.keysOf(from).reduce((result, prop) => {
61
- if (_props.includes(prop as Props)) delete result[prop];
62
- return result;
63
- }, from);
64
- }
65
- Object.exclude = exclude;
66
-
67
- function isNullOrUndefined(obj: any): obj is null | undefined {
68
- return obj === null || obj === undefined;
69
- }
70
- Object.isNullOrUndefined = isNullOrUndefined;
71
-
72
- function keysOf<From extends {} = {}>(this: object, from: From): Array<keyof From> {
73
- return Object.keys(from) as Array<keyof From>;
74
- }
75
- Object.keysOf = keysOf;
76
-
77
- Object.properties = properties;
78
-
79
- export const ObjectExtensions = {
80
- properties,
81
- array, extract, exclude, isNullOrUndefined, keysOf,
82
- };
1
+ export * from './arrays.extension';
2
+ export * from './booleans.extension';
3
+ export * from './extracts.extension';
4
+ export * from './properties.extension';
@@ -0,0 +1,59 @@
1
+ import { PropertiesWith, If } from '../../Types';
2
+ import { convertCase } from '../String/case.extension';
3
+
4
+ type PrimitiveMap = {
5
+ string: string;
6
+ number: number;
7
+ boolean: boolean;
8
+ undefined: undefined;
9
+ null: null;
10
+ object: object;
11
+ function: Function;
12
+ any: any;
13
+ Date: Date;
14
+ RegExp: RegExp;
15
+ Promise: Promise<any>;
16
+ Array: Array<any>;
17
+ Map: Map<any, any>;
18
+ Set: Set<any>;
19
+ };
20
+
21
+ /**
22
+ * Object with getPrimitiveTypes<Source, AllowFunctions extends boolean>(
23
+ * source: Source,
24
+ * allowFunctions: AllowFunctions = false
25
+ * ): Object with properties from source that matches primitive type
26
+ */
27
+ export type Properties = {
28
+ [Key in keyof PrimitiveMap as `get${Capitalize<Key>}s`]:
29
+ <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions) =>
30
+ If<AllowFunctions,
31
+ PropertiesWith<PrimitiveMap[Key] | ((...args: any[]) => PrimitiveMap[Key]), Source>,
32
+ PropertiesWith<PrimitiveMap[Key], Source>
33
+ >
34
+ };
35
+
36
+ declare global {
37
+ interface ObjectConstructor {
38
+ properties: Properties;
39
+ }
40
+ }
41
+
42
+ export const properties: Properties = [
43
+ 'string', 'number', 'boolean', 'undefined', 'null',
44
+ 'object', 'function', 'any',
45
+ 'Date', 'RegExp', 'Promise', 'Array', 'Map', 'Set'
46
+ ].reduce((result, primitive) => {
47
+ result[`get${convertCase('camel', 'pascal')}s` as keyof Properties] = function <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions: AllowFunctions = false as AllowFunctions) {
48
+ return Object.keysOf<Source>(source).reduce((result, key) => {
49
+ if ((source[key] as any).constructor.name === primitive ||
50
+ (withFunctions && typeof source[key] === 'function' && source[key] as any).constructor.name === primitive) {
51
+ result[key] = source[key];
52
+ }
53
+ return result;
54
+ }, {} as any);
55
+ };
56
+ return result;
57
+ }, {} as Properties);
58
+
59
+ Object.properties = properties;
@@ -1,22 +1,22 @@
1
1
  import { PropertiesWith, If } from '../../Types';
2
- import { StringExtensions } from '../String';
2
+ import { convertCase } from '../String/case.extension';
3
3
 
4
4
  type PrimitiveMap = {
5
- string: string;
6
- number: number;
7
- boolean: boolean;
8
- undefined: undefined;
9
- null: null;
10
- object: object;
11
- function: Function;
12
- any: any;
13
- Date: Date;
14
- RegExp: RegExp;
15
- Promise: Promise<any>;
16
- Array: Array<any>;
17
- Map: Map<any, any>;
18
- Set: Set<any>;
19
- }
5
+ string: string;
6
+ number: number;
7
+ boolean: boolean;
8
+ undefined: undefined;
9
+ null: null;
10
+ object: object;
11
+ function: Function;
12
+ any: any;
13
+ Date: Date;
14
+ RegExp: RegExp;
15
+ Promise: Promise<any>;
16
+ Array: Array<any>;
17
+ Map: Map<any, any>;
18
+ Set: Set<any>;
19
+ };
20
20
 
21
21
  /**
22
22
  * Object with getPrimitiveTypes<Source, AllowFunctions extends boolean>(
@@ -25,27 +25,27 @@ type PrimitiveMap = {
25
25
  * ): Object with properties from source that matches primitive type
26
26
  */
27
27
  export type Properties = {
28
- [Key in keyof PrimitiveMap as `get${Capitalize<Key>}s`]:
29
- <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions) =>
30
- If<AllowFunctions,
31
- PropertiesWith<PrimitiveMap[Key] | ((...args: any[]) => PrimitiveMap[Key]), Source>,
32
- PropertiesWith<PrimitiveMap[Key], Source>
33
- >
34
- }
28
+ [Key in keyof PrimitiveMap as `get${Capitalize<Key>}s`]:
29
+ <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions) =>
30
+ If<AllowFunctions,
31
+ PropertiesWith<PrimitiveMap[Key] | ((...args: any[]) => PrimitiveMap[Key]), Source>,
32
+ PropertiesWith<PrimitiveMap[Key], Source>
33
+ >
34
+ };
35
35
 
36
36
  export const properties: Properties = [
37
- 'string', 'number', 'boolean', 'undefined', 'null',
38
- 'object', 'function', 'any',
39
- 'Date', 'RegExp', 'Promise', 'Array', 'Map', 'Set'
37
+ 'string', 'number', 'boolean', 'undefined', 'null',
38
+ 'object', 'function', 'any',
39
+ 'Date', 'RegExp', 'Promise', 'Array', 'Map', 'Set'
40
40
  ].reduce((result, primitive) => {
41
- result[`get${StringExtensions.toPascalCase.bind(primitive)()}s` as keyof Properties] = function<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions: AllowFunctions = false as AllowFunctions) {
42
- return Object.keysOf<Source>(source).reduce((result, key) => {
43
- if ((source[key] as any).constructor.name === primitive ||
44
- (withFunctions && typeof source[key] === 'function' && source[key] as any).constructor.name === primitive) {
45
- result[key] = source[key];
46
- }
47
- return result;
48
- }, {} as any);
49
- }
50
- return result;
41
+ result[`get${convertCase('camel', 'pascal')}s` as keyof Properties] = function <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions: AllowFunctions = false as AllowFunctions) {
42
+ return Object.keysOf<Source>(source).reduce((result, key) => {
43
+ if ((source[key] as any).constructor.name === primitive ||
44
+ (withFunctions && typeof source[key] === 'function' && source[key] as any).constructor.name === primitive) {
45
+ result[key] = source[key];
46
+ }
47
+ return result;
48
+ }, {} as any);
49
+ };
50
+ return result;
51
51
  }, {} as Properties);
@@ -0,0 +1,95 @@
1
+ export type Case = 'camel' | 'pascal' | 'snake' | 'kebab' | 'lower' | 'upper';
2
+
3
+ declare global {
4
+ interface String {
5
+ /**
6
+ * Converts string from one case to another.
7
+ * @param from Case to convert from
8
+ * @param to Cases to convert to, in order. If multiple cases are provided, they will be applied in order
9
+ */
10
+ convertCase<To extends Array<Case>, Return extends To extends [...Array<Case>, infer To] ? To : Case>(
11
+ from: Case,
12
+ ...to: To
13
+ ): (
14
+ Return extends 'upper' ? Uppercase<string>
15
+ : Return extends 'lower' ? Lowercase<string>
16
+ : Return extends 'pascal' ? Capitalize<string>
17
+ : Return extends 'camel' ? Uncapitalize<string>
18
+ : string
19
+ );
20
+ }
21
+ }
22
+
23
+ const caseMap: Record<Case, Record<Case, (str: string) => string>> = {
24
+ camel: {
25
+ camel: (str) => str,
26
+ lower: (str: string) => str.toLowerCase(),
27
+ upper: (str: string) => str.toUpperCase(),
28
+
29
+ pascal: (str: string) => str[0].toUpperCase() + str.replace(/([A-Z])/g, (match) => ` ${match}`).slice(1),
30
+ snake: (str: string) => str.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`),
31
+ kebab: (str: string) => str.replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`),
32
+ },
33
+ pascal: {
34
+ pascal: (str) => str,
35
+ lower: (str: string) => str.toLowerCase(),
36
+ upper: (str: string) => str.toUpperCase(),
37
+
38
+ camel: (str: string) => str[0].toLowerCase() + str.slice(1),
39
+ snake: (str: string) => str.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`),
40
+ kebab: (str: string) => str.replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`),
41
+ },
42
+ snake: {
43
+ snake: (str) => str,
44
+ lower: (str: string) => str.toLowerCase(),
45
+ upper: (str: string) => str.toUpperCase(),
46
+
47
+ camel: (str: string) => str.replace(/(_\w)/g, (match) => match[1].toUpperCase()),
48
+ pascal: (str: string) => str[0].toUpperCase() + str.substring(1, str.length).replace(/(_\w)/g, (match) => match[1].toUpperCase()),
49
+ kebab: (str: string) => str.replace(/_/g, '-'),
50
+ },
51
+ kebab: {
52
+ kebab: (str) => str,
53
+ lower: (str: string) => str.toLowerCase(),
54
+ upper: (str: string) => str.toUpperCase(),
55
+
56
+ camel: (str: string) => str.replace(/(-\w)/g, (match) => match[1].toUpperCase()),
57
+ pascal: (str: string) => str[0].toUpperCase() + str.substring(1, str.length).replace(/(-\w)/g, (match) => match[1].toUpperCase()),
58
+ snake: (str: string) => str.replace(/-/g, '_'),
59
+ },
60
+
61
+ lower: {
62
+ lower: (str) => str.toLowerCase(),
63
+ upper: (str: string) => str.toUpperCase(),
64
+
65
+ camel: (str: string) => str,
66
+ pascal: (str: string) => str[0].toUpperCase() + str.slice(1),
67
+ snake: (str: string) => str,
68
+ kebab: (str: string) => str,
69
+ },
70
+
71
+ upper: {
72
+ upper: (str) => str.toUpperCase(),
73
+ camel: (str: string) => str[0].toLowerCase() + str.slice(1),
74
+ pascal: (str: string) => str[0].toUpperCase() + str.toLowerCase().slice(1),
75
+ snake: (str: string) => str.replace(/ /g, '_'),
76
+ kebab: (str: string) => str.replace(/ /g, '-'),
77
+ lower: (str: string) => str.toLowerCase(),
78
+ }
79
+ };
80
+
81
+ export const convertCase = <
82
+ TValue extends string,
83
+ To extends Array<Case>,
84
+ Return extends To extends [...Array<Case>, infer To] ? To : Case
85
+ >(
86
+ value: TValue,
87
+ from: Case,
88
+ ...to: To
89
+ ): (
90
+ Return extends 'upper' ? Uppercase<TValue>
91
+ : Return extends 'lower' ? Lowercase<TValue>
92
+ : Return extends 'pascal' ? Capitalize<TValue>
93
+ : Return extends 'camel' ? Uncapitalize<TValue>
94
+ : string
95
+ ) => to.reduce((str, toCase) => caseMap[from][toCase](str), value as string) as any;
@@ -0,0 +1 @@
1
+ export * from './case.extension';
@@ -1,24 +1,6 @@
1
-
2
1
  export * from './Array';
3
- export * from './Document';
2
+ export * from './Function';
4
3
  export * from './Map';
4
+ export * from './Number';
5
5
  export * from './Object';
6
- export * from './String';
7
-
8
- declare global {
9
- interface BooleanConstructor {
10
- /**
11
- * Parses string to boolean. Will only return true if value === "true" otherwise false
12
- */
13
- parseBoolean(value: string): boolean
14
- }
15
- }
16
-
17
- function parseBoolean(value: string) {
18
- return value === "true";
19
- };
20
- Boolean.parseBoolean = parseBoolean;
21
-
22
- export const BooleanExtensions = {
23
- parseBoolean
24
- };
6
+ export * from './String';
@@ -1,9 +1,9 @@
1
- import { Arrayable, IElement } from "../Types"
1
+ import { Arrayable, IElement } from "../Types";
2
2
 
3
3
  type Events = Record<
4
- `on${Capitalize<keyof HTMLElementEventMap>}`,
5
- (event: Event) => void
6
- >
4
+ `on${Capitalize<keyof HTMLElementEventMap>}`,
5
+ (event: Event) => void
6
+ >;
7
7
 
8
8
  /**
9
9
  * Construction options when creating an HTML element using:
@@ -12,10 +12,10 @@ type Events = Record<
12
12
  * @borrows Arrayable
13
13
  */
14
14
  export type ElementOptions = Partial<
15
- Events & Record<string, any> & {
15
+ Events & Record<string, any> & {
16
16
  id: string,
17
17
  className: Arrayable<string>;
18
18
  children: Arrayable<IElement>;
19
- dataset: Record<string, string>
20
- }>
19
+ dataset: Record<string, string>;
20
+ }>;
21
21
  export default ElementOptions;
@@ -7,7 +7,7 @@ import { StringRegex } from "../Types";
7
7
  * @borrows StringRegex
8
8
  */
9
9
  export interface IReplacement {
10
- replacer?: StringRegex,
11
- replacement?: string
10
+ replacer?: StringRegex,
11
+ replacement?: string;
12
12
  }
13
13
  export default IReplacement;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Item is function or T
3
+ */
4
+ export type Functionable<T, Args extends any[] = []> = T | ((...args: Args) => T);
5
+
6
+ /**
7
+ * Item is Promise<T> or T
8
+ */
9
+ export type Promisable<T> = T | Promise<T>;
10
+
11
+ /**
12
+ * Item is T or null
13
+ */
14
+ export type Nullable<T> = T | null;
15
+
16
+ /**
17
+ * Item cannot be null or undefined
18
+ */
19
+ export type NonNullable<T> =
20
+ T extends null ? never :
21
+ T extends undefined ? never :
22
+ T;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Item is single or multiple
3
+ */
4
+ export type Arrayable<T> = T | Array<T>;
5
+
6
+ export type SingleArrayable<T> = T | [T];
7
+ export type TFromArray<T> = T extends Array<infer U> ? U : never;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * C# Guid representation
3
+ */
4
+ export type Guid = string;
5
+
6
+ /**
7
+ * C# TimeSpan representation from JSON
8
+ */
9
+ export type TimeSpanType = string;
package/src/Types/Date.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type LongMonth = 'Janurary' | 'February' | 'March' | 'April' | 'May' | 'June' | 'July' | 'August' | 'September' | 'October' | 'November' | 'December';
1
+ export type LongMonth = 'January' | 'February' | 'March' | 'April' | 'May' | 'June' | 'July' | 'August' | 'September' | 'October' | 'November' | 'December';
2
2
  export type ShortMonth = 'Jan' | 'Feb' | 'Mar' | 'Apr' | 'May' | 'Jun' | 'Jul' | 'Aug' | 'Sep' | 'Oct' | 'Nov' | 'Dec';
3
3
  export type Month = LongMonth | ShortMonth;
4
4
 
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Default eventhandler mapper. Object with properties that are arrays
2
+ * Default event-handler mapper. Object with properties that are arrays
3
3
  */
4
- export type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Types>;
4
+ export type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Types>;
5
5
 
6
- /**
7
- * Eventhandler type for:
8
- * @see EventCollection
9
- * @borrows BaseEvent
10
- */
11
- export type EventHandler<
12
- Events extends BaseEvent<string, Array<any>> = BaseEvent<string, Array<any>>,
13
- Event extends keyof Events = keyof Events,
14
- ReturnType = any
15
- > = (...args: Events[Event]) => ReturnType;
6
+ /**
7
+ * Event-handler type for:
8
+ * @see EventCollection
9
+ * @borrows BaseEvent
10
+ */
11
+ export type EventHandler<
12
+ Events extends BaseEvent<string, Array<any>> = BaseEvent<string, Array<any>>,
13
+ Event extends keyof Events = keyof Events,
14
+ ReturnType = any
15
+ > = (...args: Events[Event]) => ReturnType;
@@ -0,0 +1,10 @@
1
+ export type NewReturnType<
2
+ Function extends (...args: any[]) => any,
3
+ NewReturnType extends any
4
+ > = (...args: Parameters<Function>) => NewReturnType;
5
+
6
+ export type PromisedReturn<
7
+ Function extends (...args: any[]) => any,
8
+ > = NewReturnType<Function, Promise<ReturnType<Function>>>;
9
+
10
+ export type NoFunctions<T> = { [K in keyof T]: T[K] extends Function ? never : T[K]; };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Return types of T
3
+ */
4
+ export type ValueOf<T> = T[keyof T];