0.6.1 • Published 9 years ago
archetype-js v0.6.1
archetype
Archetype is a runtime type-casting library. Its purpose is to compose types from existing types in a way that's easy to write and document.
const { ObjectId } = require('mongodb');
const moment = require('moment');
// `Person` is now a constructor
const Person = new Archetype({
name: 'string',
bandId: {
$type: ObjectId,
$required: true
},
createdAt: {
$type: moment,
$default: () => moment()
}
}).compile('Person');
const test = new Person({
name: 'test',
bandId: '507f191e810c19729de860ea'
});
test.bandId; // Now a mongodb ObjectId
test.createdAt; // moment representing nowIf casting fails, archetype throws a nice clean exception:
try {
Person({ // <-- calling with `new` is optional
name: 'test',
bandId: 'ImNotAValidObjectId'
});
} catch(error) {
error.errors['bandId'].message; // Mongodb ObjectId error
}Archetypes are composable, inspectable, and extendable via extends.
0.6.1
9 years ago
0.6.0
9 years ago
0.5.1
9 years ago
0.5.0
9 years ago
0.4.4
9 years ago
0.4.3
9 years ago
0.4.2
9 years ago
0.4.1
9 years ago
0.4.0
9 years ago
0.3.1
9 years ago
0.3.0
9 years ago
0.2.15
9 years ago
0.2.14
9 years ago
0.2.13
9 years ago
0.2.12
9 years ago
0.2.11
9 years ago
0.2.10
9 years ago
0.2.9
9 years ago
0.2.8
9 years ago
0.2.7
9 years ago
0.2.6
9 years ago
0.2.5
9 years ago
0.2.4
9 years ago
0.2.3
9 years ago
0.2.2
10 years ago
0.2.1
10 years ago
0.2.0
10 years ago
0.1.11
10 years ago
0.1.10
10 years ago
0.1.9
10 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago
0.1.5
10 years ago
0.1.4
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago