schemaglobin
Advanced tools
Comparing version 5.10.0 to 5.11.0
@@ -0,1 +1,3 @@ | ||
import type { ReadonlyObject, ResolvableArray } from "../types"; | ||
import { SKIP } from "../constants"; | ||
/** Is a value an array? */ | ||
@@ -42,1 +44,31 @@ export declare const isArray: <T extends unknown[]>(v: unknown) => v is T; | ||
export declare const shuffle: <T>(input: readonly T[]) => readonly T[]; | ||
/** | ||
* Map the items in an array. | ||
* | ||
* @param input The input array or object to map (if an object, `Object.entries()` will be performed automatically and the second argument to `mapper()` will be the string key). | ||
* | ||
* @param mapper Mapping function that receives the value and key and returns the corresponding value. | ||
* - Mapper can return a `Promise`. If it does will return a Promise that resolves once every value has resolved. | ||
* - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object. | ||
* - `SKIP` is useful because using `filter(Boolean)` doesn't currently filter in TypeScript (and requires another loop anyway). | ||
* - Mapper can be a non-function static value and all the values will be set to that value. | ||
* | ||
* @returns The mapped array. | ||
* - Immutable so if the values don't change then the same instance will be returned. | ||
*/ | ||
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyArray<I>, // | ||
mapper: (value: I, key: number) => Promise<typeof SKIP | O>): Promise<ReadonlyArray<O>>; | ||
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyArray<I>, // | ||
mapper: ((value: I, key: number) => typeof SKIP | O) | O): ReadonlyArray<O>; | ||
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyObject<I>, mapper: (value: I, key: string) => Promise<typeof SKIP | O>): Promise<ReadonlyArray<O>>; | ||
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyObject<I>, mapper: ((value: I, key: string) => typeof SKIP | O) | O): ReadonlyArray<O>; | ||
/** | ||
* Resolve the items in an array. | ||
* | ||
* @param input The input array. | ||
* - Any values that are `Promise` instances will be awaited. | ||
* - Any values that are the `SKIP` symbol will not be included in the output array. | ||
* | ||
* @returns Array containing resolved items. | ||
*/ | ||
export declare const resolveArray: <V>(input: readonly (typeof SKIP | V | Promise<typeof SKIP | V>)[]) => Promise<V[]>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.shuffle = exports.prevItem = exports.nextItem = exports.replaceItem = exports.removeItem = exports.addItem = exports.toggleItem = exports.arrayChunk = exports.isArray = void 0; | ||
exports.resolveArray = exports.mapArray = exports.shuffle = exports.prevItem = exports.nextItem = exports.replaceItem = exports.removeItem = exports.addItem = exports.toggleItem = exports.arrayChunk = exports.isArray = void 0; | ||
const constants_1 = require("../constants"); | ||
/** Is a value an array? */ | ||
@@ -79,1 +80,35 @@ exports.isArray = (v) => v instanceof Array; | ||
}; | ||
function mapArray(input, mapper) { | ||
let promises = false; | ||
let changed = !(input instanceof Array); | ||
const output = []; | ||
for (const [key, current] of Object.entries(input)) { | ||
const next = mapper instanceof Function ? mapper(current, key) : mapper; | ||
if (next instanceof Promise) | ||
promises = true; | ||
if (next !== constants_1.SKIP) | ||
output.push(next); | ||
if (next !== current) | ||
changed = true; | ||
} | ||
return promises ? exports.resolveArray(output) : changed ? output : input; | ||
} | ||
exports.mapArray = mapArray; | ||
/** | ||
* Resolve the items in an array. | ||
* | ||
* @param input The input array. | ||
* - Any values that are `Promise` instances will be awaited. | ||
* - Any values that are the `SKIP` symbol will not be included in the output array. | ||
* | ||
* @returns Array containing resolved items. | ||
*/ | ||
exports.resolveArray = async (input) => { | ||
const output = []; | ||
await Promise.all(input.map(async (current) => { | ||
const next = await current; | ||
if (next !== constants_1.SKIP) | ||
output.push(next); | ||
})); | ||
return output; | ||
}; |
@@ -0,1 +1,6 @@ | ||
import type { ReadonlyObject } from "../types"; | ||
/** Set of messages in `{ key: Message }` format. */ | ||
export declare type Messages = { | ||
[key: string]: Message; | ||
}; | ||
/** | ||
@@ -11,6 +16,6 @@ * Message is a status message that is safe to show to users. | ||
readonly message: string; | ||
readonly details?: Record<string, Message>; | ||
constructor(message: string, details?: Record<string, Message>); | ||
readonly details?: Readonly<Messages>; | ||
constructor(message: string, details?: Messages); | ||
/** Convert the children of this `Message` into an object in `{ name: message }` format. */ | ||
get messages(): Record<string, string>; | ||
get messages(): ReadonlyObject<string>; | ||
/** | ||
@@ -28,7 +33,7 @@ * Convert to string (equivalent to `message.details`). | ||
/** Convert a Message to a JSON format. */ | ||
toJSON(): Record<string, unknown>; | ||
toJSON(): unknown; | ||
/** Create a Message from its corresponding JSON format. */ | ||
static fromJSON(json: unknown): Message; | ||
/** Create a new Message of a registered type. */ | ||
static create(status: string, message: string, details?: Record<string, Message>): Message; | ||
static create(status: string, message: string, details?: ReadonlyObject<Message>): Message; | ||
/** Register a new Message class. */ | ||
@@ -35,0 +40,0 @@ static register(name: string, constructor: typeof Message): void; |
@@ -1,4 +0,5 @@ | ||
import type { UnknownObject } from "../types"; | ||
import type { MutableObject, ReadonlyObject, ResolvableObject, UnknownObject } from "../types"; | ||
import { SKIP } from "../constants"; | ||
/** Is a value an unknown object? (is a TypeScript assertion object that asserts various things). */ | ||
export declare const isObject: <T extends Record<string, unknown>>(value: unknown) => value is T; | ||
export declare const isObject: <T extends UnknownObject>(value: unknown) => value is T; | ||
/** | ||
@@ -8,3 +9,3 @@ * Turn an array of entries into an object. | ||
*/ | ||
export declare const objectFromEntries: <V>(entries: [string, V][]) => Record<string, V>; | ||
export declare const objectFromEntries: <V>(entries: [string, V][]) => MutableObject<V>; | ||
/** Extract the key from an object entry. */ | ||
@@ -30,34 +31,61 @@ export declare const getEntryKey: (entry: [string, unknown]) => string; | ||
}>(entry: [string, V]) => string | number; | ||
/** Symbol that allows you to filter out results during mapping. */ | ||
export declare const SKIP: unique symbol; | ||
/** | ||
* Map the (own) properties of an object (i.e. to change the prop values). | ||
* Map the (own) keys of an object (i.e. to rename the keys). | ||
* | ||
* @param input An input object whose keys you want to rename. | ||
* | ||
* @param mapper Mapping function that receives the key and value, and returns the new key. | ||
* - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object. | ||
* - `SKIP` is useful because using `filter(Boolean)` doesn't currently filter in TypeScript (and requires another loop anyway). | ||
* - Note inverted argument order in mapper from `mapObject()` (because this is almost certainly what you want. | ||
* | ||
* @returns The mapped object. | ||
* - Immutable so if the values don't change then the same instance will be returned. | ||
* - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object. | ||
* - Mapper can be a non-function static value and all the values will be set to that value. | ||
* - If the mapper returns a Promise (even once) then this will return a Promise that only has resolved props. | ||
*/ | ||
export declare function mapObject<I extends unknown, O extends unknown>(input: Readonly<Record<string, I>>, mapper: (value: I, key: string) => Promise<typeof SKIP | O>): Promise<Record<string, O>>; | ||
export declare function mapObject<I extends unknown, O extends unknown>(input: Readonly<Record<string, I>>, mapper: ((value: I, key: string) => typeof SKIP | O) | O): Record<string, O>; | ||
export declare function mapObjectKeys<V extends unknown>(input: ReadonlyObject<V>, // | ||
mapper: (key: string, value: V) => typeof SKIP | string): ReadonlyObject<V>; | ||
/** | ||
* Map the (own) keys of an object (i.e. to rename the keys). | ||
* Map the (own) property values of an object (i.e. to change the prop values). | ||
* | ||
* @param input An input object whose property values you want to modify. | ||
* | ||
* @param mapper Mapping function that receives the key and returns the new value. | ||
* - Mapper can return a `Promise`. If it does will return a Promise that resolves once every value has resolved. | ||
* - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object. | ||
* - `SKIP` is useful because using `filter(Boolean)` doesn't currently filter in TypeScript (and requires another loop anyway). | ||
* - Mapper can be a static value and all the values will be set to that value. | ||
* | ||
* @returns The mapped object. | ||
* - Immutable so if the values don't change then the same instance will be returned. | ||
* - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object. | ||
* - Note inverted argument order in mapper from `mapObject()` (because this is almost certainly what you want. | ||
*/ | ||
export declare function mapObjectKeys<V extends unknown>(input: Readonly<Record<string, V>>, mapper: (key: string, value: V) => typeof SKIP | string): Record<string, V>; | ||
export declare function mapObject<I extends unknown, O extends unknown>(input: ReadonlyObject<I>, mapper: (value: I, key: string) => Promise<typeof SKIP | O>): Promise<ReadonlyObject<O>>; | ||
export declare function mapObject<I extends unknown, O extends unknown>(input: ReadonlyObject<I>, mapper: ((value: I, key: string) => typeof SKIP | O) | O): ReadonlyObject<O>; | ||
/** | ||
* Map an array of object keys into an object using a mapper function or a single value. | ||
* | ||
* @param keys An array of keys to map into an object. | ||
* | ||
* @param mapper Mapping function that receives the key and returns the corresponding value. | ||
* - Mapper can return a `Promise`. If it does will return a Promise that resolves once every value has resolved. | ||
* - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object. | ||
* - `SKIP` is useful because using `filter(Boolean)` doesn't currently filter in TypeScript (and requires another loop anyway). | ||
* - Mapper can be a non-function static value and all the values will be set to that value. | ||
* - If the mapper returns a Promise (even once) then this will return a Promise that only has resolved props. | ||
* - Mapper can be a static value and all the values will be set to that value. | ||
* | ||
* @returns The mapped object. | ||
* - Immutable so if the values don't change then the same instance will be returned. | ||
*/ | ||
export declare function objectFromKeys<O>(input: ReadonlyArray<string>, mapper: (key: string) => Promise<typeof SKIP | O>): Promise<Record<string, O>>; | ||
export declare function objectFromKeys<O>(input: ReadonlyArray<string>, mapper: ((key: string) => typeof SKIP | O) | O): Record<string, O>; | ||
export declare function objectFromKeys<O>(keys: ReadonlyArray<string>, // | ||
mapper: (key: string) => Promise<typeof SKIP | O>): Promise<ReadonlyObject<O>>; | ||
export declare function objectFromKeys<O>(keys: ReadonlyArray<string>, // | ||
mapper: ((key: string) => typeof SKIP | O) | O): ReadonlyObject<O>; | ||
/** | ||
* Await any promised values in the own keys of an object and return a mapped object including those values. | ||
* - Any values that resolve to the `SKIP` symbol will not be included in the output object. | ||
* Resolve the property values in an object. | ||
* | ||
* @param input The input object. | ||
* - Any values that are `Promise` instances will be awaited. | ||
* - Any values that are the `SKIP` symbol will not be included in the output object. | ||
* | ||
* @returns Object containing resolved property values. | ||
*/ | ||
export declare const resolveObject: <V>(input: Record<string, typeof SKIP | V | Promise<typeof SKIP | V>>) => Promise<Record<string, V>>; | ||
export declare const resolveObject: <V>(input: ResolvableObject<V>) => Promise<MutableObject<V>>; | ||
/** | ||
@@ -67,3 +95,3 @@ * Return a new object where a named property has been removed. | ||
*/ | ||
export declare const deleteProp: <O extends Record<string, unknown>, K extends keyof O>(obj: O, key: K) => Pick<O, Exclude<keyof O, K>>; | ||
export declare const deleteProp: <O extends UnknownObject, K extends keyof O>(obj: O, key: K) => Pick<O, Exclude<keyof O, K>>; | ||
/** | ||
@@ -73,3 +101,3 @@ * Return a new object where a named property has been set. | ||
*/ | ||
export declare const setProp: <O extends Record<string, unknown>, K extends string | keyof O, V>(obj: O, key: K, value: V) => O & { [X in K]: V; }; | ||
export declare const setProp: <O extends UnknownObject, K extends string | keyof O, V>(obj: O, key: K, value: V) => O & { [X in K]: V; }; | ||
/** | ||
@@ -79,5 +107,5 @@ * Return a new object where a named property has been updated. | ||
*/ | ||
export declare const updateProp: <O extends Record<string, unknown>, K extends keyof O>(obj: O, key: K, value: O[K]) => O; | ||
export declare const updateProp: <O extends UnknownObject, K extends keyof O>(obj: O, key: K, value: O[K]) => O; | ||
/** Extract a named (possibly deep) prop from an object. */ | ||
export declare function getProp<O extends UnknownObject, K extends keyof O | string | number>(obj: O, key: K): K extends keyof O ? O[K] : undefined; | ||
export declare function getProp<O extends UnknownObject>(obj: O, key: string | number, ...deeperKeys: (string | number)[]): unknown; |
"use strict"; | ||
/* eslint-disable no-param-reassign */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getProp = exports.updateProp = exports.setProp = exports.deleteProp = exports.resolveObject = exports.objectFromKeys = exports.mapObjectKeys = exports.mapObject = exports.SKIP = exports.getEntryName = exports.getEntryTitle = exports.getEntryOrder = exports.getEntryDate = exports.getEntryValue = exports.getEntryKey = exports.objectFromEntries = exports.isObject = void 0; | ||
exports.getProp = exports.updateProp = exports.setProp = exports.deleteProp = exports.resolveObject = exports.objectFromKeys = exports.mapObject = exports.mapObjectKeys = exports.getEntryName = exports.getEntryTitle = exports.getEntryOrder = exports.getEntryDate = exports.getEntryValue = exports.getEntryKey = exports.objectFromEntries = exports.isObject = void 0; | ||
const constants_1 = require("../constants"); | ||
/** Is a value an unknown object? (is a TypeScript assertion object that asserts various things). */ | ||
@@ -33,27 +33,17 @@ exports.isObject = (value) => typeof value === "object" && value !== null; | ||
exports.getEntryName = (entry) => entry[1].name; | ||
/** Symbol that allows you to filter out results during mapping. */ | ||
exports.SKIP = Symbol("schemaglobin/object/SKIP"); | ||
function mapObject(input, mapper) { | ||
let promises = false; | ||
let changed = false; | ||
const output = {}; | ||
for (const [key, current] of Object.entries(input)) { | ||
const next = mapper instanceof Function ? mapper(current, key) : mapper; | ||
if (next instanceof Promise) | ||
promises = true; | ||
if (next !== exports.SKIP) | ||
output[key] = next; | ||
if (next !== current) | ||
changed = true; | ||
} | ||
return promises ? exports.resolveObject(output) : changed ? output : input; | ||
} | ||
exports.mapObject = mapObject; | ||
/** | ||
* Map the (own) keys of an object (i.e. to rename the keys). | ||
* - Immutable so if the values don't change then the same instance will be returned. | ||
* | ||
* @param input An input object whose keys you want to rename. | ||
* | ||
* @param mapper Mapping function that receives the key and value, and returns the new key. | ||
* - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object. | ||
* - `SKIP` is useful because using `filter(Boolean)` doesn't currently filter in TypeScript (and requires another loop anyway). | ||
* - Note inverted argument order in mapper from `mapObject()` (because this is almost certainly what you want. | ||
* | ||
* @returns The mapped object. | ||
* - Immutable so if the values don't change then the same instance will be returned. | ||
*/ | ||
function mapObjectKeys(input, mapper) { | ||
function mapObjectKeys(input, // | ||
mapper) { | ||
let changed = false; | ||
@@ -63,3 +53,3 @@ const output = {}; | ||
const next = mapper(current, value); | ||
if (next !== exports.SKIP) | ||
if (next !== constants_1.SKIP) | ||
output[next] = value; | ||
@@ -72,10 +62,27 @@ if (next !== current) | ||
exports.mapObjectKeys = mapObjectKeys; | ||
function objectFromKeys(input, mapper) { | ||
function mapObject(input, mapper) { | ||
let promises = false; | ||
let changed = false; | ||
const output = {}; | ||
for (const key of input) { | ||
for (const [key, current] of Object.entries(input)) { | ||
const next = mapper instanceof Function ? mapper(current, key) : mapper; | ||
if (next instanceof Promise) | ||
promises = true; | ||
if (next !== constants_1.SKIP) | ||
output[key] = next; | ||
if (next !== current) | ||
changed = true; | ||
} | ||
return promises ? exports.resolveObject(output) : changed ? output : input; | ||
} | ||
exports.mapObject = mapObject; | ||
function objectFromKeys(keys, // | ||
mapper) { | ||
let promises = false; | ||
const output = {}; | ||
for (const key of keys) { | ||
const next = mapper instanceof Function ? mapper(key) : mapper; | ||
if (next instanceof Promise) | ||
promises = true; | ||
if (next !== exports.SKIP) | ||
if (next !== constants_1.SKIP) | ||
output[key] = next; | ||
@@ -87,4 +94,9 @@ } | ||
/** | ||
* Await any promised values in the own keys of an object and return a mapped object including those values. | ||
* - Any values that resolve to the `SKIP` symbol will not be included in the output object. | ||
* Resolve the property values in an object. | ||
* | ||
* @param input The input object. | ||
* - Any values that are `Promise` instances will be awaited. | ||
* - Any values that are the `SKIP` symbol will not be included in the output object. | ||
* | ||
* @returns Object containing resolved property values. | ||
*/ | ||
@@ -95,3 +107,3 @@ exports.resolveObject = async (input) => { | ||
const v = await a; | ||
if (v !== exports.SKIP) | ||
if (v !== constants_1.SKIP) | ||
output[k] = v; | ||
@@ -98,0 +110,0 @@ })); |
@@ -0,1 +1,5 @@ | ||
/** Template values in `{ placeholder: value }` format. */ | ||
export declare type TemplateValues = { | ||
[placeholder: string]: string; | ||
}; | ||
/** | ||
@@ -8,3 +12,3 @@ * Split up a template into an array of separator → placeholder → separator → placeholder → separator | ||
*/ | ||
export declare const splitTemplate: (template: string) => readonly string[]; | ||
export declare const splitTemplate: (template: string) => ReadonlyArray<string>; | ||
/** | ||
@@ -16,3 +20,3 @@ * Get list of placeholders named in a template string. | ||
*/ | ||
export declare const getPlaceholders: (template: string) => readonly string[]; | ||
export declare const getPlaceholders: (template: string) => ReadonlyArray<string>; | ||
/** | ||
@@ -26,3 +30,3 @@ * Turn ":year-:month" and "2016-06..." etc ing `{ year: "2016"... }` etc. | ||
*/ | ||
export declare const matchTemplate: (templates: string | string[] | Iterable<string> | Generator<string, any, unknown> | ((target: string) => string | string[] | Iterable<string> | Generator<string>), target: string) => Record<string, string> | undefined; | ||
export declare const matchTemplate: (templates: string | string[] | Iterable<string> | Generator<string, any, unknown> | ((target: string) => string | string[] | Iterable<string> | Generator<string>), target: string) => TemplateValues | undefined; | ||
/** | ||
@@ -37,2 +41,2 @@ * Turn ":year-:month" and `{ year: "2016"... }` etc into "2016-06..." etc. | ||
*/ | ||
export declare const renderTemplate: (template: string, values: string | string[] | Record<string, string> | ((name: string) => string)) => string; | ||
export declare const renderTemplate: (template: string, values: string | string[] | TemplateValues | ((name: string) => string)) => string; |
@@ -0,3 +1,3 @@ | ||
import type { DeepPartial } from "../types"; | ||
import type { Schema } from "../Schema"; | ||
import type { PartialObject } from "../types"; | ||
/** Is a value undefined? */ | ||
@@ -17,2 +17,2 @@ export declare const isUndefined: (v: unknown) => v is undefined; | ||
*/ | ||
export declare const withPartial: <T>(schema: Schema<T>) => Schema<PartialObject<T>>; | ||
export declare const withPartial: <T>(schema: Schema<T>) => Schema<DeepPartial<T>>; |
export * from "./types"; | ||
export * from "./constants"; | ||
export * from "./Schema"; | ||
@@ -3,0 +4,0 @@ export * from "./schemas/ArraySchema"; |
@@ -15,2 +15,4 @@ "use strict"; | ||
__exportStar(require("./types"), exports); | ||
// Export constants. | ||
__exportStar(require("./constants"), exports); | ||
// Export schema. | ||
@@ -17,0 +19,0 @@ __exportStar(require("./Schema"), exports); |
@@ -0,6 +1,7 @@ | ||
import type { ReadonlyObject, UnknownObject } from "../types"; | ||
import type { Schema, SchemaOptions, SchemaType } from "../Schema"; | ||
import { Invalid } from "../helpers/message"; | ||
/** Coerce an unknown value to a map (if possible). */ | ||
export declare function coerceMap(value: unknown): Record<string, unknown> | Invalid; | ||
export declare type MapSchemaType<S extends Schema = Schema> = Readonly<Record<string, SchemaType<S>>>; | ||
export declare function coerceMap(value: unknown): UnknownObject | Invalid; | ||
export declare type MapSchemaType<S extends Schema = Schema> = ReadonlyObject<SchemaType<S>>; | ||
export interface MapSchemaOptions<S extends Schema = Schema, R extends boolean = false> extends SchemaOptions { | ||
@@ -7,0 +8,0 @@ readonly items: S; |
"use strict"; | ||
/* eslint-disable no-dupe-class-members */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -4,0 +3,0 @@ exports.object = exports.ObjectSchema = exports.coerceObject = void 0; |
@@ -0,2 +1,10 @@ | ||
import type { SKIP } from "./constants"; | ||
/** | ||
* Mutable type is the opposite of `Readonly<T>` helper type. | ||
* - See https://github.com/microsoft/TypeScript/issues/24509 | ||
*/ | ||
export declare type Mutable<T> = { | ||
-readonly [K in keyof T]: T[K]; | ||
}; | ||
/** | ||
* Unknown object: an object whose properties are unknown. | ||
@@ -7,3 +15,5 @@ * - Use this to represent POJO plain objects with string keys. | ||
*/ | ||
export declare type UnknownObject = Record<string, unknown>; | ||
export declare type UnknownObject = { | ||
[key: string]: unknown; | ||
}; | ||
/** | ||
@@ -14,39 +24,80 @@ * Empty object: an object with no properties. | ||
*/ | ||
export declare type EmptyObject = Record<never, never>; | ||
export declare type EmptyObject = { | ||
[key in never]: never; | ||
}; | ||
/** | ||
* Partial object: deeply convert an object to its partial version. | ||
* - Any value that extends `UnknownObject`has its props made partial. | ||
* - Works deeply on nested objects too. | ||
* - Only makes plain objects changed (i.e. objects that extend `UnknownObject`), not arrays and functions. | ||
* Partial object: an object with specific optional properties. | ||
* - Cleaner than using `Record<string, T | undefined>` | ||
* - Matches `Partial<T>` and `ReadonlyObject<T>` | ||
*/ | ||
export declare type PartialObject<T> = T extends UnknownObject ? { | ||
[K in keyof T]?: PartialObject<T[K]>; | ||
} : T; | ||
export declare type PartialObject<T> = { | ||
[key: string]: T | undefined; | ||
}; | ||
/** | ||
* Mutable type is the opposite of `Readonly<T>` helper type. | ||
* - See https://github.com/microsoft/TypeScript/issues/24509 | ||
* Partial object: an object with specific optional properties. | ||
* - Cleaner than using `Record<string, T | undefined>` | ||
* - Matches `ReadonlyArray<T>` | ||
*/ | ||
export declare type Mutable<T> = { | ||
-readonly [K in keyof T]: T[K]; | ||
export declare type ReadonlyObject<T> = { | ||
readonly [key: string]: T; | ||
}; | ||
/** | ||
* Mutable object: deeply convert an object to its mutable version. | ||
* - Like `Mutable<T>` but follows the same pattern and rules as `PartialObject` | ||
* - Any value that extends `UnknownObject`has its props made mutable. | ||
* Partial object: an object with specific optional properties. | ||
* - Cleaner than using `Record<string, T | undefined>` | ||
* - Matches `ReadonlyObject<T>` and `MutableArray<T>` | ||
*/ | ||
export declare type MutableObject<T> = { | ||
[key: string]: T; | ||
}; | ||
/** | ||
* Resolvable object: an object whose properties can be resolved with `resolveObject()` | ||
* - Property values can be `SKIP` symbol (and they will be removed). | ||
* - Property values can be `Promise` instances (and they will be awaited). | ||
*/ | ||
export declare type ResolvableObject<T> = { | ||
[key: string]: typeof SKIP | T | Promise<typeof SKIP | T>; | ||
}; | ||
/** | ||
* Mutable array: an array whose items can be written. | ||
* - Matches `MutableObject<T>` and `ReadonlyArray<T>` | ||
*/ | ||
export declare type MutableArray<T> = T[]; | ||
/** | ||
* Readonly array: an array whose items are readonly. | ||
* - Matches `ReadonlyObject<T>` and `MutableArray<T>` | ||
*/ | ||
export declare type ReadonlyArray<T> = readonly T[]; | ||
/** | ||
* Resolvable array: an object whose properties can be resolved with `resolveArray()` | ||
* - Items can be `SKIP` symbol (and they will be removed). | ||
* - Items can be `Promise` instances (and they will be awaited). | ||
*/ | ||
export declare type ResolvableArray<T> = (typeof SKIP | T | Promise<typeof SKIP | T>)[]; | ||
/** | ||
* Deep partial object: deeply convert an object to its partial version. | ||
* - Any value that extends `UnknownObject` has its props made partial. | ||
* - Works deeply on nested objects too. | ||
* - Only makes plain objects changed (i.e. objects that extend `UnknownObject`), not arrays and functions. | ||
* - Only affects plain objects (i.e. objects that extend `UnknownObject`), not arrays and functions. | ||
*/ | ||
export declare type MutableObject<T> = T extends UnknownObject ? { | ||
-readonly [K in keyof T]: MutableObject<T[K]>; | ||
export declare type DeepPartial<T> = T extends UnknownObject ? { | ||
[K in keyof T]?: DeepPartial<T[K]>; | ||
} : T; | ||
/** | ||
* Readonly object: deeply convert an object to its readonly version. | ||
* - Like `Readonly<T>` but follows the same pattern and rules as `PartialObject` | ||
* - Any value that extends `UnknownObject`has its props made readonly. | ||
* Deep mutable object: deeply convert an object to its mutable version. | ||
* - Any value that extends `UnknownObject` has its props made mutable. | ||
* - Works deeply on nested objects too. | ||
* - Only makes plain objects changed (i.e. objects that extend `UnknownObject`), not arrays and functions. | ||
* - Only affects plain objects (i.e. objects that extend `UnknownObject`), not arrays and functions. | ||
*/ | ||
export declare type ReadonlyObject<T> = T extends UnknownObject ? { | ||
+readonly [K in keyof T]: ReadonlyObject<T[K]>; | ||
export declare type DeepMutable<T> = T extends UnknownObject ? { | ||
-readonly [K in keyof T]: DeepMutable<T[K]>; | ||
} : T; | ||
/** | ||
* Deep readonly object: deeply convert an object to its readonly version. | ||
* - Any value that extends `UnknownObject` has its props made readonly. | ||
* - Works deeply on nested objects too. | ||
* - Only affects plain objects (i.e. objects that extend `UnknownObject`), not arrays and functions. | ||
*/ | ||
export declare type DeepReadonly<T> = T extends UnknownObject ? { | ||
+readonly [K in keyof T]: DeepReadonly<T[K]>; | ||
} : T; | ||
/** Constructor: a class constructor that can be used with `new X` to generate an object of type `T` */ | ||
@@ -53,0 +104,0 @@ export declare type Constructor<T = unknown> = { |
{ | ||
"name": "schemaglobin", | ||
"description": "Validate user-entered data.", | ||
"version": "5.10.0", | ||
"version": "5.11.0", | ||
"repository": "https://github.com/dhoulb/schemaglobin", | ||
@@ -6,0 +6,0 @@ "author": "Dave Houlbrooke <dave@shax.com>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156748
63
2939