Skip to content

tetrogem/optel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Optel

TypeScript library for making usage of objects more type-safe

This library is still in development, some features may not work as expected and be subject to change.


Examples

View the code examples on playground

(These will also be listed directly on this README as text in the future)


Functions

entries (function)

This function is a wrapper for Object.entries(), providing additional type information and no extra implementation

Parameters:

  • object (O) - The object to get the entries of

returns: [key: string, value: unknown][]

assignDefined (function)

Assigns all keys of source objects that do not have their value set to undefined to the target object It does not return the target object, but instead asserts its type. To create a new object, use optel.mergeDefined().

Parameters:

  • target (T) - The object to assign to
  • sources (AssertDefinedAssignableTo<T, S>) - The objects to get assigned values from

returns: void

mergeDefined (function)

Creates a new object with all of its keys assigned to their respective values from the source objects, only being assigned if that value is not undefined. This function creates a new object and returns it, not modifying any of the source objects. To modify an existing target object instead, use optel.assignDefined().

Parameters:

  • sources (AssertDefinedAssignableTo<{}, S>) - The objects to get assigned values from

returns: ReduceImpl<S, {}, HOTDefinedAssign>

assign (function)

This function is a wrapper for Object.assign(), providing additional type information and no extra implementation. It does not return the target object, but instead asserts its type. To create a new object, use optel.merge().

Parameters:

  • target (T) - The object to assign to
  • sources (AssertAssignableTo<T, S>) - The objects to get assigned values from

returns: void

merge (function)

This function is a wrapper for Object.assign(), providing additional type information and no extra implementation. This function creates a new object and returns it, not modifying any of the source objects. To modify an existing target object instead, use optel.assign().

Parameters:

  • sources (AssertAssignableTo<{}, S>) - The objects to get assigned values from

returns: ReduceImpl<S, {}, HOTAssign>

pick (function)

Creates a copy of the given object with only the specified keys included

Parameters:

  • object (O) - The object to pick keys from
  • keys (K) - The keys to be picked and included on the new object

returns: OptelPick<O, K>

omit (function)

Creates a copy of the given object with the specified keys removed

Parameters:

  • object (O) - The object to pick keys from
  • keys (K) - The keys to be picked and included on the new object

returns: OptelOmit<O, K>

keyOf (function)

This function returns the first key (as given by Object.entries()) that contains the given value

Parameters:

  • object (O) - The object to search for the value within
  • value (V) - The value to search for

returns: OptelKeyOf<O, V>

allKeysOf (function)

This function returns an array of keys that contain the given value

Parameters:

  • object (O) - The object to search for the value within
  • value (V) - The value to search for

returns: OptelKeyOf<O, V>[]

unlock (function)

Returns this object, but with its type changed to allow for any key to be used to index it, with its value set to unknown. This function does nothing else except return the same object passed to it with additional type information.

Parameters:

  • object (O) - The object to unlock

returns: OptelUnlocked

fromEntries (function)

This function is a wrapper for Object.fromEntries(), providing additional type information and no extra implementation.

Parameters:

  • sources - The entries to create an object from
  • entries (T)

returns: OptelFromEntries


Types

OptelPick (type)

OptelOmit (type)

OptelKeyOf (type)

OptelUnlocked (type)

OptelFromEntries (type)


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published