Library 📝 that allow you to describe data structures by subset of JavaScript syntax and validate them at runtime
MIT License
Published by sashapop10 12 months ago
To have JSDOC comments in your type annotations you need to add $meta field to your
schema; Also, your $meta properties should start with @;
({
reciever: 'number',
money: 'number',
$meta: {
'@version': 'v1',
'@name': 'Pay check',
'@description': 'Cash settlement',
'@example': '<caption>Check example</caption>\n{ money: 100, reciever: 2 }',
},
});
Published by sashapop10 12 months ago
Calculated fields supposed to do preprocessing of your schema;
Warning: experimental. We do not support some types yet: Map, Set
const schema = {
$id: 'user',
name: 'string',
phrase: (sample, schema, root) => 'Hello ' + schema.name + ' !',
};
const sample = { name: 'Alexander' };
new Schema(schema).calc(sample); // { ..., name: 'Alexander', phrase: 'Hello Alexander !'};
schema; // { $id: 'user', name: 'Alexander', phrase: 'Hello Alexander !'};
Calculated fields is a function that receives two arguments:
Warning: your return value will be assigned to samples
Method schema.calc receives mode as second parameter; This method allow to specify
return value as:
Published by sashapop10 12 months ago
Published by sashapop10 12 months ago
Published by sashapop10 12 months ago
Support latest:21 node version
Removed parser (maybe temporary)
TypeScript .d.ts support
Schema field with multiple type variants now works only with special type union
Modular mechanism (internal rework): How it works
const schema = new Schema();
schema.register((schema, options, plan) => {}); //? Register new module
By default registrated modules are:
But you also remove default modules:
Schema.modules.delete('metatest');
New shorthands for:
Removed preprocessor mechanism
Schemas now can be part of plan
Performance improvements (by removing unnecessary modules)
Lightweight inheritance
Removed type JSON (temporary)
Prototype chaining
Partial testing
New prototypes:
Published by sashapop10 about 1 year ago
Published by sashapop10 about 1 year ago
Published by sashapop10 about 1 year ago