{"id":13749433,"url":"https://github.com/lucono/xtypejs","last_synced_at":"2025-04-04T18:07:00.903Z","repository":{"id":29629352,"uuid":"33170275","full_name":"lucono/xtypejs","owner":"lucono","description":"Elegant, highly efficient data validation for JavaScript.","archived":false,"fork":false,"pushed_at":"2023-01-12T08:26:34.000Z","size":1539,"stargazers_count":361,"open_issues_count":0,"forks_count":12,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-27T17:48:52.492Z","etag":null,"topics":["data-types","data-validation","javascript"],"latest_commit_sha":null,"homepage":"https://xtype.js.org","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/lucono.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":"2015-03-31T07:05:22.000Z","updated_at":"2024-12-30T15:39:57.000Z","dependencies_parsed_at":"2023-01-14T15:20:49.139Z","dependency_job_id":null,"html_url":"https://github.com/lucono/xtypejs","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucono%2Fxtypejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucono%2Fxtypejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucono%2Fxtypejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucono%2Fxtypejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucono","download_url":"https://codeload.github.com/lucono/xtypejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226213,"owners_count":20904465,"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-types","data-validation","javascript"],"created_at":"2024-08-03T07:01:01.912Z","updated_at":"2025-04-04T18:07:00.886Z","avatar_url":"https://github.com/lucono.png","language":"JavaScript","readme":"[![xtypejs Logo](https://xtype.js.org/site/assets/img/xtypejs-logo.png)](https://xtype.js.org/) \u003ca href=\"https://travis-ci.org/lucono/xtypejs\"\u003e\u003cimg align=\"right\" src=\"https://travis-ci.org/lucono/xtypejs.svg?branch=master\"\u003e\u003c/a\u003e\n## Elegant, highly efficient data validation for JavaScript\n\n---\n\n### Overview\n\n- Provides concise, performant, readable, data and type validation for JavaScript apps, using built-in and user-defined data-validating pseudo types.\n- Improves application efficiency and readability by unifying the most basic but common data and type validations in JavaScript apps, into single, concise, highly optimized operations.\n- Employs bitwise operations, data pre-processing, and memory-efficient memoization for fast, robust performance in small and large apps and libraries.\n- Ready for nodejs, requirejs, and regular script tag.\n- Website \u0026ndash; **[xtype.js.org](https://xtype.js.org)**\n\n### Go from this:\n\n```js\nfunction searchEmployees(value) {\n    if (typeof value === 'string') {\n         if (value.trim().length \u003e 1) {\n            return EmployeeDB.searchByName(value);\n        } else if (value.trim().length === 1) {\n            return EmployeeDB.searchByMiddleInitial(value);\n        } else {\n            return { error: 'Invalid search value supplied' };\n        }\n    } else if (typeof value === 'object' \u0026\u0026 value !== null) {\n        if (Object.keys(value).length === 1) {\n            return EmployeeDB.searchByFieldValuePair(value);\n        } else if (Object.keys(value).length \u003e 1) {\n            return { error: 'Search by multiple fields not supported' };\n        } else {\n            return { error: 'Invalid search value supplied' };\n        }\n    } else if (typeof value === 'number') {\n        if (!isNaN(value) \u0026\u0026 isFinite(value) \u0026\u0026 value \u003e 0 \u0026\u0026 value % 1 === 0) {\n            return EmployeeDB.searchByEmployeeNumber(value);\n        } else {\n            return { error: 'Invalid employee number supplied' };\n        }\n    } else if (typeof value === 'undefined' || value === null) {\n        return { error: 'No search value supplied' };\n    } else {\n        return { error: 'Invalid search value supplied' };\n    }\n}\n```\n\n### To concise, performant, readable, data validation:\n\n```js\nfunction searchEmployees(value) {\n    switch (xtype.which(value, 'str2+ str1 int+ obj1 obj2+ num nil')) {\n        case 'str2+':\n            return EmployeeDB.searchByName(value);\n        case 'str1':\n            return EmployeeDB.searchByMiddleInitial(value);\n        case 'int+':\n            return EmployeeDB.searchByEmployeeNumber(value);\n        case 'obj1':\n            return EmployeeDB.searchByFieldValuePair(value);\n        case 'obj2+':\n            return { error: 'Search by multiple fields not supported' };\n        case 'num':\n            return { error: 'Invalid employee number supplied' };\n        case 'nil':\n            return { error: 'No search value supplied' };\n        default:\n            return { error: 'Invalid search value supplied' };\n    }\n}\n```\n\n### And even add custom validation types of your own:\n\n```js\nxtype.ext.registerType('ssn', {\n    validator: function(val) {\n        return typeof val === 'string' \u0026\u0026 /^\\d{3}-\\d{2}-\\d{4}$/.test(val);\n    }\n});\n\nfunction searchEmployees(value) {\n    switch (xtype.which(value, 'positive_integer, ssn, multi_char_string')) {\n        case 'positive_integer':\n            return EmployeeDB.searchByEmployeeNumber(value);\n        case 'ssn':\n            return EmployeeDB.searchBySSN(value);\n        case 'multi_char_string':\n            return EmployeeDB.searchByName(value);\n        default:\n            return { error: 'Invalid search value supplied' };\n    }\n}\n```\n\n## \u0026nbsp;\n\n#### Links\n\n- [Website](https://xtype.js.org)\n- [Examples And Guide](https://xtype.js.org/?doc=guide)\n- [API Docs](https://xtype.js.org/?doc=api)\n\n#### Installation\n\nSee [here](https://xtype.js.org/?doc=getit).\n\n#### Dependencies\n\nNone.\n\n\n#### Build / Test\n\nSee [here](https://github.com/lucono/xtypejs/tree/master/project/xtypejs/test).\n\n\n#### License\n\nMIT license.\n\n\n#### Website\n\nVisit the website for usage guide, examples, API docs, and installation.\n\n**[xtype.js.org](https://xtype.js.org/)**\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucono%2Fxtypejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucono%2Fxtypejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucono%2Fxtypejs/lists"}