Skip to content

metarhia/metaschema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2f8b9d8 Β· Aug 31, 2024
Aug 31, 2024
Nov 19, 2023
Aug 31, 2024
Dec 11, 2020
Mar 2, 2021
Mar 6, 2021
Mar 6, 2021
Jul 15, 2023
Jul 14, 2023
Aug 31, 2024
May 4, 2021
Mar 27, 2024
Mar 27, 2024
Mar 27, 2024
Nov 17, 2023
Aug 31, 2024
Nov 19, 2023
Jun 24, 2022
Aug 31, 2024
Aug 31, 2024
Aug 31, 2024
Jul 19, 2021

Repository files navigation

Metaschema

Metadata schema and interface (contract) definition language

ci snyk npm version npm downloads/month npm downloads license

Installation

$ npm install metaschema

Examples

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-2024 Metarhia contributors. Metaschema is MIT licensed.
Metaschema is a part of Metarhia technology stack.