![npm version](https://badge.fury.io/js/%40jaysalvat%2Fsmart-model.svg)
Model
Javascript object model.
Install
Install npm package
npm install @jaysalvat/smart-model
Module
import SmartModel from '@jaysalvat/smart-model'
CDN
<script src="https://unpkg.com/@jaysalvat/smart-model@latest/build/smart-model.umd.min.js"></script>
Usage
Better documentation soon...
import readingTime from 'reading-time';
const Post = SmartModel.create('Post', {
title: {
required: true,
type: String,
},
body: {
required: true,
type: String,
rule: {
'tooShort': (calue) => value.length < 100,
'tooLong': (calue) => value.length > 1000,
}
},
createdAt: {
type: Date,
default: new Date(),
transform: (value) => new Date(value),
format: (value) => value.toLocaleString()
},
updatedAt: {
type: Date,
default: new Date(),
transform: (value) => new Date(value),
format: (value) => value.toLocaleString()
},
bodyLength: (post) => post.body.length,
readingTime: (post) => readingTime(post.body)
}, {
onUpdate() {
this.updatedAt = new Date()
}
})
const post = new Post({
title: 'my new post',
body: 'lorem ipsum...'
})
Dev
Dev mode
npm run dev
Build
npm run build
Lint
npm run lint
Fix lint errors
npm run lint:fix
Bump version and publish to NPM
npm run release
npm run release:patch
npm run release:minor
npm run release:major