# valid-records

> validate field values of a set of records (js objects or newline-delimited json)

Latest version **0.0.5** (published 2014-10-01) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install valid-records
pnpm add valid-records
yarn add valid-records
bun add valid-records
```

Provides the command `valid-records`.

## 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.5 |
| Published | 2014-10-01 |
| First published | 2014-09-29 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | joyrexus |
| Maintainers | joyrexus |
| Keywords | validation, ldjson, ndjson |

## Links

- npm: https://www.npmjs.com/package/valid-records
- Repository: https://github.com/joyrexus/valid-records
- Issues: https://github.com/joyrexus/valid-records/issues
- npm.io page: https://npm.io/package/valid-records

## Dependencies (3)

- [ndjson](https://npm.io/package/ndjson.md) ~1.2.2
- [minimist](https://npm.io/package/minimist.md) ~1.1.0
- [through2](https://npm.io/package/through2.md) ~0.6.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.5 (latest) — 2014-10-01
- 0.0.4 — 2014-10-01
- 0.0.2 — 2014-09-29
- 0.0.1 — 2014-09-29

## README

# valid-records

A simple module and CLI (`validate-ndj`) for validation reporting on specified fields within a set of records.

Sample records:

```javascript
{ row: 1, X: 'x1', Y: 'y1', Z: 'z1' }
{ row: 2, X: 'x2', Y: 'y2', Z: 'z2' }
{ row: 3, X: 'x3', Y: 'y3', Z: 'z3' }
{ row: 4, X: 'OH NOES!', Y: 'y4', Z: 'z4' }
```

A simple schema containing one validation constraint for field **X**:

```javascript
var schema = {

    X: function (value) {
        column = 'X';
        if (value) {
            if (!/^x\d*$/.test(value)) {
                return value + ' is an invalid value for X';
            }
        }
    }
}
```

The CLI is designed to validate newline-delimited JSON (e.g., [`records.ndj`](records.ndj)) from [**stdout**](http://en.wikipedia.org/wiki/Standard_streams).  You just pass 
in a file containing your validation schema (e.g., [`rec.schema.js`](rec.schema.js):

    cat records.ndj | valid-records --schema=rec.schema.js


## Usage

    npm install -g valid-records
    npm run test
    npm run demo
    npm run cli-demo


## CLI example

Suppose we have an excel file (`sample.xlsx`) ...

![sample file](records.png)

We can convert the displayed worksheet (named **Transcript**) to newline-delimited JSON with [`parse-xl`](https://github.com/joyrexus/parse-xl):

    parse-xl --sheet=Transcript sample.xlsx 

This outputs ...

```json
{ "_ID": "22", "ROW": "1", "LRB": "L",     "XYZ": "x" }
{ "_ID": "22", "ROW": "2", "LRB": "L+L",   "XYZ": "y" }
{ "_ID": "22", "ROW": "3", "LRB": "L+ ",   "XYZ": "z" }
{ "_ID": "22", "ROW": "4", "LRB": "L+R+B", "XYZ": "q" }
{ "_ID": "22", "ROW": "5", "LRB": "L+R+X", "XYZ": "b" }
```

We can pipe these records to `valid-records` and check to see if any records fail to meet our specified field constraints ([`rec.schema.js`](rec.schema.js)):

    parse-xl --sheet=Transcript sample.xlsx | \
        valid-records --schema=rec.schema.js

This outputs ...

```json
{ "index": 2, "errors": [ "LRB = `L+ ` is an invalid value"] }
{ "index": 3, "errors": [ "XYZ = `q` is an invalid value"] }
{ "index": 4, "errors": [ "LRB = `L+R+X` is an invalid value", "XYZ = `b` is an invalid value" ] }
```


## See Also

* [`parse-xl`](https://github.com/joyrexus/parse-xl) - parse excel worksheets with column headers
* [`valid-xl`](https://github.com/joyrexus/valid-xl) - validate values in columns of an excel worksheet

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