This package has been deprecated

Author message:

Project deprecated in favour of JSON schemas. If you want the package name, please contact NPM.

plius

0.0.1 • Public • Published

Plius for Node

⚠️ We are working hard on an alpha release. Below is what it will be able to do.

This is the JavaScript implementation of Plius, a language-agnostic document schema engine.

$ npm i --save plius

Plius uses generators to generate only the validation messages your application needs. This saves both in terms of logic to maintain and in performance.

Consider the following schema for validating a user:

userschema.json

{
  "type": "Map",
  "keys": {
    "email": {
      "type": "String",
      "regex": "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b",
      "required": true
    },
    "name": {
      "type": "String",
      "minLength": 5
    },
    "password": {
      "minLength": 7
      "required": true
    }
  }
}

Note that the above schema can be used with any other Plius engine.

import { SchemaEngine, Validator } from "plius"
 
const engine = new SchemaEngine()
 
const validator = new Validator(engine.compile(
    JSON.parse(fs.readFileSync(__dirname+'/userschema.json'))))
 
const violations = validator.getViolations({ 
  name: "bob",
  email: "bob@example",
  password: "bobiscool"
})
 
console.log('Wrong fields:') 
for (const violation of violations)
  console.log(violation.path)

Results in the following output:

Wrong fields:
email
name

Which, using the translation engine, can be prettified to:

[{
  path: "email"
, message: "Input did not match pattern."
}, {
  path: "name",
, "message": "Minimum length of 5 characters required."
}]

API

import { SchemaEngine } from "plius"

new SchemaEngine(options)

  • useDefault: whether to add the default constraints and types, such as String, Boolean and Float.

Package Sidebar

Install

npm i plius

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • samvv