# data-structure-validator

> A validator for nested data structures

Latest version **0.0.6** (published 2017-05-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install data-structure-validator
pnpm add data-structure-validator
yarn add data-structure-validator
bun add data-structure-validator
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2017-05-31 |
| First published | 2017-05-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Luke Purton |
| Maintainers | lukepur |
| Keywords | data, validation, structure |

## Links

- npm: https://www.npmjs.com/package/data-structure-validator
- Repository: https://github.com/lukepur/data-structure-validator
- Homepage: https://github.com/lukepur/data-structure-validator#readme
- Issues: https://github.com/lukepur/data-structure-validator/issues
- npm.io page: https://npm.io/package/data-structure-validator

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [data-resolver](https://npm.io/package/data-resolver.md) 0.0.2

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2017-05-31
- 0.0.5 — 2017-05-26
- 0.0.4 — 2017-05-26
- 0.0.3 — 2017-05-25
- 0.0.2 — 2017-05-25
- 0.0.1 — 2017-05-25

## README

# data-structure-validator

## Example constraint configuration
```
const configuration = [
  {
    id: 'personal',
    children: [
      {
        id: 'title',
        type: 'string', // One day, 'enum'?
        required: true
      },
      {
        id: 'first_name',
        type: 'string' // One day, 'enum'?
      },
      {
        id: 'last_name',
        type: 'string',
        required: {
          fn: isEmpty,
          args: ['$.personal.first_name'],
          message: '$prop is required if first_name is empty'
        }
      },
      {
        id: 'contacts',
        type: 'array',
        validations: [
          {
            fn: 'minArrayLength',
            args: ['$value', 2],
            message: 'At least 2 contacts must be provided
          }
        ],
        children: { // children is object instead of array for array types
          children: [ // implicit object type
            {
              id: 'contact_type',
              type: 'string',
              required: true,
              validations: [
                {
                  fn: 'oneOf',
                  args: ['$value', ['phone', 'email', 'address']],
                  message: '$prop must be phone, email or address'
                }
              ]
            },
            {
              id: 'email',
              type: 'string',
              required: {
                fn: 'equals',
                args: ['$.personal.contacts.^.contact_type', 'email'],
                message: 'email is required'
              }
            }
          ]
        }
      }
    ]
  }
];
```

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