{"id":15230534,"url":"https://github.com/apendua/very-simple-schema","last_synced_at":"2025-04-10T03:53:15.515Z","repository":{"id":57391886,"uuid":"79114475","full_name":"apendua/very-simple-schema","owner":"apendua","description":"A minimalistic implementation of SimpleSchma most useful features","archived":false,"fork":false,"pushed_at":"2018-11-08T16:21:12.000Z","size":380,"stargazers_count":5,"open_issues_count":6,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T03:53:05.271Z","etag":null,"topics":["form-validation","form-validation-constructor","json-validation","meteor","schema"],"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/apendua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-16T12:04:50.000Z","updated_at":"2018-11-08T16:21:14.000Z","dependencies_parsed_at":"2022-09-19T01:51:18.251Z","dependency_job_id":null,"html_url":"https://github.com/apendua/very-simple-schema","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apendua%2Fvery-simple-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apendua%2Fvery-simple-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apendua%2Fvery-simple-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apendua%2Fvery-simple-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apendua","download_url":"https://codeload.github.com/apendua/very-simple-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154998,"owners_count":21056542,"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":["form-validation","form-validation-constructor","json-validation","meteor","schema"],"created_at":"2024-09-29T03:05:55.587Z","updated_at":"2025-04-10T03:53:15.494Z","avatar_url":"https://github.com/apendua.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# very-simple-schema\n\nBundle size: ~22.5 kB, ~5.5 kB gzipped\n\n[![Build Status](https://travis-ci.org/apendua/very-simple-schema.svg?branch=master)](https://travis-ci.org/apendua/very-simple-schema)\n\n## Like SimpleSchema but even simpler\n\nThis package implements an essential subset of [SimpleSchema](https://github.com/aldeed/node-simple-schema).\nUnlike the original version it does not provide validation of Mongo selectors, nor does it allow you to define default and auto values.\nDespite the limited functionality it may still be an interesting alternative for solving problems like:\n\n- form validation - it integrates nicely with [redux-form](https://github.com/erikras/redux-form)\n- function parameters validation, e.g. in remote api calls\n\n## Instllation\n\n```\nnpm install --save very-simple-schema\n```\n\n## Basic usage\n\n```javascript\nimport { Schema } from 'very-simple-schema';\n\nconst Book = new Schema({\n  author:    { type: String, nonEmpty: true }, // must be present and non-empty\n  title:     { type: String, optional: true, nonEmpty: true }, // can be missing, but if present then must be non-empty\n  abstract:  { type: String, optional: true }, // can be missing\n  signature: { type: String }, // must be present, if present can be empty\n});\n```\n\n## Gotchas\n\nUnlkie in `SimpleSchema`, empty strings are accepted even if a property is required. The reason `SimpleSchema` treats them\ndifferently is that `clean` method is being called on an object before it's validated. To emulate the original behavior\nyou can create a custom `Schema` class with different default behavior:\n```javascript\nimport { createSchema, presetDefault } from 'very-simple-schema';\n\nconst Schema = createSchema({\n  plugins: [\n    ...presetDefault,\n  ],\n  emptyStringsAreMissingValues: true,\n});\n```\n\n## Examples\n\n```javascript\nimport { Schema } from 'very-simple-schema';\n\n// a number between 0 and 10\nnew Schema(Number, { min: 0, max: 10 });\n\n// array with at least element\nSchema.arrayOf(Schema.any(), { minCount: 1 });\n\n// object that contains anything\nSchema.blackbox();\nSchema.objectOf(Schema.any());\n\n// either Yes or No\nSchema.enum(['Yes', 'No']);\n\n// can be one of the specified types\nconst Id = Schema.oneOf([String, Number]);\n\nconst User = new Schema({\n  name: { type: String },\n  email: { type: String, regEx: Schema.RegEx.Email, optional: true },\n}, {\n  // custom typeName can improve some error messages\n  typeName: 'User',\n});\n\nconst Book = new Schema({\n  id: { type: Id },\n  // type can reference another schema\n  author: { type: User },\n  // strings can be requested to be non empty\n  title: { type: String, nonEmpty: true },\n  abstract: { type: String },\n  // array can be constructed with [] shortcut, maxCount refers to array lenght, max refers to string length\n  chapters: { type: [String], '$.max': 128, maxCount: 10 },\n}, { typeName: 'Book' });\n\nconst Library = new Schema({\n  books: { type: [Book], maxCount: 1000 },\n}, {\n  typeName: 'Library',\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapendua%2Fvery-simple-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapendua%2Fvery-simple-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapendua%2Fvery-simple-schema/lists"}