New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

check-depends

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-depends

Check object depends

  • 0.6.1
  • Source
  • npm
  • Socket score

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

check-depends

数据对象检查、验证,灵感来自于 MongoDB 查询语法。

用法

const checkDepends = require('check-depends');

const data = {
  name: 'Alaska',
  license: 'MIT',
  author: 'Liang',
  tags: ['web', 'app'],
  numbers: [0, 15, 20],
  empty: [],
  obj: {},
  object: { attr: 1, foo: 'bar' },
  regexp: '/Alaska/',
  from: 2016,
  awesome: true,
  bugs: 0,
  zero: 0,
  one: 1,
  no: false,
  others: null,
  undefined: undefined
};

checkDepends('name', data); // true
checkDepends('!name', data); // false
checkDepends('others', data); // false
checkDepends({ name: 'Alaska' }, data); // true
checkDepends({ 'name.length': 6 }, data); // true
checkDepends({ name: ':regexp' }, data); // true
checkDepends({ from: { $gt: 2015 } }, data); // true
checkDepends({ tags: /web/ }, data); // true
checkDepends({ obj: {} }, data); // true
checkDepends({ object: { attr: 1, foo: 'bar' } }, data); // true
checkDepends({ 'object.foo': 'bar' }, data); // true
checkDepends({ numbers: { $all: [15, 20] } }, data); // true
checkDepends({ 'tags.length': 2 }, data); // true
checkDepends({ $or: [{ name: '/alaska/i' }, { no: true }] }, data); // true
checkDepends({ $jsonSchema: {} }); //true
checkDepends({ $jsonSchema: { properties: { name: { type: 'number' } } } }); //false

已支持的MongoDB查询操作:

  • $eq
  • $ne
  • $gt
  • $gte
  • $lt
  • $lte
  • $in
  • $nin
  • $not
  • $and
  • $or
  • $nor
  • $exists
  • $jsonSchema
  • $regex
  • $all
  • $elemMatch
  • $size

和MongoDB的差异

  • MongoDB中一般不同类型比较会返回false,而JS则会类型转换,但是undefined不会转换
  • MongoDB中不存在的值可以用null匹配,而JS中不存在的值只能用undefined匹配
  • MongoDB中undefined等于null,而JS中undefined不等于null
  • MongoDB中不能查询undefined
  • check-depends 中可以用字符串表示正则
  • MongoDB支持JSON Schema draft 4,check-depends 使用AJV验证JSON Schema
  • check-depends 中:开头的字符串 :key,代表data值引用
  • check-depends 支持 string.length 和 array.length 查询

差异举例:

ExpMongoDBcheck-depends (JS)
1 > falsefalsetrue
0 >= nullfalsetrue
false >= nullfalsetrue
1 >= nullfalsetrue
0 >= falsefalsetrue
1 >= falsefalsetrue
1 >= truefalsetrue
0 >= ''falsetrue
undefined = nulltruefalse
undefined >= nulltruefalse
undefined <= nulltruefalse
undefined >=0falsefalse
"/abc/i"stringRegExp
$jsonSchema: {name:{type:'number'}}Error(' Unknown keyword: name')true

Keywords

FAQs

Package last updated on 13 Nov 2020

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