@forzoom/models
npm i @forzoom/models
Last updated 2 years ago by forzoom .
MIT · Original npm · Tarball · package.json
$ cnpm install @forzoom/models 
SYNC missed versions from official npm registry.

Install

npm i @forzoom/models


Description

provide commonjs/es6/umd format file.

SnakeCase

for example:

  1. foo_bar
  2. foo_1

CamelCase

for example:

  1. fooBar
  2. foo1

Feature

  1. support kebabCase and snakeCase access
  2. support simple type checker
  3. provide inflate() for batch set property
  4. provide registerProperty() for add property after instance is created
  5. property support Vue reactive data bind

Example

import Schema from '@forzoom/models';

class MyModel extends Schema {
    constructor(data) {
        super({
            key1: {
                type: 'String?',
                default: 'value1',
            },
            key2: {
                type: 'Number',
            },
            fooBar: {
                type: 'String?',
                default: 'fooBar',
            },
        }, data);
        this._name = MyModel.name;
    }
}

const model = new MyModel();
model.key1; // value1
model.key2; // null
model.fooBar; // fooBar
model.foo_bar; // fooBar

model.foo_bar = 'foo_bar';
model.fooBar; // foo_bar
model.foo_bar; // foo_bar

// inflate()
model.inflate({
    key1: 'key1',
    key2: 1,
});

// registerProperty()
model.helloWorld; // undefined
model.registerProperty('helloWord', {
    type: 'String?',
    default: 'steve',
});
model.helloWorld; // steve
model.hello_world; // steve

// equal
const test = new MyModel();
model.equal(test) // false

Model

Model is object which contain property's info, such as type, default value and so on

example

{
    key1: {
        type: 'String?',
        default: 'value1',
    },
    key2: {
        type: 'Number',
    },
    fooBar: {
        type: 'String?',
        default: 'fooBar',
    },
}

type

type of property.

default

default value of property.

extra (since@0.0.9)

extra value of property.


Function

Schema

inflate(obj: object): void
registerProperty(key: string, typeInfo: TypeInfo): void
getSnake(): object
getCamel(): object
equal(to: obj): boolean
setNullable(key: string, nullable: boolean): void

Schema.utils

arrayEqual(arr1: Array<any>, arr2: Array<any>): boolean

Test

npm run test

Current Tags

  • 0.0.22                                ...           latest (2 years ago)

20 Versions

  • 0.0.22                                ...           2 years ago
  • 0.0.21                                ...           2 years ago
  • 0.0.20                                ...           2 years ago
  • 0.0.19                                ...           2 years ago
  • 0.0.18                                ...           2 years ago
  • 0.0.17                                ...           2 years ago
  • 0.0.16                                ...           2 years ago
  • 0.0.15                                ...           2 years ago
  • 0.0.14                                ...           2 years ago
  • 0.0.13                                ...           2 years ago
  • 0.0.12                                ...           2 years ago
  • 0.0.11                                ...           2 years ago
  • 0.0.10                                ...           2 years ago
  • 0.0.9                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 0.0.7 [deprecated]           ...           2 years ago
  • 0.0.6 [deprecated]           ...           2 years ago
  • 0.0.5 [deprecated]           ...           2 years ago
  • 0.0.4 [deprecated]           ...           2 years ago
  • 0.0.2 [deprecated]           ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (0)
None
Dev Dependencies (22)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |