0.0.22 • Published 7 years ago
@forzoom/models v0.0.22
Install
npm i @forzoom/models
Description
provide commonjs/es6/umd format file.
SnakeCase
for example:
- foo_bar
- foo_1
CamelCase
for example:
- fooBar
- foo1
Feature
- support kebabCase and snakeCase access
- support simple type checker
- provide inflate()for batch set property
- provide registerProperty()for add property after instance is created
- property support Vuereactive 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) // falseModel
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, arr2: Array): boolean
Test
npm run test
0.0.22
7 years ago
0.0.21
7 years ago
0.0.20
7 years ago
0.0.19
7 years ago
0.0.18
7 years ago
0.0.17
7 years ago
0.0.16
7 years ago
0.0.15
7 years ago
0.0.14
7 years ago
0.0.13
7 years ago
0.0.12
7 years ago
0.0.11
7 years ago
0.0.10
7 years ago
0.0.9
7 years ago
0.0.8
7 years ago
0.0.7
7 years ago
0.0.6
7 years ago
0.0.5
7 years ago
0.0.4
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago