Options
All
  • Public
  • Public/Protected
  • All
Menu

Package objects

@typed/objects

Useful functions for working with regular ole objects.

Index

Type aliases

ExtractUnionMember

ExtractUnionMember<A, Tag, Value>: Extract<A, Record<Tag, Value>>

Type parameters

  • A: object

  • Tag: keyof A

  • Value: A[Tag]

Immutable

Immutable<A>:

Type parameters

  • A

ImmutableObject

ImmutableObject<A>: {}

Type parameters

  • A

Type declaration

MergeObjects

MergeObjects<A, B>: {} & {}

Type parameters

  • A

  • B

Mutable

Mutable<A>: A extends Primitive ? A : A extends ImmutableArray<infer V> ? MutableArray<V> : A extends ReadonlyArray<infer V> ? MutableArray<V> : A extends ImmutableMap<infer K, infer V> ? MutableMap<K, V> : A extends ReadonlyMap<infer K, infer V> ? MutableMap<K, V> : A extends ImmutableSet<infer V> ? MutableSet<V> : A extends ReadonlySet<infer V> ? MutableSet<V> : MutableObject<A>

Type parameters

  • A

MutableObject

MutableObject<A>: {}

Type parameters

  • A

Type declaration

ObjectPath

ObjectPath<T, Keys>: Keys extends [] ? T : Keys extends [keyof T] ? Prop<T, Keys[0]> : Keys extends [PropertyKey, PropertyKey] ? Prop<Prop<T, Keys[0]>, Keys[1]> : Keys extends [PropertyKey, PropertyKey, PropertyKey] ? Prop<Prop<Prop<T, Keys[0]>, Keys[1]>, Keys[2]> : Keys extends [PropertyKey, PropertyKey, PropertyKey, PropertyKey] ? Prop<Prop<Prop<Prop<T, Keys[0]>, Keys[1]>, Keys[2]>, Keys[3]> : Keys extends [PropertyKey, PropertyKey, PropertyKey, PropertyKey, PropertyKey] ? Prop<Prop<Prop<Prop<Prop<T, Keys[0]>, Keys[1]>, Keys[2]>, Keys[3]>, Keys[4]> : undefined

Type parameters

  • T

  • Keys: PropertyKey[]

OptionalKeys

OptionalKeys<A, K>: DropKeys<A, K> & Partial<Pick<A, K>>

Type parameters

  • A

  • K: keyof A

OptionalProperties

OptionalProperties<A>: Pick<A, OptionalPropertyNames<A>>

Type parameters

  • A

OptionalPropertyNames

OptionalPropertyNames<A>: {}[keyof A]

Type parameters

  • A

Overwrite

Overwrite<A, B>: B & MergeObjects<DropKeys<A, keyof B>, B>

Type parameters

  • A

  • B

Prop

Prop<T, K>: K extends keyof T ? T[K] : undefined

Type parameters

  • T

  • K: PropertyKey

RequiredProperties

RequiredProperties<A>: Pick<A, RequiredPropertyNames<A>>

Type parameters

  • A

RequiredPropertyNames

RequiredPropertyNames<A>: {}[keyof A]

Type parameters

  • A

ValuesOf

ValuesOf<A>: {}[keyof A]

Type parameters

  • A

Variables

Const dissoc

dissoc: { <K, A>(key: K, obj: A): DropKeys<A, K>; <K>(key: K): <A>(obj: A) => DropKeys<A, K> } = curry(_dissoc) as {<K extends PropertyKey, A extends Record<K, any>>(key: K, obj: A): DropKeys<A, K><K extends PropertyKey>(key: K): <A extends Record<K, any>>(obj: A) => DropKeys<A, K>}

Disassociate a key from an object

Type declaration

    • <K, A>(key: K, obj: A): DropKeys<A, K>
    • <K>(key: K): <A>(obj: A) => DropKeys<A, K>
    • Type parameters

      • K: PropertyKey

      • A: Record<K, any>

      Parameters

      • key: K
      • obj: A

      Returns DropKeys<A, K>

    • Type parameters

      • K: PropertyKey

      Parameters

      • key: K

      Returns <A>(obj: A) => DropKeys<A, K>

Const hasOwnProperty

hasOwnProperty: { <A, B>(key: A, obj: B): obj is B & {}; <A>(key: A): <B>(obj: B) => obj is B & {} } = curry(<A extends PropertyKey, B extends object>(key: A,obj: B,): obj is B & { readonly [K in A]: unknown } =>obj && Object.prototype.hasOwnProperty.call(obj, key),) as {<A extends PropertyKey, B extends object>(key: A, obj: B): obj is B &{ readonly [K in A]: unknown }<A extends PropertyKey>(key: A): <B extends object>(obj: B,) => obj is B & { readonly [K in A]: unknown }}

