table-validator
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Table Validator

Online Demo

table-validator is an table(like csv) validator library in Typescript. With yaml schema definition, it validates an table and throw error if content does not match the schema. It implements features inspired by "csv-validator".

Installation

npm install table-validator

API

const schema = convertToSchema(fs.readFileSync("/path/to/yaml", "utf8"));
const table = convertToTable(fs.readFileSync("/path/to/csv", "utf8"), {
  header: true,
});
const validator = new Validator();
const errors = validator.validate(table, schema);
if (errors.length === 0) {
  console.log("No error");
} else {
  for (const error of errors) {
    console.log(`${error}`);
  }
}

List of available rules

Non combinatorial expressions

  • notEmpty: notEmpty
  • empty: empty
  • is: is("Japan")
  • not: not("Tokyo")
  • unique: unique
  • range: range(10,20)
  • length: length(2,10)
  • regex: regex("[bcm]at")
  • integer: integer
  • float: float
  • any: any("a","b")

Combinatorial expression

  • or: is("Japan") or is("France")
  • and: length(2) and range(10,20)

Others

  • parentheses: (length(2) and range(10,20)) or empty

Example

React example

npm run react

CLI example

npm run cli

Package Sidebar

Install

npm i table-validator

Weekly Downloads

5

Version

0.0.5

License

ISC

Unpacked Size

220 kB

Total Files

90

Last publish

Collaborators

  • wapa5pow