From e50ce30d154a93d11c132b9e97664b58c07f8c5c Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Sun, 19 Nov 2023 09:35:10 +0200 Subject: [PATCH] Add usage example to README PR-URL: https://github.com/metarhia/metaschema/pull/463 --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index d9a55a0..ae268a0 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,45 @@ Metadata schema and interface (contract) definition language $ npm install metaschema ``` +## Examples + +```js +const { Schema } = require('metaschema'); + +const schema = Schema.from({ + name: { + first: 'string', + last: 'string', + third: '?string', + }, + age: 'number', + levelOne: { + levelTwo: { + levelThree: { type: 'enum', enum: [1, 2, 3] }, + }, + }, + collection: { array: { array: 'number' } }, +}); + +const data = { + name: { + first: 'a', + last: 'b', + }, + age: 5, + levelOne: { levelTwo: { levelThree: 1 } }, + collection: [ + [1, 2, 3], + [3, 5, 6], + ], +}; + +console.log(schema.check(data)); + +// Output: +// ValidationResult { errors: [], valid: true } +``` + ## License & Contributors Copyright (c) 2017-2023 [Metarhia contributors](https://github.com/metarhia/metaschema/graphs/contributors).