immutable-to-js
Convert immutable-js value to regular js value
Last updated 5 years ago by parshap .
WTFPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install immutable-to-js 
SYNC missed versions from official npm registry.

immutable-to-js

Function to convert an immutable-js value to a regular JavaScript value. If the given value is not an immutable-js value, it is simply returned.

Use Case

When using Immutable.fromJS(value) on arbitrary values a non-immutable value can be returned (e.g., Immutable.fromJS(5) === 5). To then convert the value back to a regular js object, we have to first make sure the value is an immutable value and then call .toJS() on it. This module provides a static toJS(value) function that performs the necessary type checking to guarantee the return value is a regular js object.

var value = Immutable.fromJS(someValue); // May result in immutable, may not
var unwrapped = toJS(value); // Guarantee value is not immutable

Example

var toJS = require("immutable-to-js");
var Immutable = require("immutable");

toJS(Immutable.Map({ foo: 1 })); // -> { foo: 1 }
toJS(Immutable.fromJS([1, 2, 3])); // -> [1, 2, 3]
toJS("hello"); // -> "hello"
toJS(5); // -> 5

API

var toJS = require("immutable-to-js");

toJS(value)

Convert value to a regular js value. If value is not an immutable-js value, it is simply returned.

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

1 Versions

  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |