{"name":"data.validation","version":"1.2.0","description":"A disjunction that's more appropriate for validating inputs with better vocabulary & straight-forward failure aggregation.","main":"lib/index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"https://github.com/folktale/data.validation"},"keywords":["fantasy-land","folktale","algebraic","validation","disjunction","applicative","functor"],"author":{"name":"Quildreen Motta"},"license":"MIT","bugs":{"url":"https://github.com/folktale/data.validation/issues"},"dependencies":{},"devDependencies":{"LiveScript":"~1.2.0","hifive-tap":"~0.1.0","hifive":"~0.1.0","uglify-js":"~2.4.3","laws":"^0.2.1","claire":"~0.4.1","ink-docstrap":"git://github.com/robotlolita/docstrap","jsdoc":"^3.3.0-alpha5","browserify":"^3.41.0"},"homepage":"https://github.com/folktale/data.validation","_id":"data.validation@1.2.0","dist":{"shasum":"e23b8be64b8ffa1a0aeabcb9fb0e3f5939c2bcd5","tarball":"http://registry-npm.ywwl.com/data.validation/download/data.validation-1.2.0.tgz","integrity":"sha512-3wyX7STINY3rnBNCIJNbNxSUHMny+XoXDeF2deHKzhuJF0VXBhhS4fqcL0qv4B+/0jPveKcj4fEdHdiicQ+1jQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD75+44sbc93a6t9cmR82DG4dnIRnOMLmQawYwe5T1ocAIgZy25mDNp/YFm1XY+YL46rCnbdDexLOoFbLDE9z0TiFk="}],"size":436968,"noattachment":false,"key":"/data.validation/-/data.validation-1.2.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"killdream","email":"quildreen@gmail.com"},"maintainers":[{"name":"killdream","email":"quildreen@gmail.com"}],"directories":{},"deprecated":"This package is no longer supported. Consider switching to fp-ts","readme":"Data.Validation\n===============\n\n[![Build Status](https://secure.travis-ci.org/folktale/data.validation.png?branch=master)](https://travis-ci.org/folktale/data.validation)\n[![NPM version](https://badge.fury.io/js/data.validation.png)](http://badge.fury.io/js/data.validation)\n[![Dependencies Status](https://david-dm.org/folktale/data.validation.png)](https://david-dm.org/folktale/data.validation)\n[![stable](http://hughsk.github.io/stability-badges/dist/stable.svg)](http://github.com/hughsk/stability-badges)\n\nThe `Validation(a, b)` is a disjunction that's more appropriate for validating\ninputs, or any use case where you want to aggregate failures. Not only the\n`Validation` provides a better terminology for working with such cases\n(`Failure` and `Success` versus `Left` and `Right`), it also allows one to\neasily aggregate failures and successes as an Applicative Functor.\n\n\n## Example\n\n```js\nvar Validation = require('data.validation')\nvar Success = Validation.Success\nvar Failure = Validation.Failure\n\n// Functions that need to do validation return one of two cases:\n//\n//  -  A Success with the value they want to propagate.\n//  -  Some value representing one or more failures, using a semigroup.\n//     Lists are the more straight-forward semigroup, so we just use them\n//     here.\nfunction isPasswordLongEnough(a) {\n  return a.length > 6?    Success(a)\n  :      /* otherwise */  Failure([\"Password must have more than 6 characters\"])\n}\n\nfunction isPasswordStrongEnough(a) {\n  return /[\\W]/.test(a)?  Success(a)\n  :      /* otherwise */  Failure([\"Password must contain special characters\"])\n}\n\n// To aggregate the failures, we start with a Success case containing\n// a curried function of arity N (where N is the number of validations),\n// and we just use an `.ap`-ply chain to get either the value our Success\n// function ultimately returns, or the aggregated failures.\nfunction isPasswordValid(a) {\n  return Success(function(x){ return function(y){ return a }})\n           .ap(isPasswordLongEnough(a))\n           .ap(isPasswordStrongEnough(a))\n}\n\n\nisPasswordValid(\"foo\")\n// => Validation.Failure([\n//      \"Password must have more than 6 characters.\",\n//      \"Password must contain special characters.\"\n//    ])\n\nisPasswordValid(\"rosesarered\")\n// => Validation.Failure([\n//      \"Password must contain special characters.\"\n//    ])\n\nisPasswordValid(\"rosesarered$andstuff\")\n// => Validation.Success(\"rosesarered$andstuff\")\n```\n\n\n## Installing\n\nThe easiest way is to grab it from NPM. If you're running in a Browser\nenvironment, you can use [Browserify][]\n\n    $ npm install data.validation\n\n\n### Using with CommonJS\n\nIf you're not using NPM, [Download the latest release][release], and require\nthe `data.validation.umd.js` file:\n\n```js\nvar Validation = require('data.validation')\n```\n\n\n### Using with AMD\n\n[Download the latest release][release], and require the `data.validation.umd.js`\nfile:\n\n```js\nrequire(['data.validation'], function(Validation) {\n  ( ... )\n})\n```\n\n\n### Using without modules\n\n[Download the latest release][release], and load the `data.validation.umd.js`\nfile. The properties are exposed in the global `folktale.data.validation` object:\n\n```html\n<script src=\"/path/to/data.validation.umd.js\"></script>\n```\n\n\n### Compiling from source\n\nIf you want to compile this library from the source, you'll need [Git][],\n[Make][], [Node.js][], and run the following commands:\n\n    $ git clone git://github.com/folktale/data.validation.git\n    $ cd data.validation\n    $ npm install\n    $ make bundle\n    \nThis will generate the `dist/data.validation.umd.js` file, which you can load in\nany JavaScript environment.\n\n    \n## Documentation\n\nYou can [read the documentation online][docs] or build it yourself:\n\n    $ git clone git://github.com/folktale/data.validation.git\n    $ cd data.validation\n    $ npm install\n    $ make documentation\n\nThen open the file `docs/index.html` in your browser.\n\n\n## Platform support\n\nThis library assumes an ES5 environment, but can be easily supported in ES3\nplatforms by the use of shims. Just include [es5-shim][] :)\n\n\n## Licence\n\nCopyright (c) 2013 Quildreen Motta.\n\nReleased under the [MIT licence](https://github.com/folktale/data.validation/blob/master/LICENCE).\n\n<!-- links -->\n[Fantasy Land]: https://github.com/fantasyland/fantasy-land\n[Browserify]: http://browserify.org/\n[Git]: http://git-scm.com/\n[Make]: http://www.gnu.org/software/make/\n[Node.js]: http://nodejs.org/\n[es5-shim]: https://github.com/kriskowal/es5-shim\n[docs]: http://folktale.github.io/data.validation\n<!-- [release: https://github.com/folktale/data.validation/releases/download/v$VERSION/data.validation-$VERSION.tar.gz] -->\n[release]: https://github.com/folktale/data.validation/releases/download/v1.3.0/data.validation-1.3.0.tar.gz\n<!-- [/release] -->\n\n","publish_time":1397318715601,"_cnpm_publish_time":1397318715601,"dist-tags":{"latest":"1.3.1"}}