{"id":20818496,"url":"https://github.com/yusangeng/io-validate","last_synced_at":"2025-10-16T20:15:47.192Z","repository":{"id":57275627,"uuid":"63784467","full_name":"yusangeng/io-validate","owner":"yusangeng","description":"Javascript data validator.","archived":false,"fork":false,"pushed_at":"2024-01-09T07:34:13.000Z","size":673,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-07T14:07:32.938Z","etag":null,"topics":["data-verification"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/io-validate","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/yusangeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-07-20T13:38:59.000Z","updated_at":"2024-09-19T08:33:46.000Z","dependencies_parsed_at":"2022-09-15T19:12:54.685Z","dependency_job_id":null,"html_url":"https://github.com/yusangeng/io-validate","commit_stats":null,"previous_names":["yusangeng/param-check"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusangeng%2Fio-validate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusangeng%2Fio-validate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusangeng%2Fio-validate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusangeng%2Fio-validate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yusangeng","download_url":"https://codeload.github.com/yusangeng/io-validate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252892503,"owners_count":21820648,"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-verification"],"created_at":"2024-11-17T21:47:05.266Z","updated_at":"2025-10-16T20:15:47.085Z","avatar_url":"https://github.com/yusangeng.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# io-validate\n\n[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Build Status](https://travis-ci.org/yusangeng/param-check.svg?branch=master)](https://travis-ci.org/yusangeng/param-check) [![Coverage Status](https://coveralls.io/repos/github/yusangeng/param-check/badge.svg?branch=master)](https://coveralls.io/github/yusangeng/param-check?branch=master) [![Npm Package Info](https://badge.fury.io/js/io-validate.svg)](https://www.npmjs.com/package/io-validate) [![Downloads](https://img.shields.io/npm/dw/io-validate.svg?style=flat)](https://www.npmjs.com/package/io-validate)\n\nRuntime data validator.\n\n## Note\n\n- This package used to be named `param-check`.\n\n## Install\n\n```\nnpm install io-validate --save\n```\n\n## Usage\n\n### Basic usage\n\n```js\nimport v from 'io-validate';\n\nfunction fn(arg1, arg2) {\n  v(arg1).isString();\n\n  // If you want to print variable name, pass name as the 2nd parameter.\n  v(arg2, 'arg2').greaterThan(1).lessThan(2);\n}\n```\n\n### `not` operator\n\n```js\nimport v from 'io-validate';\n\nfunction fn(arg) {\n  v(arg).not.isString();\n}\n```\n\n### Chain call\n\nAll validators of io-validate support chain calls. A chain call means an \"and\" expression.\n\n```js\nimport v from 'io-validate';\n\nfunction fn(arg) {\n  v(arg).gt(1).lt(2); // arg \u003e 1 \u0026\u0026 arg \u003c 2\n}\n```\n\n### Specific validator\n\nIf you want smaller dependence size, just import specific validators.\n\n```js\nimport v from 'io-validate/minimum';\nimport isString from 'io-validate/lib/validators/isString';\n\nv.register(isString);\n\nfunction fn(arg) {\n  v(arg).isString();\n}\n```\n\n### Custom validator\n\n```js\nimport v from 'io-validate';\nimport isNumber from 'lodash/isNumber';\n\nfunction isEven(target, name) {\n  return isNumber(target) \u0026\u0026 !(target % 2);\n}\n\ncheck.register('isEven', isEven);\n\nfunction fn(arg) {\n  v(arg).isEven();\n}\n```\n\n### Custom chain\n\n```js\nimport v from 'io-validate'\n\nfunction isEven (target, name) {\n  return !(target % 2)\n}\n\nfunction isOdd (target, name) {\n  return target % 2\n}\n\nfunction next (target) {\n  return return target + 1\n}\n\nv.register('isEven', isEven, next)\nv.register('isOdd', isOdd, next)\n\nfunction fn (arg) {\n\tv(arg).isEven().isOdd()\n}\n```\n\n### Plan\n\n**plan** is used to generate combinable validators.\n\nBy contrast, `v('').isString()` executes the validator `isString` immediatly, `v.plan.isString()` doesn't execute any validator, just return a combinable `isString` validator.\n\n```js\nimport v from 'io-validate';\n\nv('').isString();\n\nv('').or(v.plan.isString, v.plan.isNumber);\n```\n\n## Validators\n\n#### same\n\nValidate that the input value is the same to ('===') the reference value.\n\n```js\nv(1).same(1);\n\nv({ a: 1 }).same({ a: 1 }); // Bang!\n```\n\n#### among\n\nValidate that the input value is among the reference options.\n\n```js\nv(1).among(1, 2, 3, 4);\n```\n\n#### equal | eq\n\nValidate that the input value is equal to the reference value.\n\nYou may pass in a custom equal function instead of the default equal algorithm which is a simplified implemention of deep-equal.\n\n```js\nv(1).equal(1);\nv(1).eq(1);\n\nv('foobar').equal('Foobar', (left, right) =\u003e left.toLowerCase() === right.toLowerCase());\n```\n\n#### equalOrGreaterThan | egt\n\nValidate that the input number is equal to or greater than the reference number.\n\n```js\nv(1).equalOrGreaterThan(0);\nv(1).egt(1);\n```\n\n#### equalOrLessThan | elt\n\nValidate that the input number is equal to or less than the reference number.\n\n```js\nv(1).equalOrLessThan(2);\nv(1).elt(1);\n```\n\n#### greaterThan | gt\n\nValidate that the input number is greater than the reference number.\n\n```js\nv(1).greaterThan(0);\nv(1).gt(0);\n```\n\n#### lessThan | lt\n\nValidate that the input number is less than the reference number.\n\n```js\nv(1).lessThan(2);\nv(1).lt(2);\n```\n\n#### within\n\nValidate that the input number is whthin the reference range(s).\n\nSyntax:\n\n- Open range is denoted in parentheses.\n- Closed range is denoted by square brackets.\n\n```js\nv(1).within('(0, 2)', '[-1, 3.5]');\n\nv(0).within('[0, 1)', '(-1, 0]');\n```\n\n#### is | isXXX\n\nRuntime type checking based on lodash.\n\n```\nv(1).is('number', 'string') // number or string\n\nv(1).isNumber()\n```\n\n##### lodash type validators\n\n```js\nvar isArguments = require('lodash/isArguments');\nvar isArray = require('lodash/isArray');\nvar isArrayBuffer = require('lodash/isArrayBuffer');\nvar isArrayLike = require('lodash/isArrayLike');\nvar isArrayLikeObject = require('lodash/isArrayLikeObject');\nvar isBoolean = require('lodash/isBoolean');\nvar isBuffer = require('lodash/isBuffer');\nvar isDate = require('lodash/isDate');\nvar isElement = require('lodash/isElement');\nvar isEmpty = require('lodash/isEmpty');\nvar isError = require('lodash/isError');\nvar isFunction = require('lodash/isFunction');\nvar isLength = require('lodash/isLength');\nvar isMap = require('lodash/isMap');\nvar isNative = require('lodash/isNative');\nvar isNil = require('lodash/isNil');\nvar isNull = require('lodash/isNull');\nvar isNumber = require('lodash/isNumber');\nvar isObject = require('lodash/isObject');\nvar isObjectLike = require('lodash/isObjectLike');\nvar isPlainObject = require('lodash/isPlainObject');\nvar isRegExp = require('lodash/isRegExp');\nvar isSet = require('lodash/isSet');\nvar isString = require('lodash/isString');\nvar isSymbol = require('lodash/isSymbol');\nvar isTypedArray = require('lodash/isTypedArray');\nvar isUndefined = require('lodash/isUndefined');\nvar isWeakMap = require('lodash/isWeakMap');\nvar isWeakSet = require('lodash/isWeakSet');\n```\n\n#### Other type validators\n\n```js\nvar isExist = function isExist(o) {\n  return !(isUndefined(o) || isNull(o));\n};\n```\n\n#### instanceOf\n\nValidate that the input value is an instance of the reference class.\n\nWe use the keyword 'instanceof' to implement this validator.\n\n```js\nclass Foobar {}\nconst fb = new Foobar();\n\nv(fb).instanceOf(fb);\n```\n\n#### isArrayOf\n\nValidate that the input value is an array of valid values.\n\n```js\nv(fb).isArrayOf(fb, (el) =\u003e el % 2);\n```\n\n#### match\n\nRegular expression validator.\n\n```js\nv('foobar42').match(/\\w+\\d+/);\n```\n\n#### patterns\n\nCommon regular expression validators.\n\n##### Available validators:\n\n- matchEmail\n- matchURL\n- matchIP\n\n```js\nv('yusangeng@github.com').matchEmail();\n```\n\n#### has | hasOwn\n\nValidate that the input value has an OWN property of the reference name.\n\nhas() returns a validatable object that encapsulates the validated property if it exists.\n\nIf you want the validatable object that encapsulates the origin input value, use \"owner\" or \"\\_\" operator.\n\n```js\nconst obj = {\n  a: {\n    b: {\n      c: 'foobar',\n    },\n  },\n};\n\nv(obj).has('a').has('b').has('c');\nv(obj).has('a').owner.has('a').owner.has('c');\nv(obj).has('a')._.has('a')._.has('a');\n```\n\n#### got\n\nValidate that the input value has a property (maybe NOT own property) of the reference name.\n\n```js\nconst obj = {\n  a: {\n    b: {\n      c: 'foobar',\n    },\n  },\n};\n\nv(obj).got('a').got('b').got('c');\nv(obj).got('a').got('__proto__').got('constructor');\n```\n\n#### length\n\nEquivalent of validator `got('length')`.\n\n```js\nconst arr = [1, 2, 3];\n\nv(arr).length().eq(3);\n```\n\n#### and\n\nValidator of \"and\" expression.\n\nIt is often better to express \"and\" relationships using chain calls, but this API combines functions and plans.\n\n```js\nv('Foobar').and(v.plan.isString, (target) =\u003e {\n  return target.toLowerCase() === 'foobar';\n});\n```\n\n#### or\n\nValidator of \"or\" expression.\n\n```js\nv(1).or(\n  v.plan.isString,\n  v.plan.and(v.plan.isNumber(), (target) =\u003e target % 2)\n);\n```\n\n#### meet\n\nSingle parameter version of validator `and()`.\n\n```js\nv('Foobar').meet(v.plan.isString);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusangeng%2Fio-validate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusangeng%2Fio-validate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusangeng%2Fio-validate/lists"}