@develia/commons 0.4.13 → 0.4.15
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/cjs/array.js +27 -1
- package/dist/cjs/array.js.map +1 -1
- package/dist/cjs/async-pool-executor.js +15 -0
- package/dist/cjs/async-pool-executor.js.map +1 -1
- package/dist/cjs/browser/form-utilities.js +33 -6
- package/dist/cjs/browser/form-utilities.js.map +1 -1
- package/dist/cjs/browser/geo-location.js +5 -0
- package/dist/cjs/browser/geo-location.js.map +1 -1
- package/dist/cjs/browser/index.js.map +1 -1
- package/dist/cjs/browser/native-bridge.js +9 -0
- package/dist/cjs/browser/native-bridge.js.map +1 -1
- package/dist/cjs/cancellable-promise.js.map +1 -1
- package/dist/cjs/clean-url-search-params.js +1 -0
- package/dist/cjs/clean-url-search-params.js.map +1 -1
- package/dist/cjs/collections/cache-dictionary.js +39 -0
- package/dist/cjs/collections/cache-dictionary.js.map +1 -1
- package/dist/cjs/collections/default-map.js +25 -1
- package/dist/cjs/collections/default-map.js.map +1 -1
- package/dist/cjs/collections/default-weak-map.js +23 -3
- package/dist/cjs/collections/default-weak-map.js.map +1 -1
- package/dist/cjs/{from.js → collections/from.js} +278 -4
- package/dist/cjs/collections/from.js.map +1 -0
- package/dist/cjs/collections/index.js +3 -1
- package/dist/cjs/collections/index.js.map +1 -1
- package/dist/cjs/draft.js +43 -2
- package/dist/cjs/draft.js.map +1 -1
- package/dist/cjs/event-bus.js +1 -0
- package/dist/cjs/event-bus.js.map +1 -1
- package/dist/cjs/index.js +14 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/key-value-pair.js +6 -0
- package/dist/cjs/key-value-pair.js.map +1 -1
- package/dist/cjs/lazy.js +4 -0
- package/dist/cjs/lazy.js.map +1 -1
- package/dist/cjs/math.js +19 -0
- package/dist/cjs/math.js.map +1 -1
- package/dist/cjs/order.js.map +1 -1
- package/dist/cjs/parse.js +96 -0
- package/dist/cjs/parse.js.map +1 -1
- package/dist/cjs/patch.js +10 -2
- package/dist/cjs/patch.js.map +1 -1
- package/dist/cjs/stopwatch.js +10 -0
- package/dist/cjs/stopwatch.js.map +1 -1
- package/dist/cjs/string.js +62 -0
- package/dist/cjs/string.js.map +1 -1
- package/dist/cjs/timer.js +7 -0
- package/dist/cjs/timer.js.map +1 -1
- package/dist/cjs/timespan.js +202 -0
- package/dist/cjs/timespan.js.map +1 -1
- package/dist/cjs/type-code.js.map +1 -1
- package/dist/cjs/type.js +80 -1
- package/dist/cjs/type.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utilities.js +213 -7
- package/dist/cjs/utilities.js.map +1 -1
- package/dist/esm/array.js +27 -1
- package/dist/esm/array.js.map +1 -1
- package/dist/esm/async-pool-executor.js +15 -0
- package/dist/esm/async-pool-executor.js.map +1 -1
- package/dist/esm/browser/form-utilities.js +33 -6
- package/dist/esm/browser/form-utilities.js.map +1 -1
- package/dist/esm/browser/geo-location.js +5 -0
- package/dist/esm/browser/geo-location.js.map +1 -1
- package/dist/esm/browser/index.js.map +1 -1
- package/dist/esm/browser/native-bridge.js +9 -0
- package/dist/esm/browser/native-bridge.js.map +1 -1
- package/dist/esm/cancellable-promise.js.map +1 -1
- package/dist/esm/clean-url-search-params.js +1 -0
- package/dist/esm/clean-url-search-params.js.map +1 -1
- package/dist/esm/collections/cache-dictionary.js +39 -0
- package/dist/esm/collections/cache-dictionary.js.map +1 -1
- package/dist/esm/collections/default-map.js +25 -1
- package/dist/esm/collections/default-map.js.map +1 -1
- package/dist/esm/collections/default-weak-map.js +22 -2
- package/dist/esm/collections/default-weak-map.js.map +1 -1
- package/dist/esm/{from.js → collections/from.js} +278 -4
- package/dist/esm/collections/from.js.map +1 -0
- package/dist/esm/collections/index.js +1 -0
- package/dist/esm/collections/index.js.map +1 -1
- package/dist/esm/draft.js +43 -2
- package/dist/esm/draft.js.map +1 -1
- package/dist/esm/event-bus.js +1 -0
- package/dist/esm/event-bus.js.map +1 -1
- package/dist/esm/index.js +13 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/key-value-pair.js +6 -0
- package/dist/esm/key-value-pair.js.map +1 -1
- package/dist/esm/lazy.js +4 -0
- package/dist/esm/lazy.js.map +1 -1
- package/dist/esm/math.js +19 -0
- package/dist/esm/math.js.map +1 -1
- package/dist/esm/order.js.map +1 -1
- package/dist/esm/parse.js +96 -0
- package/dist/esm/parse.js.map +1 -1
- package/dist/esm/patch.js +10 -2
- package/dist/esm/patch.js.map +1 -1
- package/dist/esm/stopwatch.js +10 -0
- package/dist/esm/stopwatch.js.map +1 -1
- package/dist/esm/string.js +62 -0
- package/dist/esm/string.js.map +1 -1
- package/dist/esm/timer.js +7 -0
- package/dist/esm/timer.js.map +1 -1
- package/dist/esm/timespan.js +202 -0
- package/dist/esm/timespan.js.map +1 -1
- package/dist/esm/type-code.js.map +1 -1
- package/dist/esm/type.js +80 -1
- package/dist/esm/type.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utilities.js +212 -7
- package/dist/esm/utilities.js.map +1 -1
- package/dist/types/array.d.ts +26 -0
- package/dist/types/array.d.ts.map +1 -1
- package/dist/types/async-pool-executor.d.ts +15 -0
- package/dist/types/async-pool-executor.d.ts.map +1 -1
- package/dist/types/browser/form-utilities.d.ts +13 -0
- package/dist/types/browser/form-utilities.d.ts.map +1 -1
- package/dist/types/browser/index.d.ts.map +1 -1
- package/dist/types/browser/native-bridge.d.ts +6 -0
- package/dist/types/browser/native-bridge.d.ts.map +1 -1
- package/dist/types/collections/cache-dictionary.d.ts +39 -0
- package/dist/types/collections/cache-dictionary.d.ts.map +1 -1
- package/dist/types/collections/default-map.d.ts +23 -0
- package/dist/types/collections/default-map.d.ts.map +1 -1
- package/dist/types/collections/default-weak-map.d.ts +20 -1
- package/dist/types/collections/default-weak-map.d.ts.map +1 -1
- package/dist/types/collections/from.d.ts +333 -0
- package/dist/types/collections/from.d.ts.map +1 -0
- package/dist/types/collections/index.d.ts +1 -0
- package/dist/types/collections/index.d.ts.map +1 -1
- package/dist/types/draft.d.ts +68 -0
- package/dist/types/draft.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/key-value-pair.d.ts +6 -0
- package/dist/types/key-value-pair.d.ts.map +1 -1
- package/dist/types/lazy.d.ts +4 -0
- package/dist/types/lazy.d.ts.map +1 -1
- package/dist/types/math.d.ts +19 -0
- package/dist/types/math.d.ts.map +1 -1
- package/dist/types/parse.d.ts +121 -0
- package/dist/types/parse.d.ts.map +1 -1
- package/dist/types/string.d.ts +51 -0
- package/dist/types/string.d.ts.map +1 -1
- package/dist/types/timer.d.ts +7 -0
- package/dist/types/timer.d.ts.map +1 -1
- package/dist/types/timespan.d.ts +202 -0
- package/dist/types/timespan.d.ts.map +1 -1
- package/dist/types/type.d.ts +40 -0
- package/dist/types/type.d.ts.map +1 -1
- package/dist/types/utilities.d.ts +174 -2
- package/dist/types/utilities.d.ts.map +1 -1
- package/dist/web/array.js +27 -1
- package/dist/web/array.js.map +1 -1
- package/dist/web/async-pool-executor.js +15 -0
- package/dist/web/async-pool-executor.js.map +1 -1
- package/dist/web/browser/form-utilities.js +33 -6
- package/dist/web/browser/form-utilities.js.map +1 -1
- package/dist/web/browser/geo-location.js +5 -0
- package/dist/web/browser/geo-location.js.map +1 -1
- package/dist/web/browser/index.js.map +1 -1
- package/dist/web/browser/native-bridge.js +9 -0
- package/dist/web/browser/native-bridge.js.map +1 -1
- package/dist/web/cancellable-promise.js.map +1 -1
- package/dist/web/clean-url-search-params.js +1 -0
- package/dist/web/clean-url-search-params.js.map +1 -1
- package/dist/web/collections/cache-dictionary.js +39 -0
- package/dist/web/collections/cache-dictionary.js.map +1 -1
- package/dist/web/collections/default-map.js +25 -1
- package/dist/web/collections/default-map.js.map +1 -1
- package/dist/web/collections/default-weak-map.js +22 -2
- package/dist/web/collections/default-weak-map.js.map +1 -1
- package/dist/web/{from.js → collections/from.js} +279 -5
- package/dist/web/collections/from.js.map +1 -0
- package/dist/web/collections/index.js +1 -0
- package/dist/web/collections/index.js.map +1 -1
- package/dist/web/draft.js +43 -2
- package/dist/web/draft.js.map +1 -1
- package/dist/web/event-bus.js +1 -0
- package/dist/web/event-bus.js.map +1 -1
- package/dist/web/index.js +13 -1
- package/dist/web/index.js.map +1 -1
- package/dist/web/key-value-pair.js +6 -0
- package/dist/web/key-value-pair.js.map +1 -1
- package/dist/web/lazy.js +4 -0
- package/dist/web/lazy.js.map +1 -1
- package/dist/web/math.js +19 -0
- package/dist/web/math.js.map +1 -1
- package/dist/web/order.js.map +1 -1
- package/dist/web/parse.js +96 -0
- package/dist/web/parse.js.map +1 -1
- package/dist/web/patch.js +10 -2
- package/dist/web/patch.js.map +1 -1
- package/dist/web/stopwatch.js +10 -0
- package/dist/web/stopwatch.js.map +1 -1
- package/dist/web/string.js +62 -0
- package/dist/web/string.js.map +1 -1
- package/dist/web/timer.js +7 -0
- package/dist/web/timer.js.map +1 -1
- package/dist/web/timespan.js +202 -0
- package/dist/web/timespan.js.map +1 -1
- package/dist/web/type-code.js.map +1 -1
- package/dist/web/type.js +80 -1
- package/dist/web/type.js.map +1 -1
- package/dist/web/types.js.map +1 -1
- package/dist/web/utilities.js +212 -7
- package/dist/web/utilities.js.map +1 -1
- package/package.json +1 -1
- package/src/browser/form-utilities.ts +7 -6
- package/src/browser/index.ts +2 -2
- package/src/collections/cache-dictionary.ts +39 -1
- package/src/collections/default-map.ts +15 -9
- package/src/collections/default-weak-map.ts +14 -12
- package/src/{from.ts → collections/from.ts} +285 -15
- package/src/collections/index.ts +4 -3
- package/src/draft.ts +6 -2
- package/src/index.ts +1 -1
- package/src/timespan.ts +199 -20
- package/src/utilities.ts +53 -9
- package/dist/cjs/from.js.map +0 -1
- package/dist/esm/from.js.map +0 -1
- package/dist/types/from.d.ts +0 -59
- package/dist/types/from.d.ts.map +0 -1
- package/dist/web/from.js.map +0 -1
package/dist/web/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,MAAM,UAAU,KAAK,CACjB,YAAiB,EACjB,GAAmB;IAEnB,MAAM,MAAM,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;IAE1F,MAAM,MAAM,GAAG,IAAI,GAAG,EAA0C,CAAC;IACjE,MAAM,OAAO,GACT,GAAG,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAQ,CAAC;IAEzE,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,UAAyB,GAAG,IAAe;YACtD,OAAQ,EAAU,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC;QACF,IAAI,CAAC;YACD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;gBAC/B,KAAK,EAAE,MAAM;gBACb,QAAQ,EAAE,IAAI;gBACd,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE,KAAK;aACpB,CAAC,CAAC;YACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC,CAAC,aAAa;QACvB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAYD;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,YAAiB,EAAE,OAAoD;IAC3F,MAAM,MAAM,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;IAC1F,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC;YACD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBAChB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC;oBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;YAC9E,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC7C,CAAC;QACL,CAAC;QAAC,MAAM,CAAC,CAAC,aAAa;QACvB,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import type {Constructor} from \"./types.js\";\r\n\r\nexport type PureMethod<T extends object, A extends any[] = any[], R = any> =\r\n (obj: T, ...args: A) => R;\r\n\r\nexport type PatchSpec<T extends object> =\r\n | Record<string, PureMethod<T, any[], any>>\r\n | Map<PropertyKey, PureMethod<T, any[], any>>;\r\n\r\n\r\nexport function patch<C extends Constructor<any>>(\r\n targetOrCtor: C,\r\n fns: PatchSpec<InstanceType<C>>\r\n): Map<PropertyKey, PropertyDescriptor | null>;\r\n\r\nexport function patch<T extends object>(\r\n targetOrCtor: T,\r\n fns: PatchSpec<T>\r\n): Map<PropertyKey, PropertyDescriptor | null>;\r\n\r\n/**\r\n * Devuelve un Map donde:\r\n * - clave -> null (método añadido nuevo)\r\n * - clave -> descriptorOriginal (método sustituido)\r\n */\r\nexport function patch(\r\n targetOrCtor: any,\r\n fns: PatchSpec<any>\r\n): Map<PropertyKey, PropertyDescriptor | null> {\r\n const target = typeof targetOrCtor === \"function\" ? targetOrCtor.prototype : targetOrCtor;\r\n\r\n const result = new Map<PropertyKey, PropertyDescriptor | null>();\r\n const entries: Array<[PropertyKey, PureMethod<any>]> =\r\n fns instanceof Map ? [...fns.entries()] : Object.entries(fns) as any;\r\n\r\n for (const [key, fn] of entries) {\r\n const prev = Object.getOwnPropertyDescriptor(target, key);\r\n const method = function (this: unknown, ...args: unknown[]) {\r\n return (fn as any)(this, ...args);\r\n };\r\n try {\r\n Object.defineProperty(target, key, {\r\n value: method,\r\n writable: true,\r\n configurable: true,\r\n enumerable: false,\r\n });\r\n result.set(key, prev ?? null);\r\n } catch { /* ignorar */\r\n }\r\n }\r\n return result;\r\n}\r\n\r\n// Overloads unpatch\r\nexport function unpatch<C extends Constructor<any>>(\r\n targetOrCtor: C,\r\n changes: Map<PropertyKey, PropertyDescriptor | null>\r\n): void;\r\nexport function unpatch<T extends object>(\r\n targetOrCtor: T,\r\n changes: Map<PropertyKey, PropertyDescriptor | null>\r\n): void;\r\n\r\n/**\r\n * Revierte un patch a partir del mapa devuelto por `patch`.\r\n */\r\nexport function unpatch(targetOrCtor: any, changes: Map<PropertyKey, PropertyDescriptor | null>): void {\r\n const target = typeof targetOrCtor === \"function\" ? targetOrCtor.prototype : targetOrCtor;\r\n for (const [key, prev] of changes) {\r\n try {\r\n if (prev === null) {\r\n if (Object.prototype.hasOwnProperty.call(target, key)) delete target[key];\r\n } else {\r\n Object.defineProperty(target, key, prev);\r\n }\r\n } catch { /* ignorar */\r\n }\r\n }\r\n}"]}
|
package/dist/web/stopwatch.js
CHANGED
|
@@ -4,6 +4,16 @@ export default class Stopwatch {
|
|
|
4
4
|
this.startTime = null;
|
|
5
5
|
this.elapsedTime = null;
|
|
6
6
|
}
|
|
7
|
+
/*static measure<T>(callback: () => T, measure: { value: TimeSpan | null }): T {
|
|
8
|
+
const stopwatch = new Stopwatch();
|
|
9
|
+
stopwatch.start();
|
|
10
|
+
try {
|
|
11
|
+
return callback();
|
|
12
|
+
} finally {
|
|
13
|
+
stopwatch.stop();
|
|
14
|
+
measure.value = stopwatch.getElapsedTime();
|
|
15
|
+
}
|
|
16
|
+
}*/
|
|
7
17
|
start() {
|
|
8
18
|
this.startTime = performance.now();
|
|
9
19
|
this.elapsedTime = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stopwatch.js","sourceRoot":"","sources":["../../src/stopwatch.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,SAAS;IAA9B;QACY,cAAS,GAAkB,IAAI,CAAC;QAChC,gBAAW,GAAkB,IAAI,CAAC;IAsC9C,CAAC;
|
|
1
|
+
{"version":3,"file":"stopwatch.js","sourceRoot":"","sources":["../../src/stopwatch.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,SAAS;IAA9B;QACY,cAAS,GAAkB,IAAI,CAAC;QAChC,gBAAW,GAAkB,IAAI,CAAC;IAsC9C,CAAC;IApCG;;;;;;;;;OASG;IAEH,KAAK;QACD,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,IAAI;QACA,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;YACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAC1B,CAAC;IACL,CAAC;IAED,MAAM;QACF,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC;YACtD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC5B,CAAC;IACL,CAAC;IAED,cAAc;QACV,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC1B,OAAO,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import TimeSpan from \"./timespan.js\";\r\n\r\nexport default class Stopwatch {\r\n private startTime: number | null = null;\r\n private elapsedTime: number | null = null;\r\n\r\n /*static measure<T>(callback: () => T, measure: { value: TimeSpan | null }): T {\r\n const stopwatch = new Stopwatch();\r\n stopwatch.start();\r\n try {\r\n return callback();\r\n } finally {\r\n stopwatch.stop();\r\n measure.value = stopwatch.getElapsedTime();\r\n }\r\n }*/\r\n\r\n start(): void {\r\n this.startTime = performance.now();\r\n this.elapsedTime = null;\r\n }\r\n\r\n stop(): void {\r\n if (this.startTime !== null) {\r\n this.elapsedTime = performance.now() - this.startTime;\r\n this.startTime = null;\r\n }\r\n }\r\n\r\n resume(): void {\r\n if (this.elapsedTime !== null) {\r\n this.startTime = performance.now() - this.elapsedTime;\r\n this.elapsedTime = null;\r\n }\r\n }\r\n\r\n getElapsedTime(): TimeSpan {\r\n if (this.startTime !== null) {\r\n return TimeSpan.fromMilliseconds(performance.now() - this.startTime);\r\n }\r\n return TimeSpan.fromMilliseconds(this.elapsedTime ?? 0.0);\r\n }\r\n}\r\n"]}
|
package/dist/web/string.js
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that a given string has a specific prefix.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string to ensure the prefix on.
|
|
5
|
+
* @param {string} prefix - The prefix to ensure on the string.
|
|
6
|
+
* @return {string} - The resulting string with the ensured prefix.
|
|
7
|
+
*/
|
|
1
8
|
export function ensurePrefix(str, prefix) {
|
|
2
9
|
if (!str.startsWith(prefix))
|
|
3
10
|
return prefix + str;
|
|
4
11
|
return str;
|
|
5
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Ensures that a string ends with a specified suffix.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} str - The original string.
|
|
17
|
+
* @param {string} suffix - The suffix to ensure.
|
|
18
|
+
* @return {string} - The modified string with the suffix added if it was not already present.
|
|
19
|
+
*/
|
|
6
20
|
export function ensureSuffix(str, suffix) {
|
|
7
21
|
if (!str.endsWith(suffix))
|
|
8
22
|
return str + suffix;
|
|
9
23
|
return str;
|
|
10
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Formats a string using a template and provided arguments.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} template - The template string containing placeholders.
|
|
29
|
+
* @param {any[]} args - Optional arguments to replace the placeholders in the template.
|
|
30
|
+
* @return {string} The formatted string.
|
|
31
|
+
*/
|
|
11
32
|
export function format(template, ...args) {
|
|
12
33
|
let regex;
|
|
13
34
|
if (args.length === 1 && typeof args[0] === 'object') {
|
|
@@ -21,24 +42,53 @@ export function format(template, ...args) {
|
|
|
21
42
|
return typeof args[key] !== 'undefined' ? args[key] : "";
|
|
22
43
|
});
|
|
23
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Splits a string into its constituent words, regardless of the original case
|
|
47
|
+
* style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,
|
|
48
|
+
* space-separated, etc.).
|
|
49
|
+
*
|
|
50
|
+
* @param {string} str - The string to split into words.
|
|
51
|
+
* @return {string[]} - The list of lowercase words extracted from the input.
|
|
52
|
+
*/
|
|
24
53
|
function toWords(str) {
|
|
25
54
|
if (!str)
|
|
26
55
|
return [];
|
|
27
56
|
return str
|
|
57
|
+
// Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)
|
|
28
58
|
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
59
|
+
// Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)
|
|
29
60
|
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
61
|
+
// Replace any non-alphanumeric character with a space
|
|
30
62
|
.replace(/[^a-zA-Z0-9]+/g, ' ')
|
|
31
63
|
.trim()
|
|
32
64
|
.toLowerCase()
|
|
33
65
|
.split(/\s+/)
|
|
34
66
|
.filter(Boolean);
|
|
35
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts a string to snake_case.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} str - The string to convert.
|
|
72
|
+
* @return {string} - The string converted to snake_case.
|
|
73
|
+
*/
|
|
36
74
|
export function toSnakeCase(str) {
|
|
37
75
|
return toWords(str).join('_');
|
|
38
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Converts a string to kebab-case.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} str - The string to convert.
|
|
81
|
+
* @return {string} - The string converted to kebab-case.
|
|
82
|
+
*/
|
|
39
83
|
export function toKebabCase(str) {
|
|
40
84
|
return toWords(str).join('-');
|
|
41
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts a string to camelCase.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} str - The string to convert.
|
|
90
|
+
* @return {string} - The string converted to camelCase.
|
|
91
|
+
*/
|
|
42
92
|
export function toCamelCase(str) {
|
|
43
93
|
const words = toWords(str);
|
|
44
94
|
if (words.length === 0)
|
|
@@ -47,11 +97,23 @@ export function toCamelCase(str) {
|
|
|
47
97
|
.map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
|
|
48
98
|
.join('');
|
|
49
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Converts a string to PascalCase.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} str - The string to convert.
|
|
104
|
+
* @return {string} - The string converted to PascalCase.
|
|
105
|
+
*/
|
|
50
106
|
export function toPascalCase(str) {
|
|
51
107
|
return toWords(str)
|
|
52
108
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
53
109
|
.join('');
|
|
54
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).
|
|
113
|
+
*
|
|
114
|
+
* @param {string} str - The string to convert.
|
|
115
|
+
* @return {string} - The string converted to CONSTANT_CASE.
|
|
116
|
+
*/
|
|
55
117
|
export function toConstantCase(str) {
|
|
56
118
|
return toWords(str).join('_').toUpperCase();
|
|
57
119
|
}
|
package/dist/web/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/string.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/string.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,MAAc;IACpD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;QACvB,OAAO,MAAM,GAAG,GAAG,CAAA;IACvB,OAAO,GAAG,CAAA;AACd,CAAC;AAGD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,MAAc;IACpD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,OAAO,GAAG,GAAG,MAAM,CAAA;IACvB,OAAO,GAAG,CAAA;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,QAAgB,EAAE,GAAG,IAAW;IAEnD,IAAI,KAAa,CAAC;IAClB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QACnD,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACf,KAAK,GAAG,UAAU,CAAC;IACvB,CAAC;SAAM,CAAC;QACJ,KAAK,GAAG,WAAW,CAAC;IACxB,CAAC;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,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,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC/E,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC;SACd,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACzD,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACtC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AAChD,CAAC","sourcesContent":["\n/**\n * Ensures that a given string has a specific prefix.\n *\n * @param {string} str - The string to ensure the prefix on.\n * @param {string} prefix - The prefix to ensure on the string.\n * @return {string} - The resulting string with the ensured prefix.\n */\nexport function ensurePrefix(str: string, prefix: string): string {\n if (!str.startsWith(prefix))\n return prefix + str\n return str\n}\n\n\n/**\n * Ensures that a string ends with a specified suffix.\n *\n * @param {string} str - The original string.\n * @param {string} suffix - The suffix to ensure.\n * @return {string} - The modified string with the suffix added if it was not already present.\n */\nexport function ensureSuffix(str: string, suffix: string): string {\n if (!str.endsWith(suffix))\n return str + suffix\n return str\n}\n\n/**\n * Formats a string using a template and provided arguments.\n *\n * @param {string} template - The template string containing placeholders.\n * @param {any[]} args - Optional arguments to replace the placeholders in the template.\n * @return {string} The formatted string.\n */\nexport function format(template: string, ...args: any[]): string {\n\n let regex: RegExp;\n if (args.length === 1 && typeof args[0] === 'object') {\n args = args[0];\n regex = /{(.+?)}/g;\n } else {\n regex = /{(\\d+?)}/g;\n }\n\n return template.replace(regex, (match, key) => {\n return typeof args[key] !== 'undefined' ? args[key] : \"\";\n });\n}\n\n/**\n * Splits a string into its constituent words, regardless of the original case\n * style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,\n * space-separated, etc.).\n *\n * @param {string} str - The string to split into words.\n * @return {string[]} - The list of lowercase words extracted from the input.\n */\nfunction toWords(str: string): string[] {\n if (!str) return [];\n\n return str\n // Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n // Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n // Replace any non-alphanumeric character with a space\n .replace(/[^a-zA-Z0-9]+/g, ' ')\n .trim()\n .toLowerCase()\n .split(/\\s+/)\n .filter(Boolean);\n}\n\n/**\n * Converts a string to snake_case.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to snake_case.\n */\nexport function toSnakeCase(str: string): string {\n return toWords(str).join('_');\n}\n\n/**\n * Converts a string to kebab-case.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to kebab-case.\n */\nexport function toKebabCase(str: string): string {\n return toWords(str).join('-');\n}\n\n/**\n * Converts a string to camelCase.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to camelCase.\n */\nexport function toCamelCase(str: string): string {\n const words = toWords(str);\n if (words.length === 0) return '';\n return words\n .map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))\n .join('');\n}\n\n/**\n * Converts a string to PascalCase.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to PascalCase.\n */\nexport function toPascalCase(str: string): string {\n return toWords(str)\n .map(word => word.charAt(0).toUpperCase() + word.slice(1))\n .join('');\n}\n\n/**\n * Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to CONSTANT_CASE.\n */\nexport function toConstantCase(str: string): string {\n return toWords(str).join('_').toUpperCase();\n}"]}
|
package/dist/web/timer.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class representing a timer that executes a callback function at a specified interval.
|
|
3
|
+
*/
|
|
1
4
|
export default class Timer {
|
|
5
|
+
/**
|
|
6
|
+
* @param callback Callback
|
|
7
|
+
* @param interval Seconds between calls
|
|
8
|
+
*/
|
|
2
9
|
constructor(callback, interval) {
|
|
3
10
|
this._callback = callback;
|
|
4
11
|
this._interval = interval;
|
package/dist/web/timer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/timer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/timer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAMtB;;;OAGG;IACH,YAAY,QAAoB,EAAE,QAAgB;QAC9C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAGD,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC;IACvE,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,QAAQ,CAAC,KAAa;QACtB,IAAI,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,IAAI,CAAC,OAAO;gBACZ,IAAI,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;IACL,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,QAAQ,CAAC,KAAiB;QAC1B,IAAI,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QAC3B,CAAC;IACL,CAAC;IAGD,KAAK;QACD,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;gBAChC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI;oBACtB,IAAI,CAAC,SAAS,EAAE,CAAC;YACzB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IAED,IAAI;QACA,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;YAC5B,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAChC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC5B,CAAC;IACL,CAAC;IAED,OAAO;QACH,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACJ","sourcesContent":["/**\r\n * A class representing a timer that executes a callback function at a specified interval.\r\n */\r\nexport default class Timer {\r\n\r\n private _callback: () => void;\r\n private _interval: number;\r\n private _intervalId: any | null;\r\n\r\n /**\r\n * @param callback Callback\r\n * @param interval Seconds between calls\r\n */\r\n constructor(callback: () => void, interval: number) {\r\n this._callback = callback;\r\n this._interval = interval;\r\n this._intervalId = null;\r\n }\r\n\r\n \r\n get running(): boolean {\r\n return this._intervalId !== null && this._intervalId !== undefined;\r\n }\r\n\r\n get interval(): number {\r\n return this._interval;\r\n }\r\n\r\n set interval(value: number) {\r\n if (value != this._interval) {\r\n this._interval = value;\r\n if (this.running)\r\n this.restart();\r\n }\r\n }\r\n\r\n get callback(): () => void {\r\n return this._callback;\r\n }\r\n\r\n set callback(value: () => void) {\r\n if (value != this._callback) {\r\n this._callback = value;\r\n }\r\n }\r\n\r\n\r\n start(): void {\r\n if (this._intervalId === null) {\r\n this._intervalId = setInterval(() => {\r\n if (this._callback != null)\r\n this._callback();\r\n }, this._interval);\r\n }\r\n }\r\n\r\n stop(): void {\r\n if (this._intervalId !== null) {\r\n clearInterval(this._intervalId);\r\n this._intervalId = null;\r\n }\r\n }\r\n\r\n restart(): void {\r\n this.stop();\r\n this.start();\r\n }\r\n}"]}
|
package/dist/web/timespan.js
CHANGED
|
@@ -1,91 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a duration of time in milliseconds.
|
|
3
|
+
*/
|
|
1
4
|
class TimeSpan {
|
|
2
5
|
constructor(milliseconds) {
|
|
3
6
|
this.milliseconds = milliseconds;
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Gets the time interval in seconds.
|
|
10
|
+
* @returns {number} The duration in seconds.
|
|
11
|
+
*/
|
|
5
12
|
seconds() {
|
|
6
13
|
return this.milliseconds / 1000;
|
|
7
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the time interval in minutes.
|
|
17
|
+
* @returns {number} The duration in minutes.
|
|
18
|
+
*/
|
|
8
19
|
minutes() {
|
|
9
20
|
return this.milliseconds / (1000 * 60);
|
|
10
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the time interval in hours.
|
|
24
|
+
* @returns {number} The duration in hours.
|
|
25
|
+
*/
|
|
11
26
|
hours() {
|
|
12
27
|
return this.milliseconds / (1000 * 60 * 60);
|
|
13
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets the time interval in days.
|
|
31
|
+
* @returns {number} The duration in days.
|
|
32
|
+
*/
|
|
14
33
|
days() {
|
|
15
34
|
return this.milliseconds / (1000 * 60 * 60 * 24);
|
|
16
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the time interval in weeks.
|
|
38
|
+
* @returns {number} The duration in weeks.
|
|
39
|
+
*/
|
|
17
40
|
weeks() {
|
|
18
41
|
return this.milliseconds / (1000 * 60 * 60 * 24 * 7);
|
|
19
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a TimeSpan from a specified number of milliseconds.
|
|
45
|
+
* @param {number} milliseconds - The number of milliseconds.
|
|
46
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
47
|
+
*/
|
|
20
48
|
static fromMilliseconds(milliseconds) {
|
|
21
49
|
return new TimeSpan(milliseconds);
|
|
22
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a TimeSpan from a specified number of seconds.
|
|
53
|
+
* @param {number} seconds - The number of seconds.
|
|
54
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
55
|
+
*/
|
|
23
56
|
static fromSeconds(seconds) {
|
|
24
57
|
return new TimeSpan(seconds * 1000);
|
|
25
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a TimeSpan from a specified number of minutes.
|
|
61
|
+
* @param {number} minutes - The number of minutes.
|
|
62
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
63
|
+
*/
|
|
26
64
|
static fromMinutes(minutes) {
|
|
27
65
|
return new TimeSpan(minutes * 1000 * 60);
|
|
28
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a TimeSpan from a specified number of hours.
|
|
69
|
+
* @param {number} hours - The number of hours.
|
|
70
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
71
|
+
*/
|
|
29
72
|
static fromHours(hours) {
|
|
30
73
|
return new TimeSpan(hours * 1000 * 60 * 60);
|
|
31
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a TimeSpan from a specified number of days.
|
|
77
|
+
* @param {number} days - The number of days.
|
|
78
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
79
|
+
*/
|
|
32
80
|
static fromDays(days) {
|
|
33
81
|
return new TimeSpan(days * 1000 * 60 * 60 * 24);
|
|
34
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a TimeSpan from a specified number of weeks.
|
|
85
|
+
* @param {number} weeks - The number of weeks.
|
|
86
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
87
|
+
*/
|
|
35
88
|
static fromWeeks(weeks) {
|
|
36
89
|
return new TimeSpan(weeks * 1000 * 60 * 60 * 24 * 7);
|
|
37
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns a new TimeSpan that adds the specified number of milliseconds to this instance.
|
|
93
|
+
* @param {number} milliseconds - The milliseconds to add.
|
|
94
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
95
|
+
*/
|
|
38
96
|
addMilliseconds(milliseconds) {
|
|
39
97
|
return new TimeSpan(this.milliseconds + milliseconds);
|
|
40
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns a new TimeSpan that adds the specified number of seconds to this instance.
|
|
101
|
+
* @param {number} seconds - The seconds to add.
|
|
102
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
103
|
+
*/
|
|
41
104
|
addSeconds(seconds) {
|
|
42
105
|
return this.addMilliseconds(seconds * 1000);
|
|
43
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns a new TimeSpan that adds the specified number of minutes to this instance.
|
|
109
|
+
* @param {number} minutes - The minutes to add.
|
|
110
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
111
|
+
*/
|
|
44
112
|
addMinutes(minutes) {
|
|
45
113
|
return this.addMilliseconds(minutes * 1000 * 60);
|
|
46
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns a new TimeSpan that adds the specified number of hours to this instance.
|
|
117
|
+
* @param {number} hours - The hours to add.
|
|
118
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
119
|
+
*/
|
|
47
120
|
addHours(hours) {
|
|
48
121
|
return this.addMilliseconds(hours * 1000 * 60 * 60);
|
|
49
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns a new TimeSpan that adds the specified number of days to this instance.
|
|
125
|
+
* @param {number} days - The days to add.
|
|
126
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
127
|
+
*/
|
|
50
128
|
addDays(days) {
|
|
51
129
|
return this.addMilliseconds(days * 1000 * 60 * 60 * 24);
|
|
52
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns a new TimeSpan that adds the specified number of weeks to this instance.
|
|
133
|
+
* @param {number} weeks - The weeks to add.
|
|
134
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
135
|
+
*/
|
|
53
136
|
addWeeks(weeks) {
|
|
54
137
|
return this.addMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
|
|
55
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns a new TimeSpan that subtracts the specified number of milliseconds from this instance.
|
|
141
|
+
* @param {number} milliseconds - The milliseconds to subtract.
|
|
142
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
143
|
+
*/
|
|
56
144
|
subtractMilliseconds(milliseconds) {
|
|
57
145
|
return new TimeSpan(this.milliseconds - milliseconds);
|
|
58
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns a new TimeSpan that subtracts the specified number of seconds from this instance.
|
|
149
|
+
* @param {number} seconds - The seconds to subtract.
|
|
150
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
151
|
+
*/
|
|
59
152
|
subtractSeconds(seconds) {
|
|
60
153
|
return this.subtractMilliseconds(seconds * 1000);
|
|
61
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns a new TimeSpan that subtracts the specified number of minutes from this instance.
|
|
157
|
+
* @param {number} minutes - The minutes to subtract.
|
|
158
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
159
|
+
*/
|
|
62
160
|
subtractMinutes(minutes) {
|
|
63
161
|
return this.subtractMilliseconds(minutes * 1000 * 60);
|
|
64
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns a new TimeSpan that subtracts the specified number of hours from this instance.
|
|
165
|
+
* @param {number} hours - The hours to subtract.
|
|
166
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
167
|
+
*/
|
|
65
168
|
subtractHours(hours) {
|
|
66
169
|
return this.subtractMilliseconds(hours * 1000 * 60 * 60);
|
|
67
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns a new TimeSpan that subtracts the specified number of days from this instance.
|
|
173
|
+
* @param {number} days - The days to subtract.
|
|
174
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
175
|
+
*/
|
|
68
176
|
subtractDays(days) {
|
|
69
177
|
return this.subtractMilliseconds(days * 1000 * 60 * 60 * 24);
|
|
70
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns a new TimeSpan that subtracts the specified number of weeks from this instance.
|
|
181
|
+
* @param {number} weeks - The weeks to subtract.
|
|
182
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
183
|
+
*/
|
|
71
184
|
subtractWeeks(weeks) {
|
|
72
185
|
return this.subtractMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
|
|
73
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns a new TimeSpan that adds the specified TimeSpan to this instance.
|
|
189
|
+
* @param {TimeSpan} other - The TimeSpan to add.
|
|
190
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
191
|
+
*/
|
|
74
192
|
add(other) {
|
|
75
193
|
return new TimeSpan(this.milliseconds + other.milliseconds);
|
|
76
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns a new TimeSpan that subtracts the specified TimeSpan from this instance.
|
|
197
|
+
* @param {TimeSpan} other - The TimeSpan to subtract.
|
|
198
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
199
|
+
*/
|
|
77
200
|
subtract(other) {
|
|
78
201
|
return new TimeSpan(this.milliseconds - other.milliseconds);
|
|
79
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Adds this TimeSpan to a specified Date.
|
|
205
|
+
* @param {Date} date - The date to add to.
|
|
206
|
+
* @returns {Date} A new Date instance.
|
|
207
|
+
*/
|
|
80
208
|
addTo(date) {
|
|
81
209
|
return new Date(date.getTime() + this.milliseconds);
|
|
82
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Subtracts this TimeSpan from a specified Date.
|
|
213
|
+
* @param {Date} date - The date to subtract from.
|
|
214
|
+
* @returns {Date} A new Date instance.
|
|
215
|
+
*/
|
|
83
216
|
subtractFrom(date) {
|
|
84
217
|
return new Date(date.getTime() - this.milliseconds);
|
|
85
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Creates a TimeSpan from the difference between two dates.
|
|
221
|
+
* @param {Date} earlierDate - The earlier date.
|
|
222
|
+
* @param {Date} laterDate - The later date.
|
|
223
|
+
* @returns {TimeSpan} A new TimeSpan instance representing the difference.
|
|
224
|
+
*/
|
|
86
225
|
static fromDifference(earlierDate, laterDate) {
|
|
87
226
|
return new TimeSpan(laterDate.getTime() - earlierDate.getTime());
|
|
88
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Formats the TimeSpan as a string.
|
|
230
|
+
* Supported tokens: hh, h, mm, m, ss, s.
|
|
231
|
+
* @param {string} format - The format string (default: 'hh:mm:ss').
|
|
232
|
+
* @returns {string} The formatted string.
|
|
233
|
+
*/
|
|
89
234
|
format(format = 'hh:mm:ss') {
|
|
90
235
|
const formatLower = format.toLowerCase();
|
|
91
236
|
const hasHours = formatLower.includes("h");
|
|
@@ -110,41 +255,98 @@ class TimeSpan {
|
|
|
110
255
|
.replace('ss', secondsPadded)
|
|
111
256
|
.replace('s', seconds.toString());
|
|
112
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Checks if this TimeSpan is equal to another.
|
|
260
|
+
* @param {TimeSpan} other - The other TimeSpan.
|
|
261
|
+
* @returns {boolean} True if equal.
|
|
262
|
+
*/
|
|
113
263
|
eq(other) {
|
|
114
264
|
return this.milliseconds === other.milliseconds;
|
|
115
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Checks if this TimeSpan is less than or equal to another.
|
|
268
|
+
* @param {TimeSpan} other - The other TimeSpan.
|
|
269
|
+
* @returns {boolean} True if less than or equal.
|
|
270
|
+
*/
|
|
116
271
|
le(other) {
|
|
117
272
|
return this.milliseconds <= other.milliseconds;
|
|
118
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Checks if this TimeSpan is less than another.
|
|
276
|
+
* @param {TimeSpan} other - The other TimeSpan.
|
|
277
|
+
* @returns {boolean} True if less than.
|
|
278
|
+
*/
|
|
119
279
|
lt(other) {
|
|
120
280
|
return this.milliseconds < other.milliseconds;
|
|
121
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Checks if this TimeSpan is greater than or equal to another.
|
|
284
|
+
* @param {TimeSpan} other - The other TimeSpan.
|
|
285
|
+
* @returns {boolean} True if greater than or equal.
|
|
286
|
+
*/
|
|
122
287
|
ge(other) {
|
|
123
288
|
return this.milliseconds >= other.milliseconds;
|
|
124
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Checks if this TimeSpan is greater than another.
|
|
292
|
+
* @param {TimeSpan} other - The other TimeSpan.
|
|
293
|
+
* @returns {boolean} True if greater than.
|
|
294
|
+
*/
|
|
125
295
|
gt(other) {
|
|
126
296
|
return this.milliseconds > other.milliseconds;
|
|
127
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Multiplies the TimeSpan by a number.
|
|
300
|
+
* @param {number} number - The multiplier.
|
|
301
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
302
|
+
*/
|
|
128
303
|
multiply(number) {
|
|
129
304
|
return new TimeSpan(this.milliseconds * number);
|
|
130
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Divides the TimeSpan by a number.
|
|
308
|
+
* @param {number} number - The divisor.
|
|
309
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
310
|
+
*/
|
|
131
311
|
divide(number) {
|
|
132
312
|
return new TimeSpan(this.milliseconds / number);
|
|
133
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Returns the absolute value of the TimeSpan.
|
|
316
|
+
* @returns {TimeSpan} A new TimeSpan instance.
|
|
317
|
+
*/
|
|
134
318
|
abs() {
|
|
135
319
|
return new TimeSpan(Math.abs(this.milliseconds));
|
|
136
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Checks if the TimeSpan is infinite.
|
|
323
|
+
* @returns {boolean} True if infinite.
|
|
324
|
+
*/
|
|
137
325
|
isInfinite() {
|
|
138
326
|
return this.milliseconds === Number.POSITIVE_INFINITY || this.milliseconds === Number.NEGATIVE_INFINITY;
|
|
139
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Checks if the TimeSpan is positive infinite.
|
|
330
|
+
* @returns {boolean} True if positive infinite.
|
|
331
|
+
*/
|
|
140
332
|
isPositiveInfinite() {
|
|
141
333
|
return this.milliseconds === Number.POSITIVE_INFINITY;
|
|
142
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Checks if the TimeSpan is negative infinite.
|
|
337
|
+
* @returns {boolean} True if negative infinite.
|
|
338
|
+
*/
|
|
143
339
|
isNegativeInfinite() {
|
|
144
340
|
return this.milliseconds === Number.NEGATIVE_INFINITY;
|
|
145
341
|
}
|
|
146
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Infinite duration.
|
|
345
|
+
*/
|
|
147
346
|
TimeSpan.INFINITE = new TimeSpan(Number.POSITIVE_INFINITY);
|
|
347
|
+
/**
|
|
348
|
+
* Negative infinite duration.
|
|
349
|
+
*/
|
|
148
350
|
TimeSpan.NEGATIVE_INFINITE = new TimeSpan(Number.NEGATIVE_INFINITY);
|
|
149
351
|
export default TimeSpan;
|
|
150
352
|
//# sourceMappingURL=timespan.js.map
|
package/dist/web/timespan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timespan.js","sourceRoot":"","sources":["../../src/timespan.ts"],"names":[],"mappings":"AAGA,MAAqB,QAAQ;IAGzB,YAAoB,YAAoB;QACpC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAID,OAAO;QACH,OAAO,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IACpC,CAAC;IAGD,OAAO;QAC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AAI,CAAC,YAAY,KAAK,MAAM,CAAC,iBAAiB,CAAA;IAC3G,CAAC;IAED;;;OAGG;IACH,kBAAkB;QACd,OAAO,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,iBAAiB,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,kBAAkB;QACd,OAAO,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,iBAAiB,CAAC;IAC1D,CAAC;;AAhCD;;GAEG;AACa,iBAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAElE;;GAEG;AACa,0BAAiB,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;eAlX1D,QAAQ","sourcesContent":["/**\r\n * Represents a duration of time in milliseconds.\r\n */\r\nexport default class TimeSpan {\r\n public milliseconds: number;\r\n\r\n private constructor(milliseconds: number) {\r\n this.milliseconds = milliseconds;\r\n }\r\n\r\n\r\n /**\r\n * Gets the time interval in seconds.\r\n * @returns {number} The duration in seconds.\r\n */\r\n seconds(): number {\r\n return this.milliseconds / 1000;\r\n }\r\n\r\n /**\r\n * Gets the time interval in minutes.\r\n * @returns {number} The duration in minutes.\r\n */\r\n minutes(): number {\r\n return this.milliseconds / (1000 * 60);\r\n }\r\n\r\n /**\r\n * Gets the time interval in hours.\r\n * @returns {number} The duration in hours.\r\n */\r\n hours(): number {\r\n return this.milliseconds / (1000 * 60 * 60);\r\n }\r\n\r\n /**\r\n * Gets the time interval in days.\r\n * @returns {number} The duration in days.\r\n */\r\n days(): number {\r\n return this.milliseconds / (1000 * 60 * 60 * 24);\r\n }\r\n\r\n /**\r\n * Gets the time interval in weeks.\r\n * @returns {number} The duration in weeks.\r\n */\r\n weeks(): number {\r\n return this.milliseconds / (1000 * 60 * 60 * 24 * 7);\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from a specified number of milliseconds.\r\n * @param {number} milliseconds - The number of milliseconds.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n static fromMilliseconds(milliseconds: number): TimeSpan {\r\n return new TimeSpan(milliseconds);\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from a specified number of seconds.\r\n * @param {number} seconds - The number of seconds.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n static fromSeconds(seconds: number): TimeSpan {\r\n return new TimeSpan(seconds * 1000);\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from a specified number of minutes.\r\n * @param {number} minutes - The number of minutes.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n static fromMinutes(minutes: number): TimeSpan {\r\n return new TimeSpan(minutes * 1000 * 60);\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from a specified number of hours.\r\n * @param {number} hours - The number of hours.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n static fromHours(hours: number): TimeSpan {\r\n return new TimeSpan(hours * 1000 * 60 * 60);\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from a specified number of days.\r\n * @param {number} days - The number of days.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n static fromDays(days: number): TimeSpan {\r\n return new TimeSpan(days * 1000 * 60 * 60 * 24);\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from a specified number of weeks.\r\n * @param {number} weeks - The number of weeks.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n static fromWeeks(weeks: number): TimeSpan {\r\n return new TimeSpan(weeks * 1000 * 60 * 60 * 24 * 7);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that adds the specified number of milliseconds to this instance.\r\n * @param {number} milliseconds - The milliseconds to add.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n addMilliseconds(milliseconds: number): TimeSpan {\r\n return new TimeSpan(this.milliseconds + milliseconds);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that adds the specified number of seconds to this instance.\r\n * @param {number} seconds - The seconds to add.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n addSeconds(seconds: number): TimeSpan {\r\n return this.addMilliseconds(seconds * 1000);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that adds the specified number of minutes to this instance.\r\n * @param {number} minutes - The minutes to add.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n addMinutes(minutes: number): TimeSpan {\r\n return this.addMilliseconds(minutes * 1000 * 60);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that adds the specified number of hours to this instance.\r\n * @param {number} hours - The hours to add.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n addHours(hours: number): TimeSpan {\r\n return this.addMilliseconds(hours * 1000 * 60 * 60);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that adds the specified number of days to this instance.\r\n * @param {number} days - The days to add.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n addDays(days: number): TimeSpan {\r\n return this.addMilliseconds(days * 1000 * 60 * 60 * 24);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that adds the specified number of weeks to this instance.\r\n * @param {number} weeks - The weeks to add.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n addWeeks(weeks: number): TimeSpan {\r\n return this.addMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that subtracts the specified number of milliseconds from this instance.\r\n * @param {number} milliseconds - The milliseconds to subtract.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n subtractMilliseconds(milliseconds: number): TimeSpan {\r\n return new TimeSpan(this.milliseconds - milliseconds);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that subtracts the specified number of seconds from this instance.\r\n * @param {number} seconds - The seconds to subtract.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n subtractSeconds(seconds: number): TimeSpan {\r\n return this.subtractMilliseconds(seconds * 1000);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that subtracts the specified number of minutes from this instance.\r\n * @param {number} minutes - The minutes to subtract.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n subtractMinutes(minutes: number): TimeSpan {\r\n return this.subtractMilliseconds(minutes * 1000 * 60);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that subtracts the specified number of hours from this instance.\r\n * @param {number} hours - The hours to subtract.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n subtractHours(hours: number): TimeSpan {\r\n return this.subtractMilliseconds(hours * 1000 * 60 * 60);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that subtracts the specified number of days from this instance.\r\n * @param {number} days - The days to subtract.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n subtractDays(days: number): TimeSpan {\r\n return this.subtractMilliseconds(days * 1000 * 60 * 60 * 24);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that subtracts the specified number of weeks from this instance.\r\n * @param {number} weeks - The weeks to subtract.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n subtractWeeks(weeks: number): TimeSpan {\r\n return this.subtractMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that adds the specified TimeSpan to this instance.\r\n * @param {TimeSpan} other - The TimeSpan to add.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n add(other: TimeSpan): TimeSpan {\r\n return new TimeSpan(this.milliseconds + other.milliseconds);\r\n }\r\n\r\n /**\r\n * Returns a new TimeSpan that subtracts the specified TimeSpan from this instance.\r\n * @param {TimeSpan} other - The TimeSpan to subtract.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n subtract(other: TimeSpan): TimeSpan {\r\n return new TimeSpan(this.milliseconds - other.milliseconds);\r\n }\r\n\r\n /**\r\n * Adds this TimeSpan to a specified Date.\r\n * @param {Date} date - The date to add to.\r\n * @returns {Date} A new Date instance.\r\n */\r\n addTo(date: Date): Date {\r\n return new Date(date.getTime() + this.milliseconds);\r\n }\r\n\r\n /**\r\n * Subtracts this TimeSpan from a specified Date.\r\n * @param {Date} date - The date to subtract from.\r\n * @returns {Date} A new Date instance.\r\n */\r\n subtractFrom(date: Date): Date {\r\n return new Date(date.getTime() - this.milliseconds);\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from the difference between two dates.\r\n * @param {Date} earlierDate - The earlier date.\r\n * @param {Date} laterDate - The later date.\r\n * @returns {TimeSpan} A new TimeSpan instance representing the difference.\r\n */\r\n static fromDifference(earlierDate: Date, laterDate: Date): TimeSpan {\r\n return new TimeSpan(laterDate.getTime() - earlierDate.getTime());\r\n }\r\n\r\n /**\r\n * Formats the TimeSpan as a string.\r\n * Supported tokens: hh, h, mm, m, ss, s.\r\n * @param {string} format - The format string (default: 'hh:mm:ss').\r\n * @returns {string} The formatted string.\r\n */\r\n format(format: string = 'hh:mm:ss'): string {\r\n const formatLower = format.toLowerCase();\r\n const hasHours = formatLower.includes(\"h\");\r\n const hasMinutes = formatLower.includes(\"m\");\r\n\r\n let hours = 0, minutes = 0, seconds = Math.floor(this.milliseconds / 1000);\r\n\r\n if (hasHours) {\r\n hours = Math.floor(seconds / 3600);\r\n seconds -= hours * 3600;\r\n }\r\n if (hasMinutes) {\r\n minutes = Math.floor(seconds / 60);\r\n seconds -= minutes * 60;\r\n }\r\n\r\n const hoursPadded = String(hours).padStart(2, '0');\r\n const minutesPadded = String(minutes).padStart(2, '0');\r\n const secondsPadded = String(seconds).padStart(2, '0');\r\n\r\n return formatLower\r\n .replace('hh', hoursPadded)\r\n .replace('h', hours.toString())\r\n .replace('mm', minutesPadded)\r\n .replace('m', minutes.toString())\r\n .replace('ss', secondsPadded)\r\n .replace('s', seconds.toString());\r\n }\r\n\r\n /**\r\n * Checks if this TimeSpan is equal to another.\r\n * @param {TimeSpan} other - The other TimeSpan.\r\n * @returns {boolean} True if equal.\r\n */\r\n eq(other: TimeSpan): boolean {\r\n return this.milliseconds === other.milliseconds;\r\n }\r\n\r\n /**\r\n * Checks if this TimeSpan is less than or equal to another.\r\n * @param {TimeSpan} other - The other TimeSpan.\r\n * @returns {boolean} True if less than or equal.\r\n */\r\n le(other: TimeSpan): boolean {\r\n return this.milliseconds <= other.milliseconds;\r\n }\r\n\r\n /**\r\n * Checks if this TimeSpan is less than another.\r\n * @param {TimeSpan} other - The other TimeSpan.\r\n * @returns {boolean} True if less than.\r\n */\r\n lt(other: TimeSpan): boolean {\r\n return this.milliseconds < other.milliseconds;\r\n }\r\n\r\n /**\r\n * Checks if this TimeSpan is greater than or equal to another.\r\n * @param {TimeSpan} other - The other TimeSpan.\r\n * @returns {boolean} True if greater than or equal.\r\n */\r\n ge(other: TimeSpan): boolean {\r\n return this.milliseconds >= other.milliseconds;\r\n }\r\n\r\n /**\r\n * Checks if this TimeSpan is greater than another.\r\n * @param {TimeSpan} other - The other TimeSpan.\r\n * @returns {boolean} True if greater than.\r\n */\r\n gt(other: TimeSpan): boolean {\r\n return this.milliseconds > other.milliseconds;\r\n }\r\n\r\n /**\r\n * Multiplies the TimeSpan by a number.\r\n * @param {number} number - The multiplier.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n multiply(number: number): TimeSpan {\r\n return new TimeSpan(this.milliseconds * number);\r\n }\r\n\r\n /**\r\n * Divides the TimeSpan by a number.\r\n * @param {number} number - The divisor.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n divide(number: number): TimeSpan {\r\n return new TimeSpan(this.milliseconds / number);\r\n }\r\n\r\n /**\r\n * Returns the absolute value of the TimeSpan.\r\n * @returns {TimeSpan} A new TimeSpan instance.\r\n */\r\n abs(): TimeSpan {\r\n return new TimeSpan(Math.abs(this.milliseconds));\r\n }\r\n\r\n /**\r\n * Infinite duration.\r\n */\r\n static readonly INFINITE = new TimeSpan(Number.POSITIVE_INFINITY);\r\n\r\n /**\r\n * Negative infinite duration.\r\n */\r\n static readonly NEGATIVE_INFINITE = new TimeSpan(Number.NEGATIVE_INFINITY);\r\n\r\n /**\r\n * Checks if the TimeSpan is infinite.\r\n * @returns {boolean} True if infinite.\r\n */\r\n isInfinite() {\r\n return this.milliseconds === Number.POSITIVE_INFINITY || this.milliseconds === Number.NEGATIVE_INFINITY\r\n }\r\n\r\n /**\r\n * Checks if the TimeSpan is positive infinite.\r\n * @returns {boolean} True if positive infinite.\r\n */\r\n isPositiveInfinite(): boolean {\r\n return this.milliseconds === Number.POSITIVE_INFINITY;\r\n }\r\n\r\n /**\r\n * Checks if the TimeSpan is negative infinite.\r\n * @returns {boolean} True if negative infinite.\r\n */\r\n isNegativeInfinite(): boolean {\r\n return this.milliseconds === Number.NEGATIVE_INFINITY;\r\n }\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
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,eAAe,QAAQ,CAAC"}
|
|
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,eAAe,QAAQ,CAAC","sourcesContent":["enum TypeCode {\r\n String = 'string',\r\n Number = 'number',\r\n Boolean = 'boolean',\r\n Symbol = 'symbol',\r\n BigInt = 'bigint',\r\n Null = 'null',\r\n Undefined = 'undefined',\r\n Object = 'object',\r\n Function = 'function',\r\n Array = 'array',\r\n Unknown = 'unknown',\r\n}\r\n\r\n\r\nexport default TypeCode;"]}
|