shelving 1.89.1 → 1.89.2
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/package.json +1 -1
- package/util/object.d.ts +5 -1
- package/util/object.js +4 -0
- package/util/transform.d.ts +2 -2
- package/util/validate.d.ts +2 -2
- package/util/validate.js +2 -1
package/package.json
CHANGED
package/util/object.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ImmutableArray } from "./array.js";
|
|
2
|
-
/** Any readonly
|
|
2
|
+
/** Any readonly object. */
|
|
3
3
|
export type ImmutableObject<K extends PropertyKey = PropertyKey, T = unknown> = {
|
|
4
4
|
readonly [KK in K]: T;
|
|
5
5
|
};
|
|
@@ -13,6 +13,8 @@ export type ObjectProp<T extends ImmutableObject = ImmutableObject> = readonly [
|
|
|
13
13
|
export type ObjectKey<T extends ImmutableObject = ImmutableObject> = keyof T;
|
|
14
14
|
/** Value for an object prop. */
|
|
15
15
|
export type ObjectValue<T extends ImmutableObject = ImmutableObject> = T[keyof T];
|
|
16
|
+
/** Something that can be converted to an object. */
|
|
17
|
+
export type PossibleObject<T extends ImmutableObject> = T | Iterable<ObjectProp<T>>;
|
|
16
18
|
/** Is an unknown value an unknown object? */
|
|
17
19
|
export declare const isObject: <T extends ImmutableObject<PropertyKey, unknown>>(value: unknown) => value is T;
|
|
18
20
|
/** Assert that a value is an object */
|
|
@@ -23,6 +25,8 @@ export declare function isPlainObject(value: ImmutableObject | unknown): value i
|
|
|
23
25
|
export declare function assertPlainObject(value: ImmutableObject | unknown): asserts value is ImmutableObject;
|
|
24
26
|
/** Is an unknown value the key for an own prop of an object. */
|
|
25
27
|
export declare const isProp: <T extends ImmutableObject<PropertyKey, unknown>>(obj: T, key: unknown) => key is keyof T;
|
|
28
|
+
/** turn a possible object into an object. */
|
|
29
|
+
export declare function getObject<T extends ImmutableObject>(obj: PossibleObject<T>): T;
|
|
26
30
|
/**
|
|
27
31
|
* Mutable type is the opposite of `Readonly<T>` helper type.
|
|
28
32
|
* - See https://github.com/microsoft/TypeScript/issues/24509
|
package/util/object.js
CHANGED
|
@@ -23,6 +23,10 @@ export function assertPlainObject(value) {
|
|
|
23
23
|
}
|
|
24
24
|
/** Is an unknown value the key for an own prop of an object. */
|
|
25
25
|
export const isProp = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
26
|
+
/** turn a possible object into an object. */
|
|
27
|
+
export function getObject(obj) {
|
|
28
|
+
return isIterable(obj) ? Object.fromEntries(obj) : obj;
|
|
29
|
+
}
|
|
26
30
|
export function getProps(obj) {
|
|
27
31
|
return isIterable(obj) ? obj : Object.entries(obj);
|
|
28
32
|
}
|
package/util/transform.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ArrayItem, ImmutableArray } from "./array.js";
|
|
|
2
2
|
import type { Entry } from "./entry.js";
|
|
3
3
|
import { Arguments } from "./function.js";
|
|
4
4
|
import { ImmutableObject, ObjectValue } from "./object.js";
|
|
5
|
-
import { ImmutableDictionary } from "./dictionary.js";
|
|
5
|
+
import { ImmutableDictionary, PossibleDictionary } from "./dictionary.js";
|
|
6
6
|
/** Object that transforms an input value into an output value with its `transform()` method. */
|
|
7
7
|
export interface Transformable<I, O, A extends Arguments = []> {
|
|
8
8
|
transform(input: I, ...args: A): O;
|
|
@@ -38,7 +38,7 @@ export declare function mapObject<T extends ImmutableObject>(obj: T, transformer
|
|
|
38
38
|
export declare function mapObject<I extends ImmutableObject, O extends ImmutableObject, A extends Arguments = []>(obj: I, transformer: (v: ObjectValue<I>, ...args: A) => ObjectValue<O>, ...args: A): O;
|
|
39
39
|
export declare function mapObject<I extends ImmutableObject, O extends ImmutableObject, A extends Arguments = []>(obj: I, transformer: Transformer<ObjectValue<I>, ObjectValue<O>>, ...args: A): O;
|
|
40
40
|
/** Modify the values of a dictionary using a transformer. */
|
|
41
|
-
export declare const mapDictionary: <I, O, A extends Arguments = []>(dictionary:
|
|
41
|
+
export declare const mapDictionary: <I, O, A extends Arguments = []>(dictionary: PossibleDictionary<I>, transformer: Transformer<I, O, A>, ...args: A) => ImmutableDictionary<O>;
|
|
42
42
|
/** Modify the values of a set of entries using a transformer. */
|
|
43
43
|
export declare function mapEntries<K, I, O, A extends Arguments = []>(entries: Iterable<Entry<K, I>>, transformer: Transformer<I, O, A>, ...args: A): Iterable<Entry<K, O>>;
|
|
44
44
|
/** Set of named transformers for a data object (or `undefined` to skip the transform). */
|
package/util/validate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Entry } from "./entry.js";
|
|
2
|
-
import
|
|
2
|
+
import { ImmutableDictionary, PossibleDictionary } from "./dictionary.js";
|
|
3
3
|
import { Data, DataProp } from "./data.js";
|
|
4
4
|
import { ImmutableArray } from "./array.js";
|
|
5
5
|
/** Object that can validate an unknown value with its `validate()` method. */
|
|
@@ -62,7 +62,7 @@ export declare function validateEntries<T>(unsafeValues: Iterable<Entry<string,
|
|
|
62
62
|
* @throw InvalidFeedback if one or more entry values did not validate.
|
|
63
63
|
* - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
|
|
64
64
|
*/
|
|
65
|
-
export declare function validateDictionary<T>(obj:
|
|
65
|
+
export declare function validateDictionary<T>(obj: PossibleDictionary<T>, validator: Validator<T>): ImmutableDictionary<T>;
|
|
66
66
|
/**
|
|
67
67
|
* Validate the props of a data object with a set of validators.
|
|
68
68
|
*
|
package/util/validate.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isFeedback } from "../feedback/Feedback.js";
|
|
2
2
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
3
|
+
import { getDictionaryItems } from "./dictionary.js";
|
|
3
4
|
import { getDataProps } from "./data.js";
|
|
4
5
|
import { getArray } from "./array.js";
|
|
5
6
|
/** Validate an unknown value with a validator. */
|
|
@@ -69,7 +70,7 @@ export function* validateEntries(unsafeValues, validator) {
|
|
|
69
70
|
* - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
|
|
70
71
|
*/
|
|
71
72
|
export function validateDictionary(obj, validator) {
|
|
72
|
-
return Object.fromEntries(validateEntries(
|
|
73
|
+
return Object.fromEntries(validateEntries(getDictionaryItems(obj), validator));
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* Validate the props of a data object with a set of validators.
|