Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

avery

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

avery

Immutable models with virtuals and validation.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-62.5%
Maintainers
1
Weekly downloads
 
Created
Source

Avery

NPM

Immutable models with virtuals and Joi-ful validation.

API

See usage below (it's pretty simple), and then go look at ImmutableJS.

Methods we add:

  • isValid - returns true if the model passed validation. You shouldn't need anything else.

Usage


var Avery = require('avery');

class User extends Avery.Model({
  defaults : {
    id : undefined,
    email : undefined,
    password : undefined,
    firstName : undefined,
    lastName : undefined
  },

  validate : Joi.object().keys({
    id : Joi.number(),
    email : Joi.string().email(),
    password : Joi.string(),
    firstName : Joi.string(),
    lastName : Joi.string()
  }),

  virtuals : {
    fullName : function() {
      // this is bound to the ImmutableJS record
      return this.get('firstName') + ' ' + this.get('lastName');
    }
  }
}) {

  myMethod() {
    return this.get('fullName');
  }

};

var myUser = new User({
  id : 1,
  email : 'archer@example.com',
  password : 'supersecret',
  firstName : 'Sterling',
  lastName : 'Archer'
});

myUser.get('fullName'); // === "Sterling Archer"
myUser.get('email'); // === "archer@example.com"

myUser.set('id', 2);
myUser.get('id'); // === 1

var mutatedUser = myUser.set('id', 2);
myUser === mutatedUser; // === false
mutatedUser.get('id'); // === 2

Keywords

FAQs

Package last updated on 14 Feb 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc