valid-records
A simple module and CLI (validate-ndj
) for validation reporting on specified fields within a set of records.
Sample records:
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:
var schema = { column = 'X'; if value if !/^x\d*$/ return value + ' is an invalid value for X'; }
The CLI is designed to validate newline-delimited JSON (e.g., records.ndj
) from stdout. You just pass
in a file containing your validation schema (e.g., 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
) ...
We can convert the displayed worksheet (named Transcript) to newline-delimited JSON with parse-xl
:
parse-xl --sheet=Transcript sample.xlsx
This outputs ...
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
):
parse-xl --sheet=Transcript sample.xlsx | \
valid-records --schema=rec.schema.js
This outputs ...