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

mutateless

v1.0.1

Published

Keep your sanity while working with immutable data structures

Downloads

4

Readme

Mutateless

Mutateless is a small utility module which provide a bunch of functions for working with immutable data structures. Instead of polluting or changing the way you work with your objects, we designed the functions to work on regular objects, lists and nested data structures of any kind.

Installation

yarn add mutateless

Examples

Lets start by looking at assign, which acts almost like Object.assign:

const todo = {
  title: 'sleep', 
  checked: false,
  notes: ['Go to bed before midnight']
}

const modifiers = {
  checked: true,
  notes: notes => [...notes, 'another note']
}

assign(modifiers, todo) // => new object with with a second note

We first pass in the properties we want to modify, each property can either be a value or a modifier function. The modifier function will receive the original value and should return the new value. You will soon see why we received the original value but first lets take a look at another function called add:

add(4, [1,2,3]) // => [1,2,3,4]

add will return a new list with the appended value. But add is also a curried function, if we only pass in the first parameter we will receive a new function which accepts the second parameter. Lets combine assign and the curried add:

assign({notes: add('another note')}, todo) // => new object with with a second note

Which is equivalent to:

assign({notes: notes => add('another note', notes)}, todo) // => new object with with a second note

remove can be used to remove items matching a reference or a predicate:

assign({notes: remove('another note')}, todo) // => new object with without the second note

modifying a nested object works the same way:

const article = {
  // ...
  author: {
    // ...
    username: 'jack.bauer'
  }
}

const setUsername = username => assign({username}) // => curried assign which accepts an object/list

assign({author: setUsername('kiefer.sutherland')}, article) // => new article with updated author.username

mutateless contains a some generic and useful predicates to help you write more readable and predictable code.

Lets take a look at the match predicate:

const todos = [
    {title: 'Bake cake', checked: true},
    {title: 'Eat cake', checked: false},
    {title: 'Profit', checked: false},   
]

const unchecked = match({checked: false}) 

replace(unchecked, assign({checked: true}), todos) // => check all elements

and the here is last predicate:

remove(last, todos) // => new list without the last item

For more examples read the tests or the documentation

License

MIT