Naughty Program Manipulator
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

abitbol-serializable

2.0.0 • Public • Published

abitbol-serializable

Build Status NPM Version License Greenkeeper badge

Abitbol Serializable is an abitbol class that can serialize its properties.

Features:

  • Serialize / Unserialize all computed properties that have a getter and a setter,
  • Skip properties annotated with "@serializable false".
  • Use custom serialization function for specific properties.

Example Class:

var SerializableClass = require("abitbol-serializable");
 
var Person = SerializableClass.$extend({
 
    __name__: "Person",  // The class name
 
    __init__: function(params) {
        this.$data.firstName = "John";
        this.$data.lastName = "DOE";
        this.$data.age = 0;
        this.$super(params);
    },
 
    getFirstName: function() {
        return this.$data.firstName;
    },
 
    setFirstName: function(firstName) {
        this.$data.firstName = firstName;
    },
 
    getLastName: function() {
        return this.$data.lastName;
    },
 
    setLastName: function(lastName) {
        this.$data.lastName = lastName;
    },
 
    getAge: function() {
        "@serializable false";
        return this.$data.age;
    },
 
    setAge: function(age) {
        this.$data.age = age;
    }
 
});

Example Serialization:

var john = new Person({
    lastName: "Wayne",
    age: 72
});
 
john.serialize();
 
// -> {
//        __name__: "Person",
//        id: "<an autogenerated uuid>",
//        firstName: "John",
//        lastName: "Wayne"
//    }

Documentation

Changelog

  • 2.0.0: Updates abitbol dependency to 2.0.0
  • 1.0.2: Documentation site
  • 1.0.1: Updates uuid dependency to 3.0.0
  • 1.0.0: Initial release

install

npm i abitbol-serializable

Downloadsweekly downloads

133

version

2.0.0

license

BSD-3-Clause

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability