@develia/commons 0.4.24 → 0.4.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.d.ts.map +1 -0
- package/dist/array.js.map +1 -0
- package/dist/async-pool-executor.d.ts.map +1 -0
- package/dist/async-pool-executor.js.map +1 -0
- package/dist/browser/form-utilities.d.ts.map +1 -0
- package/dist/browser/form-utilities.js.map +1 -0
- package/dist/browser/geo-location.d.ts.map +1 -0
- package/dist/browser/geo-location.js.map +1 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/native-bridge.d.ts.map +1 -0
- package/dist/browser/native-bridge.js.map +1 -0
- package/dist/cancellable-promise.d.ts.map +1 -0
- package/dist/cancellable-promise.js.map +1 -0
- package/dist/clean-url-search-params.d.ts.map +1 -0
- package/dist/clean-url-search-params.js.map +1 -0
- package/dist/collections/cache-dictionary.d.ts.map +1 -0
- package/dist/collections/cache-dictionary.js.map +1 -0
- package/dist/collections/default-map.d.ts.map +1 -0
- package/dist/collections/default-map.js.map +1 -0
- package/dist/collections/default-weak-map.d.ts.map +1 -0
- package/dist/collections/default-weak-map.js.map +1 -0
- package/dist/{types/collections → collections}/from.d.ts +15 -6
- package/dist/collections/from.d.ts.map +1 -0
- package/dist/{esm/collections → collections}/from.js +4 -10
- package/dist/collections/from.js.map +1 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/debouncer.d.ts.map +1 -0
- package/dist/debouncer.js.map +1 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js.map +1 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/key-value-pair.d.ts.map +1 -0
- package/dist/key-value-pair.js.map +1 -0
- package/dist/keyed-debouncer.d.ts.map +1 -0
- package/dist/keyed-debouncer.js.map +1 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js.map +1 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js.map +1 -0
- package/dist/order.d.ts.map +1 -0
- package/dist/order.js.map +1 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js.map +1 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js.map +1 -0
- package/dist/range.d.ts.map +1 -0
- package/dist/range.js.map +1 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js.map +1 -0
- package/dist/stopwatch.d.ts.map +1 -0
- package/dist/stopwatch.js.map +1 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js.map +1 -0
- package/dist/timer.d.ts.map +1 -0
- package/dist/timer.js.map +1 -0
- package/dist/timespan.d.ts.map +1 -0
- package/dist/timespan.js.map +1 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js.map +1 -0
- package/dist/type-code.d.ts.map +1 -0
- package/dist/type-code.js.map +1 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js.map +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js.map +1 -0
- package/dist/{types/utilities.d.ts → utilities.d.ts} +4 -3
- package/dist/utilities.d.ts.map +1 -0
- package/dist/{web/utilities.js → utilities.js} +4 -3
- package/dist/utilities.js.map +1 -0
- package/package.json +13 -62
- package/src/collections/from.ts +21 -11
- package/src/utilities.ts +5 -4
- package/dist/cjs/array.js +0 -106
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/async-pool-executor.js +0 -79
- package/dist/cjs/async-pool-executor.js.map +0 -1
- package/dist/cjs/browser/form-utilities.js +0 -162
- package/dist/cjs/browser/form-utilities.js.map +0 -1
- package/dist/cjs/browser/geo-location.js +0 -78
- package/dist/cjs/browser/geo-location.js.map +0 -1
- package/dist/cjs/browser/index.js +0 -99
- package/dist/cjs/browser/index.js.map +0 -1
- package/dist/cjs/browser/native-bridge.js +0 -81
- package/dist/cjs/browser/native-bridge.js.map +0 -1
- package/dist/cjs/cancellable-promise.js +0 -81
- package/dist/cjs/cancellable-promise.js.map +0 -1
- package/dist/cjs/clean-url-search-params.js +0 -34
- package/dist/cjs/clean-url-search-params.js.map +0 -1
- package/dist/cjs/collections/cache-dictionary.js +0 -102
- package/dist/cjs/collections/cache-dictionary.js.map +0 -1
- package/dist/cjs/collections/default-map.js +0 -45
- package/dist/cjs/collections/default-map.js.map +0 -1
- package/dist/cjs/collections/default-weak-map.js +0 -46
- package/dist/cjs/collections/default-weak-map.js.map +0 -1
- package/dist/cjs/collections/from.js +0 -778
- package/dist/cjs/collections/from.js.map +0 -1
- package/dist/cjs/collections/index.js +0 -15
- package/dist/cjs/collections/index.js.map +0 -1
- package/dist/cjs/debouncer.js +0 -121
- package/dist/cjs/debouncer.js.map +0 -1
- package/dist/cjs/draft.js +0 -225
- package/dist/cjs/draft.js.map +0 -1
- package/dist/cjs/event-bus.js +0 -71
- package/dist/cjs/event-bus.js.map +0 -1
- package/dist/cjs/functions.js +0 -262
- package/dist/cjs/functions.js.map +0 -1
- package/dist/cjs/index.js +0 -84
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/key-value-pair.js +0 -22
- package/dist/cjs/key-value-pair.js.map +0 -1
- package/dist/cjs/keyed-debouncer.js +0 -144
- package/dist/cjs/keyed-debouncer.js.map +0 -1
- package/dist/cjs/lazy.js +0 -29
- package/dist/cjs/lazy.js.map +0 -1
- package/dist/cjs/math.js +0 -37
- package/dist/cjs/math.js.map +0 -1
- package/dist/cjs/order.js +0 -9
- package/dist/cjs/order.js.map +0 -1
- package/dist/cjs/parse.js +0 -174
- package/dist/cjs/parse.js.map +0 -1
- package/dist/cjs/patch.js +0 -52
- package/dist/cjs/patch.js.map +0 -1
- package/dist/cjs/range.js +0 -154
- package/dist/cjs/range.js.map +0 -1
- package/dist/cjs/result.js +0 -3
- package/dist/cjs/result.js.map +0 -1
- package/dist/cjs/stopwatch.js +0 -46
- package/dist/cjs/stopwatch.js.map +0 -1
- package/dist/cjs/string.js +0 -154
- package/dist/cjs/string.js.map +0 -1
- package/dist/cjs/timer.js +0 -57
- package/dist/cjs/timer.js.map +0 -1
- package/dist/cjs/timespan.js +0 -367
- package/dist/cjs/timespan.js.map +0 -1
- package/dist/cjs/triggers.js +0 -103
- package/dist/cjs/triggers.js.map +0 -1
- package/dist/cjs/type-code.js +0 -18
- package/dist/cjs/type-code.js.map +0 -1
- package/dist/cjs/type.js +0 -296
- package/dist/cjs/type.js.map +0 -1
- package/dist/cjs/types.js +0 -3
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/utilities.js +0 -621
- package/dist/cjs/utilities.js.map +0 -1
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/async-pool-executor.js.map +0 -1
- package/dist/esm/browser/form-utilities.js.map +0 -1
- package/dist/esm/browser/geo-location.js.map +0 -1
- package/dist/esm/browser/index.js.map +0 -1
- package/dist/esm/browser/native-bridge.js.map +0 -1
- package/dist/esm/cancellable-promise.js.map +0 -1
- package/dist/esm/clean-url-search-params.js.map +0 -1
- package/dist/esm/collections/cache-dictionary.js.map +0 -1
- package/dist/esm/collections/default-map.js.map +0 -1
- package/dist/esm/collections/default-weak-map.js.map +0 -1
- package/dist/esm/collections/from.js.map +0 -1
- package/dist/esm/collections/index.js.map +0 -1
- package/dist/esm/debouncer.js.map +0 -1
- package/dist/esm/draft.js.map +0 -1
- package/dist/esm/event-bus.js.map +0 -1
- package/dist/esm/functions.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/key-value-pair.js.map +0 -1
- package/dist/esm/keyed-debouncer.js.map +0 -1
- package/dist/esm/lazy.js.map +0 -1
- package/dist/esm/math.js.map +0 -1
- package/dist/esm/order.js.map +0 -1
- package/dist/esm/parse.js.map +0 -1
- package/dist/esm/patch.js.map +0 -1
- package/dist/esm/range.js.map +0 -1
- package/dist/esm/result.js.map +0 -1
- package/dist/esm/stopwatch.js.map +0 -1
- package/dist/esm/string.js.map +0 -1
- package/dist/esm/timer.js.map +0 -1
- package/dist/esm/timespan.js.map +0 -1
- package/dist/esm/triggers.js.map +0 -1
- package/dist/esm/type-code.js.map +0 -1
- package/dist/esm/type.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utilities.js +0 -590
- package/dist/esm/utilities.js.map +0 -1
- package/dist/types/array.d.ts.map +0 -1
- package/dist/types/async-pool-executor.d.ts.map +0 -1
- package/dist/types/browser/form-utilities.d.ts.map +0 -1
- package/dist/types/browser/geo-location.d.ts.map +0 -1
- package/dist/types/browser/index.d.ts.map +0 -1
- package/dist/types/browser/native-bridge.d.ts.map +0 -1
- package/dist/types/cancellable-promise.d.ts.map +0 -1
- package/dist/types/clean-url-search-params.d.ts.map +0 -1
- package/dist/types/collections/cache-dictionary.d.ts.map +0 -1
- package/dist/types/collections/default-map.d.ts.map +0 -1
- package/dist/types/collections/default-weak-map.d.ts.map +0 -1
- package/dist/types/collections/from.d.ts.map +0 -1
- package/dist/types/collections/index.d.ts.map +0 -1
- package/dist/types/debouncer.d.ts.map +0 -1
- package/dist/types/draft.d.ts.map +0 -1
- package/dist/types/event-bus.d.ts.map +0 -1
- package/dist/types/functions.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/key-value-pair.d.ts.map +0 -1
- package/dist/types/keyed-debouncer.d.ts.map +0 -1
- package/dist/types/lazy.d.ts.map +0 -1
- package/dist/types/math.d.ts.map +0 -1
- package/dist/types/order.d.ts.map +0 -1
- package/dist/types/parse.d.ts.map +0 -1
- package/dist/types/patch.d.ts.map +0 -1
- package/dist/types/range.d.ts.map +0 -1
- package/dist/types/result.d.ts.map +0 -1
- package/dist/types/stopwatch.d.ts.map +0 -1
- package/dist/types/string.d.ts.map +0 -1
- package/dist/types/timer.d.ts.map +0 -1
- package/dist/types/timespan.d.ts.map +0 -1
- package/dist/types/triggers.d.ts.map +0 -1
- package/dist/types/type-code.d.ts.map +0 -1
- package/dist/types/type.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utilities.d.ts.map +0 -1
- package/dist/web/array.js +0 -98
- package/dist/web/array.js.map +0 -1
- package/dist/web/async-pool-executor.js +0 -76
- package/dist/web/async-pool-executor.js.map +0 -1
- package/dist/web/browser/form-utilities.js +0 -155
- package/dist/web/browser/form-utilities.js.map +0 -1
- package/dist/web/browser/geo-location.js +0 -75
- package/dist/web/browser/geo-location.js.map +0 -1
- package/dist/web/browser/index.js +0 -75
- package/dist/web/browser/index.js.map +0 -1
- package/dist/web/browser/native-bridge.js +0 -78
- package/dist/web/browser/native-bridge.js.map +0 -1
- package/dist/web/cancellable-promise.js +0 -78
- package/dist/web/cancellable-promise.js.map +0 -1
- package/dist/web/clean-url-search-params.js +0 -31
- package/dist/web/clean-url-search-params.js.map +0 -1
- package/dist/web/collections/cache-dictionary.js +0 -99
- package/dist/web/collections/cache-dictionary.js.map +0 -1
- package/dist/web/collections/default-map.js +0 -42
- package/dist/web/collections/default-map.js.map +0 -1
- package/dist/web/collections/default-weak-map.js +0 -43
- package/dist/web/collections/default-weak-map.js.map +0 -1
- package/dist/web/collections/from.js +0 -770
- package/dist/web/collections/from.js.map +0 -1
- package/dist/web/collections/index.js +0 -5
- package/dist/web/collections/index.js.map +0 -1
- package/dist/web/debouncer.js +0 -118
- package/dist/web/debouncer.js.map +0 -1
- package/dist/web/draft.js +0 -222
- package/dist/web/draft.js.map +0 -1
- package/dist/web/event-bus.js +0 -66
- package/dist/web/event-bus.js.map +0 -1
- package/dist/web/functions.js +0 -251
- package/dist/web/functions.js.map +0 -1
- package/dist/web/index.js +0 -40
- package/dist/web/index.js.map +0 -1
- package/dist/web/key-value-pair.js +0 -19
- package/dist/web/key-value-pair.js.map +0 -1
- package/dist/web/keyed-debouncer.js +0 -109
- package/dist/web/keyed-debouncer.js.map +0 -1
- package/dist/web/lazy.js +0 -26
- package/dist/web/lazy.js.map +0 -1
- package/dist/web/math.js +0 -33
- package/dist/web/math.js.map +0 -1
- package/dist/web/order.js +0 -7
- package/dist/web/order.js.map +0 -1
- package/dist/web/parse.js +0 -169
- package/dist/web/parse.js.map +0 -1
- package/dist/web/patch.js +0 -48
- package/dist/web/patch.js.map +0 -1
- package/dist/web/range.js +0 -151
- package/dist/web/range.js.map +0 -1
- package/dist/web/result.js +0 -2
- package/dist/web/result.js.map +0 -1
- package/dist/web/stopwatch.js +0 -40
- package/dist/web/stopwatch.js.map +0 -1
- package/dist/web/string.js +0 -142
- package/dist/web/string.js.map +0 -1
- package/dist/web/timer.js +0 -54
- package/dist/web/timer.js.map +0 -1
- package/dist/web/timespan.js +0 -365
- package/dist/web/timespan.js.map +0 -1
- package/dist/web/triggers.js +0 -99
- package/dist/web/triggers.js.map +0 -1
- package/dist/web/type-code.js +0 -16
- package/dist/web/type-code.js.map +0 -1
- package/dist/web/type.js +0 -292
- package/dist/web/type.js.map +0 -1
- package/dist/web/types.js +0 -2
- package/dist/web/types.js.map +0 -1
- package/dist/web/utilities.js.map +0 -1
- /package/dist/{types/array.d.ts → array.d.ts} +0 -0
- /package/dist/{esm/array.js → array.js} +0 -0
- /package/dist/{types/async-pool-executor.d.ts → async-pool-executor.d.ts} +0 -0
- /package/dist/{esm/async-pool-executor.js → async-pool-executor.js} +0 -0
- /package/dist/{types/browser → browser}/form-utilities.d.ts +0 -0
- /package/dist/{esm/browser → browser}/form-utilities.js +0 -0
- /package/dist/{types/browser → browser}/geo-location.d.ts +0 -0
- /package/dist/{esm/browser → browser}/geo-location.js +0 -0
- /package/dist/{types/browser → browser}/index.d.ts +0 -0
- /package/dist/{esm/browser → browser}/index.js +0 -0
- /package/dist/{types/browser → browser}/native-bridge.d.ts +0 -0
- /package/dist/{esm/browser → browser}/native-bridge.js +0 -0
- /package/dist/{types/cancellable-promise.d.ts → cancellable-promise.d.ts} +0 -0
- /package/dist/{esm/cancellable-promise.js → cancellable-promise.js} +0 -0
- /package/dist/{types/clean-url-search-params.d.ts → clean-url-search-params.d.ts} +0 -0
- /package/dist/{esm/clean-url-search-params.js → clean-url-search-params.js} +0 -0
- /package/dist/{types/collections → collections}/cache-dictionary.d.ts +0 -0
- /package/dist/{esm/collections → collections}/cache-dictionary.js +0 -0
- /package/dist/{types/collections → collections}/default-map.d.ts +0 -0
- /package/dist/{esm/collections → collections}/default-map.js +0 -0
- /package/dist/{types/collections → collections}/default-weak-map.d.ts +0 -0
- /package/dist/{esm/collections → collections}/default-weak-map.js +0 -0
- /package/dist/{types/collections → collections}/index.d.ts +0 -0
- /package/dist/{esm/collections → collections}/index.js +0 -0
- /package/dist/{types/debouncer.d.ts → debouncer.d.ts} +0 -0
- /package/dist/{esm/debouncer.js → debouncer.js} +0 -0
- /package/dist/{types/draft.d.ts → draft.d.ts} +0 -0
- /package/dist/{esm/draft.js → draft.js} +0 -0
- /package/dist/{types/event-bus.d.ts → event-bus.d.ts} +0 -0
- /package/dist/{esm/event-bus.js → event-bus.js} +0 -0
- /package/dist/{types/functions.d.ts → functions.d.ts} +0 -0
- /package/dist/{esm/functions.js → functions.js} +0 -0
- /package/dist/{types/index.d.ts → index.d.ts} +0 -0
- /package/dist/{esm/index.js → index.js} +0 -0
- /package/dist/{types/key-value-pair.d.ts → key-value-pair.d.ts} +0 -0
- /package/dist/{esm/key-value-pair.js → key-value-pair.js} +0 -0
- /package/dist/{types/keyed-debouncer.d.ts → keyed-debouncer.d.ts} +0 -0
- /package/dist/{esm/keyed-debouncer.js → keyed-debouncer.js} +0 -0
- /package/dist/{types/lazy.d.ts → lazy.d.ts} +0 -0
- /package/dist/{esm/lazy.js → lazy.js} +0 -0
- /package/dist/{types/math.d.ts → math.d.ts} +0 -0
- /package/dist/{esm/math.js → math.js} +0 -0
- /package/dist/{types/order.d.ts → order.d.ts} +0 -0
- /package/dist/{esm/order.js → order.js} +0 -0
- /package/dist/{types/parse.d.ts → parse.d.ts} +0 -0
- /package/dist/{esm/parse.js → parse.js} +0 -0
- /package/dist/{types/patch.d.ts → patch.d.ts} +0 -0
- /package/dist/{esm/patch.js → patch.js} +0 -0
- /package/dist/{types/range.d.ts → range.d.ts} +0 -0
- /package/dist/{esm/range.js → range.js} +0 -0
- /package/dist/{types/result.d.ts → result.d.ts} +0 -0
- /package/dist/{esm/result.js → result.js} +0 -0
- /package/dist/{types/stopwatch.d.ts → stopwatch.d.ts} +0 -0
- /package/dist/{esm/stopwatch.js → stopwatch.js} +0 -0
- /package/dist/{types/string.d.ts → string.d.ts} +0 -0
- /package/dist/{esm/string.js → string.js} +0 -0
- /package/dist/{types/timer.d.ts → timer.d.ts} +0 -0
- /package/dist/{esm/timer.js → timer.js} +0 -0
- /package/dist/{types/timespan.d.ts → timespan.d.ts} +0 -0
- /package/dist/{esm/timespan.js → timespan.js} +0 -0
- /package/dist/{types/triggers.d.ts → triggers.d.ts} +0 -0
- /package/dist/{esm/triggers.js → triggers.js} +0 -0
- /package/dist/{types/type-code.d.ts → type-code.d.ts} +0 -0
- /package/dist/{esm/type-code.js → type-code.js} +0 -0
- /package/dist/{types/type.d.ts → type.d.ts} +0 -0
- /package/dist/{esm/type.js → type.js} +0 -0
- /package/dist/{types/types.d.ts → types.d.ts} +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
package/dist/cjs/triggers.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CountTrigger = exports.TimeTrigger = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Runs a callback at most once during a configured time interval.
|
|
6
|
-
*/
|
|
7
|
-
class TimeTrigger {
|
|
8
|
-
constructor(callback, interval) {
|
|
9
|
-
this.callback = callback;
|
|
10
|
-
this.interval = interval;
|
|
11
|
-
this.lastRunTime = null;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Executes the callback when the configured interval has elapsed.
|
|
15
|
-
*/
|
|
16
|
-
async check() {
|
|
17
|
-
const currentTime = performance.now();
|
|
18
|
-
if (this.lastRunTime === null
|
|
19
|
-
|| currentTime - this.lastRunTime >= this.interval.milliseconds) {
|
|
20
|
-
return { success: true, output: await this.trigger() };
|
|
21
|
-
}
|
|
22
|
-
return { success: false };
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Executes the callback regardless of the configured interval.
|
|
26
|
-
*/
|
|
27
|
-
async trigger() {
|
|
28
|
-
this.lastRunTime = performance.now();
|
|
29
|
-
return this.callback();
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Replaces the callback executed by this trigger.
|
|
33
|
-
*/
|
|
34
|
-
setCallback(callback) {
|
|
35
|
-
this.callback = callback;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Gets the configured time interval.
|
|
39
|
-
*/
|
|
40
|
-
getInterval() {
|
|
41
|
-
return this.interval;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Replaces the configured time interval.
|
|
45
|
-
*/
|
|
46
|
-
setInterval(interval) {
|
|
47
|
-
this.interval = interval;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.TimeTrigger = TimeTrigger;
|
|
51
|
-
/**
|
|
52
|
-
* Runs a callback after a configured number of checks.
|
|
53
|
-
*/
|
|
54
|
-
class CountTrigger {
|
|
55
|
-
constructor(callback, interval) {
|
|
56
|
-
this.interval = 1;
|
|
57
|
-
this.checkCount = 0;
|
|
58
|
-
this.callback = callback;
|
|
59
|
-
this.setInterval(interval);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Executes the callback when the configured number of checks is reached.
|
|
63
|
-
*/
|
|
64
|
-
async check() {
|
|
65
|
-
this.checkCount++;
|
|
66
|
-
if (this.checkCount >= this.interval) {
|
|
67
|
-
return { success: true, output: await this.trigger() };
|
|
68
|
-
}
|
|
69
|
-
return { success: false };
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Executes the callback regardless of the configured check count.
|
|
73
|
-
*/
|
|
74
|
-
async trigger() {
|
|
75
|
-
this.checkCount = 0;
|
|
76
|
-
return this.callback();
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Replaces the callback executed by this trigger.
|
|
80
|
-
*/
|
|
81
|
-
setCallback(callback) {
|
|
82
|
-
this.callback = callback;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Gets the configured check interval.
|
|
86
|
-
*/
|
|
87
|
-
getInterval() {
|
|
88
|
-
return this.interval;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Replaces the configured check interval.
|
|
92
|
-
*
|
|
93
|
-
* @throws {RangeError} When the interval is less than one.
|
|
94
|
-
*/
|
|
95
|
-
setInterval(interval) {
|
|
96
|
-
if (interval < 1) {
|
|
97
|
-
throw new RangeError('Interval must be greater than zero.');
|
|
98
|
-
}
|
|
99
|
-
this.interval = interval;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.CountTrigger = CountTrigger;
|
|
103
|
-
//# sourceMappingURL=triggers.js.map
|
package/dist/cjs/triggers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"triggers.js","sourceRoot":"","sources":["../../src/triggers.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,MAAa,WAAW;IAKpB,YAAmB,QAAkC,EAAE,QAAkB;QACrE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QACd,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAEtC,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI;eACtB,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EACjE,CAAC;YACC,OAAO,EAAC,OAAO,EAAE,IA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C3B,CAAC;IAED;;OAEG;IACI,WAAW,CAAC,QAAkC;QACjD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,WAAW;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,QAAgB;QAC/B,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,IAAI,UAAU,CAAC,qCAAqC,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAzDD,oCAyDC","sourcesContent":["import type {Result} from './result.js';\nimport TimeSpan from './timespan.js';\nimport type {Nullable, Supplier} from './types.js';\n\n/**\n * Runs a callback at most once during a configured time interval.\n */\nexport class TimeTrigger<T> {\n private callback: Supplier<T | Promise<T>>;\n private interval: TimeSpan;\n private lastRunTime: Nullable<number>;\n\n public constructor(callback: Supplier<T | Promise<T>>, interval: TimeSpan) {\n this.callback = callback;\n this.interval = interval;\n this.lastRunTime = null;\n }\n\n /**\n * Executes the callback when the configured interval has elapsed.\n */\n public async check(): Promise<Result<T>> {\n const currentTime = performance.now();\n\n if (this.lastRunTime === null\n || currentTime - this.lastRunTime >= this.interval.milliseconds\n ) {\n return {success: true, output: await this.trigger()};\n }\n\n return {success: false};\n }\n\n /**\n * Executes the callback regardless of the configured interval.\n */\n public async trigger(): Promise<T> {\n this.lastRunTime = performance.now();\n return this.callback();\n }\n\n /**\n * Replaces the callback executed by this trigger.\n */\n public setCallback(callback: Supplier<T | Promise<T>>): void {\n this.callback = callback;\n }\n\n /**\n * Gets the configured time interval.\n */\n public getInterval(): TimeSpan {\n return this.interval;\n }\n\n /**\n * Replaces the configured time interval.\n */\n public setInterval(interval: TimeSpan): void {\n this.interval = interval;\n }\n\n\n}\n\n/**\n * Runs a callback after a configured number of checks.\n */\nexport class CountTrigger<T> {\n private callback: Supplier<T | Promise<T>>;\n private interval: number = 1;\n private checkCount: number = 0;\n\n public constructor(callback: Supplier<T | Promise<T>>, interval: number) {\n this.callback = callback;\n this.setInterval(interval);\n }\n\n /**\n * Executes the callback when the configured number of checks is reached.\n */\n public async check(): Promise<Result<T>> {\n this.checkCount++;\n\n if (this.checkCount >= this.interval) {\n return {success: true, output: await this.trigger()};\n }\n\n return {success: false};\n }\n\n /**\n * Executes the callback regardless of the configured check count.\n */\n public async trigger(): Promise<T> {\n this.checkCount = 0;\n return this.callback();\n }\n\n /**\n * Replaces the callback executed by this trigger.\n */\n public setCallback(callback: Supplier<T | Promise<T>>): void {\n this.callback = callback;\n }\n\n /**\n * Gets the configured check interval.\n */\n public getInterval(): number {\n return this.interval;\n }\n\n /**\n * Replaces the configured check interval.\n *\n * @throws {RangeError} When the interval is less than one.\n */\n public setInterval(interval: number): void {\n if (interval < 1) {\n throw new RangeError('Interval must be greater than zero.');\n }\n\n this.interval = interval;\n }\n}\n"]}
|
package/dist/cjs/type-code.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var TypeCode;
|
|
4
|
-
(function (TypeCode) {
|
|
5
|
-
TypeCode["String"] = "string";
|
|
6
|
-
TypeCode["Number"] = "number";
|
|
7
|
-
TypeCode["Boolean"] = "boolean";
|
|
8
|
-
TypeCode["Symbol"] = "symbol";
|
|
9
|
-
TypeCode["BigInt"] = "bigint";
|
|
10
|
-
TypeCode["Null"] = "null";
|
|
11
|
-
TypeCode["Undefined"] = "undefined";
|
|
12
|
-
TypeCode["Object"] = "object";
|
|
13
|
-
TypeCode["Function"] = "function";
|
|
14
|
-
TypeCode["Array"] = "array";
|
|
15
|
-
TypeCode["Unknown"] = "unknown";
|
|
16
|
-
})(TypeCode || (TypeCode = {}));
|
|
17
|
-
exports.default = TypeCode;
|
|
18
|
-
//# sourceMappingURL=type-code.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-code.js","sourceRoot":"","sources":["../../src/type-code.ts"],"names":[],"mappings":";;AAAA,IAAK,QAYJ;AAZD,WAAK,QAAQ;IACT,6BAAoB,CAAA;IACpB,6BAAoB,CAAA;IACpB,+BAAqB,CAAA;IACrB,6BAAoB,CAAA;IACpB,6BAAoB,CAAA;IACpB,yBAAkB,CAAA;IAClB,mCAAuB,CAAA;IACvB,6BAAoB,CAAA;IACpB,iCAAsB,CAAA;IACtB,2BAAmB,CAAA;IACnB,+BAAqB,CAAA;AACzB,CAAC,EAZI,QAAQ,KAAR,QAAQ,QAYZ;AAGD,kBAAe,QAAQ,CAAC","sourcesContent":["enum TypeCode {\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Symbol = 'symbol',\n BigInt = 'bigint',\n Null = 'null',\n Undefined = 'undefined',\n Object = 'object',\n Function = 'function',\n Array = 'array',\n Unknown = 'unknown',\n}\n\n\nexport default TypeCode;"]}
|
package/dist/cjs/type.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const type_code_js_1 = __importDefault(require("./type-code.js"));
|
|
7
|
-
class Type {
|
|
8
|
-
constructor(name, constructorRef, typeCode) {
|
|
9
|
-
this.name = name;
|
|
10
|
-
this.constructorRef = constructorRef;
|
|
11
|
-
this.typeCode = typeCode;
|
|
12
|
-
}
|
|
13
|
-
// ══════════════════════════════════════════════
|
|
14
|
-
// ÚNICO PUNTO DE ENTRADA
|
|
15
|
-
// ══════════════════════════════════════════════
|
|
16
|
-
/**
|
|
17
|
-
* Obtiene el `Type` de cualquier valor, constructor o primitivo.
|
|
18
|
-
*
|
|
19
|
-
* Unifica `typeof()` y `.GetType()` de C# en un solo método.
|
|
20
|
-
*
|
|
21
|
-
* **Reglas de resolución:**
|
|
22
|
-
* 1. `null` / `undefined` → tipo nullish correspondiente
|
|
23
|
-
* 2. Primitivo (`number`, `string`, etc.) → tipo primitivo
|
|
24
|
-
* 3. Array → `Type.Array`
|
|
25
|
-
* 4. Función/Constructor → tipo del constructor (no "Function")
|
|
26
|
-
* 5. Objeto → tipo basado en su constructor
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* Type.of(42) // Type<number> — primitivo
|
|
31
|
-
* Type.of('hello') // Type<string> — primitivo
|
|
32
|
-
* Type.of(new Date()) // Type<Date> — desde instancia
|
|
33
|
-
* Type.of(Date) // Type<Date> — desde constructor
|
|
34
|
-
* Type.of(null) // Type<null>
|
|
35
|
-
* Type.of([1, 2, 3]) // Type<Array>
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
static of(target) {
|
|
39
|
-
// ── Nullish ──
|
|
40
|
-
if (target === null)
|
|
41
|
-
return Type.Null;
|
|
42
|
-
if (target === undefined)
|
|
43
|
-
return Type.Undefined;
|
|
44
|
-
const jsType = typeof target;
|
|
45
|
-
// ── Primitivos ──
|
|
46
|
-
if (jsType !== 'object' && jsType !== 'function') {
|
|
47
|
-
return this._getOrCreate(jsType, undefined, jsType);
|
|
48
|
-
}
|
|
49
|
-
// ── Funciones y Constructores ──
|
|
50
|
-
if (jsType === 'function') {
|
|
51
|
-
return this._resolveFunction(target);
|
|
52
|
-
}
|
|
53
|
-
// ── Arrays ──
|
|
54
|
-
if (Array.isArray(target)) {
|
|
55
|
-
return Type.Array;
|
|
56
|
-
}
|
|
57
|
-
// ── Objetos ──
|
|
58
|
-
return this._resolveObject(target);
|
|
59
|
-
}
|
|
60
|
-
// ──────────────────────────────────────────────
|
|
61
|
-
// Resolvers privados (separan la lógica compleja)
|
|
62
|
-
// ──────────────────────────────────────────────
|
|
63
|
-
/**
|
|
64
|
-
* Resuelve funciones y constructores.
|
|
65
|
-
*
|
|
66
|
-
* Decisión clave: si la función tiene un `prototype` con
|
|
67
|
-
* miembros propios o empieza con `class`, es un constructor
|
|
68
|
-
* y devolvemos el tipo que construye. Si no, es una función.
|
|
69
|
-
*/
|
|
70
|
-
static _resolveFunction(fn) {
|
|
71
|
-
const isConstructor = this._isConstructorLike(fn);
|
|
72
|
-
if (isConstructor) {
|
|
73
|
-
// Constructor → devuelve el tipo que construye
|
|
74
|
-
return this._getOrCreate(fn, // cacheamos por referencia al constructor
|
|
75
|
-
fn, type_code_js_1.default.Object, fn.name || 'AnonymousClass');
|
|
76
|
-
}
|
|
77
|
-
// Función pura → devuelve Type<Function>
|
|
78
|
-
return Type.Function;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Resuelve objetos por su cadena de prototipos.
|
|
82
|
-
*/
|
|
83
|
-
static _resolveObject(obj) {
|
|
84
|
-
const proto = Object.getPrototypeOf(obj);
|
|
85
|
-
const ctor = proto?.constructor;
|
|
86
|
-
const name = ctor?.name || 'Object';
|
|
87
|
-
if (!ctor || ctor === Object) {
|
|
88
|
-
return Type.Object;
|
|
89
|
-
}
|
|
90
|
-
return this._getOrCreate(ctor, ctor, type_code_js_1.default.Object, name);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Heurística para distinguir constructores de funciones planas.
|
|
94
|
-
*
|
|
95
|
-
* Un "constructor" cumple al menos una de:
|
|
96
|
-
* - Su `toString()` empieza con "class "
|
|
97
|
-
* - Tiene propiedades propias en su prototype (más allá de constructor)
|
|
98
|
-
* - Es un built-in conocido (Date, Map, Set, etc.)
|
|
99
|
-
*/
|
|
100
|
-
static _isConstructorLike(fn) {
|
|
101
|
-
// 1. Clase ES6 explícita
|
|
102
|
-
try {
|
|
103
|
-
if (fn.toString().startsWith('class '))
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
// toString puede fallar en Proxy, etc.
|
|
108
|
-
}
|
|
109
|
-
// 2. Built-ins conocidos con prototype significativo
|
|
110
|
-
if (fn === Object || fn === Function || fn === Array)
|
|
111
|
-
return true;
|
|
112
|
-
const proto = fn.prototype;
|
|
113
|
-
if (!proto || typeof proto !== 'object')
|
|
114
|
-
return false;
|
|
115
|
-
// 3. Prototype con miembros propios (señal de constructor)
|
|
116
|
-
const ownKeys = Object.getOwnPropertyNames(proto);
|
|
117
|
-
return ownKeys.length > 1 || (ownKeys.length === 1 && ownKeys[0] !== 'constructor');
|
|
118
|
-
}
|
|
119
|
-
// ══════════════════════════════════════════════
|
|
120
|
-
// PROPIEDADES COMPUTADAS
|
|
121
|
-
// ══════════════════════════════════════════════
|
|
122
|
-
get isPrimitive() {
|
|
123
|
-
return (this.typeCode === type_code_js_1.default.String ||
|
|
124
|
-
this.typeCode === type_code_js_1.default.Number ||
|
|
125
|
-
this.typeCode === type_code_js_1.default.Boolean ||
|
|
126
|
-
this.typeCode === type_code_js_1.default.Symbol ||
|
|
127
|
-
this.typeCode === type_code_js_1.default.BigInt);
|
|
128
|
-
}
|
|
129
|
-
get isNullish() {
|
|
130
|
-
return this.typeCode === type_code_js_1.default.Null || this.typeCode === type_code_js_1.default.Undefined;
|
|
131
|
-
}
|
|
132
|
-
get isReferenceType() {
|
|
133
|
-
return !this.isPrimitive && !this.isNullish;
|
|
134
|
-
}
|
|
135
|
-
get isArray() {
|
|
136
|
-
return this.typeCode === type_code_js_1.default.Array ||
|
|
137
|
-
this.constructorRef === Array;
|
|
138
|
-
}
|
|
139
|
-
get isFunction() {
|
|
140
|
-
return this.typeCode === type_code_js_1.default.Function;
|
|
141
|
-
}
|
|
142
|
-
get isValueType() {
|
|
143
|
-
return this.isPrimitive;
|
|
144
|
-
}
|
|
145
|
-
get isClass() {
|
|
146
|
-
if (!this.constructorRef)
|
|
147
|
-
return false;
|
|
148
|
-
try {
|
|
149
|
-
return this.constructorRef.toString().startsWith('class ');
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
get fullName() {
|
|
156
|
-
if (this.isPrimitive || this.isNullish) {
|
|
157
|
-
return `System.${this.name.charAt(0).toUpperCase()}${this.name.slice(1)}`;
|
|
158
|
-
}
|
|
159
|
-
return this.name;
|
|
160
|
-
}
|
|
161
|
-
// ══════════════════════════════════════════════
|
|
162
|
-
// JERARQUÍA
|
|
163
|
-
// ══════════════════════════════════════════════
|
|
164
|
-
get baseType() {
|
|
165
|
-
if (!this.constructorRef)
|
|
166
|
-
return undefined;
|
|
167
|
-
const parentProto = Object.getPrototypeOf(this.constructorRef.prototype);
|
|
168
|
-
if (!parentProto || parentProto === Object.prototype) {
|
|
169
|
-
return this === Type.Object ? undefined : Type.Object;
|
|
170
|
-
}
|
|
171
|
-
const parentCtor = parentProto.constructor;
|
|
172
|
-
return Type.of(parentCtor);
|
|
173
|
-
}
|
|
174
|
-
getInheritanceChain() {
|
|
175
|
-
const chain = [this];
|
|
176
|
-
let current = this.baseType;
|
|
177
|
-
while (current && !chain.includes(current)) {
|
|
178
|
-
chain.push(current);
|
|
179
|
-
current = current.baseType;
|
|
180
|
-
}
|
|
181
|
-
return Object.freeze(chain);
|
|
182
|
-
}
|
|
183
|
-
isAssignableTo(target) {
|
|
184
|
-
if (this === target)
|
|
185
|
-
return true;
|
|
186
|
-
if (!this.constructorRef || !target.constructorRef)
|
|
187
|
-
return false;
|
|
188
|
-
let proto = this.constructorRef.prototype;
|
|
189
|
-
while (proto) {
|
|
190
|
-
if (proto.constructor === target.constructorRef)
|
|
191
|
-
return true;
|
|
192
|
-
proto = Object.getPrototypeOf(proto);
|
|
193
|
-
}
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
isAssignableFrom(source) {
|
|
197
|
-
return source.isAssignableTo(this);
|
|
198
|
-
}
|
|
199
|
-
isSubclassOf(parent) {
|
|
200
|
-
if (this === parent)
|
|
201
|
-
return false;
|
|
202
|
-
return this.isAssignableTo(parent);
|
|
203
|
-
}
|
|
204
|
-
// ══════════════════════════════════════════════
|
|
205
|
-
// REFLEXIÓN
|
|
206
|
-
// ══════════════════════════════════════════════
|
|
207
|
-
getMethodNames() {
|
|
208
|
-
return Object.freeze(this._getPrototypeMemberNames((_, descriptor) => typeof descriptor.value === 'function'));
|
|
209
|
-
}
|
|
210
|
-
getPropertyNames() {
|
|
211
|
-
return Object.freeze(this._getPrototypeMemberNames((_, descriptor) => typeof descriptor.value !== 'function'));
|
|
212
|
-
}
|
|
213
|
-
getMemberNames() {
|
|
214
|
-
return Object.freeze(this._getPrototypeMemberNames());
|
|
215
|
-
}
|
|
216
|
-
hasMethod(name) {
|
|
217
|
-
const descriptor = this._getOwnPrototypeDescriptor(name);
|
|
218
|
-
return typeof descriptor?.value === 'function';
|
|
219
|
-
}
|
|
220
|
-
hasProperty(name) {
|
|
221
|
-
const descriptor = this._getOwnPrototypeDescriptor(name);
|
|
222
|
-
return !!descriptor && typeof descriptor.value !== 'function';
|
|
223
|
-
}
|
|
224
|
-
_getPrototypeMemberNames(predicate = () => true) {
|
|
225
|
-
if (!this.constructorRef?.prototype)
|
|
226
|
-
return [];
|
|
227
|
-
return Object.getOwnPropertyNames(this.constructorRef.prototype)
|
|
228
|
-
.filter(name => {
|
|
229
|
-
const descriptor = this._getOwnPrototypeDescriptor(name);
|
|
230
|
-
return !!descriptor && predicate(name, descriptor);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
_getOwnPrototypeDescriptor(name) {
|
|
234
|
-
if (name === 'constructor' || !this.constructorRef?.prototype)
|
|
235
|
-
return undefined;
|
|
236
|
-
return Object.getOwnPropertyDescriptor(this.constructorRef.prototype, name);
|
|
237
|
-
}
|
|
238
|
-
getStaticMemberNames() {
|
|
239
|
-
if (!this.constructorRef)
|
|
240
|
-
return Object.freeze([]);
|
|
241
|
-
const skip = new Set(['prototype', 'length', 'name', 'caller', 'arguments']);
|
|
242
|
-
return Object.freeze(Object.getOwnPropertyNames(this.constructorRef)
|
|
243
|
-
.filter(n => !skip.has(n)));
|
|
244
|
-
}
|
|
245
|
-
// ══════════════════════════════════════════════
|
|
246
|
-
// SERIALIZACIÓN
|
|
247
|
-
// ══════════════════════════════════════════════
|
|
248
|
-
toString() {
|
|
249
|
-
return `Type [${this.name}]`;
|
|
250
|
-
}
|
|
251
|
-
[Symbol.toPrimitive](hint) {
|
|
252
|
-
let hash = 0;
|
|
253
|
-
for (let i = 0; i < this.name.length; i++) {
|
|
254
|
-
hash = ((hash << 5) - hash + this.name.charCodeAt(i)) | 0;
|
|
255
|
-
}
|
|
256
|
-
return hint === 'number' ? hash : this.toString();
|
|
257
|
-
}
|
|
258
|
-
get [Symbol.toStringTag]() {
|
|
259
|
-
return `Type<${this.name}>`;
|
|
260
|
-
}
|
|
261
|
-
// ──────────────────────────────────────────────
|
|
262
|
-
// FACTORY INTERNA
|
|
263
|
-
// ──────────────────────────────────────────────
|
|
264
|
-
static _getOrCreate(key, constructorRef, typeCode, customName) {
|
|
265
|
-
const cached = this._cache.get(key);
|
|
266
|
-
if (cached)
|
|
267
|
-
return cached;
|
|
268
|
-
const name = customName
|
|
269
|
-
?? (typeof key === 'string' ? key : 'unknown');
|
|
270
|
-
const ref = typeof constructorRef === 'function'
|
|
271
|
-
? constructorRef
|
|
272
|
-
: undefined;
|
|
273
|
-
const instance = new Type(name, ref, typeCode);
|
|
274
|
-
this._cache.set(key, instance);
|
|
275
|
-
return instance;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
// ──────────────────────────────────────────────
|
|
279
|
-
// Caché (Flyweight)
|
|
280
|
-
// ──────────────────────────────────────────────
|
|
281
|
-
Type._cache = new Map();
|
|
282
|
-
// ──────────────────────────────────────────────
|
|
283
|
-
// Tipos predefinidos
|
|
284
|
-
// ──────────────────────────────────────────────
|
|
285
|
-
Type.String = Type._getOrCreate('string', undefined, type_code_js_1.default.String, 'string');
|
|
286
|
-
Type.Number = Type._getOrCreate('number', undefined, type_code_js_1.default.Number, 'number');
|
|
287
|
-
Type.Boolean = Type._getOrCreate('boolean', undefined, type_code_js_1.default.Boolean, 'boolean');
|
|
288
|
-
Type.Symbol = Type._getOrCreate('symbol', undefined, type_code_js_1.default.Symbol, 'symbol');
|
|
289
|
-
Type.BigInt = Type._getOrCreate('bigint', undefined, type_code_js_1.default.BigInt, 'bigint');
|
|
290
|
-
Type.Null = Type._getOrCreate('null', undefined, type_code_js_1.default.Null, 'null');
|
|
291
|
-
Type.Undefined = Type._getOrCreate('undefined', undefined, type_code_js_1.default.Undefined, 'undefined');
|
|
292
|
-
Type.Object = Type._getOrCreate(Object, Object, type_code_js_1.default.Object, 'Object');
|
|
293
|
-
Type.Function = Type._getOrCreate(Function, Function, type_code_js_1.default.Function, 'Function');
|
|
294
|
-
Type.Array = Type._getOrCreate(Array, Array, type_code_js_1.default.Array, 'Array');
|
|
295
|
-
exports.default = Type;
|
|
296
|
-
//# sourceMappingURL=type.js.map
|
package/dist/cjs/type.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":";;;;;AAAA,kEAAsC;AAGtC,MAAqB,IAAI;IAgCrB,YACI,IAAY,EACZ,cAA0C,EAC1C,QAAkB;QAElB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,iDAAiD;IACjD,0BAA0B;IAC1B,iDAAiD;IAEjD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,MAAM,CAAC,EAAE,CAAI,MAA0B;QAC1C,gBAAgB;QAChB,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,IAAe,CAAC;QACjD,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,SAAoB,CAAC;QAE3D,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;QAE7B,mBAAmB;QACnB,IAAI,MAAM,K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C,CAAC;AACnF,WAAM,GAAG,IAAI,CAAC,YAAY,CAAS,QAAQ,EAAE,SAAS,EAAE,sBAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACnF,YAAO,GAAG,IAAI,CAAC,YAAY,CAAU,SAAS,EAAE,SAAS,EAAE,sBAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACxF,WAAM,GAAG,IAAI,CAAC,YAAY,CAAS,QAAQ,EAAE,SAAS,EAAE,sBAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACnF,WAAM,GAAG,IAAI,CAAC,YAAY,CAAS,QAAQ,EAAE,SAAS,EAAE,sBAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACnF,SAAI,GAAG,IAAI,CAAC,YAAY,CAAO,MAAM,EAAE,SAAS,EAAE,sBAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACzE,cAAS,GAAG,IAAI,CAAC,YAAY,CAAY,WAAW,EAAE,SAAS,EAAE,sBAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAClG,WAAM,GAAG,IAAI,CAAC,YAAY,CAAS,MAAM,EAAE,MAAM,EAAE,sBAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC9E,aAAQ,GAAG,IAAI,CAAC,YAAY,CAAW,QAAQ,EAAE,QAAQ,EAAE,sBAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC1F,UAAK,GAAG,IAAI,CAAC,YAAY,CAAY,KAAK,EAAE,KAAK,EAAE,sBAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;kBArBlF,IAAI","sourcesContent":["import TypeCode from \"./type-code.js\";\nimport {type Constructor} from \"./types.js\";\n\nexport default class Type<T = unknown> {\n\n // ──────────────────────────────────────────────\n // Caché (Flyweight)\n // ──────────────────────────────────────────────\n\n private static readonly _cache = new Map<unknown, Type>();\n\n // ──────────────────────────────────────────────\n // Tipos predefinidos\n // ──────────────────────────────────────────────\n\n public static readonly String = Type._getOrCreate<string>('string', undefined, TypeCode.String, 'string');\n public static readonly Number = Type._getOrCreate<number>('number', undefined, TypeCode.Number, 'number');\n public static readonly Boolean = Type._getOrCreate<boolean>('boolean', undefined, TypeCode.Boolean, 'boolean');\n public static readonly Symbol = Type._getOrCreate<symbol>('symbol', undefined, TypeCode.Symbol, 'symbol');\n public static readonly BigInt = Type._getOrCreate<bigint>('bigint', undefined, TypeCode.BigInt, 'bigint');\n public static readonly Null = Type._getOrCreate<null>('null', undefined, TypeCode.Null, 'null');\n public static readonly Undefined = Type._getOrCreate<undefined>('undefined', undefined, TypeCode.Undefined, 'undefined');\n public static readonly Object = Type._getOrCreate<object>(Object, Object, TypeCode.Object, 'Object');\n public static readonly Function = Type._getOrCreate<Function>(Function, Function, TypeCode.Function, 'Function');\n public static readonly Array = Type._getOrCreate<unknown[]>(Array, Array, TypeCode.Array, 'Array');\n\n // ──────────────────────────────────────────────\n // Propiedades inmutables\n // ──────────────────────────────────────────────\n\n public readonly name: string;\n public readonly constructorRef:\n Constructor<T> | undefined;\n public readonly typeCode: TypeCode;\n\n private constructor(\n name: string,\n constructorRef: Constructor<T> | undefined,\n typeCode: TypeCode,\n ) {\n this.name = name;\n this.constructorRef = constructorRef;\n this.typeCode = typeCode;\n }\n\n // ══════════════════════════════════════════════\n // ÚNICO PUNTO DE ENTRADA\n // ══════════════════════════════════════════════\n\n /**\n * Obtiene el `Type` de cualquier valor, constructor o primitivo.\n *\n * Unifica `typeof()` y `.GetType()` de C# en un solo método.\n *\n * **Reglas de resolución:**\n * 1. `null` / `undefined` → tipo nullish correspondiente\n * 2. Primitivo (`number`, `string`, etc.) → tipo primitivo\n * 3. Array → `Type.Array`\n * 4. Función/Constructor → tipo del constructor (no \"Function\")\n * 5. Objeto → tipo basado en su constructor\n *\n * @example\n * ```ts\n * Type.of(42) // Type<number> — primitivo\n * Type.of('hello') // Type<string> — primitivo\n * Type.of(new Date()) // Type<Date> — desde instancia\n * Type.of(Date) // Type<Date> — desde constructor\n * Type.of(null) // Type<null>\n * Type.of([1, 2, 3]) // Type<Array>\n * ```\n */\n public static of<U>(target: U | Constructor<U>): Type<U> {\n // ── Nullish ──\n if (target === null) return Type.Null as Type<U>;\n if (target === undefined) return Type.Undefined as Type<U>;\n\n const jsType = typeof target;\n\n // ── Primitivos ──\n if (jsType !== 'object' && jsType !== 'function') {\n return this._getOrCreate<U>(jsType, undefined, jsType as TypeCode);\n }\n\n // ── Funciones y Constructores ──\n if (jsType === 'function') {\n return this._resolveFunction<U>(target as Function & Constructor<U>);\n }\n\n // ── Arrays ──\n if (Array.isArray(target)) {\n return Type.Array as Type<U>;\n }\n\n // ── Objetos ──\n return this._resolveObject<U>(target as object);\n }\n\n // ──────────────────────────────────────────────\n // Resolvers privados (separan la lógica compleja)\n // ──────────────────────────────────────────────\n\n /**\n * Resuelve funciones y constructores.\n *\n * Decisión clave: si la función tiene un `prototype` con\n * miembros propios o empieza con `class`, es un constructor\n * y devolvemos el tipo que construye. Si no, es una función.\n */\n private static _resolveFunction<U>(fn: Function & Constructor<U>): Type<U> {\n const isConstructor = this._isConstructorLike(fn);\n\n if (isConstructor) {\n // Constructor → devuelve el tipo que construye\n return this._getOrCreate<U>(\n fn, // cacheamos por referencia al constructor\n fn as Constructor<U>,\n TypeCode.Object,\n fn.name || 'AnonymousClass',\n );\n }\n\n // Función pura → devuelve Type<Function>\n return Type.Function as Type<U>;\n }\n\n /**\n * Resuelve objetos por su cadena de prototipos.\n */\n private static _resolveObject<U>(obj: object): Type<U> {\n const proto = Object.getPrototypeOf(obj) as { constructor?: Constructor<U> } | null;\n const ctor = proto?.constructor as Constructor<U> | undefined;\n const name = ctor?.name || 'Object';\n\n if (!ctor || ctor === (Object as unknown)) {\n return Type.Object as Type<U>;\n }\n\n return this._getOrCreate<U>(ctor, ctor, TypeCode.Object, name);\n }\n\n /**\n * Heurística para distinguir constructores de funciones planas.\n *\n * Un \"constructor\" cumple al menos una de:\n * - Su `toString()` empieza con \"class \"\n * - Tiene propiedades propias en su prototype (más allá de constructor)\n * - Es un built-in conocido (Date, Map, Set, etc.)\n */\n private static _isConstructorLike(fn: Function): boolean {\n // 1. Clase ES6 explícita\n try {\n if (fn.toString().startsWith('class ')) return true;\n } catch {\n // toString puede fallar en Proxy, etc.\n }\n\n // 2. Built-ins conocidos con prototype significativo\n if (fn === Object || fn === Function || fn === Array) return true;\n\n const proto = fn.prototype;\n if (!proto || typeof proto !== 'object') return false;\n\n // 3. Prototype con miembros propios (señal de constructor)\n const ownKeys = Object.getOwnPropertyNames(proto);\n return ownKeys.length > 1 || (ownKeys.length === 1 && ownKeys[0] !== 'constructor');\n }\n\n // ══════════════════════════════════════════════\n // PROPIEDADES COMPUTADAS\n // ══════════════════════════════════════════════\n\n public get isPrimitive(): boolean {\n return (\n this.typeCode === TypeCode.String ||\n this.typeCode === TypeCode.Number ||\n this.typeCode === TypeCode.Boolean ||\n this.typeCode === TypeCode.Symbol ||\n this.typeCode === TypeCode.BigInt\n );\n }\n\n public get isNullish(): boolean {\n return this.typeCode === TypeCode.Null || this.typeCode === TypeCode.Undefined;\n }\n\n public get isReferenceType(): boolean {\n return !this.isPrimitive && !this.isNullish;\n }\n\n public get isArray(): boolean {\n return this.typeCode === TypeCode.Array ||\n this.constructorRef === (Array as unknown as Constructor<T>);\n }\n\n public get isFunction(): boolean {\n return this.typeCode === TypeCode.Function;\n }\n\n public get isValueType(): boolean {\n return this.isPrimitive;\n }\n\n public get isClass(): boolean {\n if (!this.constructorRef) return false;\n try {\n return this.constructorRef.toString().startsWith('class ');\n } catch {\n return false;\n }\n }\n\n public get fullName(): string {\n if (this.isPrimitive || this.isNullish) {\n return `System.${this.name.charAt(0).toUpperCase()}${this.name.slice(1)}`;\n }\n return this.name;\n }\n\n // ══════════════════════════════════════════════\n // JERARQUÍA\n // ══════════════════════════════════════════════\n\n public get baseType(): Type | undefined {\n if (!this.constructorRef) return undefined;\n\n const parentProto = Object.getPrototypeOf(this.constructorRef.prototype);\n if (!parentProto || parentProto === Object.prototype) {\n return this === Type.Object ? undefined : Type.Object;\n }\n\n const parentCtor = parentProto.constructor as Constructor;\n return Type.of(parentCtor);\n }\n\n public getInheritanceChain(): ReadonlyArray<Type> {\n const chain: Type[] = [this];\n let current: Type | undefined = this.baseType;\n\n while (current && !chain.includes(current)) {\n chain.push(current);\n current = current.baseType;\n }\n\n return Object.freeze(chain);\n }\n\n public isAssignableTo(target: Type): boolean {\n if (this === target) return true;\n if (!this.constructorRef || !target.constructorRef) return false;\n\n let proto: object | null = this.constructorRef.prototype;\n while (proto) {\n if (proto.constructor === target.constructorRef) return true;\n proto = Object.getPrototypeOf(proto) as object | null;\n }\n return false;\n }\n\n public isAssignableFrom(source: Type): boolean {\n return source.isAssignableTo(this);\n }\n\n public isSubclassOf(parent: Type): boolean {\n if (this === parent) return false;\n return this.isAssignableTo(parent);\n }\n\n\n // ══════════════════════════════════════════════\n // REFLEXIÓN\n // ══════════════════════════════════════════════\n\n public getMethodNames(): ReadonlyArray<string> {\n return Object.freeze(\n this._getPrototypeMemberNames((_, descriptor) => typeof descriptor.value === 'function')\n );\n }\n\n public getPropertyNames(): ReadonlyArray<string> {\n return Object.freeze(\n this._getPrototypeMemberNames((_, descriptor) => typeof descriptor.value !== 'function')\n );\n }\n\n public getMemberNames(): ReadonlyArray<string> {\n return Object.freeze(this._getPrototypeMemberNames());\n }\n\n public hasMethod(name: string): boolean {\n const descriptor = this._getOwnPrototypeDescriptor(name);\n return typeof descriptor?.value === 'function';\n }\n\n public hasProperty(name: string): boolean {\n const descriptor = this._getOwnPrototypeDescriptor(name);\n return !!descriptor && typeof descriptor.value !== 'function';\n }\n\n private _getPrototypeMemberNames(\n predicate: (name: string, descriptor: PropertyDescriptor) => boolean = () => true\n ): string[] {\n if (!this.constructorRef?.prototype) return [];\n\n return Object.getOwnPropertyNames(this.constructorRef.prototype)\n .filter(name => {\n const descriptor = this._getOwnPrototypeDescriptor(name);\n return !!descriptor && predicate(name, descriptor);\n });\n }\n\n private _getOwnPrototypeDescriptor(name: string): PropertyDescriptor | undefined {\n if (name === 'constructor' || !this.constructorRef?.prototype) return undefined;\n return Object.getOwnPropertyDescriptor(this.constructorRef.prototype, name);\n }\n\n public getStaticMemberNames(): ReadonlyArray<string> {\n if (!this.constructorRef) return Object.freeze([]);\n const skip = new Set(['prototype', 'length', 'name', 'caller', 'arguments']);\n return Object.freeze(\n Object.getOwnPropertyNames(this.constructorRef)\n .filter(n => !skip.has(n))\n );\n }\n\n\n // ══════════════════════════════════════════════\n // SERIALIZACIÓN\n // ══════════════════════════════════════════════\n\n public toString(): string {\n return `Type [${this.name}]`;\n }\n\n\n public [Symbol.toPrimitive](hint: string): string | number {\n\n let hash = 0;\n for (let i = 0; i < this.name.length; i++) {\n hash = ((hash << 5) - hash + this.name.charCodeAt(i)) | 0;\n }\n\n return hint === 'number' ? hash : this.toString();\n }\n\n public get [Symbol.toStringTag](): string {\n return `Type<${this.name}>`;\n }\n\n // ──────────────────────────────────────────────\n // FACTORY INTERNA\n // ──────────────────────────────────────────────\n\n private static _getOrCreate<V>(\n key: unknown,\n constructorRef: Constructor<V> | unknown,\n typeCode: TypeCode,\n customName?: string,\n ): Type<V> {\n const cached = this._cache.get(key);\n if (cached) return cached as Type<V>;\n\n const name = customName\n ?? (typeof key === 'string' ? key : 'unknown');\n\n const ref = typeof constructorRef === 'function'\n ? constructorRef as Constructor<V>\n : undefined;\n\n const instance = new Type<V>(name, ref, typeCode);\n this._cache.set(key, instance as Type);\n return instance;\n }\n}"]}
|
package/dist/cjs/types.js
DELETED
package/dist/cjs/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["\n\nexport type EqualityComparer<T> = (arg1: T, arg2: T) => boolean;\n\nexport type Consumer<T> = (arg: T) => void;\n\nexport type Predicate<T> = (arg: T) => boolean;\n\nexport type Supplier<T> = () => T;\n\nexport type Nullable<T> = T | null;\n\nexport type Nullish = null | undefined;\n\nexport type Resolvable<T> = T | Promise<T> | Supplier<T>;\n\nexport type UnaryFunction<T, R> = (arg: T) => R;\n\nexport type BinaryFunction<T1, T2, R> = (arg1: T1, arg2: T2) => R;\n\nexport type TernaryFunction<T1, T2, T3, R> = (arg1: T1, arg2: T2, arg3: T3) => R;\n\nexport type QuaternaryFunction<T1, T2, T3, T4, R> = (\n arg1: T1,\n arg2: T2,\n arg3: T3,\n arg4: T4\n) => R;\n\nexport type Constructor<T = unknown> = abstract new (...args: any[]) => T;\n\n\n"]}
|