{"id":24893033,"url":"https://github.com/barry127/sontaran","last_synced_at":"2025-10-16T08:31:14.950Z","repository":{"id":15086632,"uuid":"77535237","full_name":"Barry127/sontaran","owner":"Barry127","description":"Javascript validator for Array, Boolean, Number, Object, String","archived":false,"fork":false,"pushed_at":"2024-09-24T19:37:21.000Z","size":2017,"stargazers_count":0,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-01T09:13:58.888Z","etag":null,"topics":["javascript","javascript-validation"],"latest_commit_sha":null,"homepage":"https://barry127.github.io/sontaran/","language":"TypeScript","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/Barry127.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-28T13:36:25.000Z","updated_at":"2024-09-24T19:37:21.000Z","dependencies_parsed_at":"2023-01-13T22:15:20.344Z","dependency_job_id":"f78af1a9-07d7-4f3e-8106-3f7d39cdb9e9","html_url":"https://github.com/Barry127/sontaran","commit_stats":{"total_commits":167,"total_committers":3,"mean_commits":"55.666666666666664","dds":"0.13772455089820357","last_synced_commit":"05c09af7248d4609e00f4f990ed9a71bf0a1d761"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Barry127%2Fsontaran","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Barry127%2Fsontaran/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Barry127%2Fsontaran/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Barry127%2Fsontaran/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Barry127","download_url":"https://codeload.github.com/Barry127/sontaran/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236699544,"owners_count":19190841,"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":["javascript","javascript-validation"],"created_at":"2025-02-01T18:18:42.170Z","updated_at":"2025-10-16T08:31:09.556Z","avatar_url":"https://github.com/Barry127.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sontaran\n\n[![Build Status](https://travis-ci.com/Barry127/sontaran.svg?branch=master)](https://travis-ci.com/Barry127/sontaran)\n[![Coverage Status](https://coveralls.io/repos/github/Barry127/sontaran/badge.svg?branch=master)](https://coveralls.io/github/Barry127/sontaran?branch=master)\n\nSontaran is a javascript validator library. It has a lot validation options out of the box and all validators are extendable with custom validation functions.\n\nSome key features\n\n- Completely written in Typescript\n- CommonJS build for Node JS\n- Tree shakable ES build\n- Fluid, chainable api\n- Support for async validators with the `validateAsync` method\n\n## Installation\n\nSontaran can be installed using npm.\n\n```bash\nnpm install --save sontaran\n```\n\nFor the complete code including all tests the repo can be cloned.\n\n```bash\ngit clone https://github.com/Barry127/sontaran.git\ncd sontaran\nnpm run test\n```\n\n## Getting Started\n\nThe `object().schema()` function takes a schema of Sontaran validators as an argument.\n\nIn this example:\n\n**username**\n\n- Must be a string\n- Cannot be only empty characters (spaces, tabs, return, ...)\n- Must have a length between 3 and 10 characters\n- Must match the given RegExp (only contain alphanumeric characters and dash, underscore)\n\n**email**\n\n- Must be a valid email\n\n**password**\n\n- Must be a string\n- Must have a length of at least 8 characters\n\n```javascript\nimport { object, string, email } from 'sontaran';\n\nconst schema = object().schema({\n  username: string()\n    .notEmpty()\n    .between(3, 10)\n    .match(/^[a-zA-Z0-9_\\-]*$/),\n  email: email(),\n  password: string().min(8)\n});\n\n// Valid schema (return true)\nschema.validate({\n  username: 'sontaran',\n  email: 'email@domain.com',\n  password: 'mySuperSecretPassword'\n}); /** =\u003e {\n  valid: true,\n  value: {\n    username: 'sontaran',\n    email: 'email@domain.com',\n    password: 'mySuperSecretPassword\n  }\n}*/\n\n// invalid usernames\nlet a = 123; // =\u003e not a string\nlet b = ' \\t\\r'; // =\u003e Empty characters\nlet c = 'aa'; // =\u003e too short\nlet d = 'Hello-World'; // =\u003e too long\nlet e = 'B@dInput'; // =\u003e invalid character\n```\n\nSontarans `custom` can take any `ValidatorFunction` function as argument to validate and / or transform a value.\n\n```javascript\nimport { string, ValidationError } from 'sontaran';\n\n// value cannot be root and is transformed to lowercase\nconst myCustomValidator = (value) =\u003e {\n  if (value.toLocaleLowercase() === 'root') {\n    throw new ValidationError('root is not allowed');\n  }\n\n  return value.toLocaleLowercase();\n};\n\nconst schema = string().custom(myCustomValidator);\n\n// valid result transformed to lowercase\nconst result = schema.label('username').validate('Admin');\n/* =\u003e {\n  valid: true,\n  value: 'admin'\n}*/\n\n// invalid result\nconst result = schema.label('username').validate('Root');\n/* =\u003e {\n  valid: false,\n  value: 'Root',\n  errors: [{\n    field: 'username',\n    message: 'root is not allowed',\n    type: 'root is not allowed'\n  }]\n}\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarry127%2Fsontaran","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarry127%2Fsontaran","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarry127%2Fsontaran/lists"}