Options
All
  • Public
  • Public/Protected
  • All
Menu

@tsfun/object — Reference

Index

Type aliases

AddProperty

AddProperty<Proto, Key, Value>: {}[Key]

Return type of addProperty

Type parameters

  • Proto: object | null

  • Key: string | number | symbol

  • Value

DeepPartialNonArray

DeepPartialNonArray<Object>: Object extends readonly any[] ? Object | undefined : Object extends object ? {} : Object | undefined

Make all properties in a dict optional

Type parameters

  • Object

ErrorProcessorParam

ErrorProcessorParam: PropertyCollision

Param to pass to ErrorProcessor should deepMergeWithoutCollision fails

Key

Key: string | symbol | number

MaybeParam

MaybeParam<Fn>: Fn extends (...args: any[]) => any ? Parameters<Fn> : never

Extract parameter types from Fn if it is a function

Type parameters

  • Fn

MaybeReturn

MaybeReturn<Fn>: Fn extends (...args: any[]) => any ? ReturnType<Fn> : never

Extract return type from Fn if it is a function

Type parameters

  • Fn

NullObject

NullObject<X>: X extends null ? {} : X

Turn null into {}

Type parameters

  • X

ObjectExtends

ObjectExtends<Proto, Properties>: Assign<NullObject<Proto>, NullObject<Properties>>

Return type of objectExtends

Type parameters

  • Proto: object | null

  • Properties: object | null

Properties

Properties<Type>: {}

Turn a type into a set of properties

Type parameters

  • Type

Type declaration

SimpleDeepMerge

SimpleDeepMerge<A, B>: Properties<A> & Properties<B>

Merge two types

Type parameters

  • A

  • B

SingleDict

SingleDict<Key, Value>: {}

Create a dict of one key-value pair

Type parameters

  • Key: string | number | symbol

  • Value

Type declaration

Variables

defineProperty

defineProperty: defineProperty

Const protoBind

protoBind: bind = Function.prototype.bind

Functions

Const DMWOC_DEF_ERR_HDLR

Const PREFER_RIGHT

addProperty

  • addProperty<Proto, Key, Value>(proto: Proto, key: Key, value: Value): AddProperty<Proto, Key, Value>
  • Create an object with proto as prototype and [key]: value as the only own properties

    note

    If you need own properties, use setProperty instead

    note

    If key is a property setter in proto (such as __proto__), the setter will be invoked

    Type parameters

    • Proto: object | null

    • Key: string | number | symbol

    • Value

    Parameters

    • proto: Proto

      Prototype to extends upon

    • key: Key

      Property key

    • value: Value

      Property value

    Returns AddProperty<Proto, Key, Value>

Const applyMethod

  • applyMethod<Object, MethodName, Method>(object: Object, name: MethodName, args: Readonly<MaybeParam<Method>>): MaybeReturn<Method>
  • Execute a method

    Type parameters

    • Object: object

    • MethodName: FunctionKeys<Object>

    • Method: Object[MethodName]

    Parameters

    • object: Object

      Object that has the method

    • name: MethodName

      Name of the method

    • args: Readonly<MaybeParam<Method>>

      Arguments to pass to the method

    Returns MaybeReturn<Method>

    Returning value of the method

Const bindContext

  • bindContext<Fn>(fn: Fn, ctx: ThisParameterType<Fn>): OmitThisParameter<Fn>
  • Type parameters

    • Fn: Function

    Parameters

    • fn: Fn
    • ctx: ThisParameterType<Fn>

    Returns OmitThisParameter<Fn>

Const callMethod

  • callMethod<Object, MethodName, Method>(object: Object, name: MethodName, ...args: MaybeParam<Method>): MaybeReturn<Method>
  • Execute a method

    Type parameters

    • Object: object

    • MethodName: FunctionKeys<Object>

    • Method: Object[MethodName]

    Parameters

    • object: Object

      Object that has the method

    • name: MethodName

      Name of the method

    • Rest ...args: MaybeParam<Method>

      Arguments to pass to the method

    Returns MaybeReturn<Method>

    Returning value of the method

deepMergeOverwrite

  • deepMergeOverwrite<Value>(left: Value, right: Value): Value
  • Merge two objects of the same interface

    left is prioritized for overlapping non-object properties

    Type parameters

    • Value

    Parameters

    • left: Value

      Object or value to merge

    • right: Value

      Object or value to merge

    Returns Value

    Result of the merge

deepMergePartial

  • Merge an object and a partial object of the same interface

    Type parameters

    • Object

    Parameters

    • left: Object

      Object to merge

    • right: DeepPartial<Object>

      Partial object to merge

    • resolveConflict: PropertyConflictResolver

      Function that resolves property conflict

    Returns Object

    Result of the merge

deepMergeWithPreference

  • Merge two objects of the same interface

    Type parameters

    • Value

    Parameters

    • left: Value

      Object or value to merge

    • right: Value

      Object or value to merge

    • resolveConflict: PropertyConflictResolver

      Function that resolves property conflict

    Returns Value

    Result of the merge

deepMergeWithoutCollision

  • deepMergeWithoutCollision<Left, Right>(left: Left, right: Right, onerror?: ErrorProcessor): DeepMergeWithoutCollision<Left, Right>
  • Merge two objects

    The two objects are expected to not have overlapping non-object properties

    Type parameters

    • Left: object

    • Right: object

    Parameters

    • left: Left

      Object to merge

    • right: Right

      Object to merge

    • Default value onerror: ErrorProcessor = DMWOC_DEF_ERR_HDLR

      Function to handle should error occurs

    Returns DeepMergeWithoutCollision<Left, Right>

    A merged object of a and b

