自定义规则对象验证库 Spected

码农软件 · 软件分类 · 常用JavaScript包 · 2019-04-04 20:28:24

软件介绍

Spected 是一个 JavaScript 编写的验证库,用于根据自定义的验证规则验证对象。它使你可以完全自由地使用验证规则,并且可以用于表单输入,深度嵌套的对象或客户端和服务器端的任何其他数据结构。

Basic Example

import {
  compose,
  curry,
  head,
  isEmpty,
  length,
  not,
  prop,
} from 'ramda'

import spected from 'spected'

// predicates

const notEmpty = compose(not, isEmpty)
const hasCapitalLetter = a => /[A-Z]/.test(a)
const isGreaterThan = curry((len, a) => (a > len))
const isLengthGreaterThan = len => compose(isGreaterThan(len), prop('length'))


// error messages

const notEmptyMsg = field => `${field} should not be empty.`
const minimumMsg = (field, len) => `Minimum ${field} length of ${len} is required.`
const capitalLetterMag = field => `${field} should contain at least one uppercase letter.`

// rules

const nameValidationRule = [[notEmpty, notEmptyMsg('Name')]]

const randomValidationRule = [
  [isLengthGreaterThan(2), minimumMsg('Random', 3)],
  [hasCapitalLetter, capitalLetterMag('Random')],
]

const validationRules = {
  name: nameValidationRule,
  random: randomValidationRule,
}

spected(validationRules, {name: 'foo', random: 'Abcd'})
// {name: true, random: true}

本文地址:https://codercto.com/soft/d/2869.html

计算理论导引

计算理论导引

[美]Michael Sipser / 唐常杰、陈鹏、向勇、刘齐宏 / 机械工业出版社 / 2006-7 / 36.00元

本书是计算理论领域的经典著作,被国外多所大学选用为教材。本书以注重思路、深入引导为特色,系统地介绍计算理论的三大主要内容:自动机与语言、可计算性理论和计算复杂性理论。同时,对可计算性和计算复杂性理论中的某些高级内容作了重点讲解。全书通过启发性的问题、精彩的结果和待解决问题来引导读者挑战此领域中的高层次问题。新版的一大亮点是增加了更多习题、教辅资料和部分习题解答,更加有利于教学。 全书叙述由浅......一起来看看 《计算理论导引》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具