npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

optel

v0.6.3

Published

TypeScript library for type-safe assigning and merging objects

Downloads

10

Readme

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)