{"id":19921871,"url":"https://github.com/dhershman1/simply_valid","last_synced_at":"2025-05-03T07:30:30.395Z","repository":{"id":57361567,"uuid":"89741734","full_name":"dhershman1/simply_valid","owner":"dhershman1","description":"A simple to use data driven validation system","archived":false,"fork":false,"pushed_at":"2019-01-31T17:22:08.000Z","size":663,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T00:38:51.425Z","etag":null,"topics":["data","easy-to-use","plug-and-play","simple","validation"],"latest_commit_sha":null,"homepage":"http://simply_valid.dusty.codes","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhershman1.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-28T20:17:59.000Z","updated_at":"2019-02-27T15:18:29.000Z","dependencies_parsed_at":"2022-09-26T16:41:00.447Z","dependency_job_id":null,"html_url":"https://github.com/dhershman1/simply_valid","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhershman1%2Fsimply_valid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhershman1%2Fsimply_valid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhershman1%2Fsimply_valid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhershman1%2Fsimply_valid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhershman1","download_url":"https://codeload.github.com/dhershman1/simply_valid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252156692,"owners_count":21703327,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","easy-to-use","plug-and-play","simple","validation"],"created_at":"2024-11-12T22:08:42.397Z","updated_at":"2025-05-03T07:30:30.099Z","avatar_url":"https://github.com/dhershman1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/simply_valid.svg?style=flat-square)](https://www.npmjs.com/package/simply_valid)\n[![David](https://img.shields.io/david/dhershman1/simply_valid.svg?style=flat-square)](https://david-dm.org/dhershman1/simply_valid)\n[![David](https://img.shields.io/david/dev/dhershman1/simply_valid.svg?style=flat-square)](https://david-dm.org/dhershman1/simply_valid?type=dev)\n[![Travis](https://img.shields.io/travis/dhershman1/simply_valid.svg?style=flat-square)](https://travis-ci.org/dhershman1/simply_valid)\n[![Coverage Status](https://img.shields.io/coveralls/github/dhershman1/simply_valid.svg?style=flat-square)](https://coveralls.io/github/dhershman1/simply_valid?branch=master)\n\n![main-mid](https://user-images.githubusercontent.com/8997380/49965860-6977dc80-feec-11e8-90ae-3bcbe43639b3.png)\n\nA simple and lightweight validation system. Ships with prebuilt rules and accepts custom rules.\n\n## Documentation\n\nFind individual documentation per function on the site: **[You can click here to go there](https://simply_valid.dusty.codes)**\n\n## Content\n* [Philosophy](#philosophy)\n* [Parameters](#parameters)\n* [Usage](#usage)\n* [Schema](#schema)\n* [Custom Rules](#custom-rules)\n* [Return](#return)\n\n## Philosophy\n\nThe idea behind `simply_valid` was a ui free data driven validation system. It started as something I wanted at work over our current validation library and then grew into this. (You can see the inspiration of some of the validation types that lives currently in the functions)\n\nI wanted this module to be `fast`, `easy to use`, and above all as `plug and play` as I could get it.\n\nWith the schema system in place for the module you can easily validate complex objects such as form data put into an object, applying an array of rules or even just a single rule to your data value. Making it easy to create validation `instances` for different forms or multiple data styles.\n\n## Parameters\n\n- `schema` - `Object`: An object of rules to overwrite the default rules\n- `data` - `String|Array|Object`: Data is the value sent in with the 2nd call made to simplyValid (curried call)\n\n## Usage\n\nUsing Standard JS\n```js\nimport { validate } from 'simply_valid'\n\nvalidate(schema, data)\n\n// Or\nconst valid = validate(schema)\n\nvalid(data)\n```\n\nUsing commonjs\n```js\nconst { validate } = require('simply_valid')\n\nvalidate(schema, data)\n\n// Or\nconst valid = validate(schema)\n\nvalid(data)\n```\n\nUsing a CDN\n```html\n\u003c!-- It is recommended to replace @latest with a strict version number --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/simply_valid@latest/dist/simply-valid.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  validate(schema, data)\n\n  // Or\n  const valid = validate(schema)\n\n  valid(data)\n\u003c/script\u003e\n```\n\nIn the browser\n```html\n\u003cscript src=\"path/to/dist/simplyValid.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  validate(schema, data)\n\n  // Or\n  const valid = validate(schema)\n\n  valid(data)\n\u003c/script\u003e\n```\n\n## Schema\n\nSimply_Valid supports a schema system, the schema should be either an `Array` or `Object` type. Even when using just one function\n\n\u003e **Note** If you are validating an object the schema **MUST** also be an object\n\nExamples:\n```js\nimport { validate, hasValue, isNumber, isPositive, hasLetters, hasNumbers, isZip, noNumbers } from 'simply_valid'\n\n// Single/Primitive data value\nvalidate([isNumber], 2) // =\u003e { isValid: true }\nvalidate([isNumber, isPositive], 3) // =\u003e { isValid: true }\n\n// Array of Data\nvalidate([isNumber], [1, 2, 3]) // =\u003e { isValid: true }\nvalidate([isNumber, isPositive], [1, 2, 3]) // =\u003e { isValid: true }\nvalidate([isNumber, isPositive], [1, 2, -3]) // =\u003e { isValid: false, rule: 'isPositive', data: [1, 2, -3] }\n\n// Object of Data\nvalidate({\n  zip: isZip,\n  address: [hasLetters, hasNumbers]\n}, {\n  zip: 11234,\n  address: '123 test dr'\n}) // =\u003e { isValid: true }\n\n// Object with nested data\nvalidate({\n  zip: isZip,\n  address: validate({ num: isNumber, name: [hasLetters, noNumbers] })\n}, {\n  zip: 11234,\n  address: {\n    num: 123,\n    name: 'test dr'\n  }\n}) // =\u003e { isValid: true }\n```\n\n## Custom Rules\n\nSimply_Valid also supports the use of custom rules\n\n- Custom rules returns will be treated on a true/false basis so try to have them return a boolean\n- If you want a multi param rules name to show up in a failure make sure you name the inner function\n- The inner function should be the same name but with an underscore at the start (it will be formatted out)\n\n```js\nimport { validate } from 'simply_valid'\n\nconst isEven = val =\u003e val % 2 === 0\n// For multi param functions you need to use the function keyword\n// If you want the name to show up in failures, it also relies on partial execution\nconst notMin = function notMin (min) {\n  // The inner function should be named the same but with a _ in front of it\n  // (This gets removed when you get the rule)\n  // This ensures you get an accurate rule back in your object\n  return function _notMin (val) {\n    return val !== min\n  }\n}\nconst schema = {\n  foo: isEven,\n  bar: [isEven, notMin(4)]\n}\n\nvalidate(schema, { foo: 4, bar: 6 }) // =\u003e { isValid: true }\nvalidate(schema, { foo:4, bar: 4 }) // =\u003e { isValid: false, rule: 'notMin', data: 4 }\nvalidate(schema, { foo:4, bar: 5 }) // =\u003e { isValid: false, rule: 'isEven', data: 5 }\n```\n\n## Return\n\nSimply_Valid will return upon the first failing rule it finds, with information about the failure.\n\n```js\n// Passing Validation\n{ isValid: true }\n\n// Failing returns will look like this\n{\n  isValid: false,\n  prop: 'propName',\n  rule: 'functionName'\n  data: 'cool'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhershman1%2Fsimply_valid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhershman1%2Fsimply_valid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhershman1%2Fsimply_valid/lists"}