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,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluralize = exports.randomId = exports.classNames = void 0;
4
+ function classNames(...args) {
5
+ return args.reduce((acc, arg) => {
6
+ if (!arg)
7
+ return acc;
8
+ switch (typeof arg) {
9
+ case 'string': {
10
+ acc += arg;
11
+ break;
12
+ }
13
+ case 'object': {
14
+ if (Array.isArray(arg)) {
15
+ acc += classNames(...arg);
16
+ break;
17
+ }
18
+ else {
19
+ acc += Object.entries(arg).reduce((objAcc, [key, value]) => objAcc + (value ? key : ''), '');
20
+ break;
21
+ }
22
+ }
23
+ default: {
24
+ acc += `${arg}`;
25
+ break;
26
+ }
27
+ }
28
+ return acc + ' ';
29
+ }, '').trim();
30
+ }
31
+ exports.classNames = classNames;
32
+ function randomId(length = 16) {
33
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
34
+ return Array.from({ length }, () => characters.charAt(Math.floor(Math.random() * characters.length))).join('');
35
+ }
36
+ exports.randomId = randomId;
37
+ function pluralize(countable, singular, plural) {
38
+ const count = (typeof countable === 'number' ? countable
39
+ : countable instanceof Map ? countable.size
40
+ : countable.length);
41
+ if (count === 1)
42
+ return singular;
43
+ if (plural)
44
+ return plural;
45
+ return `${singular}s`;
46
+ }
47
+ exports.pluralize = pluralize;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Delay running the callback until delay milliseconds have passed without the function being called again.
3
+ * If the function is called again before the delay has passed, the timer resets.
4
+ *
5
+ * @param debounceId A unique identifier for the debounce instance. Call with the same ID to reset the timer.
6
+ * @param callback The callback to run after the delay has passed without the function being called again
7
+ * @param delay The delay in milliseconds to wait before running the callback after the last call
8
+ * @param signal Optional AbortSignal to cancel the debounced operation
9
+ * @returns A promise that resolves to the result of the callback when it is eventually called, or rejects if aborted
10
+ */
11
+ export declare function debounce<T>(debounceId: string, callback: () => T, delay: number, signal?: AbortSignal): Promise<T>;
12
+ /**
13
+ * Wrap a callback in a debounce, allowing it to be called multiple times, but only run after the delay has passed without it being called again
14
+ * @param callback The callback to run after the delay has passed without the function being called again
15
+ * @param delay The delay in milliseconds to wait before running the callback after the last call
16
+ * @returns An object containing the debounced function, an AbortController to cancel operations, and the abort method for convenience
17
+ */
18
+ export declare function wrapInDebounce<T>(callback: (...args: T[]) => void, delay: number): {
19
+ debounced: (...args: T[]) => Promise<void>;
20
+ controller: AbortController;
21
+ abort: () => void;
22
+ };
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapInDebounce = exports.debounce = void 0;
4
+ const DebounceManager = {
5
+ timers: new Map(),
6
+ abortListeners: new Map(),
7
+ };
8
+ /**
9
+ * Delay running the callback until delay milliseconds have passed without the function being called again.
10
+ * If the function is called again before the delay has passed, the timer resets.
11
+ *
12
+ * @param debounceId A unique identifier for the debounce instance. Call with the same ID to reset the timer.
13
+ * @param callback The callback to run after the delay has passed without the function being called again
14
+ * @param delay The delay in milliseconds to wait before running the callback after the last call
15
+ * @param signal Optional AbortSignal to cancel the debounced operation
16
+ * @returns A promise that resolves to the result of the callback when it is eventually called, or rejects if aborted
17
+ */
18
+ function debounce(debounceId, callback, delay, signal) {
19
+ const { timers, abortListeners } = DebounceManager;
20
+ // Clean up existing debounce with the same ID
21
+ if (timers.has(debounceId)) {
22
+ clearTimeout(timers.get(debounceId));
23
+ timers.delete(debounceId);
24
+ const existingListener = abortListeners.get(debounceId);
25
+ if (existingListener && signal) {
26
+ signal.removeEventListener('abort', existingListener);
27
+ }
28
+ abortListeners.delete(debounceId);
29
+ }
30
+ const promise = new Promise((resolve, reject) => {
31
+ // Check if already aborted
32
+ if (signal?.aborted) {
33
+ const error = new DOMException('Debounce aborted', 'AbortError');
34
+ reject(error);
35
+ return;
36
+ }
37
+ const timeoutId = setTimeout(() => {
38
+ timers.delete(debounceId);
39
+ abortListeners.delete(debounceId);
40
+ try {
41
+ resolve(callback());
42
+ }
43
+ catch (error) {
44
+ reject(error);
45
+ }
46
+ }, delay);
47
+ timers.set(debounceId, timeoutId);
48
+ // Set up abort listener
49
+ if (signal) {
50
+ const abortListener = () => {
51
+ clearTimeout(timeoutId);
52
+ timers.delete(debounceId);
53
+ abortListeners.delete(debounceId);
54
+ const error = new DOMException('Debounce aborted', 'AbortError');
55
+ reject(error);
56
+ };
57
+ signal.addEventListener('abort', abortListener, { once: true });
58
+ abortListeners.set(debounceId, abortListener);
59
+ }
60
+ });
61
+ return promise;
62
+ }
63
+ exports.debounce = debounce;
64
+ /**
65
+ * Wrap a callback in a debounce, allowing it to be called multiple times, but only run after the delay has passed without it being called again
66
+ * @param callback The callback to run after the delay has passed without the function being called again
67
+ * @param delay The delay in milliseconds to wait before running the callback after the last call
68
+ * @returns An object containing the debounced function, an AbortController to cancel operations, and the abort method for convenience
69
+ */
70
+ function wrapInDebounce(callback, delay) {
71
+ const controller = new AbortController();
72
+ return {
73
+ debounced: (...args) => debounce(Symbol().toString(), () => callback(...args), delay, controller.signal),
74
+ controller,
75
+ abort: () => controller.abort(),
76
+ };
77
+ }
78
+ exports.wrapInDebounce = wrapInDebounce;
@@ -0,0 +1,4 @@
1
+ export declare function wait<T>(time: number): Promise<void>;
2
+ export declare function wait<T>(callback: (...args: any[]) => T, time: number): Promise<T>;
3
+ export declare function getUnixTime(date: Date | string): number;
4
+ export declare function getUnixTime(timestamp: number): number;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUnixTime = exports.wait = void 0;
4
+ function wait(callbackOrTime, time) {
5
+ const callback = typeof callbackOrTime === 'function' ? callbackOrTime : (() => undefined);
6
+ time ??= callbackOrTime;
7
+ return new Promise((resolve, reject) => {
8
+ try {
9
+ setTimeout(() => resolve(callback()), time);
10
+ }
11
+ catch (err) {
12
+ reject(err);
13
+ }
14
+ });
15
+ }
16
+ exports.wait = wait;
17
+ function getUnixTime(arg) {
18
+ const timestamp = typeof arg === 'number' ? arg : new Date(arg).getTime();
19
+ return Math.floor(timestamp / 1000);
20
+ }
21
+ exports.getUnixTime = getUnixTime;
@@ -0,0 +1,15 @@
1
+ export declare const TimeUtils: {
2
+ throttle<T>(throttleId: string, callback: () => T, cooldown: number): T;
3
+ wrapInThrottle<T_1>(callback: (...args: T_1[]) => void, cooldown: number): (...args: T_1[]) => void;
4
+ isThrottleOnCooldown(throttleId: string): boolean;
5
+ debounce<T_2>(debounceId: string, callback: () => T_2, delay: number, signal?: AbortSignal | undefined): Promise<T_2>;
6
+ wrapInDebounce<T_3>(callback: (...args: T_3[]) => void, delay: number): {
7
+ debounced: (...args: T_3[]) => Promise<void>;
8
+ controller: AbortController;
9
+ abort: () => void;
10
+ };
11
+ wait<T_4>(time: number): Promise<void>;
12
+ wait<T_5>(callback: (...args: any[]) => T_5, time: number): Promise<T_5>;
13
+ getUnixTime(date: string | Date): number;
14
+ getUnixTime(timestamp: number): number;
15
+ };
@@ -0,0 +1,34 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.TimeUtils = void 0;
27
+ const Debounce = __importStar(require("./debounce.util"));
28
+ const Functions = __importStar(require("./functions.util"));
29
+ const Throttle = __importStar(require("./throttle.util"));
30
+ exports.TimeUtils = {
31
+ ...Functions,
32
+ ...Debounce,
33
+ ...Throttle,
34
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Allow callback to be run once every cooldown period, regardless of calls
3
+ * @param callback The callback to run
4
+ * @param cooldown The delay to wait before allowing the callback to be called again
5
+ * @returns A throttled version of the callback
6
+ */
7
+ export declare function throttle<T>(throttleId: string, callback: () => T, cooldown: number): T;
8
+ /**
9
+ * Wrap a callback in a throttle, allowing it to be called multiple times, but only run once every cooldown period
10
+ * @param callback The callback to run
11
+ * @param cooldown The delay to wait before allowing the callback to be called again
12
+ * @returns A throttled version of the callback that can be called multiple times, but will only run once every cooldown period
13
+ */
14
+ export declare function wrapInThrottle<T>(callback: (...args: T[]) => void, cooldown: number): (...args: T[]) => void;
15
+ export declare function isThrottleOnCooldown(throttleId: string): boolean;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isThrottleOnCooldown = exports.wrapInThrottle = exports.throttle = void 0;
4
+ const ThrottleManager = {
5
+ cooldowns: new Map(),
6
+ results: new Map(),
7
+ };
8
+ /**
9
+ * Allow callback to be run once every cooldown period, regardless of calls
10
+ * @param callback The callback to run
11
+ * @param cooldown The delay to wait before allowing the callback to be called again
12
+ * @returns A throttled version of the callback
13
+ */
14
+ function throttle(throttleId, callback, cooldown) {
15
+ const { cooldowns, results } = ThrottleManager;
16
+ const isCooldown = cooldowns.get(throttleId) ?? false;
17
+ if (isCooldown)
18
+ return results.get(throttleId);
19
+ const result = callback();
20
+ setTimeout(() => {
21
+ cooldowns.delete(throttleId);
22
+ results.delete(throttleId);
23
+ }, cooldown);
24
+ cooldowns.set(throttleId, true);
25
+ results.set(throttleId, result);
26
+ return result;
27
+ }
28
+ exports.throttle = throttle;
29
+ /**
30
+ * Wrap a callback in a throttle, allowing it to be called multiple times, but only run once every cooldown period
31
+ * @param callback The callback to run
32
+ * @param cooldown The delay to wait before allowing the callback to be called again
33
+ * @returns A throttled version of the callback that can be called multiple times, but will only run once every cooldown period
34
+ */
35
+ function wrapInThrottle(callback, cooldown) {
36
+ const throttleId = Symbol().toString();
37
+ return (...args) => throttle(throttleId, () => callback(...args), cooldown);
38
+ }
39
+ exports.wrapInThrottle = wrapInThrottle;
40
+ function isThrottleOnCooldown(throttleId) {
41
+ return ThrottleManager.cooldowns.get(throttleId) ?? false;
42
+ }
43
+ exports.isThrottleOnCooldown = isThrottleOnCooldown;
@@ -1,2 +1,7 @@
1
- export * from './ApiUtil';
2
- export * from './FormUtil';
1
+ export * from './ApiUtils';
2
+ export * from './TimeUtils';
3
+ export * from './ColorUtils';
4
+ export * from './FormUtils';
5
+ export * from './NumberUtils';
6
+ export * from './PatcherUtils';
7
+ export * from './StringUtils';
@@ -1,18 +1,23 @@
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("./ApiUtil"), exports);
18
- __exportStar(require("./FormUtil"), 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("./ApiUtils"), exports);
18
+ __exportStar(require("./TimeUtils"), exports);
19
+ __exportStar(require("./ColorUtils"), exports);
20
+ __exportStar(require("./FormUtils"), exports);
21
+ __exportStar(require("./NumberUtils"), exports);
22
+ __exportStar(require("./PatcherUtils"), exports);
23
+ __exportStar(require("./StringUtils"), exports);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './Classes';
2
- export * from './Extensions';
3
- export * from './Functions';
4
- export * from './Interfaces';
5
- export * from './Types';
1
+ export * from './Classes';
2
+ export * from './Extensions';
3
+ export * from './Functions';
4
+ export * from './Interfaces';
5
+ export * from './Types';
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
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("./Classes"), exports);
18
- __exportStar(require("./Extensions"), exports);
19
- __exportStar(require("./Functions"), exports);
20
- __exportStar(require("./Interfaces"), exports);
21
- __exportStar(require("./Types"), 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("./Classes"), exports);
18
+ __exportStar(require("./Extensions"), exports);
19
+ __exportStar(require("./Functions"), exports);
20
+ __exportStar(require("./Interfaces"), exports);
21
+ __exportStar(require("./Types"), exports);
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
-
3
2
  "name": "danholibraryjs",
