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

immutably

v1.7.0

Published

Non-mutating operations on data structures.

Downloads

36

Readme

immutably

Non-mutating operations on data structures.

Install

immutably is available to download through NPM.

$ npm install immutably

Import

import immutably from 'immutably';

Use

apply

Applies the given function to the respective part of the input data structure.

output = immutably.apply(input, path, applyFn);

Arguments

  • input (any) input data structure.
  • path (string) input data structure new nested value path.
  • applyFn (function) a function that gets a value as an argument, applies a change and returns a new value.

Returns

  • output (any) output data structure with the given new nested value set to the given path.

Examples

Basic use:

const input = {foo: {bar: {baz: false}}};
const output = immutably.apply(input, 'foo.bar.baz', (value) => !value);
output; // {foo: {bar: {baz: true}}}

You can find more examples in the test files.

set

Sets the given value to the respective part of the input data structure.

output = immutably.set(input, path, value);

Arguments

  • input (any) input data structure.
  • path (string) input data structure new nested value path.
  • value (any) input data structure new nested value.

Returns

  • output (any) output data structure with the given new nested value set to the given path.

Examples

Basic use:

const input = {foo: {bar: {baz: false}}};
const output = immutably.set(input, 'foo.bar.baz', true);
output; // {foo: {bar: {baz: true}}}

You can find more examples in the test files.

merge

Merges the given object with the respective part of the input data structure.

output = immutably.merge(input, path, delta, deep);

Arguments

  • input (any) input data structure.
  • path (string) input data structure merging path.
  • delta (object) merge data structure.
  • deep (object) deep merge switch.

Returns

  • output (any) output data structure merged with the given merge data structure on the given path.

Examples

Basic use:

const input = {foo: {bar: {baz: false}}};
const output = immutably.merge(input, 'foo.bar', {baz: true});
output; // {foo: {bar: {baz: true}}}

You can find more examples in the test files.

alt

Sets the given alternative value to the respective part of the input data structure if it's empty (undefined).

output = immutably.alt(input, path, altValue);

Arguments

  • input (any) input data structure.
  • path (string) input data structure nested value path.
  • altValue (any) input data structure alternative value.

Returns

  • output (any) output data structure with the given alternative value set to the given path if necessary.

Examples

Basic use:

const input = {foo: {bar: {baz: undefined}}};
const output = immutably.alt(input, 'foo.bar.baz', true);
output; // {foo: {bar: {baz: true}}}

You can find more examples in the test files.

clone

Clones the respective part of the input data structure.

output = immutably.clone(input, path, deep);

Arguments

  • input (any) input data structure.
  • path (string) input data structure's merging path.
  • deep (object) deep clone switch.

Returns

  • output (any) output data structure cloned on the given path.

Examples

Basic use:

const input = {foo: {bar: {baz: false}}};
const output = immutably.clone(input, 'foo.bar', false);
output; // {foo: {bar: {baz: false}}}
input.foo.bar === output.foo.bar; // false

You can find more examples in the test files.

Extensions

Changelog

1.7.0

  • merging with empty value fixed
  • build JS compression switched off
  • package.json module configured
  • .npmignore update

1.6.0

  • immutably.merge deep switch
  • immutably.merge undefined input bug fixed

1.5.0

  • immutably.alt implemented & unit tested
  • minor refactoring

1.4.0

  • distribution package UMD setup
  • distribution package includes dependency

1.3.2

  • npm broken publish fixed

1.3.1

  • module section removed from package.json
  • dependency related change

1.3.0

  • immutably.clone implemented & unit tested

1.2.2

  • minor refactoring
  • project metadata update

1.2.1

  • import/export bug fixed

1.2.0

  • immutably.merge implemented & unit tested
  • immutably.apply refactoring
  • empty path proper handling

1.1.0

  • immutably.apply implemented & unit tested
  • more unit tests for immutably.set

1.0.0

  • immutably.set implemented & unit tested

Develop

If you want to fork and develop immutably, these commands are for you:

$ npm run dev
$ npm run test-dev

Test

immutably is equipped with a test suite. You can run it with:

$ npm run test

Licence

MIT