deletePropertyPath

  • deletePropertyPath(object: any, path: readonly Key[]): any

Const getMethod

  • getMethod<Object, MethodName, Method>(object: Object, name: MethodName): OmitThisParameter<Method>
  • Get a method from and bind it to an object

    Type parameters

    • Object: object

    • MethodName: FunctionKeys<Object>

    • Method: Object[MethodName]

    Parameters

    • object: Object

      Object to get method from

    • name: MethodName

      Name of the method

    Returns OmitThisParameter<Method>

    Bound method

Const getProperty

  • getProperty<Object, Key>(object: Object, key: Key): Object[Key]
  • Access a property from an object

    Type parameters

    • Object: object

    • Key: keyof Object = keyof Object

    Parameters

    • object: Object

      Object to get property from

    • key: Key

      Property key

    Returns Object[Key]

    Property value

getPropertyPath

  • getPropertyPath(object: any, path: readonly Key[]): any

Const isObject

  • isObject(value: any): value is object
  • isObject(object: any): object is object

methodApplierOf

  • methodApplierOf<MethodName>(name: MethodName): (Anonymous function)
  • Create a function that executes a particular method of an object

    Type parameters

    • MethodName: string | number | symbol

    Parameters

    • name: MethodName

      Method name

    Returns (Anonymous function)

    Function that executes method [name] of an object

methodCallerOf

  • methodCallerOf<MethodName>(name: MethodName): (Anonymous function)
  • Create a function that executes a particular method of an object

    Type parameters

    • MethodName: string | number | symbol

    Parameters

    • name: MethodName

      Method name

    Returns (Anonymous function)

    Function that executes method [name] of an object

Const methodGetter

  • methodGetter<Object>(object: Object): (Anonymous function)
  • Create a function that get methods of an object

    Type parameters

    • Object: object

    Parameters

    • object: Object

      Object to get methods from

    Returns (Anonymous function)

    A function that get object method

mutObj

  • mutObj<Object, Key, Value>(object: Object, key: Key, value: Value): assertsobject is Object & Record<Key, Value>
  • Type parameters

    • Object

    • Key: string | number | symbol

    • Value

    Parameters

    • object: Object
    • key: Key
    • value: Value

    Returns assertsobject is Object & Record<Key, Value>

objectExtends

  • objectExtends<Proto, Properties>(proto: Proto, properties: Properties): ObjectExtends<Proto, Properties>
  • Create an object with proto as prototype and properties as own properties

    Type parameters

    • Proto: object | null

    • Properties: object

    Parameters

    • proto: Proto

      Prototype to extends upon

    • properties: Properties

      Properties to add

    Returns ObjectExtends<Proto, Properties>

omit

  • omit<Object, Key>(object: Object, keys: Iterable<Key>): Omit<Object, Key> & Partial<Pick<Object, Key>>
  • Creates a shallow clone of an object without certain properties

    Type parameters

    • Object

    • Key: keyof Object

    Parameters

    • object: Object

      Object to omit properties

    • keys: Iterable<Key>

      Property keys to not include

    Returns Omit<Object, Key> & Partial<Pick<Object, Key>>

    A shallow clone of object but without keys

omitOne

  • omitOne<Object, Key>(object: Object, key: Key): Omit<Object, Key>
  • Creates a shallow clone of an object without one property

    Type parameters

    • Object

    • Key: keyof Object

    Parameters

    • object: Object

      Object to omit property

    • key: Key

      Property key to not include

    Returns Omit<Object, Key>

    A shallow clone of object but without key

pick

  • pick<Object, Key>(object: Object, keys: Iterable<Key>): Partial<Pick<Object, Key>>
  • Pick properties from an object into a new object

    Type parameters

    • Object

    • Key: keyof Object

    Parameters

    • object: Object

      Object to pick properties from

    • keys: Iterable<Key>

      Property keys

    Returns Partial<Pick<Object, Key>>

    An object with only picked properties

Const pickOne

  • pickOne<Object, Key>(object: Object, key: Key): Pick<Object, Key>
  • Pick a single property from an object into a new object

    Type parameters

    • Object

    • Key: keyof Object

    Parameters

    • object: Object

      Object to pick property from

    • key: Key

      Property key

    Returns Pick<Object, Key>

    An object with the picked property

Const propertyGetter

  • Create a function that lookups properties of an object

    Type parameters

    • Object: object

    Parameters

    • object: Object

      Object to get properties from

    Returns PropertyGetter<Object>

    A function that lookup an object property

Const propertyOf

  • propertyOf<Key>(key: Key): (Anonymous function)
  • Create a function that accesses a particular key from an object

    Type parameters

    • Key: string | number | symbol

    Parameters

    • key: Key

      Property key

    Returns (Anonymous function)

    Function that accesses [key] of an object

Const setProperty

  • setProperty<Object, Key, Value>(object: Object, key: Key, value: Value): SetProperty<Object, Key, Value>
  • Shallow clone an object and alter one property

    hint

    If you don't need remaining properties to be own properties, consider addProperty instead

    Type parameters

    • Object: object

    • Key: string | number | symbol

    • Value

    Parameters

    • object: Object

      Object to get remaining properties from

    • key: Key

      Property key

    • value: Value

      Property value

    Returns SetProperty<Object, Key, Value>

setPropertyPath

  • setPropertyPath(object: any, path: readonly Key[], value: any): any

Generated using TypeDoc