2.0.1 • Published 7 years ago

rauricoste-immutable v2.0.1

Weekly downloads
2
License
ISC
Repository
-
Last release
7 years ago

Summary

rauricoste-immutable is an immutable data structure that combine capabilities of both classic javascript Object and Array

Installation

npm install rauricoste-immutable

API

path

Many methods use a path to access or update fields. A path is similar to the javascript notation but there are differences : if the data structure is :

{
    value: 1,
    subObject: {
        a: 1,
        b: "plop"
    },
    arr: [1, 2, 3]
}

you can access data using these paths :

value
subObject.a
subObject.b
arr.0
arr.1
arr.2

constructor

const Immutable = require("rauricoste-immutable")
const object = new Immutable()
// or
const object = Immutable.fromObject({
    value: 1,
    subObject: {
        a: 1,
        b: "plop"
    },
    arr: [1, 2, 3]
})

read methods

  • get(path) : returns the data at path location. similar to immuableObject.key.

  • toObject() : returns a vanilla js object corresponding to the data structure. Warning : this method can be time consuming.

write methods (returns a new object since it is immutable)

  • set(path, value) : replaces the value of the data at path with value. similar to immuableObject.key = value.

  • delete(path) : deletes the value at path. If the data at path does not exists, returns the same object. similar to delete immuableObject.key.

  • push(path, value) : push value on the array at path. If there is no data at path, the array is created. Otherwise, if the data is an object, an error is thrown.

  • remove(path, value) : iterates over the array at path and removes the first occurence of value. If the data at path is an object, an error is thrown.

  • resetWith(object) : replaces all the data with object. similar to immuableObject = object.

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago