0.0.5 • Published 1 year ago

@mmyoji/object-validator v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

object-validator

This is a learn-to-code repo. Production use is not recommended.

If you need a practical validation library, use Yup or Zod instead.

Breaking changes are often added during v0.

Installation

$ npm install @mmyoji/object-validator

Usage

import { initValidator } from "@mmyoji/object-validator";

type TargetObject = {
  name: string;
  age: number;
  isAdmin?: boolean;
};

const validate = initValidator<TargetObject>({
  name: {
    type: "string",
    required: true,
    minLength: 3,
  },
  age: {
    type: "number",
    required: true,
    min: 18,
    max: 65,
  },
  isAdmin: {
    type: "boolean",
  },
});

const errors = validate({
  name: "a",
  count: 22,
  isAdmin: true,
});
console.log(errors);
//=> [{key:"name",message:"name is too short. It must be 3 length at least."}]
0.0.5

1 year ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago