{"_id":"fire-validations","_rev":"7-a2673ef288b65ebf78dd277d09dc63ec","name":"fire-validations","description":"Validation expressions for fire.js","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"fire-validations","description":"Validation expressions for fire.js","version":"0.1.0","homepage":"http://firejs.firebase.co","author":{"name":"Firebase.co","email":"npm@firebase.co","url":"http://www.firebase.co"},"main":"./index.js","repository":{"type":"git","url":"git://github.com/firejs/fire-validations.git"},"bugs":{"email":"firejs@firebase.co","url":"https://github.com/firejs/fire-validations/issues"},"keywords":["fire","fire.js","assert","validation","validations","input","ignitable"],"devDependencies":{"vows":">= 0.5.11"},"dependencies":{"fire":">= 0.1.0","fire-i18n":">= 0.1.0","fire-assert":">= 0.1.0"},"engines":{"node":">= 0.4.5"},"scripts":{"test":"make"},"licenses":[{"type":"MIT","url":"https://github.com/firejs/fire-validations/blob/master/LICENSE"}],"_npmUser":{"name":"firebaseco","email":"npm@firebase.co"},"_id":"fire-validations@0.1.0","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.4.5","_defaultsLoaded":true,"dist":{"shasum":"6bf6a7afddd5845c5195f9c5540c9e3ddd88d485","tarball":"https://registry.npmjs.org/fire-validations/-/fire-validations-0.1.0.tgz","integrity":"sha512-nFp9p3uT3dwXyE/RhJutRuTITPiiy+XBTN9/L/nAqWvMhot8/s41BcjoLAkU/J1FuoWDtgKRFP+L+SLRj0WqpQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBrQlF63ZTH3vtyuTUF+t4K+h0cdfKXgOojBqKgE7pt4AiBqiMD2B9lrE6lfVxGRLG5NBwejlH5+HwzC6AMC2AUAXg=="}]},"maintainers":[{"name":"firebaseco","email":"npm@firebase.co"}]},"0.1.1":{"name":"fire-validations","description":"Validation expressions for fire.js","version":"0.1.1","homepage":"http://firejs.firebase.co","author":{"name":"Firebase.co","email":"npm@firebase.co","url":"http://www.firebase.co"},"main":"./index.js","repository":{"type":"git","url":"git://github.com/firejs/fire-validations.git"},"bugs":{"email":"firejs@firebase.co","url":"https://github.com/firejs/fire-validations/issues"},"keywords":["fire","fire.js","assert","validation","validations","input","ignitable"],"devDependencies":{"vows":">= 0.5.11"},"dependencies":{"fire":">= 0.1.1","fire-i18n":">= 0.1.0","fire-assert":">= 0.1.1"},"engines":{"node":">= 0.4.5"},"scripts":{"test":"make"},"licenses":[{"type":"MIT","url":"https://github.com/firejs/fire-validations/blob/master/LICENSE"}],"_npmUser":{"name":"firebaseco","email":"npm@firebase.co"},"_id":"fire-validations@0.1.1","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.3","_defaultsLoaded":true,"dist":{"shasum":"41827fbd80044e5b2f29d6fb754b91e8a5cc1a4e","tarball":"https://registry.npmjs.org/fire-validations/-/fire-validations-0.1.1.tgz","integrity":"sha512-YlAYcdMgiEkoJEjjHtAiIBhIEJyBN+YQBTElk0rEu/gRAagatNB2iV0wibMf76cwJ6irvxn9R29FV7W5o6bMRg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDbBbbsT0Om/QUcXlGjfcaMMZJOIVlDJxLQYj7FeGYb2gIgPV16TEH65hc7mb9dPhowax8nY1+GeULqvrrfBT/twDo="}]},"maintainers":[{"name":"firebaseco","email":"npm@firebase.co"}]}},"readme":"#fire-validations\n\nValidations module for [fire.js](https://github.com/firejs/firejs) and  [fire-assert](https://github.com/firejs/fire-assert)\n***\n\n## Installing\n\n### using NPM\n\n    npm install fire-validations\n\n### using Github(unstable)\nIn the root of your project run:\n\n    git clone git://github.com/firejs/fire-validations.git node_modules/fire-validations\n\n## Introduction\n\nValidation works providing the context for assertions based on [fire-assert](https://github.com/firejs/fire-assert) and tracking the paths of the errors found.\n\n## Expressions\n\n### @Validations.Context\n\nExecutes a set of validations on a variable path given in the hint. Returns an array with all the errors found. A variable called \"validation\" is provided in the input and contains the context of the current validation and also the path. \"validation.target\" contains what is the object being validated and \"validation.path\" contains what is the path of the validation.\n\n### @Validations.Property\n\nTakes a hint with the name of the member to validate in the current target. Bypass the result in the block.\n\n### @Validations.Array\n\nTakes a hint with the name of the array to validate in the current target. Executes the input per item in the array. If the member is not an array it will bypass. Bypass the result in the block.\n\nThe member name in the hint is optional, this way to can validate the current target as an array.\n\n**Note:** `@Validations.Array` is not a loop, using `@break` or `@continue` will not affect the iteration. If you want to interrupt the sequence on the first error in the array use `@Validations.Checkpoint`.\n\n### @Validations.Checkpoint\n\nCheck for errors reported by previous validations and stop the execution of further validations, otherwise it just bypass:\n\nExample:\n\n    \"@Validations.Context(contacts)\": {\n\t\t\"@Validations.Property(name)\": {\n\t\t\t\"@Assert.NotEmpty\": null\n\t\t},\n\t\t\"@Validations.Property(age)\": {\n\t\t\t\"@Assert.NotEmpty\": null\n\t\t},\n\t\t\"@Validations.Checkpoint\": null,\n\t\t\"@Validations.Property(tags)\": {\n\t\t\t\"@Assert.NotEmpty\": null\n\t\t}\n\t}\n\n## Examples:\n\n### Validating a Simple Field\n\n    \"@set(person)\": {\n\t\t\"email\": \"\"\n\t},\n\t\"@Validations.Context(person)\": {\n\t\t\"@Validations.Property(email)\": {\n\t\t\t\"@Assert.NotEmpty\": null\n\t\t}\n\t}\n\nThe result:\n\n    [{\"path\":\"/email\",\"message\":\"Can't be empty\"}]\n\n### Validating an Array\n\n    \"@set(person)\": {\n\t\t\"emails\": [\"chuch@examplecom\", \"chuch at examplescom\"]\n\t},\n\t\"@Validations.Context(person)\": {\n\t\t\"@Validations.Array(emails)\": {\n\t\t\t\"@Assert.NotEmpty\": null,\n\t\t\t\"@Assert.Email\": null\n\t\t}\n\t}\n\nThe result, both email addresses are invalid so we get two messages:\n\n    [{\"path\":\"/emails/0\",\"message\":\"Not a valid Email address\"},{\"path\":\"/emails/1\",\"message\":\"Not a valid Email address\"}]\n\n### Validating nested objects in Arrays\n\n    \"@set(categories)\": [\n\t\t{\n\t\t\t\"name\": \"Category A\",\n\t\t\t\"description\": null \n\t\t},\n\t\t{\n\t\t\t\"description\": \"Description for Category B\" \n\t\t}]\n\t,\n\t\"@Validations.Context(categories)\": {\n\t\t\"@Validations.Array\": {\n\t\t\t\"@Validations.Property(name)\": {\n\t\t\t\t\"@Assert.NotEmpty\": null\n\t\t\t},\n\t\t\t\"@Validations.Property(description)\": {\n\t\t\t\t\"@Assert.NotEmpty\": null\n\t\t\t}\n\t\t}\n\t}\n\nThe result:\n\n    [{\"path\":\"/0/description\",\"message\":\"Can't be empty\"},{\"path\":\"/1/name\",\"message\":\"Can't be empty\"}]\n\n\n## Understanding Paths\n\npaths provide an easy and readable way to know at which level of the object the error occurred.\n\nAll the paths begins with slash '/', this is known as the `root of the validation` which is the value in the variable path to `@Validations.Context`. A slash is also the separator of the path.\n\nExamples:\n\n* `/`: the error was reported at the root value.\n* `/name`: the error was reported at the *name* property .\n* `/tags/0/`: the error was reported at the index *0* of the *tags* array.\n* `/tags/0/name`: the error was reported at the property *name* of the index *0* of the *tags* array.\n* `/0`: the root value is an `Array` and the error was reported at index *0*. \n\n## Considerations with empty values.\n\nA validator will validate only a certain aspect of the logic and just bypass if they can't accomplish the validation, the goal of this is to avoid repeating validation logic across different validators. \n\nIn the following example the Email validator will not report any error because the field is empty:\n\n    \"@set(contact)\": {\n        \"email\": null\n    }\n    ,\n    \"@Validations.Context(contact)\": {\n        \"@Validations.Property(email)\": {\n            \"@Assert.Email\": null\n        }\n    }\n\nThis makes sense because Email will only validate if the value matches an email address, it will not validate the presence of the field because that's not part of what 'validating the email address' means, in fact, checking if the field is empty or not is part of another validator called `@Assert.NotEmpty`.\n\nThis is when you must use multiple validators over the same field.\n\nLike this:\n\n    {\n\t    \"name\": \"TestVal.Main\",\n\t    \"json\": {\n\t        \"@set(contact)\": {\n\t            \"email\": null\n\t        }\n\t        ,\n\t        \"@Validations.Context(contact)\": {\n\t            \"@Validations.Property(email)\": {\n\t\t\t\t\t\"@Assert.NotEmpty\": null,\n\t                \"@Assert.Email\": null\n\t            }\n\t        }\n\t    }\n\t}\n\nThe result:\n\n    [{\"path\":\"/email\",\"message\":\"Can't be empty\"}]\n\nStill you will not see the Email validator reporting any error because NonEmpty is reporting first. This situations changes when Email validator founds a value to validate like in the following example:\n\n    {\n\t    \"name\": \"TestVal.Main\",\n\t    \"json\": {\n\t        \"@set(contact)\": {\n\t            \"email\": \"some invalid email value\"\n\t        }\n\t        ,\n\t        \"@Validations.Context(contact)\": {\n\t            \"@Validations.Property(email)\": {\n\t\t\t\t\t\"@Assert.NotEmpty\": null,\n\t                \"@Assert.Email\": null\n\t            }\n\t        }\n\t    }\n\t}\n\nThe result:\n\n    [{\"path\":\"/email\",\"message\":\"Not a valid Email address\"}]\n\nNow you see the Email validator doing it's job.\n\n## Localization Support\n\n`fire-validations` has built-in support for a small set of languages via [fire-i18n](https://github.com/firejs/fire-i18n), [check the wiki for more information](https://github.com/firejs/fire-validations/wiki/Localization).\n\n## Reporting validation errors\n\nIf you want to report validations errors you can use `@Validations.Error`, which input is the message of the error:\n\nExample\n\n    @Validations.Context(contacts)\": {\n\t\t\"@Validations.Error\": \"This is my custom error report\"\n\t}\n\t\nThe result is:\n\n    [{ \"path\": \"/\", \"message\": \"This is my custom error report\" }]\n\n## Cloning the Repository\n\n    git clone git://github.com/firejs/fire-validations.git\n\n\n## Tests\n\n    make\n\n### Contributors\n\n* Johan (author). Email: *johan@firebase.co*\n\n## MIT License\n\nCopyright (c) 2011 Firebase.co - http://www.firebase.co\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.","maintainers":[{"name":"firebaseco","email":"npm@firebase.co"}],"time":{"modified":"2022-06-18T01:01:30.247Z","created":"2011-11-21T07:47:23.713Z","0.1.0":"2011-11-21T07:47:24.792Z","0.1.1":"2011-12-29T22:17:09.616Z"},"author":{"name":"Firebase.co","email":"npm@firebase.co","url":"http://www.firebase.co"},"repository":{"type":"git","url":"git://github.com/firejs/fire-validations.git"}}