Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serializr

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serializr - npm Package Compare versions

Comparing version 1.1.12 to 1.1.13

lib/es/serializr.js

24

package.json
{
"name": "serializr",
"version": "1.1.12",
"version": "1.1.13",
"description": "Serialize and deserialize complex object graphs to JSON",
"main": "serializr.js",
"main": "lib/serializr.js",
"module": "lib/es/serializr.js",
"typings": "serializr.d.ts",
"scripts": {
"test": "npm run build-test && node test/index",
"lint": "eslint serializr.js",
"prepublish": "npm run small-build && npm run build-docs",
"small-build": "uglifyjs -m sort,toplevel -c --screw-ie8 --preamble \"/** serializr - (c) Michel Weststrate 2016 - MIT Licensed */\" --source-map serializr.min.js.map -o serializr.min.js serializr.js",
"build-docs": "documentation readme serializr.js --github --section API",
"lint": "eslint src",
"prepublish": "npm run build && npm run build-docs",
"build": "node scripts/build.js",
"build-docs": "documentation readme src/serializr.js --github --section API",
"build-test": "npm run build-test-babel && npm run build-test-ts",

@@ -35,5 +36,3 @@ "build-test-ts": "tsc -p test/typescript",

"files": [
"serializr.js",
"serializr.min.js",
"serializr.min.js.map",
"lib",
"serializr.d.ts"

@@ -43,2 +42,3 @@ ],

"babel-cli": "^6.11.4",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-decorators-legacy": "^1.3.4",

@@ -50,4 +50,10 @@ "babel-preset-es2015": "^6.9.0",

"eslint": "^2.12.0",
"eslint-plugin-import": "^2.7.0",
"istanbul": "^0.4.4",
"lodash.merge": "^4.6.0",
"mobx": "^2.4.1 || ^3.0.0",
"rollup": "^0.49.2",
"rollup-plugin-commonjs": "^8.2.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^2.0.1",
"tape": "^4.5.1",

@@ -54,0 +60,0 @@ "typescript": "^2.1.4",

@@ -298,3 +298,3 @@ # Serializr

[serializr.js:128-135](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L128-L135 "Source code on GitHub")
[src/serializr.js:52-52](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/serializr.js#L52-L52 "Source code on GitHub")

@@ -307,3 +307,2 @@ JSDOC type defintions for usage w/o typescript.

- `props`
- `value` **any**

@@ -328,2 +327,3 @@ - `writeable` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**

- `factory`
- `props`
- `targetClass`

@@ -347,3 +347,3 @@

[serializr.js:128-135](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L128-L135 "Source code on GitHub")
[src/api/createSimpleSchema.js:17-24](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/api/createSimpleSchema.js#L17-L24 "Source code on GitHub")

@@ -373,3 +373,3 @@ Creates a model schema that (de)serializes from / to plain javascript objects.

[serializr.js:161-179](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L161-L179 "Source code on GitHub")
[src/api/createModelSchema.js:29-47](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/api/createModelSchema.js#L29-L47 "Source code on GitHub")

@@ -405,39 +405,5 @@ Creates a model schema that (de)serializes an object created by a constructor function (class).

## serializable
[serializr.js:209-219](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L209-L219 "Source code on GitHub")
Decorator that defines a new property mapping on the default model schema for the class
it is used in.
When using typescript, the decorator can also be used on fields declared as constructor arguments (using the `private` / `protected` / `public` keywords).
The default factory will then invoke the constructor with the correct arguments as well.
**Parameters**
- `arg1`
- `arg2`
- `arg3`
**Examples**
```javascript
class Todo {
```
Returns **PropertyDescriptor**
## serializeAll
[serializr.js:292-303](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L292-L303 "Source code on GitHub")
The `serializeAll` decorator can be used on a class to signal that all primitive properties should be serialized automatically.
**Parameters**
- `target`
## getDefaultModelSchema
[serializr.js:311-320](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L311-L320 "Source code on GitHub")
[src/api/getDefaultModelSchema.js:9-18](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/api/getDefaultModelSchema.js#L9-L18 "Source code on GitHub")

@@ -454,3 +420,3 @@ Returns the standard model schema associated with a class / constructor function

[serializr.js:334-337](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L334-L337 "Source code on GitHub")
[src/api/setDefaultModelSchema.js:15-18](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/api/setDefaultModelSchema.js#L15-L18 "Source code on GitHub")

@@ -471,5 +437,29 @@ Sets the default model schema for class / constructor function.

## serializable
[src/api/serializable.js:93-103](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/api/serializable.js#L93-L103 "Source code on GitHub")
Decorator that defines a new property mapping on the default model schema for the class
it is used in.
When using typescript, the decorator can also be used on fields declared as constructor arguments (using the `private` / `protected` / `public` keywords).
The default factory will then invoke the constructor with the correct arguments as well.
**Parameters**
- `arg1`
- `arg2`
- `arg3`
**Examples**
```javascript
class Todo {
```
Returns **PropertyDescriptor**
## serialize
[serializr.js:389-407](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L389-L407 "Source code on GitHub")
[src/core/serialize.js:16-34](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/core/serialize.js#L16-L34 "Source code on GitHub")

@@ -487,5 +477,15 @@ Serializes an object (graph) into json using the provided model schema.

## serializeAll
[src/core/serialize.js:89-100](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/core/serialize.js#L89-L100 "Source code on GitHub")
The `serializeAll` decorator can be used on a class to signal that all primitive properties should be serialized automatically.
**Parameters**
- `target`
## deserialize
[serializr.js:465-483](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L465-L483 "Source code on GitHub")
[src/core/deserialize.js:38-56](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/core/deserialize.js#L38-L56 "Source code on GitHub")

@@ -509,3 +509,3 @@ Deserializes a json structor into an object graph.

[serializr.js:652-673](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L652-L673 "Source code on GitHub")
[src/core/update.js:21-42](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/core/update.js#L21-L42 "Source code on GitHub")

@@ -524,5 +524,5 @@ Similar to deserialize, but updates an existing object instance.

##
## primitive
[serializr.js:679-679](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L679-L679 "Source code on GitHub")
[src/types/primitive.js:17-29](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/primitive.js#L17-L29 "Source code on GitHub")

@@ -546,3 +546,3 @@ Indicates that this field contains a primitive value (or Date) which should be serialized literally to json.

[serializr.js:743-757](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L743-L757 "Source code on GitHub")
[src/types/identifier.js:42-56](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/identifier.js#L42-L56 "Source code on GitHub")

@@ -587,3 +587,3 @@ Similar to primitive, but this field will be marked as the identifier for the given Model type.

[serializr.js:768-783](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L768-L783 "Source code on GitHub")
[src/types/date.js:8-23](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/date.js#L8-L23 "Source code on GitHub")

@@ -594,3 +594,3 @@ Similar to primitive, serializes instances of Date objects

[serializr.js:802-813](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L802-L813 "Source code on GitHub")
[src/types/alias.js:20-31](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/alias.js#L20-L31 "Source code on GitHub")

@@ -620,10 +620,22 @@ Alias indicates that this model property should be named differently in the generated json.

[serializr.js:836-845](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L836-L845 "Source code on GitHub")
[src/types/custom.js:36-45](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/custom.js#L36-L45 "Source code on GitHub")
Can be used to create simple custom propSchema.
Can be used to create simple custom propSchema. Multiple things can be done inside of a custom propSchema, like deserializing and serializing other (polymorphic) objects, skipping the serialization of something or checking the context of the obj being (de)serialized.
The `custom` function takes two parameters, the `serializer` function and the `deserializer` function.
The `serializer` function has the signature:
`(value, key, obj) => void`
When serializing the object `{a: 1}` the `serializer` function will be called with `serializer(1, 'a', {a: 1})`.
The `deserializer` function has the signature:
`(value, context) => void`
When deserializing the object `{b: 2}` the `deserializer` function will be called with `deserializer(2, contextObj)` ([contextObj reference](https://github.com/mobxjs/serializr#deserialization-context)).
**Parameters**
- `serializer` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** function that takes a model value and turns it into a json value
- `deserializer` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** function that takes a json value and turns it into a model value
- `deserializer` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** function that takes a json value and turns it into a model value. It also takes context argument, which can allow you to deserialize based on the context of other parameters.

@@ -651,3 +663,3 @@ **Examples**

[serializr.js:875-893](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L875-L893 "Source code on GitHub")
[src/types/object.js:34-52](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/object.js#L34-L52 "Source code on GitHub")

@@ -689,3 +701,3 @@ `object` indicates that this property contains an object that needs to be (de)serialized

[serializr.js:950-983](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L950-L983 "Source code on GitHub")
[src/types/reference.js:65-98](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/reference.js#L65-L98 "Source code on GitHub")

@@ -754,3 +766,3 @@ `reference` can be used to (de)serialize references that point to other models.

[serializr.js:1021-1042](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L1021-L1042 "Source code on GitHub")
[src/types/list.js:33-54](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/list.js#L33-L54 "Source code on GitHub")

@@ -793,3 +805,3 @@ List indicates that this property contains a list of things.

[serializr.js:1056-1105](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L1056-L1105 "Source code on GitHub")
[src/types/map.js:13-62](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/map.js#L13-L62 "Source code on GitHub")

@@ -806,3 +818,3 @@ Similar to list, but map represents a string keyed dynamic collection.

[serializr.js:1118-1154](https://github.com/mobxjs/serializr/blob/5a5ed016a487e4547204760153ab51addc32c851/serializr.js#L1118-L1154 "Source code on GitHub")
[src/types/mapAsArray.js:15-52](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/types/mapAsArray.js#L15-L52 "Source code on GitHub")

@@ -820,2 +832,25 @@ Similar to map, mapAsArray can be used to serialize a map-like collection where the key is contained in the 'value object'.

## SKIP
[src/constants.js:20-20](https://github.com/mobxjs/serializr/blob/c924b623c150db5caa92ae202b9ff87b953de710/src/constants.js#L20-L20 "Source code on GitHub")
In the event that a property needs to be deserialized, but not serialized, you can use the SKIP symbol to omit the property. This has to be used with the custom serializer.
**Examples**
```javascript
var schema = _.createSimpleSchema({
a: _.custom(
function(v) {
return _.SKIP
},
function(v) {
return v;
}
),
});
t.deepEqual(_.serialize(s, { a: 4 }), { });
t.deepEqual(_.deserialize(s, { a: 4 }), { a: 4 });
```
# Recipes and examples

@@ -983,20 +1018,2 @@

export class Box {
<<<<<<< HEAD
@serializable(identifier())
id = randomId();
@serializable
@observable
x = 0;
@serializable
@observable
y = 0;
@serializable
@observable
location = 0;
constructor(location, x, y) {
=======
@serializable(identifier()) id = randomId();

@@ -1007,4 +1024,3 @@ @serializable @observable x = 0;

constructor(location, x, y){
>>>>>>> Updated readme and changelog
constructor(location, x, y) {
this.location = location;

@@ -1015,9 +1031,3 @@ this.x = x;

<<<<<<< HEAD
@serializable
@computed
get area() {
=======
@serializable @computed get area() {
>>>>>>> Updated readme and changelog
return this.x * this.y;

@@ -1028,10 +1038,5 @@ }

export class Arrow {
@serializable(identifier())
id = randomId();
@serializable(reference(Box))
from;
@serializable(reference(Box))
to;
@serializable(identifier()) id = randomId();
@serializable(reference(Box)) from;
@serializable(reference(Box)) to;
}

@@ -1038,0 +1043,0 @@

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