0.4.0 • Published 5 years ago
@perfective/object v0.4.0
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 therecordonly with the givenproperty.omit<T, K extends keyof T>(record: T, ...property: readonly K[]): Omit<T, K>— creates a copy of therecordwithout the givenproperty.filter<T, K extends keyof T>(record: T, condition: Predicate<T[K]>): Partial<T>— creates a copy of therecordwhere 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): booleanisRecord<T>(value: T): booleanisTruthy<T>(value: T): booleanisFalsy<T>(value: T): booleanisEmpty<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 | undefinednumberInput(input: Input<number>): number | undefinedbooleanInput(input: Input<boolean>): boolean | undefinedarrayInput<T>(input: Input<T[]>): Input<T>[] | undefined— checks that theinputis an array and returns it as an array of unvalidated elements.objectInput<T>(input: Input<T>): InputObject<T> | undefined— checks that theinputis 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.
0.4.0
5 years ago
0.3.0
5 years ago
0.2.1
5 years ago
0.2.0
5 years ago
0.2.0-beta
5 years ago
0.2.0-alpha.2
5 years ago
0.2.0-alpha.1
5 years ago
0.2.0-alpha
5 years ago
0.1.0
5 years ago