Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

serially

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serially

Serializes circular references and other unserializable types like Dates, .prototype and functions to JSON.

latest
Source
npmnpm
Version
3.0.3
Version published
Maintainers
1
Created
Source

The Serially Function Serialization Javascript Library

build status coverage report npm version dependencies Status

Codeship Status for TSavo/serially Build Status Codacy Badge

What it does

Serializes circular references and other unserializable types like Dates, .prototype and functions to JSON.

What is supported

TypeJSON.stringifySerially.serialize
StringsYesYes
NumbersYesYes
DatesAs a stringYes
NaN / Infinity / UndefinedNoYes
Circular referencesNoYes
FunctionsNoYes
Native functionsNoYes*
  • *Native functions can be optionally ignored, but should be avoided in serialized graphs as a best practice.

Installation

npm install --save serially

Example Usage

As a module:

var should = require("chai");
var expect = chai.expect;
chai.should();

var serially = require("serially");

var toBeSerialized = {
        int: 1,
        float: 2.99e81,
        str: "test",
        obj: {
          int: 1,
          str: "test"
        },
        nullValue: null,
        arrayValue: [{}],
        infinityValue: Infinity,
        negInfinityValue: -Infinity,
        nanValue: NaN,
        dateValue: new Date(),
        func: function(a, b) {
          return a + b;
        }
      };
toBeSerialized.circularReference = toBeSerialized;

//Serialize the whole graph to a string
var str = serially.serialize(toBeSerialized);

//Deserialize the graph
var deserialized = serially.deserialize(str);

toBeSerialized.int.should.equal(deserialized.int);
toBeSerialized.str.should.equal(deserialized.str);
toBeSerialized.float.should.equal(deserialized.float);
toBeSerialized.obj.int.should.equal(deserialized.obj.int);
toBeSerialized.obj.str.should.equal(deserialized.obj.str);
expect(toBeSerialized.nullValue).to.equal(deserialized.nullValue);
toBeSerialized.infinityValue.should.equal(deserialized.infinityValue);
toBeSerialized.negInfinityValue.should.equal(deserialized.negInfinityValue);
expect(deserialized.nanValue).to.be.NaN;
toBeSerialized.func.toString().should.equal(deserialized.func.toString());
deserialized.func(2, 2).should.equal(4);
deserialized.circularReference.circularReference.circularReference.circularReference.should.equal(deserialized);

Contributing

Pull requests are welcome, please file any bugs on https://github.com/tsavo/serially

Keywords

Javascript

FAQs

Package last updated on 14 Dec 2016

Did you know?

Socket

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