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

@rbxts/remap

v0.2.1

Published

Functions for transforming readonly maps

Downloads

71

Readme

🧊 Remap

A module for transforming read-only maps in Roblox TypeScript. Intended for using ReadonlyMap in a state manager like Reflex.

All functions assume the map is immutable, and will return a new map if changes are made. Some functions will return the original map if a change is not necessary.

📦 Installation

npm install @rbxts/remap
pnpm add @rbxts/remap
yarn add @rbxts/remap

🔎 Example

import Remap from "@rbxts/remap";

let map = new ReadonlyMap<string, number>();

map = Remap.assign(map, { foo: 1, bar: 2, baz: 3 }, { baz: Remap.None });
map = Remap.delete(map, "foo");
map = Remap.set(map, "baz", 3);

📚 API

set(object, key, value)

function set<K, V>(object: ReadonlyMap<K, V>, key: K, value: V): ReadonlyMap<K, V>;

Remap.set(map, "foo", 1); // { foo: 1 }

Sets the value at key to value.


delete(object, key)

function delete<K, V>(object: ReadonlyMap<K, V>, key: K): ReadonlyMap<K, V>;

Remap.delete(map, "foo"); // deletes the entry at "foo"

Deletes the entry with the given key from the map.


deleteValue(object, value)

function deleteValue<K, V>(object: ReadonlyMap<K, V>, value: V): ReadonlyMap<K, V>;

Remap.deleteValue(map, 1); // deletes the entry with the value 1

Deletes the entry with the given value from the map.


update(object, key, updater)

function update<K, V>(object: ReadonlyMap<K, V>, key: K, updater: (value?: V) => V | undefined): ReadonlyMap<K, V>;

Remap.update(map, "foo", (value = 0) => value + 1); // adds 1 to the value at "foo"

Updates the value at key with the result of updater. Returning undefined from updater will delete the entry.


map(object, updater)

function map<K, V, R>(object: ReadonlyMap<K, V>, updater: (value: V, key: K) => R | undefined): ReadonlyMap<K, R>;

Remap.map(map, (value, key) => value + 1); // adds 1 to each value

Updates each entry in the map with the result of updater. Returning undefined from updater will delete the entry.


filter(object, predicate)

function filter<K, V>(object: ReadonlyMap<K, V>, predicate: (value: V, key: K) => boolean): ReadonlyMap<K, V>;

Remap.filter(map, (value, key) => value > 1); // removes values less than 1

Deletes all entries from the map for which predicate returns false.


reduce(object, reducer, initialValue)

function reduce<K, V, R>(
	object: ReadonlyMap<K, V>,
	reducer: (accumulator: R, value: V, key: K) => R,
	initialValue: R,
): R;

Remap.reduce(map, (accumulator, value, key) => accumulator + value, 0); // sum of values

Reduces the map to a single value using reducer. The result of each call to reducer is passed as the first argument to the next call.


assign(object, ...sources)

function assign<K, V>(map: ReadonlyMap<K, V | None>, ...sources: ReadonlyMap<K, V | None>[]): ReadonlyMap<K, V>;

Remap.assign(map, { foo: 1, bar: 2, baz: 3 }, { baz: Remap.None }); // { foo: 1, bar: 2 }

Returns a new map with the keys and values from sources merged into map. Use the Remap.None symbol to mark a value for deletion.

If the key is a string, number, or symbol, you may pass objects to ...sources instead of maps.


clone(object)

function clone<K, V>(object: ReadonlyMap<K, V>): Map<K, V>;

Remap.clone(map).set("foo", 1);

Returns a mutable shallow copy of the map.


clear(object)

function clear<K, V>(object: ReadonlyMap<K, V>): Map<K, V>;

Remap.clear(map).set("foo", 1);

Returns an empty writable map of the same type as object.


omit(object, ...keys)

function omit<K, V>(object: ReadonlyMap<K, V>, ...keys: K[]): ReadonlyMap<K, V>;

Remap.omit(map, "foo", "bar"); // { baz: 3 }

Returns a subset of the map excluding the keys specified.


pick(object, ...keys)

function pick<K, V>(object: ReadonlyMap<K, V>, ...keys: K[]): ReadonlyMap<K, V>;

Remap.pick(map, "foo", "bar"); // { foo: 1, bar: 2 }

Returns a subset of the object with only the keys specified.

📄 License

Remap is available under the terms of the MIT license. See LICENSE for details.