New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tipe-model

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tipe-model

A simple business model library

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Tipe: a very simple model library

Tipe is an experiment in building a very simple library for building javascript business models.

Installation

You can install Tipe with NPM:

% npm install tipe-model

Then you can require it in your code:

var Tipe = require('tipe');

Documentation

See the annotated source code.

Usage

You can define models by extending Tipe.Model and defining your model schema in a callback function:

var Person = Tipe.Model.extend(function(attr) {
  attr.accessor('firstName');
  attr.accessor('lastName');
  attr.property('fullName', {
    serialize: false,
    get: function() {
      return this.firstName + ' ' + this.lastName;
    }
  });
  attr.accessor('age', {
    default: 20,
    serialize: function(val) {
      return val * 2;
    },
    set: function(val) {
      this.attributes.age = parseInt(val);
    }
  });
});

This Person model has four attributes:

  • firstName
  • lastName
  • fullName (read-only, computed based on firstName and lastName and not included in any JSON representation)
  • age (defaults to 20, parsed to integer when set and doubled in JSON representation)

You can use it as follows:

var john = new Person({ firstName: 'John' });
john.lastName = 'Cleese';
console.log(john.firstName);
// => 'John'
console.log(john.fullName);
// => 'John Cleese'
console.log(john.age);
// => 20
console.log(john.toJSON());
// => { firstName: 'John', lastName: 'Cleese', age: 40 }

Credits

Author: Arjan van der Gaag
Email: arjan@arjanvandergaag.nl
URL: http://github.com/avdgaag/tipe

Released under a MIT license. See LICENSE for more information.

FAQs

Package last updated on 21 Dec 2014

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