Representor
Library for building and using representors.
Install
npm install representor --save
Usage
Creating a Representor
Create a new instance of the representor.
var representor = ;
Adding Attributes
The attributes
property is a JavaScript object literal.
representorattributesemail = 'john@example.com';
Adding links
representorlinks;
Adding Forms
let changePasswordForm = representorforms; formfields;
Adding Embedded Representors
let embedded = representorembeddeds; embeddedlinks; let changePasswordForm = embeddedforms; changePasswordFormfields;
Converting to an Object Literal
Each object has its own #toValue
function that may be called to output an object literal.
const rep = ; replinks; const changePasswordForm = repforms; changePasswordFormfields; repembeddeds; repValue = rep; // repValue above deep equals objLiteral hereconst objLiteral = attributes: {} links: rel: 'next' href: 'http://example.com/user/2' forms: name: 'change-password' href: 'http://example.com/user/2/password' method: 'POST' fields: name: 'password' value: 'foobar' embeddeds: rel: 'next' href: 'http://example.com/user/3' attributes: {} links: forms: embeddeds: ;