4
- "version": "1.11.0",
3
+ "publishConfig": {
4
+ "registry": "https://registry.npmjs.org/"
5
+ },
6
+ "version": "2.0.0",
5
7
  "description": "Library for Javascript.",
6
8
  "main": "dist/index.js",
7
9
  "types": "dist/index.d.ts",
@@ -0,0 +1,78 @@
1
+ type LogOptions = {
2
+ name?: string;
3
+ color?: string;
4
+ preferCollapsed?: boolean;
5
+ }
6
+
7
+ export default class DanhoLogger {
8
+ public name: string;
9
+ public color?: string
10
+ private _preferCollapsed: boolean;
11
+
12
+ constructor(options: LogOptions = {}) {
13
+ this.name = options.name || 'DanhoLogger';
14
+ this.color = options.color;
15
+ this._preferCollapsed = options.preferCollapsed ?? false;
16
+ }
17
+
18
+ private _getPrefix() {
19
+ return {
20
+ prefix: `%c[${this.name}]`,
21
+ style: `color: ${this.color || 'inherit'}; font-weight: bold;`
22
+ };
23
+ }
24
+ private _log(
25
+ type: 'log' | 'warn' | 'error',
26
+ ...args: any[]
27
+ ) {
28
+ const { prefix, style } = this._getPrefix();
29
+ console[type](prefix, style, ...args);
30
+ return this;
31
+ }
32
+
33
+ public log(...args: any[]) {
34
+ return this._log('log', ...args);
35
+ }
36
+ public warn(...args: any[]) {
37
+ return this._log('warn', ...args);
38
+ }
39
+ public error(...args: any[]) {
40
+ return this._log('error', ...args);
41
+ }
42
+
43
+ public group(...args: any[]) {
44
+ const { prefix, style } = this._getPrefix();
45
+
46
+ const groupMethod = this._preferCollapsed ? console.groupCollapsed : console.group;
47
+ groupMethod(prefix, style, ...args);
48
+
49
+ return this;
50
+ }
51
+ public groupCollapsed(...args: any[]) {
52
+ const { prefix, style } = this._getPrefix();
53
+ console.groupCollapsed(prefix, style, ...args);
54
+ return this;
55
+ }
56
+ public groupEnd(...args: any[]) {
57
+ if (args.length) console.log(...args);
58
+ console.groupEnd();
59
+ return this;
60
+ }
61
+
62
+ time(label: string) {
63
+ const { prefix } = this._getPrefix();
64
+ console.time(`${prefix} ${label}`);
65
+ return this;
66
+ }
67
+ timeEnd(label: string) {
68
+ const { prefix } = this._getPrefix();
69
+ console.timeEnd(`${prefix} ${label}`);
70
+ return this;
71
+ }
72
+
73
+ table(data: any, columns?: string[]) {
74
+ this.log();
75
+ console.table(data, columns);
76
+ return this;
77
+ }
78
+ }