ramda-fantasy-validation
Fantasy Land compatible Validation with Ramda.
Last updated 4 years ago by mrkm4ntr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ramda-fantasy-validation 
SYNC missed versions from official npm registry.

ramda-fantasy-validation

npm version

Fantasy Land compatible Validation with Ramda.

Example

var Validation = require('ramda-fantasy-validation');
var R = require('ramda');

function validateName(name) {
  if (name.length > 0) {
    return Validation.of(name);
  }
  return Validation.failure(['Name is required.']);
}

function validateAge(age) {
  if (age >= 18) {
    return Validation.of(age);
  }
  return Validation.failure(['Age must be or over 18.']);
}

function createUser(name, age) {
  return { 'name': name, 'age': age };
}

// Validation.Success({"age": 99, "name": "mrkm4ntr"})
validateName('mrkm4ntr').map(R.curry(createUser)).ap(validateAge(99));
// or 
Validation.liftAN(2, createUser)(validateName('mrkm4ntr'))(validateAge(99));

// Validation can accumulate error informations.
// Validation.Failure(["Name is required.", "Age must be or over 18."])
Validation.liftAN(2, createUser)(validateName(''))(validateAge(17));

Current Tags

  • 0.2.0                                ...           latest (4 years ago)

2 Versions

  • 0.2.0                                ...           4 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (5)

Copyright 2014 - 2017 © taobao.org |