csval
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "csval", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Check CSV files against a set of validation rules.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -50,20 +50,20 @@ # csval | ||
``` | ||
```json | ||
{ | ||
"type": "object", // This line is implied and can be left out | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
"salary": { | ||
"type": "number" | ||
} | ||
}, | ||
"required": ["name"] | ||
} | ||
} | ||
``` | ||
The rules above say that each row is required to have a name, which is a string. | ||
This CSV file would pass. | ||
The rules above say that the "salary" field on each row must be a number. This | ||
CSV file would pass. | ||
``` | ||
name,age,salary | ||
John,30,100000 | ||
Jane,50,150000 | ||
name,salary | ||
John,100000 | ||
Jane,150000 | ||
``` | ||
@@ -74,5 +74,5 @@ | ||
``` | ||
age,salary | ||
30,100000 | ||
50,150000 | ||
name,salary | ||
John,100000 | ||
Jane,idk | ||
``` | ||
@@ -82,5 +82,5 @@ | ||
``` | ||
```json | ||
{ | ||
properties: { | ||
"properties": { | ||
"age": { | ||
@@ -110,2 +110,35 @@ "type": "number", | ||
You can require certain fields, as well. Consider this rules file. | ||
```json | ||
{ | ||
"properties": { | ||
"age": { | ||
"type": "number" | ||
} | ||
}, | ||
"required": ["age"] | ||
} | ||
``` | ||
This CSV file would pass. | ||
``` | ||
name,age,salary | ||
John,30,100000 | ||
Jane,50,150000 | ||
``` | ||
This one would fail. | ||
``` | ||
name,salary | ||
John,100000 | ||
Jane,150000 | ||
``` | ||
There are many other possible rules. See the [JSON | ||
Schema](https://json-schema.org/understanding-json-schema/reference/index.html) | ||
for more information. | ||
## Programmatic API | ||
@@ -121,3 +154,3 @@ | ||
``` | ||
```javascript | ||
const csval = require("csval"); | ||
@@ -147,3 +180,3 @@ | ||
``` | ||
```javascript | ||
const csval = require("csval"); | ||
@@ -150,0 +183,0 @@ |
10037
260