Nerfing Powerful Megalomaniacs
    Have ideas to improve npm?Join in the discussion! »

    jsonlize

    0.4.2 • Public • Published

    serialize

    Serialize Objects, Functions, primitive types, builtin objects, nested objects, class instances, methods, setters and getters, cross and self references objects, Regular Expressions (including status), Maps, Sets, Errors, binary arrays

    Setup

    1. Install

    npm install jsonlize

    Usage

    1. Serialize and deserialize an class instance

    const { serialize, deserialize } = require('jsonlize')
    class A {
      constructor(n) {
        this.n = n
      }
      inc(n) {
        this.n += n
      }
    }
    const a = new A(10)
    
    const json = serialize(a)
    
    const aa = deserialize(json)
    aa.inc(5)

    2. Serialize and deserialize nested objects

    const { serialize, deserialize } = require('jsonlize')
    class A {
      constructor(n) {
        this.n = n
      }
      inc(n) {
        this.n += n
      }
    }
    
    class C {
      constructor(n) {
        this._a = new A(n)
      }
      set a (value) {
        this._a = value
      }
      get a () {
        return this._a
      }
    }
    
    const c = new C(10)
    
    const json = serialize(c)
    
    const cc = deserialize(json)
    cc.a.inc(5)

    Install

    npm i jsonlize

    DownloadsWeekly Downloads

    1

    Version

    0.4.2

    License

    MIT

    Unpacked Size

    54.1 kB

    Total Files

    32

    Last publish

    Collaborators

    • avatar