Socket
Socket
Sign inDemoInstall

immutable-to-js

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    immutable-to-js

Convert immutable-js value to regular js value


Version published
Weekly downloads
48
decreased by-61.29%
Maintainers
1
Install size
433 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 16 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc