New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 - npm Package Compare versions

Comparing version 3.0.1 to 4.0.0

History.md

217

index.js

@@ -5,3 +5,4 @@ "use strict"

let methods = require('./methods')
let Types = require('./type')
let symbols = require('./symbol')

@@ -37,14 +38,15 @@ class Parser {

// 选项为对象
// 选项值为对象
if (typeof options === 'object') {
// 选项为验证表达式
// 选项值为验证表达式
if (options.type) {
// 优先使用别名
let field = options.name || key
// 前置空值拦截
// 空值处理
if (this.isNull(data, options.ignore)) {
// 默认
// 默认值
if (options.default) {

@@ -54,3 +56,3 @@ data = options.default

// 直接赋值
// value赋值
else if (options.value) {

@@ -60,3 +62,3 @@ data = options.value

// 允许空值
// 禁止空值
else if (options.allowNull === false) {

@@ -69,5 +71,3 @@ return {

else {
return {
data: undefined
}
return {}
}

@@ -78,9 +78,10 @@

// type为内置构造函数或字符串(字符串用于表示自定义数据类型)
if (methods[options.type]) {
if (Types[options.type]) {
let funObj = methods[options.type]
let funObj = Types[options.type]
for (let name in options) {
let fun = funObj[name]
if (fun) {
let { error, data: subData } = fun({ data, option: options[name], origin: this.origin })
let option = options[name]
let { error, data: subData } = fun({ data, option, origin: this.origin })
if (error) {

@@ -108,57 +109,60 @@ return {

// 选项为数组表达式
// 选项值为数组结构
else if (Array.isArray(options)) {
let [itemOptions, allowNull] = options
if (!Array.isArray(data)) {
if (Array.isArray(data)) {
if (itemOptions.allowNull === false) {
if (data.length === 0) {
return {
error: `数组${key}值不能为空`
}
}
return {
error: `${key}必须为数组类型`
}
} else {
if (this.isNull(data)) {
if (allowNull === false) {
}
let dataArray = []
let itemKey = 0
// options为单数时采用通用匹配
if (options.length === 1) {
let [option] = options
for (let itemData of data) {
// 子集递归验证
let { error, data: subData } = this.recursion(itemData, option, itemKey)
if (error) {
return {
error: `${key}数组不能为空`
error: `[${itemKey}]${error}`
}
} else {
return {
data: undefined
}
dataArray.push(subData)
}
} else {
return {
error: `${key}必须为数组类型`
}
itemKey++
}
}
let dataArray = []
let itemKey = 0
// options为复数时采用精确匹配
else {
for (let itemData of data) {
for (let option of options) {
let { error, data: subData } = this.recursion(itemData, itemOptions, itemKey++)
let itemData = data[itemKey]
if (error) {
return {
error: `数组${key}中key:${error}`
}
} else {
// 空数组提示
if (itemOptions.allowNull === false) {
if (this.isNull(subData)) {
return {
error: `数组${key}中key:${itemKey}值不能为空`
}
// 子集递归验证
let { error, data: subData } = this.recursion(itemData, option, itemKey)
if (error) {
return {
error: `[${itemKey}]${error}`
}
} else {
dataArray.push(subData)
}
dataArray.push(subData)
itemKey++
}
}

@@ -172,12 +176,8 @@

// 选项为对象表达式
// 选项值为对象结构
else {
if (data === undefined) {
return { data: undefined }
}
if (typeof data !== 'object') {
return {
error: `${key}值必须为对象`
error: `值必须为对象`
}

@@ -195,9 +195,10 @@ }

if (error) {
// 非根节点
if (key) {
return {
error: `对象${key}中${error}`
error: `.${subKey}${error}`
}
} else {
return {
error: error
error: `${subKey}${error}`
}

@@ -219,13 +220,13 @@ }

// 选项为构造函数或字符串(字符串表示自定义数据类型)
else if (methods[options]) {
// 选项值为数据类型(值为构造函数或字符串,字符串表示自定义类型)
else if (Types[options]) {
if (this.isNull(data)) {
return { data: undefined }
return {}
}
let { error, data: subData } = methods[options].type({ data })
let { error, data: subData } = Types[options].type({ data })
if (error) {
return { error: `${key}值${error}` }
return { error: `值${error}` }
} else {

@@ -237,2 +238,16 @@ return { data: subData }

// 选项值为严格匹配的精确值类型
else if (data === options) {
return { data }
}
// 精确值匹配失败
else {
return { error: `值必须为${options}` }
}
}

@@ -248,3 +263,3 @@

*/
function Validator(data, options, handler = {}) {
function Check(data, options, handler = {}) {

@@ -274,21 +289,75 @@ let output = new Parser(data, options)

// 自定义数据类型扩展方法
Validator.use = function (type, options) {
Check.types = symbols
methods[type] = options
/**
* 自定义数据类型扩展方法
* @param {Function, Symbol, String} type 数据类型
* @param {Object} options 扩展选项
* @param {Object.Function} options 扩展方法
*/
Check.use = function (type, options = {}) {
if (!type) return
// 通过Function、Symbol定位,扩展已有数据类型
if (Types[type]) {
Object.assign(Types[type], options)
}
// 通过String定位,扩展已有数据类型或创建新类型
else if (typeof type === 'string') {
// 扩展已有Symbol类型
if (symbols[type]) {
let symbol = symbols[type]
Object.assign(Types[symbol], options)
}
// 创建新类型
else {
let symbol = Symbol(type)
symbols[type] = symbol
Types[symbol] = options
}
}
}
// 通过预处理方式,将提前处理好的静态options持久化驻留在内存中
// 避免同一个对象被多次重复的创建和销毁,实现options跨接口复用,在节省资源的同时,也增加了代码复用率
Validator.schema = function (name, options, handler) {
Validator[name] = function (data) {
return Validator(data, options, handler)
/**
* 通过预处理方式,将提前处理好的静态options持久化驻留在内存中
* 避免同一个对象被多次重复的创建和销毁,实现options跨接口复用,在节省资源的同时,也增加了代码复用率
* @param {String} name schema名称
* @param {*} options 验证表达式
* @param {Object} extend 数据扩展选项
*/
Check.schema = function (name, options, extend) {
Check[name] = function (data) {
return Check(data, options, extend)
}
return Validator[name]
/**
* 严格模式,禁止空值
*/
Check[name].strict = function () {
}
/**
* 宽松模式,用于数据更新
* 忽略所有allowNull值,有值验证,无值跳过,
*/
Check[name].loose = function () {
}
return Check[name]
}
module.exports = Validator
module.exports = Check
{
"name": "check-data",
"version": "3.0.1",
"description": "JS对象验证器",
"version": "4.0.0",
"description": "JS数据验证、转换递归器",
"main": "index.js",
"scripts": {
"dev": "nodemon test/object",
"test": "ava test/ -w"

@@ -17,14 +16,10 @@ },

"devDependencies": {
"ava": "^0.25.0",
"nodemon": "^1.11.0"
"ava": "^0.25.0"
},
"keywords": [
"JSON",
"check",
"check data",
"schema",
"validator",
"validation",
"jsonschema",
"json-schema",
"json-schema-validator",
"json-schema-validation"
"validation"
],

@@ -31,0 +26,0 @@ "repository": {

@@ -10,5 +10,5 @@ ### Install

```js
let Validator = require('check-data')
let Check = require('check-data')
let { error, data } = Validator(data, options, extend)
let { error, data } = Check(data, options, extend)
```

@@ -18,11 +18,11 @@

* `data` *Objcte, Array, String, Number, Date, Boolean* - 输入待验证数据
* `data` * - 待验证数据,允许任意数据类型
* `options` *Objcte, Array, Function* - 数据验证表达式,类型参考type选项。
* `options` * - 待验证数据的结构镜像验证表达式,参考[验证表达式](###验证表达式)。
* `extend` *Objcte* - 自定义数据构建对象,根据输入数据生成新的数据结构(可选)
* `extend` *Objcte* - 数据扩展选项,根据输入数据生成新的数据结构(可选)
* `extend.$name` *Function* - 数据扩展函数,基于已验证的数据构建新的数据结构,输出结果将以函数名作为key保存到返回值的data中。函数中this和第一个入参指向data(已存在的同名属性值会被函数返回值覆盖)
* `extend.$name` * - 数据扩展,除函数外的其它任意数据类型,在已验证的数据结构上添加新的属性或覆盖已存在的同名属性
* `extend.$name` * - 除函数外的其它任意数据类型,在已验证的数据结构上添加新的属性或覆盖已存在的同名属性

@@ -33,3 +33,3 @@ ### 返回值

* `data` * - 经过验证、处理后导出数据,内置空值过滤,自动剔除对象、数组中的空字符串、undefind值。(更多空值过滤特性请参考[filter-null模块](https://github.com/xiangle/filter-null))
* `data` * - 经过验证、处理后导出数据,仅保留options中定义的数据结构,未定义的部分会被忽略。内置空值过滤,自动剔除对象、数组中的空字符串、undefind值。

@@ -40,3 +40,3 @@ * `error` *String* - 验证失败时返回的错误信息,包含错误的具体位置信息,仅供开发者调试使用

### options验证表达式
### 验证表达式

@@ -49,2 +49,4 @@ options数据验证表达式支持无限嵌套,不管你的数据层级有多深。整体数据结构与待验证数据结构基本保持一致,除了使用type对象表达式不得不增加额外的数据结构。

> 当使用数组表达式时,需要区分单数和复数模式,单数时会共享同一个子表达式,通常用于验证具有相似结构的子集。复数时为精确匹配模式,可以完整定义每个子集。
#### 通用选项

@@ -86,2 +88,4 @@

> 内置类型转换,允许字符串类型的纯数字
* `min` *Number* - 限制最小值

@@ -95,39 +99,42 @@

* `minLength` *Number* - 限制字符串最小长度
* `minLength` *Number* - 限制数组最小长度
* `maxLength` *Number* - 限制字符串最大长度
* `maxLength` *Number* - 限制数组最大长度
##### Object
##### Object、Date、Boolean、Function
> 仅支持类型验证
> 无专用选项
##### Date、Boolean、Function
> 仅支持类型验证
#### 其它数据类型
其它类型通过Check.types定义,types中内置了以下常见类型
#### 其它数据类型
##### email
##### 'MongoId'
验证Email
> 验证mongodb中的ObjectId
##### mobilePhone
##### 'MobilePhone'
验证手机号
> 验证手机号
##### mongoId
##### 'Email'
验证mongodb中的ObjectId
> 验证Email
### 扩展自定义数据类型
验证器中只内置了一部分常用的数据类型,如果不能满足你的需求,可以通过Validator.use()自行扩展,使用时和扩展类型一样,用类型名称字符串声明数据类型
验证器中仅内置了一部分常用的数据类型,如果不能满足你的需求,可以通过Check.use()自行扩展。
check-data依赖validator库,你可以使用Check.use()搭配validator来定制自己的数据类型。
> 当定义的数据类型不存在时则创建,已存在时则合并,新的验证函数会覆盖内置的同名验证函数。
```js
Validator.use(name, options)
Check.use(name, options)
```
* `name` *String* - 类型名称(必填)
* `name` *Function, Symbol, String* - 类型Key(必填)

@@ -138,7 +145,7 @@ * `options` *Object* - 类型选项(必填)

* `options.$name` *Function* - 其它验证函数(可选)
* `options.$name` *Function* - 自定义验证函数(可选)
```js
Validator.use('Int', {
Check.use('int', {
type({ data }) {

@@ -148,3 +155,3 @@ if (Number.isInteger(data)) {

} else {
return { error: '必须为Int类型' }
return { error: '必须为int类型' }
}

@@ -172,7 +179,8 @@ },

通过预定义schema,实现options单例复用(option为静态数据),避免频繁创建重复的实例,可节省内存和减少计算开销。在环境允许的情况下应优先考虑schema方式。
schema用于创建可复用的验证器,在环境允许的情况下应优先使用schema模式。
> schema的定义应该在应用启动时被执行,而不是运行时。目的是通过预先缓存一部分静态数据,从而减少运行时的内存和计算开销。
```js
Validator.schema(name, options)
Check.schema(name, options)
```

@@ -184,2 +192,3 @@

* `extend` Object - 数据扩展选项

@@ -191,3 +200,3 @@ ### 参考示例

```js
let schema = Validator.schema('demo', {
let test = Check.schema('test', {
a: {

@@ -206,3 +215,3 @@ a1: {

let json = {
let sample = {
a: {

@@ -216,6 +225,7 @@ a1: "jj",

let { error, data } = schema(json)
let { error, data } = test(sample)
// 或
let { error, data } = Validator.demo(json)
let { error, data } = Check.test(sample)
```

@@ -226,19 +236,53 @@

```js
// 一维数组
let { error, data } = Validator(["a", "b", "c"], [String])
let sample = {
a: ['xx', 'kk'],
b: [666, 999, 88,],
c: [{ a: 1 }, { a: 2 }, { b: '3' }],
d: [
{
d1: 666,
d2: "888"
},
999,
[
{
xa: 1,
xb: [1, 2, 3],
},
{
xa: 9,
xb: [2, 4, 3],
}
],
"hello"
],
e: [1, 2, 3],
}
// 内嵌对象
let { error, data } = Validator([{
"a":1,
"b":"bibi",
"c":"test"
},{
"a":1,
"b":"bibi",
"c":"test"
}], [{
a: Number,
b: String,
c: String
}])
let { error, data } = Check(sample, {
a: [{ "type": String }],
b: [{
"type": Number,
"allowNull": false
}],
c: [{ a: Number, b: Number }],
d: [
{
d1: 666,
d2: String
},
Number,
[
{
xa: Number,
xb: [{
"type": Number,
"allowNull": false
}],
}
],
String
],
e: Array
})
```

@@ -249,19 +293,37 @@

```js
let { error, data } = Validator({
"a": 1,
"b": "xx",
"c": [1,32,34],
"d": 666
}, {
"a": Number,
"b": String,
"c": [String],
"d": Number
})
let sample = {
a: {
a1: 1,
a2: 12,
},
b: 99,
f(a, b) {
return a + b
},
}
let { error, data } = Check(sample,
{
a: {
a1: {
type: Number,
allowNull: false
},
a2: 12
},
b: 99,
f: {
type: Function,
set(func) {
return func(1, 1)
}
},
}
)
```
#### and验证
#### and依赖验证
```js
let { error, data } = Validator({
let { error, data } = Check({
"username": "莉莉",

@@ -294,6 +356,6 @@ "addressee": "嘟嘟",

#### or验证
#### or依赖验证
```js
let { error, data } = Validator({
let { error, data } = Check({
"username": "莉莉",

@@ -320,16 +382,23 @@ "addressee": "嘟嘟",

```js
let { error, data } = Validator({
"id": "5968d3b4956fe04299ea5c18",
"mobilePhone": "18555555555",
}, {
"id": "MongoId",
"mobilePhone": "MobilePhone"
})
let { mongoId, email, mobilePhone, int } = Check.types
let { error, data } = Check(
{
"id": "5968d3b4956fe04299ea5c18",
"mobilePhone": "18555555555",
"age": 20,
},
{
"age": int,
"id": mongoId,
"mobilePhone": mobilePhone
}
)
```
#### 完整示例
#### 混合示例
```js
// 输入数据
let json = {
let sample = {
"username": "测试",

@@ -372,3 +441,3 @@ "num": "123456789987",

// 验证表达式
let { error, data } = Validator(json,
let { error, data } = Check(sample,
{

@@ -439,3 +508,3 @@ "username": {

{
filter({ search, email, integral }) {
filter({ email, integral }) {
return {

@@ -446,21 +515,12 @@ "email": email,

a: 1,
b: undefined,
c: "",
d: null,
e: NaN,
e: 0,
},
}
}
},
more({ email }) {
return [email]
},
xxx: 1,
yyy: 222
}
)
```
### 版本更新内容
* 新增Function类型验证
* 将handle函数名改为set
* 升级filter-null,取消递归执行嵌套函数
```

@@ -6,21 +6,60 @@ "use strict"

let json = {
a: ['xx', 'kk'],
b: [666, 999, 88],
}
test(t => {
test('example', t => {
let sample = {
a: ['xx', 'kk'],
b: [666, 999, 88,],
c: [{ a: 1 }, { a: 2 }, { b: 3 }],
d: [
{
d1: 666,
d2: "888"
},
999,
[
{
xa: 1,
xb: [1, 2, 3],
},
{
xa: 9,
xb: [2, 4, 3],
}
],
"hello"
],
e: [1, 2, 3],
}
let { error, data } = Check(json, {
let { error, data } = Check(sample, {
a: [{ "type": String }],
b: [{
"type": Number,
"allowNull": false
}, {
"allowNull": false
}]
}],
c: [{ a: Number, b: Number }],
d: [
{
d1: 666,
d2: String
},
Number,
[
{
xa: Number,
xb: [{
"type": Number,
"allowNull": false
}],
}
],
String
],
e: Array
})
// console.log(data);
t.truthy(data, error);
t.deepEqual(sample, data, error);
});

@@ -6,4 +6,3 @@ "use strict"

Check.use('Int', {
Check.use('int', {
type({ data }) {

@@ -13,3 +12,3 @@ if (Number.isInteger(data)) {

} else {
return { error: '必须为Int类型' }
return { error: '必须为int类型' }
}

@@ -19,19 +18,57 @@ },

test('extend', t => {
let { error, data } = Check(
{
"name": 666,
let { mongoId, email, mobilePhone, int } = Check.types
test(t => {
let sample = {
"id": "5687862c08d67e29cd000001",
"age": 28,
"email": "erer@gmail.com",
"mobile": "15855555547",
"mobileArr": [
"15855155547",
"18955535547",
"13055655547",
"18655655512",
"15055655512"
],
"mobileArr2": [
"13055656647",
"18655655512",
"15055699512",
"15855155547"
],
}
let { error, data } = Check(sample, {
"id": {
"type": mongoId,
"allowNull": false
},
{
"name": {
"type": 'Int',
"name": "名称",
"allowNull": false,
"default": "默认值",
"age": {
"type": int,
"allowNull": false
},
"email": {
"type": email,
},
"mobile": {
"type": mobilePhone,
},
"mobileArr": [mobilePhone],
"mobileArr2": [
mobilePhone,
"18655655512",
mobilePhone,
{
type: mobilePhone,
"allowNull": false
}
}
)
]
})
t.truthy(data, error);
// console.log(data)
t.deepEqual(sample, data, error);
});

@@ -6,23 +6,45 @@ "use strict"

test('function', t => {
test(t => {
let { error, data } = Check(
{
a: {
a1: 1,
a2: "12",
},
b: "666",
function func() { }
let { error, data } = Check(func, Function)
// console.log(data);
t.deepEqual(func, data, error);
});
test('inline', t => {
let sample = {
a(x, y) {
return [x, y]
},
b(a, b) {
return a + b
},
}
let { error, data } = Check(sample,
{
a: {
a1: Number,
a2: Number,
a: Function,
b: {
type: Function,
set(func) {
return func(1, 1)
}
},
b: Number,
}
)
t.truthy(data, error);
// console.log(data);
t.deepEqual({
a: sample.a,
b: 2,
}, data, error, data);
});

@@ -6,3 +6,3 @@ "use strict"

let json = {
let sample = {
"name": "测试",

@@ -28,7 +28,14 @@ "num": "123456789987",

"username": "吖吖",
"age": 16,
"age": {
"kk": [{ kkk: 666 }]
},
},
{
"username": "可可",
"age": 15,
"age": {
"kk": [
{ kkk: 666 },
{ kkk: 999 }
]
},
}

@@ -51,124 +58,126 @@ ],

test('mixing', t => {
let { error, data } = Check(json,
{
"name": {
"type": String,
"name": "名称",
"allowNull": false,
"default": "默认值"
},
"num": {
"type": Number,
"value": 666,
},
"tenderEndTime": {
"type": Date,
"name": "时间",
"allowNull": false,
},
"ObjectId": {
"type": "MongoId",
},
"user": {
"username": String,
"age": Number,
"address": [
{
"city": String,
},
{
"city": String,
}
],
},
"list": [
let { error, data } = Check(sample,
{
"name": {
"type": String,
"name": "名称",
"allowNull": false,
"default": "默认值"
},
"num": {
"type": Number,
"value": 666,
},
"tenderEndTime": {
"type": Date,
"name": "时间",
"allowNull": false,
},
"ObjectId": {
"type": "MongoId",
},
"user": {
"username": String,
"age": Number,
"address": [
{
"username": String,
"age": Number,
"city": String,
},
{
"allowNull": false,
"city": String,
}
],
"money": {
"type": Number,
// "min": 15,
// "in": [1, 2],
},
"list": [
{
"username": String,
"age": {
"kk": [{ kkk: Number }]
},
},
"files": [{
"type": String,
{
"allowNull": false,
}, false],
"guaranteeFormat": {
}
],
"money": {
"type": Number,
// "min": 15,
// "in": [1, 2],
},
"files": [{
"type": String,
"allowNull": false,
}, false],
"guaranteeFormat": {
"type": Number,
"to": Boolean,
},
"addressee": String,
"search": {
"type": String,
// "or": ["searchField"],
},
"phone": {
"type": "MobilePhone"
},
"coupon": {
"type": String,
set(value) {
return { "$gt": value }
}
},
"integral": {
"lala": {
"type": Number,
"to": Boolean,
},
"addressee": String,
"search": {
"type": String,
// "or": ["searchField"],
},
"phone": {
"type": "MobilePhone"
},
"coupon": {
"type": String,
set(value) {
return { "$gt": value }
"kaka": {
"type": Number,
"allowNull": false,
"in": [1, 3, 8, 6],
}
},
"email": {
"type": 'Email',
set(value) {
return [value, , null, , undefined, 666]
}
},
"arr": [String],
},
{
filter({ email, integral }) {
return {
"email": email,
"integral": integral,
"test": {
v1: 1,
v2: undefined,
v3: "",
v4: null,
v5: NaN,
v6: 0,
}
},
"integral": {
"lala": {
"type": Number,
},
"kaka": {
"type": Number,
"allowNull": false,
"in": [1, 3, 8, 6],
}
},
"email": {
"type": 'Email',
set(value) {
return [value, , null, , undefined, 666]
}
},
"arr": [String],
}
},
{
filter({ search, email, integral }) {
return {
"email": email,
"integral": integral,
"test": {
v1: 1,
v2: undefined,
v3: "",
v4: null,
v5: NaN,
v6: 0,
}
where({ email, integral }) {
return {
"email": email,
"integral": integral,
"test": {
v1: 1,
v2: undefined,
v3: "",
v4: null,
v5: NaN,
v6: 0,
}
},
where({ search, email, integral }) {
return {
"email": email,
"integral": integral,
"test": {
v1: 1,
v2: undefined,
v3: "",
v4: null,
v5: NaN,
v6: 0,
}
}
}
}
)
}
)
t.truthy(data, error);
test(t => {
t.truthy(error, data);
});

@@ -6,31 +6,32 @@ "use strict"

test('null', t => {
let sample = {
a: undefined,
b: ["kkk", "xxx"],
c: "666"
}
let { error, data } = Check(
{
a: undefined,
b: ["kkk", "xxx"],
c: "是"
let { error, data } = Check(sample,
{
a: {
type: String,
allowNull: false,
default: 'xxx',
},
{
a: {
type: String
},
b: {
type: Array,
handle(data) {
return data.join()
}
},
c: {
type: String,
handle(data) {
return data
}
}
b: [String],
c: {
type: String
}
)
}
)
t.truthy(data, error);
// console.log(data);
test(t => {
t.deepEqual({
a: 'xxx',
b: ["kkk", "xxx"],
c: "666"
}, data, error);
});

@@ -6,30 +6,28 @@ "use strict"

let json = {
a: {
a1: 1,
a2: "12",
},
b: 2,
s: 99,
c(a, b) {
return a + b
},
}
test('null', t => {
test(t => {
let { error, data } = Check(json,
let sample = {
a: {
a1: 1,
a2: 12,
},
b: 99,
f(a, b) {
return a + b
},
}
let { error, data } = Check(sample,
{
// a: {
// a1: {
// type: Number,
// allowNull: false
// },
// a2: {
// type: Number,
// allowNull: false
// }
// },
a: {
a1: {
type: Number,
allowNull: false
},
a2: Number
},
b: {
type: Number,
name: "拉拉",
set(data) {

@@ -39,7 +37,8 @@ return data * 2

},
s: {
type: Number,
name: "拉拉",
f: {
type: Function,
set(func) {
return func(1, 1)
}
},
c: Function,
},

@@ -54,4 +53,11 @@ {

t.truthy(data, error);
t.deepEqual({
a: { a1: 1, a2: 12 },
b: 198,
f: 2,
test: 888,
ss: 999
}, data, error);
});

@@ -31,3 +31,3 @@ "use strict"

test('schema 1', t => {
test('通过对象访问 A', t => {

@@ -47,3 +47,3 @@ let { error, data } = Check.demo({

test('schema 2', t => {
test('通过对象访问 B', t => {

@@ -61,2 +61,18 @@ let { error, data } = Check.demo({

});
test('通过导出变量访问', t => {
let { error, data } = schema({
a: {
a1: 4545,
a2: "888",
},
b: 990,
c: 1212,
})
t.truthy(data, error);
});
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