couture
v0.0.9
Published
When [jsface](https://github.com/tnhu/jsface) meets [node-schema-object](https://github.com/scotthovestadt/node-schema-object).
Downloads
2
Readme
Couture
When jsface meets node-schema-object.
Installation
npm install couture --save
Example
var Couture = require('couture');
var Identity = Couture({
$schema: {
name: String
}
});
var Person = Couture([Identity], {
$schema: {
age: Number
},
$construct: {
create: ['name', 'age']
},
hello: function () {
console.log('hello', this.name);
}
});
var jd = Person.create('John Doe', '25');
console.log(jd);
// CoutureClass { name: 'John Doe', age: 25 }
jd.hello();
// hello John Doe
API
$const
var clazz = Couture({
$const: {
FOO: 'foo',
BAR: 'bar'
}
});
console.log(clazz.FOO, clazz.BAR);
// foo bar
$construct
var clazz = Couture({
$schema: {
a: String,
b: String
},
$construct: {
create: ['a', 'b'],
create2: function (a, b) {
return {
a:a,
b:b
};
}
}
});
console.log(new clazz({a:'x', b:'y'}));
// CoutureClass { a: 'x', b: 'y' }
console.log(clazz.create('x', 'y'));
// CoutureClass { a: 'x', b: 'y' }
console.log(clazz.create2('x', 'y'));
// CoutureClass { a: 'x', b: 'y' }
$schema
var clazz = Couture({
$schema: {
a: String,
b: Number,
c: Boolean,
}
});
console.log(new clazz({ a: 'x', b: '7', c: 'no'}));
// CoutureClass { a: 'x', b: 7, c: false }
$setUndefined
var clazz = Couture({
$setUndefined: false,
$schema: {
a: String,
b: String
}
});
console.log(new clazz({a:'x'}));
// CoutureClass { a: 'x' }
$singleton
var clazz = Couture({
$singleton: true,
$schema: {
a: String
}
});
console.log(new clazz({a:'x'}));
// CoutureClass { a: 'x' }
console.log(new clazz({a:'y'}));
// CoutureClass { a: 'x' }
$static
var clazz = Couture({
$const: {
FOO: 'foo',
BAR: 'bar'
},
$static: {
foobar: function () {
console.log(this.FOO, this.BAR);
}
}
});
clazz.foobar();
// foo bar
$strict
var clazz = Couture({
$strict: true,
$schema: {
a: String
}
});
console.log(new clazz({ a: 'x', b: 'y'}));
// CoutureClass { a: 'x' }
License
MIT