# check-depends

> Check object depends

Latest version **0.9.0** (published 2022-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install check-depends
pnpm add check-depends
yarn add check-depends
bun add check-depends
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2022-01-07 |
| First published | 2017-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Liang |
| Maintainers | liangxingchen |
| Keywords | data check, validator |

## Links

- npm: https://www.npmjs.com/package/check-depends
- Repository: https://github.com/liangxingchen/check-depends
- Homepage: https://github.com/liangxingchen/check-depends#readme
- Issues: https://github.com/liangxingchen/check-depends/issues
- npm.io page: https://npm.io/package/check-depends

## Dependencies (2)

- [ajv](https://npm.io/package/ajv.md) ^8.8.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.9.0 (latest) — 2022-01-07
- 0.8.0 — 2021-11-17
- 0.7.0 — 2021-01-15
- 0.6.1 — 2020-11-13
- 0.6.0 — 2020-06-23
- 0.5.2 — 2019-02-21
- 0.5.1 — 2019-01-21
- 0.5.0 — 2019-01-07
- 0.4.0 — 2018-11-09
- 0.3.1 — 2018-01-08
- 0.3.0 — 2018-01-07
- 0.2.0 — 2017-04-21
- 0.1.0 — 2017-01-17

## README

# check-depends


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


## 用法

```js
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](https://docs.mongodb.com/manual/reference/operator/query/eq/)
- [$ne](https://docs.mongodb.com/manual/reference/operator/query/ne/)
- [$gt](https://docs.mongodb.com/manual/reference/operator/query/gt/)
- [$gte](https://docs.mongodb.com/manual/reference/operator/query/gte/)
- [$lt](https://docs.mongodb.com/manual/reference/operator/query/lt/)
- [$lte](https://docs.mongodb.com/manual/reference/operator/query/lte/)
- [$in](https://docs.mongodb.com/manual/reference/operator/query/in/)
- [$nin](https://docs.mongodb.com/manual/reference/operator/query/nin/)
- [$not](https://docs.mongodb.com/manual/reference/operator/query/not/)
- [$and](https://docs.mongodb.com/manual/reference/operator/query/and/)
- [$or](https://docs.mongodb.com/manual/reference/operator/query/or/)
- [$nor](https://docs.mongodb.com/manual/reference/operator/query/nor/)
- [$exists](https://docs.mongodb.com/manual/reference/operator/query/exists/)
- [$jsonSchema](https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/)
- [$regex](https://docs.mongodb.com/manual/reference/operator/query/regex/)
- [$all](https://docs.mongodb.com/manual/reference/operator/query/all/)
- [$elemMatch](https://docs.mongodb.com/manual/reference/operator/query/elemMatch/)
- [$size](https://docs.mongodb.com/manual/reference/operator/query/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位字符串相等

差异举例：

| Exp                                 | MongoDB                         | check-depends      |
| ----------------------------------- | ------------------------------- | ------------------ |
| `"/abc/i"`                          | string                          | RegExp             |
| $jsonSchema: {name:{type:'number'}} | Error(' Unknown keyword: name') | true               |



## 和纯JS的差异

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

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

---
_Source: https://npm.io/package/check-depends · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
