# is-my-ssb-valid

> build scuttlebutt message validators from JSON Schema

Latest version **1.2.2** (published 2023-03-01) · LGPL-3.0-only license · 0 weekly downloads

## Install

```sh
npm install is-my-ssb-valid
pnpm add is-my-ssb-valid
yarn add is-my-ssb-valid
bun add is-my-ssb-valid
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2023-03-01 |
| First published | 2020-02-03 |
| Weekly downloads | 0 |
| License | LGPL-3.0-only |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | mixmix |
| Maintainers | powersource, arj03, staltz, mixmix, cel |
| Keywords | scuttlebutt, schema, validator |

## Links

- npm: https://www.npmjs.com/package/is-my-ssb-valid
- Repository: https://github.com/ssbc/is-my-ssb-valid
- Homepage: https://github.com/ssbc/is-my-ssb-valid#readme
- Issues: https://github.com/ssbc/is-my-ssb-valid/issues
- npm.io page: https://npm.io/package/is-my-ssb-valid

## Dependencies (2)

- [ssb-msg-content](https://npm.io/package/ssb-msg-content.md) ^1.0.1
- [is-my-json-valid](https://npm.io/package/is-my-json-valid.md) ^2.20.0

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 1.2.2 (latest) — 2023-03-01
- 1.2.1 — 2022-11-29
- 1.2.0 — 2022-04-08
- 1.1.0 — 2020-05-17
- 1.0.1 — 2020-02-03
- 1.0.0 — 2020-02-03

## README

# is-my-ssb-valid

Build message validators for scuttlebutt using JSON schema.
Uses `is-my-json-valid` under the hood

## Example usage

```js
const Validator = require('is-my-ssb-valid')
const profileSchema = require('ssb-profile/spec/profile/schema')

const isProfile = Validator(profileSchema)
```

```js
const A = {
  //....
}

isProfile(A)
// => true | false

console.log(isProfile.errors)
// => null | [Error]

console.log(isProfile.errorsString)
// => '' | 'data.type is required'  (example)
```

```js
const pull = require('pull-stream')

pull(
  sbot.messagesByType({ type: 'profile/person', reverse: true }),
  pull.filter(isProfile),
  pull.take(50),
  pull.collect((err, profileUpdates) => {
    // ...
  })
)
```

## API

### `Validator(schema) => isValid`

where: 
- `schema` *Object* is a JSON schema
- `extras` *Array* (optional) is an Array of additional custom validation functions.
    - These will be run _after_ the schema-based validation, and are expected to either return `true` (no problem) or an `Error` (a problem) was found.
    - any error returned be added to the `isValid.errors` and `isValid.errorsString` for you (see below)

### `isValid(msg) => Boolean`

where `msg` can be any of 
  - a full message a "full message" of form `{ key, value, timestamp }`
  - just the `value` of a message (`msg.value`)
  - just the `content` field of a message (`msg.value.content`)

If the last message tested came back invalid ("false"), then you can also check out the specific errors:
  - `isValid.errors` will be populated with those errors
  - `isValid.errorsString` will be populated with a (crudely) flattened version in case you need a String

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