{"id":15607913,"url":"https://github.com/suyesh/redux-state-validator","last_synced_at":"2025-04-28T10:19:26.135Z","repository":{"id":57351656,"uuid":"142589246","full_name":"suyesh/redux-state-validator","owner":"suyesh","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-27T19:00:18.000Z","size":9,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-22T13:06:20.475Z","etag":null,"topics":["flux","json-schema","redux","redux-state","redux-state-validation"],"latest_commit_sha":null,"homepage":null,"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/suyesh.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-07-27T14:44:48.000Z","updated_at":"2023-04-03T12:29:29.000Z","dependencies_parsed_at":"2022-09-19T00:02:27.639Z","dependency_job_id":null,"html_url":"https://github.com/suyesh/redux-state-validator","commit_stats":null,"previous_names":["suyesh/redux-json-schema"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyesh%2Fredux-state-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyesh%2Fredux-state-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyesh%2Fredux-state-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyesh%2Fredux-state-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suyesh","download_url":"https://codeload.github.com/suyesh/redux-state-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251238682,"owners_count":21557489,"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":["flux","json-schema","redux","redux-state","redux-state-validation"],"created_at":"2024-10-03T05:05:10.596Z","updated_at":"2025-04-28T10:19:26.090Z","avatar_url":"https://github.com/suyesh.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Redux State Validator\n\n![Redux State Validator](http://res.cloudinary.com/dvnjqhdxp/image/upload/c_scale,w_2153/v1532706169/imgonline-com-ua-twotoone-OYK8DdNX1DBiXj.jpg)\n\nA Simple Redux middleware to validate redux state values and object types using JSON Schema.\n\n![How it looks](https://res.cloudinary.com/dvnjqhdxp/image/upload/v1532708882/stateValidation.gif)\n\n## PRE-REQUIREMENT (IMPORTANT)\n\nYou need to create JSONSchema file going to [Jsonschema.net](https://jsonschema.net). Its super simple. When you go to jsonschema.net, you will see an editor on the left. Type your state in there with default values and it will autodetect the types and generate Schema on the right. Copy and paste that in a file and export it as default. Like below\n\n![jsonSchemaEditor](http://res.cloudinary.com/dvnjqhdxp/image/upload/v1532707027/Screen_Shot_2018-07-27_at_11.56.34_AM.png)\n\n```\nexport default {\n\t$id: 'http://example.com/example.json',\n\ttype: 'object',\n\tdefinitions: {},\n\t$schema: 'http://json-schema.org/draft-07/schema#',\n\tproperties: {\n\t\tfirstReducer: {\n\t\t\t$id: '/properties/firstReducer',\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tstate1: {\n\t\t\t\t\t$id: '/properties/firstReducer/properties/state1',\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\ttitle: 'The State1 Schema ',\n\t\t\t\t\tdefault: false,\n\t\t\t\t\texamples: [true]\n\t\t\t\t},\n\t\t\t\tstate2: {\n\t\t\t\t\t$id: '/properties/firstReducer/properties/state2',\n\t\t\t\t\ttype: 'integer',\n\t\t\t\t\ttitle: 'The State2 Schema ',\n\t\t\t\t\tdefault: 0,\n\t\t\t\t\texamples: [22]\n\t\t\t\t},\n\t\t\t\tstate3: {\n\t\t\t\t\t$id: '/properties/firstReducer/properties/state3',\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\titems: {\n\t\t\t\t\t\t$id: '/properties/firstReducer/properties/state3/items',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\ttitle: 'The 0th Schema ',\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\texamples: ['apple', 'orange']\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tsecondReducer: {\n\t\t\t$id: '/properties/secondReducer',\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tstate1: {\n\t\t\t\t\t$id: '/properties/secondReducer/properties/state1',\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\ttitle: 'The State1 Schema ',\n\t\t\t\t\tdefault: false,\n\t\t\t\t\texamples: [true]\n\t\t\t\t},\n\t\t\t\tstate2: {\n\t\t\t\t\t$id: '/properties/secondReducer/properties/state2',\n\t\t\t\t\ttype: 'integer',\n\t\t\t\t\ttitle: 'The State2 Schema ',\n\t\t\t\t\tdefault: 0,\n\t\t\t\t\texamples: [22]\n\t\t\t\t},\n\t\t\t\tstate3: {\n\t\t\t\t\t$id: '/properties/secondReducer/properties/state3',\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\titems: {\n\t\t\t\t\t\t$id: '/properties/secondReducer/properties/state3/items',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\ttitle: 'The 0th Schema ',\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\texamples: ['apple', 'orange']\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n```\n\n## Installation\n\nInstall it as:\n\n    $ npm install --save redux-state-validator\n\n## USAGE\n\n### Import Validator from redux-state-validator\n\n```\nimport Validator from 'redux-state-validator';\n```\n\n### Import Json Schema on the file\n\n```\nimport stateSchema from './your-json-schema';\n```\n\n### Setup `Validator` to use the schema\n\n```\nconst stateValidator = Validator.Schema(stateSchema);\n```\n\n### Apply to the redux middleware\n\n```\nconst store = createStore(\n    reducers,\n    initialState,\n    applyMiddleware(stateValidator)\n);\n```\n\nThats it.\n\nBy default it will log message only when the validation fails, If you also want to log the validation success message you can pass an additional parameter like follows:\n\n```\nconst stateValidator = Validator.Schema(stateSchema, true)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuyesh%2Fredux-state-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuyesh%2Fredux-state-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuyesh%2Fredux-state-validator/lists"}