Skip to content

Commit

Permalink
Add usage example to README
Browse files Browse the repository at this point in the history
PR-URL: #463
  • Loading branch information
tshemsedinov committed Nov 19, 2023
1 parent 8d20257 commit e50ce30
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit e50ce30

Please sign in to comment.