Socket
Socket
Sign inDemoInstall

immutable

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

14

dist/Immutable.d.ts

@@ -39,3 +39,3 @@ /**

/**
* `Immutable.fromJSON()` deeply converts plain JS objects and arrays to
* `Immutable.fromJS()` deeply converts plain JS objects and arrays to
* Immutable sequences.

@@ -46,9 +46,9 @@ *

* original sequence itself), along with the key refering to this Sequence
* and the parent JSON object provided as `this`. For the top level, object,
* and the parent JS object provided as `this`. For the top level, object,
* the key will be "". This `converter` is expected to return a new Sequence,
* allowing for custom convertions from JSON.
* allowing for custom convertions from deep JS objects.
*
* This example converts JSON to Vector and OrderedMap:
*
* Immutable.fromJSON({a: {b: [10, 20, 30]}, c: 40}, function (value, key) {
* Immutable.fromJS({a: {b: [10, 20, 30]}, c: 40}, function (value, key) {
* var isIndexed = value instanceof IndexedSequence;

@@ -69,3 +69,3 @@ * console.log(isIndexed, key, this);

*/
export declare function fromJSON(
export declare function fromJS(
json: any,

@@ -177,3 +177,3 @@ converter?: (k: any, v: Sequence<any, any>) => any

/**
* Deeply converts this sequence to equivalent JSON.
* Deeply converts this sequence to equivalent JS.
*

@@ -183,3 +183,3 @@ * IndexedSequences, Vectors, Ranges, Repeats and Sets become Arrays, while

*/
toJSON(): any;
toJS(): any;

@@ -186,0 +186,0 @@ /**

@@ -37,17 +37,16 @@ /**

function fromJSON(json, converter) {
function fromJS(json, converter) {
if (converter) {
var parentJSON = {'': json};
return fromJSONWith(converter, json, '', parentJSON);
return fromJSWith(converter, json, '', {'': json});
}
return fromJSONDefault(json);
return fromJSDefault(json);
}
function fromJSONDefault(json) {
function fromJSDefault(json) {
if (json) {
if (Array.isArray(json)) {
return Sequence(json).map(fromJSONDefault).toVector();
return Sequence(json).map(fromJSDefault).toVector();
}
if (json.constructor === Object) {
return Sequence(json).map(fromJSONDefault).toMap();
return Sequence(json).map(fromJSDefault).toMap();
}

@@ -58,5 +57,5 @@ }

function fromJSONWith(converter, json, key, parentJSON) {
function fromJSWith(converter, json, key, parentJSON) {
if (json && (Array.isArray(json) || json.constructor === Object)) {
return converter.call(parentJSON, key, Sequence(json).map(function(v, k) {return fromJSONWith(converter, v, k, json);}));
return converter.call(parentJSON, key, Sequence(json).map(function(v, k) {return fromJSWith(converter, v, k, json);}));
}

@@ -67,3 +66,3 @@ return json;

exports.is = is;
exports.fromJSON = fromJSON;
exports.fromJS = fromJS;
exports.Sequence = Sequence;

@@ -70,0 +69,0 @@ exports.Range = Range;

@@ -48,4 +48,4 @@ /**

Sequence.prototype.toJSON=function() {"use strict";
return this.map(function(value) {return value.toJSON ? value.toJSON() : value;}).__toJS();
Sequence.prototype.toJS=function() {"use strict";
return this.map(function(value) {return value instanceof Sequence ? value.toJS() : value;}).__toJS();
};

@@ -468,2 +468,3 @@

Sequence.prototype.toJSON = Sequence.prototype.toJS;
Sequence.prototype.inspect = Sequence.prototype.toSource = function() { return this.toString(); };

@@ -470,0 +471,0 @@ Sequence.prototype.__toJS = Sequence.prototype.toObject;

{
"name": "immutable",
"version": "2.0.1",
"version": "2.0.2",
"description": "Immutable Data Collections",

@@ -37,3 +37,3 @@ "homepage": "https://github.com/facebook/immutable-js",

"engines": {
"node": "0.8.x || 0.10.x"
"node": "^0.8.0"
},

@@ -40,0 +40,0 @@ "files": [

@@ -34,5 +34,5 @@ Immutable Data Collections

### TypeScript
Use these Immutable collections and sequences as you would use native
collections in your [TypeScript](typescriptlang.org) programs while still taking
collections in your [TypeScript](http://typescriptlang.org) programs while still taking
advantage of type generics, error detection, and auto-complete in your IDE.

@@ -103,4 +103,6 @@

The only difference is that every method that would mutate the collection
instead returns a new collection.
The difference for the immutable collections is that method which would mutate
the collection, like `push`, `set`, `unshift` or `splice` instead return a new
immutable collection. Methods which return new arrays like `slice` or `concat`
instead return new immutable collections.

@@ -110,9 +112,9 @@ ```javascript

var vect2 = vect1.push(3, 4, 5);
var vect3 = vect2.slice(1, -1);
var vect4 = vect1.concat(vect2, vect3, vect4);
var vect3 = vect2.unshift(0);
var vect4 = vect1.concat(vect2, vect3);
assert(vect1.length === 2);
assert(vect2.length === 5);
assert(vect3.length === 3);
assert(vect4.length === 10);
assert(vect4.get(0) === 2);
assert(vect3.length === 6);
assert(vect4.length === 13);
assert(vect4.get(0) === 1);
```

@@ -141,6 +143,6 @@

var map3 = map1.merge(map2, obj);
// Map { a: 20, b: 2, c: 10, d: 1000, t: 30, o: 2000, g: 300 }
// Map { a: 20, b: 2, c: 10, d: 100, t: 30, o: 200, g: 300 }
```
This is possible because `immutible` can treat any JavaScript Array or Object
This is possible because `immutable` can treat any JavaScript Array or Object
as a Sequence. You can take advantage of this in order to get sophisticated

@@ -160,4 +162,5 @@ sequence methods on JavaScript Objects, which otherwise have a very sparse

All `immutable` Sequences can be converted to plain JavaScript Arrays and
Objects shallowly with `toArray()` and `toObject()` or deeply with `toJSON()`,
allowing `JSON.stringify` to work automatically.
Objects shallowly with `toArray()` and `toObject()` or deeply with `toJS()`.
All sequences also implement `toJSON()` allowing them to be passed to
`JSON.stringify` directly.

@@ -168,3 +171,3 @@ ```javascript

deep.toArray() // [ 1, 2, Vector [ 3, 4, 5 ] ]
deep.toJSON() // { a: 1, b: 2, c: [ 3, 4, 5 ] }
deep.toJS() // { a: 1, b: 2, c: [ 3, 4, 5 ] }
JSON.stringify(deep) // '{"a":1,"b":2,"c":[3,4,5]}'

@@ -181,3 +184,3 @@ ```

```javascript
var nested = Immutable.fromJSON({a:{b:{c:[3,4,5]}}});
var nested = Immutable.fromJS({a:{b:{c:[3,4,5]}}});
// Map { a: Map { b: Map { c: Vector [ 3, 4, 5 ] } } }

@@ -226,3 +229,3 @@ ```

console.log(evenSquares.last()); // 49
console.log(oddSquares.last()); // 49

@@ -229,0 +232,0 @@ Lazy Sequences allow for the efficient chaining of sequence operations, allowing

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc