Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

check-data

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-data

JS数据验证器

  • 1.2.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by80%
Maintainers
1
Weekly downloads
 
Created
Source

Installation

  npm install check-data --save

使用方法

let verify = Verify(data, options)
  • data Objcte - 验证数据

  • options Objcte - 验证数据表达式

导出验证结果

  • verify.error String - 错误信息

  • verify.data Objcte - 验证数据

使用示例

验证数据
  let data = {
     "name": "测试",
     "time": "2017-07-07T09:53:30.000Z",
     "companyName": ["a.js", "b.js", "c.js"],
     "multiple": ["a", "b", "c", "d"],
     "money": 555,
     "email": "abc@gmail.com"
  }
表达式
  let verify = Verify(data, {
     "name": String,
     "time": Date,
     "companyName": [String],
     "money": Number,
     "multiple": [{
        "type": String,
        "allowNull": true,
        "export": "filter",
     }],
     "email": {
        "type": String,
        "allowNull": true,
        "export": "filter",
     }
  })

同构数据可复用验证表达式

验证数据
  let data = {
     "t0": false,
     "t1": false,
     "t2": true,
     "t3": true,
     "t4": false,
     "t5": true,
     "t6": true,
     "t7": false,
     "t8": true
  }
表达式
  let verify = Verify(data, {
     $: {
        type: Boolean,
        allowNull: true,
     }
  })

数组验证

验证数据
  let data = ["a.js", "b.js", "c.js"]
表达式
  let verify = Verify(data, [String])

Number转Boolean

验证数据
  let data = {
     "a": 0,
     "b": 3,
  }
表达式
  let verify = Verify(data, {
     a: {
        "type": Number,
        "conversion": Boolean
     },
     b: {
        "type": Number,
        "conversion": Boolean
     }
  })

  // Returns {a:false, b:true}

自定义类型

验证数据
  let data = {
     "id": "5968d3b4956fe04299ea5c18",
     "mobilePhone": "18555555555"
  }
表达式
  let verify = Verify(data, {
     "id": "ObjectId",
     "mobilePhone": "MobilePhone"
  })

关联验证

验证数据
  let data = {
     "username": "莉莉",
     "addressee": "嘟嘟",
  }
表达式
  let verify = Verify(data, {
     "username": {
        "type": String,
        "&": ["addressee", "address"]
     },
     "addressee": {
        "type": String,
        "allowNull": true
     },
     "address": {
        "type": String,
        "allowNull": true
     }
  })

FAQs

Package last updated on 22 Jul 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc