1.0.14 • Published 8 years ago

modeller v1.0.14

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

Modeller

Object modeler for node.js

Installing

npm install modeller --save

Getting start

const Modeller = require('modeller');
 
// sync rule
Modeller.register('myRule', (valueReceived, valueOfRule) => {
  return (valueReceived <= valueOfRule);
});
 
// async rule
Modeller.register('myRuleAsync', valueReceived => new Promise((resolve, reject) => {
  setTimeout(() => {
    if (valueReceived >= 18) {
      resolve();
    } else {
      reject();
    }
  }, 150);
}); 
 
const userMold = Modeller.createMold({
  name: 'string',
  age: 'integer|myRule:110|myRuleAsync',
});
  
userMold.test({
  name: 'User name',
  age: 19,
}).then(() => {
  // validated
}).catch((errors) => {
  //
});
 
userMold.test({
  name: 'User name',
  age: 10,
}).then(() => {
  //
}).catch((errors) => {
  // errors = { age: [ 'myRuleAsync' ] }
});
 
userMold.test({
  name: 'User name',
  age: 115,
}).then(() => {
  //
}).catch((errors) => {
  // errors = { age: [ 'myRule', 110 ] }
});

Build Setup

# install dependencies
npm install
   
# start application
npm run start
  
# watch lib files and run on change.
npm run watch
  
# run tests
npm run test
1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago