You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

easy-object-validator

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-object-validator

深度校验一个值是否合法

2.0.1
latest
Source
npmnpm
Version published
Weekly downloads
21
Maintainers
1
Weekly downloads
 
Created
Source

easy-object-validator

深度校验一个值是否合法

Travis (.org) branch Codecov npm npm GitHub

更新日志

当前文档版本是2.x,API不兼容1.x版本,点击查看1.x文档

Features

  • 支持 Node、浏览器端完美运行
  • 无任何依赖,代码压缩后仅3kb
  • 支持深度对象校验,提供的API友好、易用
  • 支持自定义校验方法扩展

安装

npm i -S easy-object-validator

# 构建
npm run build
# 单元测试
npm run test

快速开始

import validator from 'easy-object-validator'

const obj = {
  foo: 123,
  bar: 'hello',
  child: {
    foo: true,
    bar: [1, 2, 3, 4],
    child: {
      bar: null
    }
  }
};

validator(obj, {
  foo: validator.test(/^\d+$/),
  bar: validator.string.length(5),
  child: {
   foo: validator.boolean.isRequired,
   bar: validator.array.length(4),
   child: validator.shape({
      bar: validator.isEmpty
   })
  }
})
// true

API

validator 的校验规则基于 Validate 类

API参考

结语

用得不爽就造轮子😶,欢迎提issues或PR

Keywords

objcet validator

FAQs

Package last updated on 20 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts