@develia/commons 0.3.43 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/array.js +44 -0
- package/dist/cjs/array.js.map +1 -0
- package/dist/cjs/async-pool-executor.js +49 -0
- package/dist/cjs/async-pool-executor.js.map +1 -0
- package/dist/cjs/cache-dictionary.js +67 -0
- package/dist/cjs/cache-dictionary.js.map +1 -0
- package/dist/cjs/clean-url-search-params.js +10 -0
- package/dist/cjs/clean-url-search-params.js.map +1 -0
- package/dist/cjs/collections/default-map.js +21 -0
- package/dist/cjs/collections/default-map.js.map +1 -0
- package/dist/cjs/collections/lazy-map.js +22 -0
- package/dist/cjs/collections/lazy-map.js.map +1 -0
- package/dist/cjs/collections.js +11 -0
- package/dist/cjs/collections.js.map +1 -0
- package/dist/cjs/from.js +504 -0
- package/dist/cjs/from.js.map +1 -0
- package/dist/cjs/index.js +73 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/key-value-pair.js +16 -0
- package/dist/cjs/key-value-pair.js.map +1 -0
- package/dist/cjs/lazy.js +25 -0
- package/dist/cjs/lazy.js.map +1 -0
- package/dist/cjs/math.js +15 -0
- package/dist/cjs/math.js.map +1 -0
- package/dist/cjs/order.js +9 -0
- package/dist/cjs/order.js.map +1 -0
- package/dist/cjs/patch.js +44 -0
- package/dist/cjs/patch.js.map +1 -0
- package/dist/cjs/stopwatch.js +36 -0
- package/dist/cjs/stopwatch.js.map +1 -0
- package/dist/cjs/string.js +29 -0
- package/dist/cjs/string.js.map +1 -0
- package/dist/cjs/timer.js +50 -0
- package/dist/cjs/timer.js.map +1 -0
- package/dist/cjs/timespan.js +152 -0
- package/dist/cjs/timespan.js.map +1 -0
- package/dist/cjs/type.js +16 -0
- package/dist/cjs/type.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utilities.js +309 -0
- package/dist/cjs/utilities.js.map +1 -0
- package/dist/esm/array.js +38 -0
- package/dist/esm/array.js.map +1 -0
- package/dist/esm/async-pool-executor.js +46 -0
- package/dist/esm/async-pool-executor.js.map +1 -0
- package/dist/esm/cache-dictionary.js +64 -0
- package/dist/esm/cache-dictionary.js.map +1 -0
- package/dist/esm/clean-url-search-params.js +7 -0
- package/dist/esm/clean-url-search-params.js.map +1 -0
- package/dist/esm/collections/default-map.js +18 -0
- package/dist/esm/collections/default-map.js.map +1 -0
- package/dist/esm/collections/lazy-map.js +19 -0
- package/dist/esm/collections/lazy-map.js.map +1 -0
- package/dist/esm/collections.js +3 -0
- package/dist/esm/collections.js.map +1 -0
- package/dist/esm/from.js +495 -0
- package/dist/esm/from.js.map +1 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/key-value-pair.js +13 -0
- package/dist/esm/key-value-pair.js.map +1 -0
- package/dist/esm/lazy.js +22 -0
- package/dist/esm/lazy.js.map +1 -0
- package/dist/esm/math.js +11 -0
- package/dist/esm/math.js.map +1 -0
- package/dist/esm/order.js +7 -0
- package/dist/esm/order.js.map +1 -0
- package/dist/esm/patch.js +40 -0
- package/dist/esm/patch.js.map +1 -0
- package/dist/esm/stopwatch.js +30 -0
- package/dist/esm/stopwatch.js.map +1 -0
- package/dist/esm/string.js +24 -0
- package/dist/esm/string.js.map +1 -0
- package/dist/esm/timer.js +47 -0
- package/dist/esm/timer.js.map +1 -0
- package/dist/esm/timespan.js +150 -0
- package/dist/esm/timespan.js.map +1 -0
- package/dist/esm/type.js +14 -0
- package/dist/esm/type.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utilities.js +277 -0
- package/dist/esm/utilities.js.map +1 -0
- package/dist/types/array.d.ts +6 -0
- package/dist/types/array.d.ts.map +1 -0
- package/dist/types/async-pool-executor.d.ts +14 -0
- package/dist/types/async-pool-executor.d.ts.map +1 -0
- package/dist/types/cache-dictionary.d.ts +16 -0
- package/dist/types/cache-dictionary.d.ts.map +1 -0
- package/dist/types/clean-url-search-params.d.ts +4 -0
- package/dist/types/clean-url-search-params.d.ts.map +1 -0
- package/dist/types/collections/default-map.d.ts +7 -0
- package/dist/types/collections/default-map.d.ts.map +1 -0
- package/dist/types/collections/lazy-map.d.ts +6 -0
- package/dist/types/collections/lazy-map.d.ts.map +1 -0
- package/dist/types/collections.d.ts +3 -0
- package/dist/types/collections.d.ts.map +1 -0
- package/dist/types/from.d.ts +59 -0
- package/dist/types/from.d.ts.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/key-value-pair.d.ts +8 -0
- package/dist/types/key-value-pair.d.ts.map +1 -0
- package/dist/types/lazy.d.ts +11 -0
- package/dist/types/lazy.d.ts.map +1 -0
- package/dist/types/math.d.ts +3 -0
- package/dist/types/math.d.ts.map +1 -0
- package/dist/types/order.d.ts +6 -0
- package/dist/types/order.d.ts.map +1 -0
- package/dist/types/patch.d.ts +8 -0
- package/dist/types/patch.d.ts.map +1 -0
- package/dist/types/stopwatch.d.ts +10 -0
- package/dist/types/stopwatch.d.ts.map +1 -0
- package/dist/types/string.d.ts +4 -0
- package/dist/types/string.d.ts.map +1 -0
- package/dist/types/timer.d.ts +15 -0
- package/dist/types/timer.d.ts.map +1 -0
- package/dist/types/timespan.d.ts +47 -0
- package/dist/types/timespan.d.ts.map +1 -0
- package/dist/types/type.d.ts +13 -0
- package/dist/types/type.d.ts.map +1 -0
- package/dist/types/types.d.ts +14 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utilities.d.ts +31 -0
- package/dist/types/utilities.d.ts.map +1 -0
- package/dist/web/array.js +38 -0
- package/dist/web/array.js.map +1 -0
- package/dist/web/async-pool-executor.js +46 -0
- package/dist/web/async-pool-executor.js.map +1 -0
- package/dist/web/cache-dictionary.js +64 -0
- package/dist/web/cache-dictionary.js.map +1 -0
- package/dist/web/clean-url-search-params.js +7 -0
- package/dist/web/clean-url-search-params.js.map +1 -0
- package/dist/web/collections/default-map.js +18 -0
- package/dist/web/collections/default-map.js.map +1 -0
- package/dist/web/collections/lazy-map.js +19 -0
- package/dist/web/collections/lazy-map.js.map +1 -0
- package/dist/web/collections.js +3 -0
- package/dist/web/collections.js.map +1 -0
- package/dist/web/from.js +496 -0
- package/dist/web/from.js.map +1 -0
- package/dist/web/index.js +19 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/key-value-pair.js +13 -0
- package/dist/web/key-value-pair.js.map +1 -0
- package/dist/web/lazy.js +22 -0
- package/dist/web/lazy.js.map +1 -0
- package/dist/web/math.js +11 -0
- package/dist/web/math.js.map +1 -0
- package/dist/web/order.js +7 -0
- package/dist/web/order.js.map +1 -0
- package/dist/web/patch.js +40 -0
- package/dist/web/patch.js.map +1 -0
- package/dist/web/stopwatch.js +30 -0
- package/dist/web/stopwatch.js.map +1 -0
- package/dist/web/string.js +24 -0
- package/dist/web/string.js.map +1 -0
- package/dist/web/timer.js +47 -0
- package/dist/web/timer.js.map +1 -0
- package/dist/web/timespan.js +150 -0
- package/dist/web/timespan.js.map +1 -0
- package/dist/web/type.js +14 -0
- package/dist/web/type.js.map +1 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/dist/web/utilities.js +277 -0
- package/dist/web/utilities.js.map +1 -0
- package/package.json +25 -12
- package/src/array.ts +49 -0
- package/src/async-pool-executor.ts +2 -2
- package/src/collections/default-map.ts +42 -0
- package/src/collections/lazy-map.ts +24 -0
- package/src/collections.ts +2 -24
- package/src/from.ts +4 -4
- package/src/index.ts +28 -22
- package/src/lazy.ts +1 -1
- package/src/patch.ts +80 -0
- package/src/stopwatch.ts +1 -1
- package/src/{typing.ts → type.ts} +3 -1
- package/src/types.ts +4 -1
- package/src/utilities.ts +23 -3
- package/dist/develia-commons.js +0 -1670
- package/dist/develia-commons.min.js +0 -1
- package/dist/index.cjs.js +0 -1668
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -1622
- package/dist/index.esm.js.map +0 -1
- package/src/array-manipulator.ts +0 -159
package/src/array.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type {Predicate} from "./types.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Removes all given values from the provided array and returns the number of removed elements.
|
|
3
5
|
* The operation mutates the original array.
|
|
@@ -17,4 +19,51 @@ export function pull<T>(array: Array<T>, ...items: Array<T>): number {
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
return output;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Splits an array into chunks of a given size.
|
|
26
|
+
* @template T
|
|
27
|
+
* @param {Array<T>} array - The array to split.
|
|
28
|
+
* @param {number} size - The size of each chunk.
|
|
29
|
+
* @return {Array<Array<T>>} The array of chunks.
|
|
30
|
+
*/
|
|
31
|
+
export function chunk<T>(array: Array<T>, size: number): Array<Array<T>> {
|
|
32
|
+
if (size <= 0) throw new Error("Size must be greater than 0");
|
|
33
|
+
const result: Array<Array<T>> = [];
|
|
34
|
+
for (let i = 0; i < array.length; i += size) {
|
|
35
|
+
result.push(array.slice(i, i + size));
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Removes all elements from the array, mutating it.
|
|
42
|
+
* @template T
|
|
43
|
+
* @param {Array<T>} array - The array to clear.
|
|
44
|
+
*/
|
|
45
|
+
export function clear<T>(array: Array<T>): void {
|
|
46
|
+
array.length = 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Removes all elements from the array that satisfy the predicate.
|
|
51
|
+
* The operation mutates the original array.
|
|
52
|
+
* @template T
|
|
53
|
+
* @return {Array<T>} An array of removed elements.
|
|
54
|
+
*/
|
|
55
|
+
export function remove<T>(array: Array<T>,predicate: Predicate<T>): Array<T> {
|
|
56
|
+
const removed: Array<T> = [];
|
|
57
|
+
let i = 0;
|
|
58
|
+
|
|
59
|
+
while (i < array.length) {
|
|
60
|
+
if (predicate(array[i])) {
|
|
61
|
+
removed.push(array[i]);
|
|
62
|
+
array.splice(i, 1); // muta el array
|
|
63
|
+
} else {
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return removed;
|
|
20
69
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {UnaryFunction} from "../types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DefaultMap<K, V>
|
|
5
|
+
* Un Map que crea y guarda automáticamente un valor por defecto
|
|
6
|
+
* cuando accedes a una clave inexistente con get(key).
|
|
7
|
+
*
|
|
8
|
+
* Ejemplo rápido:
|
|
9
|
+
* const m = new DefaultMap<string, number>(() => 0);
|
|
10
|
+
* m.get("a") += 1; // ahora m.get("a") === 1
|
|
11
|
+
*/
|
|
12
|
+
export default class DefaultMap<K, V> extends Map<K, V> {
|
|
13
|
+
private readonly _factoryMethod: (key: K) => V;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param factoryMethod Función que produce el valor por defecto para una clave.
|
|
17
|
+
* @param entries Entradas iniciales.
|
|
18
|
+
*/
|
|
19
|
+
constructor(factoryMethod: UnaryFunction<K, V>, entries?: Iterable<[K, V]>) {
|
|
20
|
+
super(entries);
|
|
21
|
+
if (typeof factoryMethod !== "function") {
|
|
22
|
+
throw new TypeError("DefaultMap necesita una factory (key => defaultValue).");
|
|
23
|
+
}
|
|
24
|
+
this._factoryMethod = factoryMethod;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Obtiene el valor de la clave. Si no existe, lo crea con la factory,
|
|
29
|
+
* lo guarda y lo devuelve.
|
|
30
|
+
*/
|
|
31
|
+
override get(key: K): V {
|
|
32
|
+
if (!super.has(key)) {
|
|
33
|
+
const value = this._factoryMethod(key);
|
|
34
|
+
super.set(key, value);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
// ¡super.get puede devolver undefined si no existe! Pero ya comprobamos has(key)
|
|
38
|
+
return super.get(key)!;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {isFunction} from "../utilities.js";
|
|
2
|
+
|
|
3
|
+
export default class LazyMap<K, V> extends Map<K, V> {
|
|
4
|
+
|
|
5
|
+
private readonly _factoryMethod: (key: K) => V;
|
|
6
|
+
|
|
7
|
+
constructor(factoryMethod: (key: K) => V, entries?: readonly (readonly [K, V])[] | null) {
|
|
8
|
+
super(entries);
|
|
9
|
+
if (!isFunction(factoryMethod)) {
|
|
10
|
+
throw new Error("factoryMethod is not a function");
|
|
11
|
+
}
|
|
12
|
+
this._factoryMethod = factoryMethod;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Sobrescribir el método get
|
|
16
|
+
get(key: K): V {
|
|
17
|
+
if (!this.has(key)) {
|
|
18
|
+
const value = this._factoryMethod(key);
|
|
19
|
+
this.set(key, value);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
return super.get(key) as V;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/collections.ts
CHANGED
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export class LazyMap<K, V> extends Map<K, V> {
|
|
4
|
-
|
|
5
|
-
private readonly _factoryMethod: (key: K) => V;
|
|
6
|
-
|
|
7
|
-
constructor(factoryMethod: (key: K) => V, entries?: readonly (readonly [K, V])[] | null) {
|
|
8
|
-
super(entries);
|
|
9
|
-
if (!isFunction(factoryMethod)) {
|
|
10
|
-
throw new Error("factoryMethod is not a function");
|
|
11
|
-
}
|
|
12
|
-
this._factoryMethod = factoryMethod;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Sobrescribir el método get
|
|
16
|
-
get(key: K): V {
|
|
17
|
-
if (!this.has(key)) {
|
|
18
|
-
const value = this._factoryMethod(key);
|
|
19
|
-
this.set(key, value);
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
return super.get(key) as V;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
export {default as LazyMap} from './collections/lazy-map.js'
|
|
2
|
+
export {default as DefaultMap} from './collections/default-map.js'
|
package/src/from.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {Consumer, EqualityComparer, UnaryFunction, Predicate, Supplier, Optional, Nullable} from "./types";
|
|
2
|
-
import {shallowEqual, toPairs} from "./utilities";
|
|
3
|
-
import KeyValuePair from "./key-value-pair";
|
|
4
|
-
import Order from "./order";
|
|
1
|
+
import type {Consumer, EqualityComparer, UnaryFunction, Predicate, Supplier, Optional, Nullable} from "./types.js";
|
|
2
|
+
import {shallowEqual, toPairs} from "./utilities.js";
|
|
3
|
+
import KeyValuePair from "./key-value-pair.js";
|
|
4
|
+
import Order from "./order.js";
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export default function from<T>(source: Iterable<T> | Supplier<Iterable<T>>): From<T> | From<KeyValuePair<any, any>> {
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export
|
|
8
|
-
export {default as
|
|
9
|
-
export {default as
|
|
10
|
-
export {default as
|
|
11
|
-
export {default as
|
|
12
|
-
export {default as
|
|
13
|
-
export {default as
|
|
14
|
-
export {default as
|
|
15
|
-
export {default as
|
|
16
|
-
export {default as
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export * from './array'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export {default as Tipe} from "./type.js";
|
|
3
|
+
|
|
4
|
+
export * from './utilities.js';
|
|
5
|
+
export * from './string.js';
|
|
6
|
+
export * from './math.js';
|
|
7
|
+
export {default as CacheDictionary} from './cache-dictionary.js';
|
|
8
|
+
export {default as from, From} from './from.js';
|
|
9
|
+
export {default as Timer} from './timer.js'
|
|
10
|
+
export {default as TimeSpan} from './timespan.js'
|
|
11
|
+
export {default as Lazy} from './lazy.js'
|
|
12
|
+
export {default as KeyValuePair} from './key-value-pair.js'
|
|
13
|
+
export {default as AsyncPoolExecutor} from './async-pool-executor.js';
|
|
14
|
+
export {default as Order} from './order.js';
|
|
15
|
+
export {default as CleanURLSearchParams} from './clean-url-search-params.js'
|
|
16
|
+
export {default as Stopwatch} from './stopwatch.js'
|
|
17
|
+
|
|
18
|
+
/** @deprecated */
|
|
19
|
+
export * from './array.js'
|
|
20
|
+
export * as array from "./array.js";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export * from './collections.js'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
package/src/lazy.ts
CHANGED
package/src/patch.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type {AbstractConstructor} from "./types.js";
|
|
2
|
+
|
|
3
|
+
export type PureMethod<T extends object, A extends any[] = any[], R = any> =
|
|
4
|
+
(obj: T, ...args: A) => R;
|
|
5
|
+
|
|
6
|
+
export type PatchSpec<T extends object> =
|
|
7
|
+
| Record<string, PureMethod<T, any[], any>>
|
|
8
|
+
| Map<PropertyKey, PureMethod<T, any[], any>>;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export function patch<C extends AbstractConstructor<any>>(
|
|
12
|
+
targetOrCtor: C,
|
|
13
|
+
fns: PatchSpec<InstanceType<C>>
|
|
14
|
+
): Map<PropertyKey, PropertyDescriptor | null>;
|
|
15
|
+
|
|
16
|
+
export function patch<T extends object>(
|
|
17
|
+
targetOrCtor: T,
|
|
18
|
+
fns: PatchSpec<T>
|
|
19
|
+
): Map<PropertyKey, PropertyDescriptor | null>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Devuelve un Map donde:
|
|
23
|
+
* - clave -> null (método añadido nuevo)
|
|
24
|
+
* - clave -> descriptorOriginal (método sustituido)
|
|
25
|
+
*/
|
|
26
|
+
export function patch(
|
|
27
|
+
targetOrCtor: any,
|
|
28
|
+
fns: PatchSpec<any>
|
|
29
|
+
): Map<PropertyKey, PropertyDescriptor | null> {
|
|
30
|
+
const target = typeof targetOrCtor === "function" ? targetOrCtor.prototype : targetOrCtor;
|
|
31
|
+
|
|
32
|
+
const result = new Map<PropertyKey, PropertyDescriptor | null>();
|
|
33
|
+
const entries: Array<[PropertyKey, PureMethod<any>]> =
|
|
34
|
+
fns instanceof Map ? [...fns.entries()] : Object.entries(fns) as any;
|
|
35
|
+
|
|
36
|
+
for (const [key, fn] of entries) {
|
|
37
|
+
const prev = Object.getOwnPropertyDescriptor(target, key);
|
|
38
|
+
const method = function (this: unknown, ...args: unknown[]) {
|
|
39
|
+
return (fn as any)(this, ...args);
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
Object.defineProperty(target, key, {
|
|
43
|
+
value: method,
|
|
44
|
+
writable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
enumerable: false,
|
|
47
|
+
});
|
|
48
|
+
result.set(key, prev ?? null);
|
|
49
|
+
} catch { /* ignorar */
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Overloads unpatch
|
|
56
|
+
export function unpatch<C extends AbstractConstructor<any>>(
|
|
57
|
+
targetOrCtor: C,
|
|
58
|
+
changes: Map<PropertyKey, PropertyDescriptor | null>
|
|
59
|
+
): void;
|
|
60
|
+
export function unpatch<T extends object>(
|
|
61
|
+
targetOrCtor: T,
|
|
62
|
+
changes: Map<PropertyKey, PropertyDescriptor | null>
|
|
63
|
+
): void;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Revierte un patch a partir del mapa devuelto por `patch`.
|
|
67
|
+
*/
|
|
68
|
+
export function unpatch(targetOrCtor: any, changes: Map<PropertyKey, PropertyDescriptor | null>): void {
|
|
69
|
+
const target = typeof targetOrCtor === "function" ? targetOrCtor.prototype : targetOrCtor;
|
|
70
|
+
for (const [key, prev] of changes) {
|
|
71
|
+
try {
|
|
72
|
+
if (prev === null) {
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) delete target[key];
|
|
74
|
+
} else {
|
|
75
|
+
Object.defineProperty(target, key, prev);
|
|
76
|
+
}
|
|
77
|
+
} catch { /* ignorar */
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/stopwatch.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Represents different types in JavaScript.
|
|
4
4
|
* @enum {string}
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
enum Type {
|
|
7
7
|
Undefined = "undefined",
|
|
8
8
|
Number = "number",
|
|
9
9
|
String = "string",
|
|
@@ -15,3 +15,5 @@ export enum Type {
|
|
|
15
15
|
Null = "null"
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
export default Type;
|
|
19
|
+
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export type EqualityComparer<T> = (arg1: T, arg2: T) => boolean;
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
export type Consumer<T> = (arg: T) => void
|
|
5
4
|
|
|
6
5
|
export type Predicate<T> = (arg: T) => boolean;
|
|
@@ -26,4 +25,8 @@ export type QuaternaryFunction<T1, T2, T3, T4, R> = (
|
|
|
26
25
|
arg4: T4
|
|
27
26
|
) => R;
|
|
28
27
|
|
|
28
|
+
export type Constructor<T = object, A extends any[] = any[]> =
|
|
29
|
+
new (...args: A) => T;
|
|
29
30
|
|
|
31
|
+
export type AbstractConstructor<T = object, A extends any[] = any[]> =
|
|
32
|
+
abstract new (...args: A) => T;
|
package/src/utilities.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// noinspection JSUnusedGlobalSymbols
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import KeyValuePair from "./key-value-pair";
|
|
5
|
-
import {Optional, Resolvable, Supplier} from "./types";
|
|
6
|
-
import
|
|
4
|
+
import KeyValuePair from "./key-value-pair.js";
|
|
5
|
+
import type {Optional, Resolvable, Supplier} from "./types.js";
|
|
6
|
+
import Type from "./type.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Checks if an object is iterable.
|
|
@@ -453,6 +453,26 @@ export function getType(value: any): Type {
|
|
|
453
453
|
return value === null ? Type.Null : Type[typeof value as keyof typeof Type];
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
export function formToObject(form: HTMLFormElement): Record<string, FormDataEntryValue | FormDataEntryValue[]> {
|
|
457
|
+
const fd = new FormData(form);
|
|
458
|
+
const out: Record<string, FormDataEntryValue | FormDataEntryValue[]> = {};
|
|
459
|
+
|
|
460
|
+
for (const [key, value] of fd.entries()) {
|
|
461
|
+
if (key in out) {
|
|
462
|
+
const current = out[key];
|
|
463
|
+
if (Array.isArray(current)) {
|
|
464
|
+
current.push(value);
|
|
465
|
+
} else {
|
|
466
|
+
out[key] = [current, value];
|
|
467
|
+
}
|
|
468
|
+
} else {
|
|
469
|
+
out[key] = value;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return out;
|
|
474
|
+
}
|
|
475
|
+
|
|
456
476
|
/**
|
|
457
477
|
* Converts an object to `FormData` format recursively.
|
|
458
478
|
*
|