{"id":40604146,"url":"https://github.com/stetsd/univalid","last_synced_at":"2026-01-21T04:38:39.141Z","repository":{"id":57386526,"uuid":"123389599","full_name":"stetsd/univalid","owner":"stetsd","description":"Universal validator for server and client side","archived":false,"fork":false,"pushed_at":"2018-07-04T03:54:58.000Z","size":9,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-11T05:03:56.599Z","etag":null,"topics":["client-server","form","javascript","js","univalid","univalid-strategy","univalid-strategy-default","univalid-strategy-form","universal-validator","validate","validation","validator"],"latest_commit_sha":null,"homepage":"https://stetsd.github.io/univalid-sandbox/public/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stetsd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-01T06:00:14.000Z","updated_at":"2018-07-04T03:54:59.000Z","dependencies_parsed_at":"2022-09-26T16:31:17.804Z","dependency_job_id":null,"html_url":"https://github.com/stetsd/univalid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stetsd/univalid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stetsd%2Funivalid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stetsd%2Funivalid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stetsd%2Funivalid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stetsd%2Funivalid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stetsd","download_url":"https://codeload.github.com/stetsd/univalid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stetsd%2Funivalid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28626553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T02:47:06.670Z","status":"ssl_error","status_checked_at":"2026-01-21T02:45:44.886Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["client-server","form","javascript","js","univalid","univalid-strategy","univalid-strategy-default","univalid-strategy-form","universal-validator","validate","validation","validator"],"created_at":"2026-01-21T04:37:58.147Z","updated_at":"2026-01-21T04:38:36.204Z","avatar_url":"https://github.com/stetsd.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# univalid\n\nUniversal validation module. It may use different strategies for client validation, server validation and more.\n\nIn current moment exists two strategies:\n\n- [univalid-strategy-default](https://github.com/StetsD/univalid-strategy-default) (use by default)\n- [univalid-strategy-form](https://github.com/StetsD/univalid-strategy-form)\n\n## Install\n\n```sh\nnpm i univalid\n```\n\n\n## Base usage\n\n```js\nconst Univalid = require('univalid');\nconst univalid = Univalid();\n\nunivalid.check([\n    {\n        name: 'login',\n        val: 'User01',\n        type: 'required'\n    },\n    {\n        name: 'email',\n        val: 'test@test.ts',\n        type: 'email'\n    },\n    {\n        name: 'password',\n        val: undefined,\n        type: 'password'\n    }\n]);\n\nconsole.log(univalid.getCommonState, univalid.getState);\nunivalid.clearState();\n\n```\n\n\n## API\n\n\n### check(pack)\n\nValidating the pack\n\n**pack** - Type `object`\n\nStructure of pack must be strict.\n\n- packItem.name - Type `string` - (required) - filed name\n- packItem.type - Type `string` - (required) - by default has: 'required', 'email', 'password', 'equal'\n- packItem.val - Type `string` - (required) value of field\n- packItem.filter - Type `boolean` - filter type (see more [univalid-strategy](https://github.com/StetsD/univalid-strategy))\n- packItem.msg - Type `boolean` - message config. See in example below\n\nname, val, type - required fields\n```js\n//name, val, type - required fields\n\nunivalid.check(\n    [\n        {\n            name: 'username',\n            val: 'Uriy',\n            type: 'required',\n            filter: 'oL',\n            msg: {\n                empty: 'You shall not pass',\n                invalid: 'Validation error',\n                filter: 'Filter error',\n                success: 'All right'\n            }\n        },\n        {\n            name: 'email',\n            val: 'Uriy@mzf.com',\n            type: 'email',\n            filter: val =\u003e {\n                // Your custom filter\n                \n                console.log('Filter', val);\n                \n                // if FilterHandler is Ok then \"return true\"\n                    return true;\n                // else return false\n            },\n            msg: {\n                empty: 'You shall not pass',\n                invalid: 'Bad email',\n                filter: 'Only lat/numbers/specials symbols',\n                success: 'All right'\n            }\n        }\n    ]\n);\n\n```\n\n\n### setStrategy(strategy)\n\nSet new Strategy of validation\n\n**strategy** - Type `object` - instance of strategy\n\n```js\nconst UnivalidStrategyForm = require('univalid-strategy-form');\n\nunivalid.setStrategy(\n    UnivalidStrategyForm({\n        core: univalid, /* required prop */\n        $form: '.js-reg-form' /* required prop */\n    })\n);\n```\n\n\n### setValidHandler(pack)\n\nSet new Validation Handler\n\n**pack** - Type `object`\n\nNew validationHandler must return true\\false how result validation of field\n\n```js\nunivalid.setValidHandler({\n    'newValidator': val =\u003e {\n        console.log(val, 'Valid');\n        return true;\n    }\n});\n```\n\n\n### setMsgConfig(config)\n\nSet new  Default Message config\n\nIf in item of validation pack not define 'msg' field, will be message from msgConfig be default \n\n**config** - Type `object`\n\n```js\nunivalid.setMsgConfig({\n    empty: 'NEW EMPTY ERROR', \n    invalid: 'NEW INVALID', \n    filter: \"NEW FILTER\", \n    success: 'NEW SUCCESS'\n});\n```\n\n\n### toggleDefaultMsgConfig()\n\nToggle to default and common configuration of messages.\n\nThis configuration is common for all univalid modules.\n\n```js\nunivalid.toggleDefaultMsgConfig(); // default msgConfig\nunivalid.toggleDefaultMsgConfig(); // msgConfig of instance\n```\n\n\n### setDefaultMsgConfig(config)\n\nSet new Common Message config \n\n**config** - Type `object`\n\n```js\nunivalid.setMsgConfig({\n    empty: 'NEW COMMON EMPTY ERROR', \n    invalid: 'NEW COMMON INVALID', \n    filter: \"NEW COMMON FILTER\", \n    success: 'NEW COMMON SUCCESS'\n});\n\n//or\n\nunivalid.setMsgConfig({\n    empty: 'NEW COMMON EMPTY ERROR'\n});\n \n```\n\n\n### set(option, val)\n\nSet new prop to your current strategy of validation \n\n**option** - Type `string`\n\n```js\nunivalid.set('core', univalid);\n```\n\n\n### get(prop, args)\n\nGet prop your current strategy or call the method your strategy.  \n\n**prop** - Type `string`\n\n**args** - if it a method of strategy\n\n```js\n\n//univalid-strategy-form example\n\nunivalid.get('addEvent', {\n    newEvent(){document.addEventListener('click', ()=\u003e{\n\t    console.log('Click in document!');\n    })}\n});\n\nunivalid.get('clsConfig');\n\n```\n\n\n### clearState()\n\nClear your current validation state\n\n\n### getState()\n\nGet last validation state\n\n\n### getStrategy()\n\nGet current Strategy of validation\n\n\n### getValidHandler()\n\nGet current validation handler\n\n\n### getCommonState()\n\nGet Common state of validation (true\\false)\n\n\n\n## EVENTS\n\nYou can subscribe on univalid events (univalid extends EventEmitter)\n\n```js\n\nunivalid.on('start:valid', (args) =\u003e {\n    console.log('Check!');\n});\n\n```\n\n**Table of events**\n\n| Event | Description |\n|:------:|:-----------:|\n|start:valid|Start validation pack|\n|end:valid|End validation pack|\n|start:valid:field|Start validation field|\n|end:valid:field|End validation field|\n|change:strategy|Change strategy event|\n|set:new-ValidationHandler|Set new ValidationHandler event|\n|change:msg-config|Change message config event|\n|clear:state|Clear state of last validation event|\n|error|Error event|\n\n\n## License\nISC ©\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstetsd%2Funivalid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstetsd%2Funivalid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstetsd%2Funivalid/lists"}