{"id":13624329,"url":"https://github.com/juliangruber/schema","last_synced_at":"2025-04-15T21:30:34.516Z","repository":{"id":15402302,"uuid":"18134268","full_name":"juliangruber/schema","owner":"juliangruber","description":"A simple, fluent API for generating immutable schemas.","archived":false,"fork":true,"pushed_at":"2014-03-26T10:29:14.000Z","size":141,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-01T21:59:42.364Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"component/schema","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliangruber.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","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":"2014-03-26T10:21:25.000Z","updated_at":"2021-01-13T19:41:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/juliangruber/schema","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliangruber%2Fschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliangruber%2Fschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliangruber%2Fschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliangruber%2Fschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliangruber","download_url":"https://codeload.github.com/juliangruber/schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223685184,"owners_count":17185796,"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-08-01T21:01:41.410Z","updated_at":"2024-11-08T12:31:23.891Z","avatar_url":"https://github.com/juliangruber.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\n# schema\n\n  A simple, fluent API for generating immutable schemas.\n\n## Installation\n\n    $ component install component/schema\n\n## Example\n\nWhat's nice about your schemas being immutable is that it makes sharing them between different parts of your codebase very simple. For example, you might have a basic user schema:\n\n```js\nvar Schema = require('schema');\n\nvar user = new Schema()\n  .string('id', { required: true })\n  .string('name')\n  .email('email')\n  .url('website')\n  .date('created', { default: function () { return new Date(); }});\n\nuser.toJSON();\n```\n```js\n{\n  \"id\": {\n    \"type\": \"string\",\n    \"required\": true,\n    \"validators\": [Function, Function],\n  },\n  \"name\": {\n    \"type\": \"string\",\n    \"validators\": [Function]\n  },\n  \"email\": {\n    \"type\": \"email\",\n    \"validators\": [Function]\n  },\n  \"website\": {\n    \"type\": \"url\",\n    \"validators\": [Function]\n  },\n  \"created\": {\n    \"type\": \"date\",\n    \"validators\": [Function]\n  }\n}\n```\n\nBut then on your servers, you might want to add a few private properties to a user that you don't expose to the public:\n\n```js\nvar user = require('user-schema');\n\nvar backendUser = user\n  .number('version', { default: 0 })\n  .boolean('admin', { default: false });\n```\n\nAnd in the browser, you might want to add a few conveniences:\n\n```js\nvar user = require('user-schema');\n\nvar frontendUser = user\n  .url('gravatar', { default: {} })\n  .object('features', { default: {} });\n```\n\nAnd in your tests, you might want to have different defaults, so that creating generating fixtures is super simple:\n\n```js\nvar user = require('user-schema');\nvar uid = require('uid');\nvar randomName = require('random-name');\nvar randomEmail = require('random-email');\nvar randomUrl = require('random-url');\n\nvar fixtureUser = user\n  .string('id', { default: uid })\n  .string('name', { default: randomName })\n  .email('email', { default: randomEmail })\n  .url('website', { default: randomWebsite });\n```\n\n## API\n\n#### new Schema()\n\n  Create a new `Schema`.\n\n#### #\u003ctype\u003e(key, settings)\n\n  Return a new `Schema`, adding a property of `type` by `key` with optional extra `settings`. The supported types are:\n\n    array\n    boolean\n    date\n    function\n    number\n    object\n    regexp\n    string\n    email\n    url\n\n#### #add(key, settings)\n\n  Return a new `Schema`, adding a non-typed property by `key` with optional `settings`. If you pass a `required: true` setting, an required validator will be added.\n\n#### #remove(key)\n\n  Return a new `Schema`, removing a property by `key`.\n\n#### #toJSON()\n\n  Return a JSON representation of the schema.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliangruber%2Fschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliangruber%2Fschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliangruber%2Fschema/lists"}