@panda-tesla/bereshit-metadata-structure-validator
v1.0.2
Published
accepts a metadata object as input and returns true or false if metadata object is in correct form
Downloads
6
Readme
@panda-tesla/bereshit-metadata-structure-validator
This package exposes single function called validateMetadataStructure which accepts a metadata object as input and returns true or false if metadata object is in correct form
Installation
Install Node, and then:
npm i @panda-tesla/bereshit-metadata-structure-validator --save
Usage
Validate metadata example:
Import & validate:
import { validateMetadataStructure } from '@panda-tesla/bereshit-metadata-structure-validator'
const isValid = validateMetadataStructure(metadata);
console.log(isValid);
Will print:
//for valid metadata
{valid: true, errors: null}
//for invalid metadata
{valid: false, errors: [errors array]}
MetaData examples:
//valid metadata
const metadata = [{
entity: 'Cat',
attributes: [
{'name': 'smelly cat'},
{'age': 8}
]
}];
valid metadata explanation:
metadata should be an array with two items. first item 'entity' with value string or number. second item 'attributes' with multiple object items, key value pair of string or number.
//inValid metadata
const metadata = {
entity: {id: 123},
attributes: {
'name': 'smelly cat',
'age': 8
}
};
build your own schema!
validateMetadataStructure
can receive an relative schema and vlidate occording to it.
const relativeSchema = {
'type': 'object',
'properties': {
'entity': { 'type': 'number' },
'attributes': { 'type': 'object' }
}
};
const isValid = validateMetadataStructure(metadata, relativeSchema);
console.log(isValid);