🚀 Launch Week Day 3:Introducing Supply Chain Attack Campaigns Tracking.Learn More
Socket
Book a DemoInstallSign in
Socket

util-interface

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

util-interface

接口修正工具

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

拿到方法

import interfaceRepair from 'util-interface'

或者

var interfaceRepair = require('util-interface')

或者

<script src="node_modules/util-interface/dist/index.min.js"></script>
<script>
//直接使用 interfaceRepair 函数
</script>

使用方法

/*
所有需要用到的参数,都要设置默认值
逻辑 :
    如果默认值为数字,就将对应参数转化为数字,接口参数不存在,或转化失败(NaN),采取默认值
    如果默认值为字符串,就将对应参数转化为字符串,接口参数不存在,采取默认值
    如果默认值为json,就将对应参数转化为json,接口参数不存在或为其他数据类型, 就采取默认值
    如果默认值为数组, 就将对应参数转化为数组, 接口参数不存在或为其他数据类型, 就转化为空数组
*/
//默认值
var def = {
    status : 1,
    msg : '调用成功',
    data : {
        data : [{
            name : '新浪用户'
        }]
    }
}
//接口
result = {
    status : 0,
    data : {
        data : [{
            name : '义薄云天黑心小王子'
        },{
            name : ''
        }]
    }
}
result = interfaceRepair(def, 接口result, options)
/*
{
	"status": 1,
	"msg": "调用成功",
	"data": {
		"data": [{
			"name": "义薄云天黑心小王子"
		}, {
			"name": "新浪用户"
		}]
	}
}
*/

Options

NameDefaultDescription
stringEmptyToDeftrue参数为空字符串, 是否采取默认值

FAQs

Package last updated on 06 Apr 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