{"id":20109812,"url":"https://github.com/hyper63/specify","last_synced_at":"2025-10-27T19:13:50.649Z","repository":{"id":110719201,"uuid":"330700432","full_name":"hyper63/specify","owner":"hyper63","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-09T21:56:05.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T18:32:23.662Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/hyper63.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":"2021-01-18T14:59:16.000Z","updated_at":"2021-08-17T19:20:06.000Z","dependencies_parsed_at":"2023-04-07T02:22:25.292Z","dependency_job_id":null,"html_url":"https://github.com/hyper63/specify","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/hyper63/specify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Fspecify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Fspecify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Fspecify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Fspecify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyper63","download_url":"https://codeload.github.com/hyper63/specify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Fspecify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264951612,"owners_count":23687974,"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-13T18:09:31.437Z","updated_at":"2025-10-27T19:13:45.607Z","avatar_url":"https://github.com/hyper63.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003eSpecify\u003c/h1\u003e\n\u003cp align=\"center\"\u003eA lightweight spec framework\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/hyper63/specify/tags/\"\u003e\u003cimg src=\"https://img.shields.io/github/tag/hyper63/specify\" alt=\"Current Version\" /\u003e\u003c/a\u003e\n  \u003cimg src=\"https://github.com/hyper63/specify/workflows/.github/workflows/test.yml/badge.svg\" /\u003e\n\n\u003ca href=\"https://nest.land/package/specify\"\u003e\u003cimg src=\"https://nest.land/badge.svg\" alt=\"nest badge\" /\u003e\u003c/a\u003e\n\n\u003c/p\u003e\n\n---\n\n## Table of Contents\n\n- [Getting Started](#getting-started)\n- [Installation](#installation)\n- [Features](#features)\n- [Contributing](#contributing)\n- [License](#license)\n- [Acknowledgements](#acknowledgements)\n\n## Getting Started\n\nSpecify is a validation framework based on functional principals. This barebones\nvalidation framework gives you the building blocks to create simple validations\nor create your own validation library. The goal of this project is just to\ncontain the building blocks of a validation library and not all of the\nvalidations, so it has no validations actually in the project. Specify just\ncontains the data types to create a schema validation library using a functional\napproach.\n\nSpecify contains a validate method that takes a spec definition object and a\nvalue object, this validate function compares the spec defintion object and the\nvalue object and returns a data type with a fold method, this fold method takes\ntwo functions as arguments, the first function is invoked if the validation\nfails and the second function is invoked if the validation passes.\n\nThe result in the first fold function is an array of error messages, the result\nin the second fold function is the object that is being evaluated.\n\n```js\nconst spec = {\n  name: isPresent,\n  email: isEmail,\n};\n\nconst obj = {\n  name: \"Wilbur\",\n  email: \"wilbur@email.com\",\n};\n\nvalidate(spec, obj).fold(\n  (msgs) =\u003e console.log(msgs),\n  (obj) =\u003e console.log(obj),\n);\n```\n\n### Creating your own validations\n\nThis module contains the building blocks to create your own validation\nfunctions, these functions need to be modeled in the `Validation` data type and\nthe function should return either a Fail or Success data type.\n\n```js\nconst isPresent = Validation((key, value) =\u003e\n  !!value ? Success(value) : Fail([`${key} should be present`])\n```\n\nAs you can see in this validation, we return the `Validation` type and we create\nthat type by passing in a function with the arguments `key` and `value`, these\nare the arguments that get passed to the function when it is evaluating an\nobject. Then as a result of the function, a `Success` or `Fail` type should be\nreturned. Finally, the value in the Fail type should be enclosed in an array so\nthat all the failures can be concatenated together in a single array list.\n\n## Installation\n\ndeps.js\n\n```js\nexport {\n  and,\n  Fail,\n  or,\n  Success,\n  validate,\n  Validation,\n} from \"https://x.nest.land/specify@0.0.2/mod.js\";\n```\n\n## Features\n\n#### validate(spec, obj).fold(console.error, console.log)\n\n`validate` is the main function that takes a spec object and a value object. The\nfunction then applies the spec to the value and returns a `Validation` instance\nthat contains a `fold` method, the fold method has two arguments which are\nhandler functions. The first argument gets called if the spec validation failed\nthe second argument gets called if the spec validation passes.\n\n#### Validation((key, value) =\u003e check ? Success(value) : Fail([`${key} something failied`])\n\nThis type is how you create validations for specify.\n\nThe Validation constructor takes a function, this function takes two arguments a\nkey and value, and returns a Success or Fail type. The success type should\ninclude the value in its method call, and the Fail type should return an array\nwith one or more strings.\n\n#### Success and Fail\n\nBe sure to import both the Success and Fail types to you validation project,\neach validation definition must return the `Fail` or `Success` data type.\n\n#### and,or are two helper methods\n\n`and`, `or`, are two Validation functions that make specify a little easier to\ncombine Validations.\n\nExample:\n\n```js\nconst spec = {\n  name: and(isString, isPresent, maxLength(50)),\n  email: and(isString, isPresent, isEmail),\n  description: or(maxLength(255), optional()),\n};\n```\n\nThe and helper, makes sure every validation passes, and the or helper one or the\nother can pass but both can not fail.\n\n## Contributing\n\nBug fixes are welcome\n\n## License\n\nMIT\n\n## Acknowledgements\n\nThe initial core of this library was a result of the Frontend Masters course\nHardcore JS Patterns with Brian Lonsdorf aka Dr Boolean. For more details about\nhow Monoids, foldMap and other functional concepts work, check out this couses:\nhttps://frontendmasters.com/courses/hardcore-js-patterns/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper63%2Fspecify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyper63%2Fspecify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper63%2Fspecify/lists"}