{"id":21039419,"url":"https://github.com/arjunu/typoscope","last_synced_at":"2025-11-08T04:03:52.770Z","repository":{"id":57384180,"uuid":"51519974","full_name":"arjunu/typoscope","owner":"arjunu","description":"A runtime type schema validator for compound Javascript objects \u0026 arrays","archived":false,"fork":false,"pushed_at":"2016-03-08T06:28:37.000Z","size":23,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T10:13:24.533Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/arjunu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-11T14:29:44.000Z","updated_at":"2023-03-11T17:09:10.000Z","dependencies_parsed_at":"2022-09-14T17:43:01.917Z","dependency_job_id":null,"html_url":"https://github.com/arjunu/typoscope","commit_stats":null,"previous_names":["razorthink-software/type-validator"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Ftyposcope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Ftyposcope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Ftyposcope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Ftyposcope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arjunu","download_url":"https://codeload.github.com/arjunu/typoscope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254377286,"owners_count":22061114,"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":[],"created_at":"2024-11-19T13:41:14.819Z","updated_at":"2025-11-08T04:03:52.742Z","avatar_url":"https://github.com/arjunu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typoscope\nA runtime type schema validator for compound Javascript objects \u0026 arrays\n\nFor a given type schema and a value (object or array), it checks if the object or array satisfies the schema.\n\nTyposcope checks from given type schema:\n - if your object (or array of objects) has all the properties of corresponding types mentioned\n - if your array (including any nested objects or arrays) has items of given type (heterogeneous arrays not yet supported, use type 'Any' for now)\n\nExtra properties, if any, are ignored. It returns true or false. Pass a third boolean param `true` to enable error logging for failed validations.\n\n```javascript\nvalidate(userSchema, user); //returns true or false\nvalidate(userSchema, user, true); //returns true or false and logs errors for any type mismatches \u0026 missing properties\n```\n\nCompound nested objects \u0026 arrays are supported:\n\n```javascript\n{\n    name: 'Sandeep',\n    id: 1,\n    active: true,\n    projects: [{\n        name: 'Tada Todo',\n        id: 1,\n        titles: ['JS', 'React'],\n        lead: 'Michael'\n    }],\n    tasks: [{\n        project: 'Life',\n        id: 1,\n        items: ['Eat', 'Code']\n    }]\n};\n\n```\nSupported types:\n\n- Boolean\n- String\n- Number\n- Null\n- Undefined\n- Array\n- Object\n- Any\n\nType `any` means the property can be any of the other types: primitives (including `null` and `undefined`) or Array or Object\nbut the property cannot be missing from the object.\n\n## Installation\n\n```javascript\nnpm install typoscope --save\n```\n\n## Usage Example (ES6)\n\n```javascript\nimport { validate, types } from 'typoscope';\n\n/**Simple objects*/\n\nlet schema = {\n    a: types.string, b: types.number, c: types.boolean, d: types.object\n};\n\nlet trueValue = {\n    a: 'Sandeep', b: 123, c: false, d: {x: 2}\n};\nvalidate(schema, trueValue, true); //returns true\n\nlet falseValue = {\n    a: 'Sandeep', b: 123, c: false, d: []\n};\nvalidate(schema, falseValue, true); \n//returns false, log - Type mismatch for 'd': expected Object, got Array\n\nlet falseValue2 = {\n  a: 'Sandeep', b: 123, c: 1, d: 1\n};\nvalidate(schema, falseValue2, true); \n//returns false, log - \n//Type mismatch for 'c': expected Boolean, got Number\n//Type mismatch for 'd': expected Object, got Number\n\n/**Nested compound objects*/\n\nlet userSchema = {\n        name: types.string,\n        id: types.number,\n        active: types.boolean,\n        projects: [{\n            name: types.string,\n            id: types.number,\n            titles: [types.string],\n            lead: types.any\n        }],\n        tasks: types.any\n    };\n    \nlet user = {\n      username: 'stardoge',\n      name: {firstName: 'Arjun', lastName: 'Umesh'},\n      id: 56,\n      active: true,\n      projects: [{\n          name: 'Tada Todo',\n          id: 1,\n          titles: ['JS', 'React'],\n          lead: 'Michael'\n      }],\n      tasks: []\n  };\n\nvalidate(userSchema, user, true); //returns true\n\nlet user2 = {\n      username: 'sandeep2149',\n      id: 1,\n      active: 0,\n      name: {firstName: \"Sandeep\"},\n      projects: [{\n          name: \"TadaTodo\",\n          id: 1,\n          titles: ['A', 1],\n          lead: 'Michael'\n      },{\n          id: 2,\n          titles: ['X', 'Y'],\n          lead: 'Michael'\n      }],\n      tasks: [{\n          project: 'String',\n          id: 1,\n          items: ['Eat', 'Code']\n      }]\n};\n\nvalidate(userSchema, user2); \n//returns false\n//log -\n//Typoscope found 4 errors:\n//Missing property: 'name.lastName'\n//Type mismatch for 'active': expected Boolean, got Number\n//Type mismatch for 'projects[0].titles[1]': expected String, got Number\n//Missing property: 'projects[1].name'\n```\n\n## Motivation\n\nDuring front end (and server) development we want to know if the server is sending correct data. Same goes for posting\ndata to server. At least until we perfect both and go into production. A missing property (`user.email`) or a value of\nwrong type (number in place of string) could produce a bug or even crash the application. In the hunt for the cause, you\nwill head to the network tab under browser dev tools and manually inspect the response object. Instead we could have a\nutility (enter Typoscope) doing the inspection for data to and fro the server.\n\nInspecting server communications is just one use case! Do tell us where you have used it.\n\n## License\n\nThe MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunu%2Ftyposcope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farjunu%2Ftyposcope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunu%2Ftyposcope/lists"}