Check if an object has a given property.

Type declaration

    • <A, B>(key: A, obj: B): obj is B & {}
    • <A>(key: A): <B>(obj: B) => obj is B & {}
    • Type parameters

      • A: PropertyKey

      • B: object

      Parameters

      • key: A
      • obj: B

      Returns obj is B & {}

    • Type parameters

      • A: PropertyKey

      Parameters

      • key: A

      Returns <B>(obj: B) => obj is B & {}

        • <B>(obj: B): obj is B & {}
        • Type parameters

          • B: object

          Parameters

          • obj: B

          Returns obj is B & {}

Const mapObj

mapObj: { <A, B, C>(fn: <K>(key: K, value: C[K]) => B, obj: C): {}; <A, B, C>(fn: <K>(key: K, value: C[K]) => B): (obj: C) => {} } = curry(__mapObj) as {<A, B, C extends Record<PropertyKey, A>>(fn: <K extends keyof C>(key: K, value: C[K]) => B,obj: C,): { [K in keyof C]: B }<A, B, C extends Record<PropertyKey, A>>(fn: <K extends keyof C>(key: K, value: C[K]) => B): (obj: C,) => { [K in keyof C]: B }}

Map over values contained in an object.

Type declaration

    • <A, B, C>(fn: <K>(key: K, value: C[K]) => B, obj: C): {}
    • <A, B, C>(fn: <K>(key: K, value: C[K]) => B): (obj: C) => {}
    • Type parameters

      • A

      • B

      • C: Record<PropertyKey, A>

      Parameters

      • fn: <K>(key: K, value: C[K]) => B
          • <K>(key: K, value: C[K]): B
          • Type parameters

            • K: keyof C

            Parameters

            • key: K
            • value: C[K]

            Returns B

      • obj: C

      Returns {}

    • Type parameters

      • A

      • B

      • C: Record<PropertyKey, A>

      Parameters

      • fn: <K>(key: K, value: C[K]) => B
          • <K>(key: K, value: C[K]): B
          • Type parameters

            • K: keyof C

            Parameters

            • key: K
            • value: C[K]

            Returns B

      Returns (obj: C) => {}

        • (obj: C): {}
        • Parameters

          • obj: C

          Returns {}

Const mapToList

mapToList: { <A, B, C>(fn: (key: A, value: B) => C, obj: Record<A, B>): C[]; <A, B, C>(fn: (key: A, value: B) => C): (obj: Record<A, B>) => C[] } = curry(__mapToList)

Map over an object into a list of values.

Type declaration

    • <A, B, C>(fn: (key: A, value: B) => C, obj: Record<A, B>): C[]
    • <A, B, C>(fn: (key: A, value: B) => C): (obj: Record<A, B>) => C[]
    • Type parameters

      • A: keyof any

      • B

      • C

      Parameters

      • fn: (key: A, value: B) => C
          • (key: A, value: B): C
          • Parameters

            • key: A
            • value: B

            Returns C

      • obj: Record<A, B>

      Returns C[]

    • Type parameters

      • A: keyof any

      • B

      • C

      Parameters

      • fn: (key: A, value: B) => C
          • (key: A, value: B): C
          • Parameters

            • key: A
            • value: B

            Returns C

      Returns (obj: Record<A, B>) => C[]

        • Parameters

          Returns C[]

Const path

path: { <Keys, A>(keys: Keys, obj: A): Maybe<ObjectPath<A, Keys>>; <Keys>(keys: Keys): <A>(obj: A) => Maybe<ObjectPath<A, Keys>> } = curry(<Keys extends PropertyKey[], A extends object>(keys: Keys, obj: A): Maybe<ObjectPath<A, Keys>> =>(keys.length === 0? Maybe.of(obj): keys.length === 1? prop(keys[0], obj): keys.slice(1).reduce((maybe, key) => chain(prop(key) as any, maybe) as any,prop(keys[0], obj),)) as Maybe<ObjectPath<A, Keys>>,) as {<Keys extends PropertyKey[], A extends object>(keys: Keys, obj: A): Maybe<ObjectPath<A, Keys>><Keys extends PropertyKey[]>(keys: Keys): <A extends object>(obj: A) => Maybe<ObjectPath<A, Keys>>}

Get value at a given path.

Type declaration

    • Type parameters

      • Keys: PropertyKey[]

      • A: object

      Parameters

      • keys: Keys
      • obj: A

      Returns Maybe<ObjectPath<A, Keys>>

    • Type parameters

      • Keys: PropertyKey[]

      Parameters

      • keys: Keys

      Returns <A>(obj: A) => Maybe<ObjectPath<A, Keys>>

