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.9.0
  • latest
  • 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: 'CheckDepends',
  license: 'MIT',
  author: 'Liang',
  tags: ['web', 'app'],
  numbers: [0, 15, 20],
  empty: [],
  obj: {},
  object: { attr: 1, foo: 'bar' },
  regexp: '/check/',
  from: 2016,
  awesome: true,
  bugs: 0,
  zero: 0,
  one: 1,
  no: false,
  null: null,
  undefined: undefined
};

checkDepends('name', data); // true
checkDepends('!name', data); // false
checkDepends('null', data); // false
checkDepends({ name: 'CheckDepends' }, 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: '/check/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的差异

  • check-depends 中可以用字符串表示正则
  • MongoDB支持JSON Schema draft 4,check-depends 使用AJV验证JSON Schema
  • check-depends 中:开头的字符串 :key,代表data值引用
  • check-depends 支持 string.length 和 array.length 查询
  • check-depends 中ObjectID和24位字符串相等

差异举例:

ExpMongoDBcheck-depends
"/abc/i"stringRegExp
$jsonSchema: {name:{type:'number'}}Error(' Unknown keyword: name')true

和纯JS的差异

为了尽可能贴近MongoDB,0.8版本进行了重构,主要在两个方面:

  • 不同类型间进行大小对比始终返回false,比如 0 < true 在JS中为真,在MongoDB和check-depends中为假
  • undefined被视作null

Keywords

FAQs

Package last updated on 07 Jan 2022

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