<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Spected自定義規(guī)則對象驗證庫

          聯(lián)合創(chuàng)作 · 2023-09-22 03:05

          Spected 是一個 JavaScript 編寫的驗證庫,用于根據(jù)自定義的驗證規(guī)則驗證對象。它使你可以完全自由地使用驗證規(guī)則,并且可以用于表單輸入,深度嵌套的對象或客戶端和服務(wù)器端的任何其他數(shù)據(jù)結(jié)構(gòu)。

          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}
          瀏覽 12
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  夜色av无码 | 亚洲一区欧美国产日韩 云播 | 国产亚洲美女手机毛片 | 三级成人电影 | 成人黄色电影免费在线观看 |