Const prop

prop: { <K, O>(key: K, obj: O): Maybe<O[K]>; <K>(key: K): <O>(obj: O) => Maybe<O[K]> } = curry(<K extends PropertyKey, O extends Partial<{ [_ in K]: any }>>(key: K, obj: O): Maybe<O[K]> =>hasOwnProperty(key, obj) ? Maybe.of(obj[key]) : Nothing,) as {<K extends PropertyKey, O extends Partial<{ [_ in K]: any }>>(key: K, obj: O): Maybe<O[K]><K extends PropertyKey>(key: K): <O extends Partial<{ [_ in K]: any }>>(obj: O) => Maybe<O[K]>}

Get a value from an object.

Type declaration

    • <K, O>(key: K, obj: O): Maybe<O[K]>
    • <K>(key: K): <O>(obj: O) => Maybe<O[K]>
    • Type parameters

      • K: PropertyKey

      • O: Partial<{}>

      Parameters

      • key: K
      • obj: O

      Returns Maybe<O[K]>

    • Type parameters

      • K: PropertyKey

      Parameters

      • key: K

      Returns <O>(obj: O) => Maybe<O[K]>

        • <O>(obj: O): Maybe<O[K]>
        • Type parameters

          • O: Partial<{}>

          Parameters

          • obj: O

          Returns Maybe<O[K]>

Const propOf

propOf: { <K, O>(key: K, obj: O): O[K]; <K>(key: K): <O>(obj: O) => O[K] } = curry(<K extends PropertyKey, O extends Record<K, any>>(key: K, obj: O): O[K] => obj[key],) as {<K extends PropertyKey, O extends Record<K, any>>(key: K, obj: O): O[K]<K extends PropertyKey>(key: K): <O extends Record<K, any>>(obj: O) => O[K]}

Type declaration

    • <K, O>(key: K, obj: O): O[K]
    • <K>(key: K): <O>(obj: O) => O[K]
    • Type parameters

      • K: PropertyKey

      • O: Record<K, any>

      Parameters

      • key: K
      • obj: O

      Returns O[K]

    • Type parameters

      • K: PropertyKey

      Parameters

      • key: K

      Returns <O>(obj: O) => O[K]

        • <O>(obj: O): O[K]
        • Type parameters

          Parameters

          • obj: O

          Returns O[K]

Const set

set: { <K, V, O>(key: K, value: V, obj: O): O; <K, V>(key: K, value: V): <O>(obj: O) => O; <K>(key: K): { <V, O>(value: V, obj: O): O; <V>(value: V): <O>(obj: O) => O } } = curry(__set) as {<K extends PropertyKey, V, O extends { [Key in K]: V }>(key: K, value: V, obj: O): O<K extends PropertyKey, V>(key: K, value: V): <O extends { [Key in K]: V }>(obj: O) => O<K extends PropertyKey>(key: K): {<V, O extends { [Key in K]: V }>(value: V, obj: O): O<V>(value: V): <O extends { [Key in K]: V }>(obj: O) => O}}

Set the value of an object

Type declaration

    • <K, V, O>(key: K, value: V, obj: O): O
    • <K, V>(key: K, value: V): <O>(obj: O) => O
    • <K>(key: K): { <V, O>(value: V, obj: O): O; <V>(value: V): <O>(obj: O) => O }
    • Type parameters

      • K: PropertyKey

      • V

      • O: {}

      Parameters

      • key: K
      • value: V
      • obj: O

      Returns O

    • Type parameters

      • K: PropertyKey

      • V

      Parameters

      • key: K
      • value: V

      Returns <O>(obj: O) => O

        • <O>(obj: O): O
        • Type parameters

          • O: {}

          Parameters

          • obj: O

          Returns O

    • Type parameters

      • K: PropertyKey

      Parameters

      • key: K

      Returns { <V, O>(value: V, obj: O): O; <V>(value: V): <O>(obj: O) => O }

        • <V, O>(value: V, obj: O): O
        • <V>(value: V): <O>(obj: O) => O
        • Type parameters

          • V

          • O: {}

          Parameters

          • value: V
          • obj: O

          Returns O

        • Type parameters

          • V

          Parameters

          • value: V

          Returns <O>(obj: O) => O

            • <O>(obj: O): O
            • Type parameters

              • O: {}

              Parameters

              • obj: O

              Returns O

Functions

Const clone

  • clone<A>(value: A): A

isEmpty

  • isEmpty(x: any): boolean

Const keysOf

  • keysOf<A>(obj: A): ReadonlyArray<keyof A>

Const valuesOf

  • valuesOf<A>(obj: A): A extends Record<any, infer R> ? R[] : []

Generated using TypeDoc