{"id":18358789,"url":"https://github.com/uppercod/schema","last_synced_at":"2025-04-10T03:00:24.723Z","repository":{"id":113251514,"uuid":"314577853","full_name":"UpperCod/schema","owner":"UpperCod","description":null,"archived":false,"fork":false,"pushed_at":"2020-12-10T00:31:19.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-16T19:51:42.990Z","etag":null,"topics":[],"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/UpperCod.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-20T14:28:56.000Z","updated_at":"2020-12-10T00:31:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"b038c8ad-0854-42f6-a7f4-c8b79515b85c","html_url":"https://github.com/UpperCod/schema","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"UpperCod/pkg-base","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UpperCod%2Fschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UpperCod%2Fschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UpperCod%2Fschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UpperCod%2Fschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UpperCod","download_url":"https://codeload.github.com/UpperCod/schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248148217,"owners_count":21055547,"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-05T22:19:25.627Z","updated_at":"2025-04-10T03:00:24.634Z","avatar_url":"https://github.com/UpperCod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @uppercod/schema\n\ndeclare validations, filters or transformers in a simple and functional.\n\n## install\n\n```\nnpm install @uppercod/schema\n```\n\n## Usage\n\n### Simple\n\n```js\nimport { schema, error } from \"@uppercod/schema\";\n\nconst transform = schema({\n    age: Number,\n    email: (value) =\u003e {\n        if (/\\w+@\\w+.\\w+$/.test(value)) {\n            return value;\n        }\n        throw \"invalid email\";\n    },\n});\n\ntransform({ age: \"20\" }).then(\n    (valid) =\u003e console.log(\"valid: \", valid),\n    (invalid) =\u003e console.log(\"invalid: \", invalid)\n);\n```\n\n### multiple validations in per field\n\n```js\nconst min = (minValue) =\u003e (value) =\u003e\n    minValue \u003c= value ? error`The ${value} is less than ${minValue}` : value;\n\nconst transform = schema({\n    age: [Number, min(3)],\n});\n```\n\n### nested\n\n```js\nconst trim = (value) =\u003e value.trim();\n\nconst user = schema({\n    id: Number,\n    userName: trim,\n});\n\nconst data = schema({\n    user: user,\n});\n```\n\n### context\n\n```js\nconst user = schema({\n    firstName: String,\n    lastName: String,\n    fullName: (value, prop, { fistName, lastName }) =\u003e\n        fistName + \" \" + lastName,\n});\n```\n\n## filters\n\n```js\nimport is from \"is_js\";\nimport { schema } from \"@uppercod/schema\";\nimport { filter, date, options } from \"@uppercod/schema/filter\";\n\nschema({\n    email: filter(is.email),\n    date: date({ min: new Date(\"01-02-2020\") }),\n    status: options(\"active\", \"inactive\"),\n});\n```\n\n## Api 2\n\n```js\nimport { schema, optional, use } from \"@uppercod/schema\";\n\nschema({\n    id: (value, field, context) =\u003e {},\n    firstName : minLength(3)\n    fullName: () =\u003e {\n        const {firstName,lastName} = use(\"valid\");\n        return firstName + \" \"+ lastName;\n    },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuppercod%2Fschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuppercod%2Fschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuppercod%2Fschema/lists"}