1.6.5 • Published 2 years ago

another-fluent-validator v1.6.5

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

npm version Dependencies devDependencies Status

another-fluent-validator

Simple validator, but with an fluent interface

Features

  • Validate and assign in an fluent way
  • casting numeric values directly to number
  • additional static interface wich returns boolean

Installation

npm install another-fluent-validator

Examples

fluent interface

const FluentValidator = require('another-fluent-validator')

// example object
const myDirtyObject = {
  code: 'ABC'
  name: '',
  value: '123'
}

let code = new FluentValidator(myDirtyObject.code, 'my code')
  .isString()
  .isNotEmpty()
  .value
// -> wil set code to 'ABC'

let name  = new FluentValidator(myDirtyObject.name, 'my name')
  .isString()
  .isNotEmpty()
  .hasMinimumLength(3)
  .value
// -> will throw Error with message: "my name should not be empty"

let value  = new FluentValidator(myDirtyObject.value, 'my value')
  .toInteger()
// -> checks if "isNumeric" and casts to number (value = 123)
}

static interface

Cant be use as pre-check (e.g. only validate when defined)

FluentValidator.isArray('abc') // -> returns false

Contributing & Development

Style

https://github.com/standard/standard

Testing

Run mocha tests:

npm test

Check code coverage (creates "./coverage/index.html"):

npm run-script cover

1.6.5

2 years ago

1.6.4

2 years ago

1.6.3

4 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago