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

typescript-immutable-utils

v0.1.2

Published

Type-safe immutability helpers for simple objects and arrays

Downloads

346

Readme

TypeScript Immutable Utils npm version Build Status

Type-safe immutability helpers for simple objects and arrays.

Installation

npm install --save typescript-immutable-utils

API

Arrays

  • setAt<T>(items: T[], index: number, item: T): T[]

    Returns new array with replaced item at given index.

    If item is equal to the old one, original array is returned.

  • insertAt<T>(items: T[], index: number, item: T): T[]

    Returns new array with inserted item at given index.

    If index is negative, counts from the end of the array.

  • removeAt<T>(items: T[], index: number): T[]

    Returns new array with removed item at given index.

    If index is out of bounds, original array is returned.

    If index is negative, counts from the end of the array.

  • removeValue<T>(items: T[], item: T): T[]

    Returns new array with given value removed.

    If value is not present in the array, it is returned unchanged.

Objects

  • update<T>(target: T, values: Partial<T>): T

    Returns new object with updated values.

    If all values are the same, original object is returned.

Maps (ES-2015)

  • mapValues<K, T, R>(src: Map<K, T>, map: (value: T, key: K) => R): Map<K, R>

    Returns new Map with updated values

Dicts

Dictionary type is a simple index signature:

type Dict<V> = {[key: string]: V};
  • createDict<V>(): Dict<V>

    Creates empty dict.

  • copyDict<V>(dict: Dict<V>): Dict<V>

    Copies given dict.

  • hasKey(dict: Dict<any>, key: any): boolean

    Checks whether dict has given key.

  • mapValues<T, R>(dict: Dict<T>, map: (value: T) => R): Dict<R>

    Creates new dict with same keys as given dict whose values are the result of applying mapping function on given dict values.

    If every returned value is the same as in original dict, original dict is returned.

  • union<V>(target: Dict<V>, source: Dict<V>): Dict<V>

    Creates new dict with values from both given dicts.

  • setKey<V>(dict: Dict<V>, key: any, value: V): Dict<V>

    Returns new dict with given key set to given value.

    If the value is the same as in original dict, original dict is returned.

  • removeKey<V>(dict: Dict<V>, ...keys: any[]): Dict<V>

    Returns new dict with given keys removed.

    If none of the keys are present in original dict, original dict is returned.

  • fromKeys<V>(keys: any[], values: V | ((key: any) => V)): Dict<V>

    If values is not a function, creates new dict with given keys whose values are all the same and equal to values.

    If values is function, creates new dict with given keys whose values are the result of applying this function to the key.