README
Object
The @perfective/object
package provides functions to work with the standard JS
Object
class.
- Types:
ObjectWithDefined<T, K extends keyof T>
ObjectWithUndefined<T, K extends keyof T>
ObjectWithNotNull<T, K extends keyof T>
ObjectWithNull<T, K extends keyof T>
ObjectWithPresent<T, K extends keyof T>
ObjectWithAbsent<T, K extends keyof T>
RecursivePartial<T>
Entry<T = unknown>
- Unit functions:
copy<T>(value: T): T
— creates a shallow copy of the given value. (Experimental).clone<T>(value: T): T
— creates a clone (deep copy) of the given value. (Experimental).pick<T, K extends keyof T>(record: T, ...property: readonly K[]): Pick<T, K>
— creates a copy of therecord
only with the givenproperty
.omit<T, K extends keyof T>(record: T, ...property: readonly K[]): Omit<T, K>
— creates a copy of therecord
without the givenproperty
.filter<T, K extends keyof T>(record: T, condition: Predicate<T[K]>): Partial<T>
— creates a copy of therecord
where each value meets thecondition
.assign<T, V = Partial<T>>(value: T, ...overrides: (V | Partial<T>)[]): T & V
— creates a shallow copy of the given value with the given overrides.recordFromArray(array: string[]): Record<string, number>
recordFromEntries(entries: Entry[]): Record<string, unknown>
recordWithPicked<T, K extends keyof T>(...property: readonly K[]): Unary<T, Pick<T, K>>
— partially applies thepick()
function for the givenproperty
.recordWithOmitted<T, K extends keyof T>(...property: readonly K[]): Unary<T, Omit<T, K>>
— partially applies theomit()
function for the givenproperty
.recordFiltered<T, K extends keyof T = keyof T>(condition: Predicate<T[K]>): Unary<T, Partial<T>>
— partially applies thefilter()
function for the givencondition
.
- Type guards:
hasDefinedProperty<T, K extends keyof T>(property: K, ...and: readonly K[]): (value: T) => value is ObjectWithDefined<T, K>
hasUndefinedProperty<T, K extends keyof T>(property: K, ...and: readonly K[]): (value: T) => value is ObjectWithUndefined<T, K>
hasNotNullProperty<T, K extends keyof T>(property: K, ...and: readonly K[]): (value: T) => value is ObjectWithNotNull<T, K>
hasNullProperty<T, K extends keyof T>(property: K, ...and: readonly K[]): (value: T) => value is ObjectWithNull<T, K>
hasPresentProperty<T, K extends keyof T>(property: K, ...and: readonly K[]): (value: T) => value is ObjectWithPresent<T, K>
hasAbsentProperty<T, K extends keyof T>(property: K, ...and: readonly K[]): (value: T) => value is ObjectWithAbsent<T, K>
- Predicates:
isObject<T>(value: T | null): boolean
isRecord<T>(value: T): boolean
isTruthy<T>(value: T): boolean
isFalsy<T>(value: T): boolean
isEmpty<T>(value: T): boolean
- Reducers:
toRecordFromEntries(record: Record<string, unknown>, value: Entry): Record<string, unknown>
- Property functions:
property<T, K extends keyof T>(property: K): Unary<T, T[K]>
property<T, K extends keyof T>(property: K, condition: Predicate<T[K]>): Predicate<T>
by<T, K extends keyof T>(property: K, ordering: Compare<T[K]>): Compare<T>
- Input:
Input<T>
InputArray<T>
InputObject<T>
InputPrimitive<T>
input<T>(input: unknown): Input<T>
— type cast toInput<T>
.stringInput(input: Input<string>): string | undefined
numberInput(input: Input<number>): number | undefined
booleanInput(input: Input<boolean>): boolean | undefined
arrayInput<T>(input: Input<T[]>): Input<T>[] | undefined
— checks that theinput
is an array and returns it as an array of unvalidated elements.objectInput<T>(input: Input<T>): InputObject<T> | undefined
— checks that theinput
is a non-null, non-array object, and returns it as an object with unvalidated properties.nullInput(input: Input<null>): null | undefined
.
Read the full documentation in the repository.