New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

schemat

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schemat

![npm](https://img.shields.io/npm/v/schemat) [![Build Status](https://travis-ci.com/michal-wrzosek/schemat.svg?branch=master)](https://travis-ci.com/michal-wrzosek/schemat)

Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
1
-92.86%
Maintainers
1
Weekly downloads
 
Created
Source

schemat - simple runtime schema validator

npm Build Status

How to install:

npm i schemat

How to use

Validate objects with simple functions and receive error messages if any:

import { createVadidator } from 'schemat';

const validator = createVadidator({
  a: (data: any) => (data === 'A' ? undefined : '"a" should be "A"'),
  likeA: (data: any, siblingsData: any) => siblingsData && siblingsData.a === data ? undefined : '"likeA" should be equal to param "a"',
  nested: createVadidator({
    c: (data: any) => (data === 'C' ? undefined : '"nested.c" should be "C"'),
  }),
});


// No errror messages here:
// errorMessages => undefined
const errorMessages = validator({
  a: 'A',
  likeA: 'A',
  nested: {
    c: 'C',
  },
});


// wrong b and nested.c params:
// errorMessages => {
//   b: '"likeA" should be equal to param "a"',
//   nested: {
//     c: '"nested.c" should be "C"',
//   },
// };
const errorMessages = validator({
  a: 'A',
  likeA: 'wrong!!!',
  nested: {
    c: 'wrong!!!',
  },
});

This package was bootstrapped with typescript-lib-boilerplate

FAQs

Package last updated on 27 Sep 2019

Related posts