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
@@ -1,52 +1,52 @@
1
- export type UpdateFinder<T> = (item: T, index: number, self: Array<T>) => boolean;
2
- declare global {
3
- interface Array<T> {
4
- /**
5
- * Pushes items to array and returns self with new items
6
- * @param items Items to add to array
7
- */
8
- add(...items: Array<T>): this;
9
- /**
10
- * Update an item in array
11
- * @param old The old value or index to update
12
- * @param updated Updated value
13
- */
14
- update(old: T | number | UpdateFinder<T>, updated: T): T;
15
- /**
16
- * Removes item from array and returns self without item
17
- * @param item Item or index to remove
18
- */
19
- remove(item: T | number): this;
20
- /**
21
- * Returns a random element from array
22
- */
23
- random(): T;
24
- /**
25
- * Returns item matching index. If negative number, subtracts number from length
26
- * @param i Index of item
27
- */
28
- index(i: number): T;
29
- /**
30
- * For every x in array, execute callback
31
- * @param every i.e every 2nd item in array
32
- * @param callback Function to execute
33
- * @returns Array of results
34
- */
35
- nth<U>(every: number, callback: (item: T, index: number, collection: Array<T>, self: this) => U): Array<U>;
36
- }
37
- }
38
- declare function add<T>(this: Array<T>, ...items: Array<T>): T[];
39
- declare function update<T>(this: Array<T>, old: T | number | UpdateFinder<T>, updated: T): T;
40
- declare function remove<T>(this: Array<T>, value: T | number): Array<T>;
41
- declare function random<T>(this: Array<T>): T;
42
- declare function index<T>(this: Array<T>, i: number): T;
43
- declare function nth<T, U>(this: Array<T>, every: number, callback: (item: T, index: number, collection: Array<T>, self: Array<T>) => U): Array<U>;
44
- export declare const ArrayExtensions: {
45
- add: typeof add;
46
- update: typeof update;
47
- remove: typeof remove;
48
- random: typeof random;
49
- index: typeof index;
50
- nth: typeof nth;
51
- };
52
- export {};
1
+ export type UpdateFinder<T> = (item: T, index: number, self: Array<T>) => boolean;
2
+ declare global {
3
+ interface Array<T> {
4
+ /**
5
+ * Pushes items to array and returns self with new items
6
+ * @param items Items to add to array
7
+ */
8
+ add(...items: Array<T>): this;
9
+ /**
10
+ * Update an item in array
11
+ * @param old The old value or index to update
12
+ * @param updated Updated value
13
+ */
14
+ update(old: T | number | UpdateFinder<T>, updated: T): T;
15
+ /**
16
+ * Removes item from array and returns self without item
17
+ * @param item Item or index to remove
18
+ */
19
+ remove(item: T | number): this;
20
+ /**
21
+ * Returns a random element from array
22
+ */
23
+ random(): T;
24
+ /**
25
+ * Returns item matching index. If negative number, subtracts number from length
26
+ * @param i Index of item
27
+ */
28
+ index(i: number): T;
29
+ /**
30
+ * For every x in array, execute callback
31
+ * @param every i.e every 2nd item in array
32
+ * @param callback Function to execute
33
+ * @returns Array of results
34
+ */
35
+ nth<U>(every: number, callback: (item: T, index: number, collection: Array<T>, self: this) => U): Array<U>;
36
+ }
37
+ }
38
+ declare function add<T>(this: Array<T>, ...items: Array<T>): T[];
39
+ declare function update<T>(this: Array<T>, old: T | number | UpdateFinder<T>, updated: T): T;
40
+ declare function remove<T>(this: Array<T>, value: T | number): Array<T>;
41
+ declare function random<T>(this: Array<T>): T;
42
+ declare function index<T>(this: Array<T>, i: number): T;
43
+ declare function nth<T, U>(this: Array<T>, every: number, callback: (item: T, index: number, collection: Array<T>, self: Array<T>) => U): Array<U>;
44
+ export declare const ArrayExtensions: {
45
+ add: typeof add;
46
+ update: typeof update;
47
+ remove: typeof remove;
48
+ random: typeof random;
49
+ index: typeof index;
50
+ nth: typeof nth;
51
+ };
52
+ export {};
@@ -1,51 +1,51 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayExtensions = void 0;
4
- function add(...items) {
5
- this.push(...items);
6
- return this;
7
- }
8
- Array.prototype.add = add;
9
- function update(old, updated) {
10
- const item = typeof old === 'number' ? this[old]
11
- : typeof old === 'function' ? this.find(old)
12
- : old;
13
- if (!item)
14
- throw new Error('Old was not found in array!');
15
- const index = this.indexOf(item);
16
- return this[index] = updated;
17
- }
18
- Array.prototype.update = update;
19
- function remove(value) {
20
- const index = typeof value === 'number' ? value : this.indexOf(value);
21
- if (index > -1)
22
- this.splice(index, 1);
23
- return this;
24
- }
25
- Array.prototype.remove = remove;
26
- function random() {
27
- const randomIndex = Math.round(Math.random() * this.length);
28
- return this[randomIndex];
29
- }
30
- Array.prototype.random = random;
31
- function index(i) {
32
- return this[i < 0 ? this.length + i : i];
33
- }
34
- Array.prototype.index = index;
35
- function nth(every, callback) {
36
- const result = new Array();
37
- let collection = new Array();
38
- for (let i = 0; i < this.length; i++) {
39
- collection.push(this[i]);
40
- if (i % every === 0) {
41
- result.push(callback(this[i], i, collection, this));
42
- collection = new Array();
43
- }
44
- }
45
- return result;
46
- }
47
- Array.prototype.nth = nth;
48
- exports.ArrayExtensions = {
49
- add, update, remove,
50
- random, index, nth
51
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArrayExtensions = void 0;
4
+ function add(...items) {
5
+ this.push(...items);
6
+ return this;
7
+ }
8
+ Array.prototype.add = add;
9
+ function update(old, updated) {
10
+ const item = typeof old === 'number' ? this[old]
11
+ : typeof old === 'function' ? this.find(old)
12
+ : old;
13
+ if (!item)
14
+ throw new Error('Old was not found in array!');
15
+ const index = this.indexOf(item);
16
+ return this[index] = updated;
17
+ }
18
+ Array.prototype.update = update;
19
+ function remove(value) {
20
+ const index = typeof value === 'number' ? value : this.indexOf(value);
21
+ if (index > -1)
22
+ this.splice(index, 1);
23
+ return this;
24
+ }
25
+ Array.prototype.remove = remove;
26
+ function random() {
27
+ const randomIndex = Math.round(Math.random() * this.length);
28
+ return this[randomIndex];
29
+ }
30
+ Array.prototype.random = random;
31
+ function index(i) {
32
+ return this[i < 0 ? this.length + i : i];
33
+ }
34
+ Array.prototype.index = index;
35
+ function nth(every, callback) {
36
+ const result = new Array();
37
+ let collection = new Array();
38
+ for (let i = 0; i < this.length; i++) {
39
+ collection.push(this[i]);
40
+ if (i % every === 0) {
41
+ result.push(callback(this[i], i, collection, this));
42
+ collection = new Array();
43
+ }
44
+ }
45
+ return result;
46
+ }
47
+ Array.prototype.nth = nth;
48
+ exports.ArrayExtensions = {
49
+ add, update, remove,
50
+ random, index, nth
51
+ };
@@ -1,27 +1,27 @@
1
- import { IElement } from "../Types";
2
- declare global {
3
- interface Document {
4
- /**
5
- * Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
6
- * @param tagName HTMLElement tag name
7
- * @param options Construction options, instead of assigning values after construction
8
- * @param children Child elements
9
- */
10
- createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]>, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
11
- createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
12
- createElementFromString<K extends keyof HTMLElementTagNameMap>(html: string, parentTag?: K): HTMLElementTagNameMap[K];
13
- }
14
- interface HTMLCollection {
15
- /**
16
- * Converts HTMLCollection to Element[]
17
- */
18
- array(): Element[];
19
- }
20
- }
21
- declare function createElement<Tag extends keyof HTMLElementTagNameMap>(this: Document, tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]> | string, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
22
- declare function createElementFromString<Tag extends keyof HTMLElementTagNameMap>(this: Document, html: string, tag?: Tag): HTMLElementTagNameMap[Tag];
23
- export declare const DocumentExtensions: {
24
- createElement: typeof createElement;
25
- createElementFromString: typeof createElementFromString;
26
- };
27
- export {};
1
+ import { IElement } from "../Types";
2
+ declare global {
3
+ interface Document {
4
+ /**
5
+ * Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
6
+ * @param tagName HTMLElement tag name
7
+ * @param options Construction options, instead of assigning values after construction
8
+ * @param children Child elements
9
+ */
10
+ createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]>, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
11
+ createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
12
+ createElementFromString<K extends keyof HTMLElementTagNameMap>(html: string, parentTag?: K): HTMLElementTagNameMap[K];
13
+ }
14
+ interface HTMLCollection {
15
+ /**
16
+ * Converts HTMLCollection to Element[]
17
+ */
18
+ array(): Element[];
19
+ }
20
+ }
21
+ declare function createElement<Tag extends keyof HTMLElementTagNameMap>(this: Document, tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]> | string, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
22
+ declare function createElementFromString<Tag extends keyof HTMLElementTagNameMap>(this: Document, html: string, tag?: Tag): HTMLElementTagNameMap[Tag];
23
+ export declare const DocumentExtensions: {
24
+ createElement: typeof createElement;
25
+ createElementFromString: typeof createElementFromString;
26
+ };
27
+ export {};
@@ -1,32 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentExtensions = void 0;
4
- function createElement(tagName, options, ...children) {
5
- const element = Object.assign(document.createElement(tagName), typeof options === 'string' ? {} : options);
6
- children ??= typeof options === 'string' ? [options] : [];
7
- typeof options === 'string' && children.unshift(options);
8
- if (!children.length)
9
- return element;
10
- else if (typeof children === 'string')
11
- element.innerHTML = children;
12
- else if (children instanceof Array)
13
- children.forEach(child => (typeof child === 'string' ?
14
- element.innerHTML += child :
15
- element.appendChild(child)));
16
- else
17
- element.appendChild(children);
18
- return element;
19
- }
20
- Document.prototype.createProperElement = createElement;
21
- function createElementFromString(html, tag) {
22
- if (!html.startsWith(`<${tag}`))
23
- html = `<${tag}>${html}</${tag}>`;
24
- return new DOMParser().parseFromString(html, 'text/html').body.firstElementChild;
25
- }
26
- Document.prototype.createElementFromString = createElementFromString;
27
- HTMLCollection.prototype.array = function () {
28
- return Array.from(this);
29
- };
30
- exports.DocumentExtensions = {
31
- createElement, createElementFromString
32
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentExtensions = void 0;
4
+ function createElement(tagName, options, ...children) {
5
+ const element = Object.assign(document.createElement(tagName), typeof options === 'string' ? {} : options);
6
+ children ??= typeof options === 'string' ? [options] : [];
7
+ typeof options === 'string' && children.unshift(options);
8
+ if (!children.length)
9
+ return element;
10
+ else if (typeof children === 'string')
11
+ element.innerHTML = children;
12
+ else if (children instanceof Array)
13
+ children.forEach(child => (typeof child === 'string' ?
14
+ element.innerHTML += child :
15
+ element.appendChild(child)));
16
+ else
17
+ element.appendChild(children);
18
+ return element;
19
+ }
20
+ Document.prototype.createProperElement = createElement;
21
+ function createElementFromString(html, tag) {
22
+ if (!html.startsWith(`<${tag}`))
23
+ html = `<${tag}>${html}</${tag}>`;
24
+ return new DOMParser().parseFromString(html, 'text/html').body.firstElementChild;
25
+ }
26
+ Document.prototype.createElementFromString = createElementFromString;
27
+ HTMLCollection.prototype.array = function () {
28
+ return Array.from(this);
29
+ };
30
+ exports.DocumentExtensions = {
31
+ createElement, createElementFromString
32
+ };
@@ -1,14 +1,29 @@
1
- declare global {
2
- interface Function {
3
- /**
4
- * Checks if obj is a function
5
- * @param obj Object to check
6
- */
7
- is(obj: any): obj is Function;
8
- }
9
- }
10
- declare function is(obj: any): obj is Function;
11
- export declare const FunctionExtensions: {
12
- is: typeof is;
13
- };
14
- export {};
1
+ import { Functionable } from "../Types";
2
+ declare global {
3
+ interface Function {
4
+ /**
5
+ * Checks if obj is a function
6
+ * @param obj Object to check
7
+ */
8
+ is(obj: any): obj is Function;
9
+ /**
10
+ * Resolves a Functionable<T> to T, if it's a function, it will be called with the provided arguments and its return value will be returned, otherwise the value itself will be returned.
11
+ * @param functionable The Functionable<T> to resolve
12
+ * @param args Arguments to call the function with if functionable is a function
13
+ */
14
+ resolveFunctionable<T, TArgs extends any[] = any[]>(functionable: Functionable<T, TArgs>, ...args: TArgs): T;
15
+ /**
16
+ * Forces a Functionable<T> to be a function, if it's already a function, it will be returned as is, otherwise a function that returns the value will be returned.
17
+ * @param functionable The Functionable<T> to force to be a function
18
+ */
19
+ forceFunction<T, TArgs extends any[] = any[]>(functionable: Functionable<T, TArgs>): (...args: TArgs) => T;
20
+ }
21
+ }
22
+ export declare function is(obj: any): obj is Function;
23
+ export declare function resolveFunctionable<T, TArgs extends any[] = any[]>(functionable: Functionable<T, TArgs>, ...args: TArgs): T;
24
+ export declare function forceFunction<T, TArgs extends any[] = any[]>(functionable: Functionable<T, TArgs>): (...args: TArgs) => T;
25
+ export declare const FunctionExtensions: {
26
+ is: typeof is;
27
+ resolveFunctionable: typeof resolveFunctionable;
28
+ forceFunction: typeof forceFunction;
29
+ };
@@ -1,10 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FunctionExtensions = void 0;
4
- function is(obj) {
5
- return typeof obj === 'function';
6
- }
7
- Function.is = is;
8
- exports.FunctionExtensions = {
9
- is
10
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionExtensions = exports.forceFunction = exports.resolveFunctionable = exports.is = void 0;
4
+ function is(obj) {
5
+ return typeof obj === 'function';
6
+ }
7
+ exports.is = is;
8
+ Function.is = is;
9
+ function resolveFunctionable(functionable, ...args) {
10
+ return is(functionable) ? functionable(...args) : functionable;
11
+ }
12
+ exports.resolveFunctionable = resolveFunctionable;
13
+ Function.resolveFunctionable = resolveFunctionable;
14
+ function forceFunction(functionable) {
15
+ return is(functionable) ? functionable : () => functionable;
16
+ }
17
+ exports.forceFunction = forceFunction;
18
+ Function.forceFunction = forceFunction;
19
+ exports.FunctionExtensions = {
20
+ is,
21
+ resolveFunctionable,
22
+ forceFunction
23
+ };
@@ -1,54 +1,54 @@
1
- declare global {
2
- interface Map<K, V> {
3
- /**
4
- * Converts into Array<[Key, Value]>
5
- */
6
- array(): Array<[K, V]>;
7
- /**
8
- * Maps values into new types of generics
9
- * @param callback Callbacking function to map values
10
- */
11
- map<EK, EV>(callback: (value: V, key: K, index: number, self: this) => [EK, EV]): Map<EK, EV>;
12
- /**
13
- * Returns array of "accepted" values. Criteria defined in callback param
14
- * @param callback Callbacking function to filter away unwanted values
15
- */
16
- filter(callback: (value: V, key: K, index: number, self: this) => boolean): Map<K, V>;
17
- /**
18
- * Returns array of keys
19
- */
20
- keyArr(): Array<K>;
21
- /**
22
- * Returns array of values
23
- */
24
- valueArr(): Array<V>;
25
- /**
26
- * Returns first [key, value] match to callback param. Returns undefined if nothing found
27
- * @param callback Callbacking function to find KeyValuePair
28
- */
29
- find(callback: (value: V, key: K, index: number, self: this) => boolean): [K, V] | undefined;
30
- /**
31
- * Whether or not map includes a value. Returns true if it does, false if not ¯\_(ツ)_/¯
32
- * @param value Value that may be includded in map
33
- * @param fromIndex Start looking for value from specific index+. Default: 0
34
- */
35
- includes(value: V, fromIndex?: number): boolean;
36
- }
37
- }
38
- declare function array<K, V>(this: Map<K, V>): Array<[K, V]>;
39
- declare function map<K, V, EK, EV>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => [EK, EV]): Map<EK, EV>;
40
- declare function filter<K, V>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => boolean): Map<K, V>;
41
- declare function keyArr<K, V>(this: Map<K, V>): Array<K>;
42
- declare function valueArr<K, V>(this: Map<K, V>): Array<V>;
43
- declare function find<K, V>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => boolean): [K, V] | undefined;
44
- declare function includes<K, V>(this: Map<K, V>, item: V, fromIndex?: number): boolean;
45
- export declare const MapExtensions: {
46
- array: typeof array;
47
- map: typeof map;
48
- filter: typeof filter;
49
- keyArr: typeof keyArr;
50
- valueArr: typeof valueArr;
51
- find: typeof find;
52
- includes: typeof includes;
53
- };
54
- export {};
1
+ declare global {
2
+ interface Map<K, V> {
3
+ /**
4
+ * Converts into Array<[Key, Value]>
5
+ */
6
+ array(): Array<[K, V]>;
7
+ /**
8
+ * Maps values into new types of generics
9
+ * @param callback Callbacking function to map values
10
+ */
11
+ map<EK, EV>(callback: (value: V, key: K, index: number, self: this) => [EK, EV]): Map<EK, EV>;
12
+ /**
13
+ * Returns array of "accepted" values. Criteria defined in callback param
14
+ * @param callback Callbacking function to filter away unwanted values
15
+ */
16
+ filter(callback: (value: V, key: K, index: number, self: this) => boolean): Map<K, V>;
17
+ /**
18
+ * Returns array of keys
19
+ */
20
+ keyArr(): Array<K>;
21
+ /**
22
+ * Returns array of values
23
+ */
24
+ valueArr(): Array<V>;
25
+ /**
26
+ * Returns first [key, value] match to callback param. Returns undefined if nothing found
27
+ * @param callback Callbacking function to find KeyValuePair
28
+ */
29
+ find(callback: (value: V, key: K, index: number, self: this) => boolean): [K, V] | undefined;
30
+ /**
31
+ * Whether or not map includes a value. Returns true if it does, false if not ¯\_(ツ)_/¯
32
+ * @param value Value that may be includded in map
33
+ * @param fromIndex Start looking for value from specific index+. Default: 0
34
+ */
35
+ includes(value: V, fromIndex?: number): boolean;
36
+ }
37
+ }
38
+ declare function array<K, V>(this: Map<K, V>): Array<[K, V]>;
39
+ declare function map<K, V, EK, EV>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => [EK, EV]): Map<EK, EV>;
40
+ declare function filter<K, V>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => boolean): Map<K, V>;
41
+ declare function keyArr<K, V>(this: Map<K, V>): Array<K>;
42
+ declare function valueArr<K, V>(this: Map<K, V>): Array<V>;
43
+ declare function find<K, V>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => boolean): [K, V] | undefined;
44
+ declare function includes<K, V>(this: Map<K, V>, item: V, fromIndex?: number): boolean;
45
+ export declare const MapExtensions: {
46
+ array: typeof array;
47
+ map: typeof map;
48
+ filter: typeof filter;
49
+ keyArr: typeof keyArr;
50
+ valueArr: typeof valueArr;
51
+ find: typeof find;
52
+ includes: typeof includes;
53
+ };
54
+ export {};
@@ -1,42 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MapExtensions = void 0;
4
- function array() {
5
- let result = new Array();
6
- for (const kvp of this) {
7
- result.push(kvp);
8
- }
9
- return result;
10
- }
11
- Map.prototype.array = array;
12
- function map(callback) {
13
- return this.array()
14
- .map(([k, v], i) => callback(v, k, i, this))
15
- .reduce((map, [key, value]) => map.set(key, value), new Map());
16
- }
17
- Map.prototype.map = map;
18
- function filter(callback) {
19
- return this.array()
20
- .filter(([k, v], i) => callback(v, k, i, this))
21
- .reduce((map, [key, value]) => map.set(key, value), new Map());
22
- }
23
- Map.prototype.filter = filter;
24
- function keyArr() {
25
- return this.array().map(([k]) => k);
26
- }
27
- Map.prototype.keyArr = keyArr;
28
- function valueArr() {
29
- return this.array().map(([_, v]) => v);
30
- }
31
- Map.prototype.valueArr = valueArr;
32
- function find(callback) {
33
- return this.array().find(([k, v], i) => callback(v, k, i, this));
34
- }
35
- Map.prototype.find = find;
36
- function includes(item, fromIndex) {
37
- return this.valueArr().includes(item, fromIndex);
38
- }
39
- Map.prototype.includes = includes;
40
- exports.MapExtensions = {
41
- array, map, filter, keyArr, valueArr, find, includes
42
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MapExtensions = void 0;
4
+ function array() {
5
+ let result = new Array();
6
+ for (const kvp of this) {
7
+ result.push(kvp);
8
+ }
9
+ return result;
10
+ }
11
+ Map.prototype.array = array;
12
+ function map(callback) {
13
+ return this.array()
14
+ .map(([k, v], i) => callback(v, k, i, this))
15
+ .reduce((map, [key, value]) => map.set(key, value), new Map());
16
+ }
17
+ Map.prototype.map = map;
18
+ function filter(callback) {
19
+ return this.array()
20
+ .filter(([k, v], i) => callback(v, k, i, this))
21
+ .reduce((map, [key, value]) => map.set(key, value), new Map());
22
+ }
23
+ Map.prototype.filter = filter;
24
+ function keyArr() {
25
+ return this.array().map(([k]) => k);
26
+ }
27
+ Map.prototype.keyArr = keyArr;
28
+ function valueArr() {
29
+ return this.array().map(([_, v]) => v);
30
+ }
31
+ Map.prototype.valueArr = valueArr;
32
+ function find(callback) {
33
+ return this.array().find(([k, v], i) => callback(v, k, i, this));
34
+ }
35
+ Map.prototype.find = find;
36
+ function includes(item, fromIndex) {
37
+ return this.valueArr().includes(item, fromIndex);
38
+ }
39
+ Map.prototype.includes = includes;
40
+ exports.MapExtensions = {
41
+ array, map, filter, keyArr, valueArr, find, includes
42
+ };
@@ -0,0 +1,13 @@
1
+ type Separators = {
2
+ thousand: string;
3
+ decimal: string;
4
+ };
5
+ declare global {
6
+ interface Number {
7
+ toSeparationString(separators: Partial<Separators>): string;
8
+ toRomanNumeral(): string;
9
+ }
10
+ }
11
+ export declare function toSeparationString(this: number, separators: Partial<Separators>): string;
12
+ export declare function toRomanNumeral(this: number): string;
13
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRomanNumeral = exports.toSeparationString = void 0;
4
+ function toSeparationString(separators) {
5
+ const { thousand = '.', decimal = '.' } = separators;
6
+ const [integerPart, decimalPart] = this.toString().split('.');
7
+ const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, thousand);
8
+ return decimalPart ? `${formattedInteger}${decimal}${decimalPart}` : formattedInteger;
9
+ }
10
+ exports.toSeparationString = toSeparationString;
11
+ Number.prototype.toSeparationString = toSeparationString;
12
+ function toRomanNumeral() {
13
+ if (this <= 0 || this >= 4000)
14
+ throw new RangeError('Number must be between 1 and 3999 to convert to Roman numeral');
15
+ const numeralMap = [
16
+ [1000, 'M'],
17
+ [900, 'CM'],
18
+ [500, 'D'],
19
+ [400, 'CD'],
20
+ [100, 'C'],
21
+ [90, 'XC'],
22
+ [50, 'L'],
23
+ [40, 'XL'],
24
+ [10, 'X'],
25
+ [9, 'IX'],
26
+ [5, 'V'],
27
+ [4, 'IV'],
28
+ [1, 'I']
29
+ ];
30
+ let value = this;
31
+ return numeralMap.reduce((acc, [numeralValue, numeral]) => {
32
+ while (value >= numeralValue) {
33
+ acc += numeral;
34
+ value -= numeralValue;
35
+ }
36
+ return acc;
37
+ }, '');
38
+ }
39
+ exports.toRomanNumeral = toRomanNumeral;
40
+ Number.prototype.toRomanNumeral = toRomanNumeral;