@rrangelo/descriptor v0.0.1
descriptor
Prototypes manager for JavaScript
npm package @rrangelo/descriptor
Description
Prototypes manager for JavaScript
When we use a JavaScript Object prototype (the main and most used Object definition on JavaScript language). Sometimes we do use the composition, but we can't access to a super caller method. Descriptor, allow us to add a Base Object prototype adding to our Custom Object prototype.
The descriptor's objects contains new properties and methods, some likes:
- a baseproperty, where we save the base prototype reference. Used to represent the single inherit.
- a createmethod, where we get a new object based on the prototype caller.
- a makermethod, where we get a new object with started data one-line.
- a chainmethod, where we get a stringify of object (just properties NOT methods).
- a clonemethod, where we get a new instance with same data of source object.
Getting Started
Install
npm i -S @rrangelo/descriptorUse
You must include the module in your proyect with:
const descriptor = require('@rrangelo/descriptor');Our custom objects we'll be able to access over node process, just calling the new global property prototypes. That means, all prototypes describes with descriptor.describe(name, prototype); will be adding to prototypes with the name defined, some like:
let person = {
    name: '',
    bday: {},
    hasChildren: true,
    children: [],
    get age() {
        sentences;
    },
    someMethod: function() {
        sentences;
    }
};
descriptor.describe('myperson', person);
let pepe = prototypes.myperson.create();You also can create an object with the maker function, like:
let pancho = prototypes.myperson.maker().name('Pancho').hasChildren(false).make();Errors
the name param is required to describe a prototype. Otherwise, the describe function will throws the 'A name must be defined' error message.
Properties and Methods
Each prototype defined will contains new properties and method with its own functionalities. Below will be descriptes
Properties
Below you'll find the properties descriptions.
IMPORTANT: I RECOMMEND NOT MODIFY ANY PROPERTIES OR METHODS, ANY CHANGE CAN CAUSE MANY TROUBLES IN OTHER METHODS AND PROPERTIES.
_ property
name property
The prototype's name.
base property
The based prototype from which the prototype inherits its properties and methods.
base property
This property is just a reference to this._.base
Methods
Below you'll find the methods descriptions.
IMPORTANT: I RECOMMEND NOT MODIFY ANY PROPERTIES OR METHODS, ANY CHANGE CAN CAUSE MANY TROUBLES IN OTHER METHODS AND PROPERTIES.
create method
This method creates a new instance based on the prototype caller, adding base's methods and properties if is specified.
Without base
let obj = propertypes.myperson.create();with base
let obj = propertypes.myperson.create(prototypes.baseptototype);maker method
This method retrives an intemediate object prototype to create a new object's instance, this intemediate allows you to load values in the same time.
let obj = prototypes.myperson.maker()
    .name('Pepe')
    .bday(new Date(1980, 10,9))
    .hasChildren(true)
    .make();make method
This method ends the maker method to create the new prototype's instance. 
let obj = prototypes.myperson.maker().name('Pepe').make();chain method
This methods gives the string representation of object's properties and values
let str = obj.chain();
console.log(str); Expected:
{ name: "Pepe", bday: "Tue Aug 11 1980 20:22:49 GMT-0400 (hora estándar de Venezuela)", hasChildren: false, children: [] }clone method
This methods gives a new instance of object. It means, if you change any value, the other object will not changes.
let ob = obj.clone();Code Coverage
If you want to see the coverage, please go to: