# tipe-model

> A simple business model library

Latest version **0.1.0** (published 2014-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install tipe-model
pnpm add tipe-model
yarn add tipe-model
bun add tipe-model
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2014-12-21 |
| First published | 2014-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Arjan van der Gaag |
| Maintainers | avdgaag |

## Links

- npm: https://www.npmjs.com/package/tipe-model
- Repository: git@github.com:avdgaag/tipe
- Homepage: https://github.com/avdgaag/tipe
- Issues: https://github.com/avdgaag/tipe/issues
- npm.io page: https://npm.io/package/tipe-model

## Dependencies (1)

- [docco](https://npm.io/package/docco.md) ^0.6.3

## Recent versions

- 0.1.0 (latest) — 2014-12-21

## README

# 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:

```js
var Tipe = require('tipe');
```

## Documentation

See the [annotated source code](http://avdgaag.github.io/tipe).

## Usage

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

```js
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:

```js
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.

---
_Source: https://npm.io/package/tipe-model · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
