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

api-checker

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-checker

check api data

  • 1.2.0
  • latest
  • lastest
  • tag/1.2.0
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

api-checker.js

根据自定义的模板数据结构来检测后端数据接口返回的数据是否满足前端要求.

对于必要属性发生缺失,直接报错;对于非必要属性,可以通过模板数据赋值合并,且可以设置默认值

Installation

In a browser:

  <script src="api-checker.js"></script>

Using npm:

  $ npm i -S api-checker / yarn add api-checker

data model

  1. model 目前支持对象,数组,和简单数据类型。
  2. data 中的简单数据类型属性如果不为必要属性,需如下设置:
    key1: '', // 字符串类型
    key2: 0, // 数字类型
    key3: true, // 布尔类型
    ...
  1. data 中的简单数据类型属性如果为必要属性,需如下设置:
    key: {
      v: '', // 这里可以设置任意简单数据类型的初始值
      required: true
    }
  1. data 中的复杂数据类型属性如果为必要属性,需如下设置:
    key: {
      v: [...],
      required: true
    }

    or

    key: {
      v: {..},
      required: true
    }
  1. 被设置为必要属性的字段发生缺失或类型错误,直接抛出错误,所以凡是前端可以用默认值替代的字段尽量不建议设置为必要字段。其次,接口数据如果在模板数据中为出现,直接过滤掉。

  2. 数据模板结构: img

Usage

  apiChecker.check(tplData, apiData, {
      showLog: true,
      success: function (data) {
        console.log(data)
      },
      error: function (err) {
        console.log(err)
      },
      warn: function (curVal, oldItem, newItem) {
        // console.log('warn!')
      }
    })

Keywords

FAQs

Package last updated on 23 May 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