0.2.1 • Published 5 years ago

immutable-validator v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Immutable validator

Deep validates an Object/Array/Map/List

Simple tool to validate that your immutable-js object is fully immutable. Deep validates and logs paths if there are any leafs that are not an instance from immutable-js. Primitive values are ignored.

What do I use it for?

  • If you got a large nested state and expect everything (non-primitives) to be an instance of immutable-js
  • Validate that your redux store is fully immutable

Installation

npm install immutable-validator --save

Usage example

import { Map, List } from 'immutable'
import ImmutableValidator from 'immutable-validator'

const obj = Map({
    a: 1,
    b: 2,
    c: {},
    d: [],
    e: List([
        1,
        2,
        Map({
            aa: 1,
            bb: {}
        })
    ])
})

ImmutableValidator(obj /**, options **/)

/** LOGS:
 * root.c
 * root.d
 * root.e.2.bb
 * /

Redux example

Usage with Redux

import { createStore } from 'redux'
import rootReducer from '../rootReducer'
import ImmutableValidator from 'immutable-validator'

const Store = createStore(rootReducer)

Store.subscribe(() => ImmutableValidator(Store.getState()))

Options

Object passed as second argument

CommanddefaultDescription
logToConsoletrueLog result to console
collapsedtrueCollapse the result in console

Changes

  • 0.2.0: Dependency updates (babel 7, immutable 4)
  • 0.1.0: First version