{"id":13465024,"url":"https://github.com/xogroup/felicity","last_synced_at":"2025-04-10T04:56:28.132Z","repository":{"id":54570780,"uuid":"69062584","full_name":"xogroup/felicity","owner":"xogroup","description":"Javascript object constructors and sample data based on Joi schema.","archived":false,"fork":false,"pushed_at":"2021-02-10T03:05:34.000Z","size":508,"stargazers_count":111,"open_issues_count":9,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T03:32:45.028Z","etag":null,"topics":["hapi","javascript","joi","models","nodejs","schema","validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xogroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-23T21:40:42.000Z","updated_at":"2024-07-28T03:18:45.000Z","dependencies_parsed_at":"2022-08-13T20:01:06.739Z","dependency_job_id":null,"html_url":"https://github.com/xogroup/felicity","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xogroup%2Ffelicity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xogroup%2Ffelicity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xogroup%2Ffelicity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xogroup%2Ffelicity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xogroup","download_url":"https://codeload.github.com/xogroup/felicity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161261,"owners_count":21057554,"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":["hapi","javascript","joi","models","nodejs","schema","validation"],"created_at":"2024-07-31T14:00:55.358Z","updated_at":"2025-04-10T04:56:28.112Z","avatar_url":"https://github.com/xogroup.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# felicity\nFelicity supports [Joi](https://www.github.com/hapijs/joi) schema management by providing 2 primary functions:\n\n  1. **Testing support** - Felicity will leverage your Joi schema to generate randomized data directly from the schema. This can be used for database seeding or fuzz testing.\n  2. **Model management in source code** - Felicity can additionally leverage your Joi schema to create constructor functions that contain immutable copies of the Joi schema as well as a simple `.validate()` method that will run Joi validation of the object instance values against the referenced Joi schema.\n\n[![npm version](https://badge.fury.io/js/felicity.svg)](https://badge.fury.io/js/felicity)\n[![Build Status](https://travis-ci.org/xogroup/felicity.svg?branch=master)](https://travis-ci.org/xogroup/felicity)\n[![Known Vulnerabilities](https://snyk.io/test/github/xogroup/felicity/badge.svg)](https://snyk.io/test/github/xogroup/felicity)\n\nLead Maintainer: [Wes Tyler](https://github.com/WesTyler)\n\n## Introduction\n\u003e **fe·lic·i·ty** *noun* intense happiness; the ability to find appropriate expression for one's thoughts or intentions.\n\nFelicity provides object instances, or expressions, of the data intentions represented by Joi schema.\n\nFelicity builds upon Joi by allowing validation to be contained cleanly and nicely in constructors while also allowing easy example generation for documentation, tests, and more.\n\n## Installation\n```\nnpm install felicity\n```\n\n## Usage\n### Model Management\nGiven a [joi](https://www.github.com/hapijs/joi) schema, create an object Constructor and instantiate skeleton objects:\n```JavaScript\nconst Joi      = require('joi');\nconst Felicity = require('felicity');\n\nconst joiSchema = Joi.object().keys({\n    key1: Joi.string().required(),\n    key2: Joi.array().items(Joi.string().guid()).min(3).required(),\n    key3: Joi.object().keys({\n        innerKey: Joi.number()\n    })\n});\n\nconst FelicityModelConstructor = Felicity.entityFor(joiSchema);\nconst modelInstance = new FelicityModelConstructor({ key1: 'some value' });\n\nconsole.log(modelInstance);\n/*\n{\n    key1: 'some value',\n    key2: [],\n    key3: {\n        innerKey: 0\n    }\n}\n*/\n```\n\nThese model instances can self-validate against the schema they were built upon:\n```JavaScript\nmodelInstance.key3.innerKey = 42;\n\nconst validationResult = modelInstance.validate(); // uses immutable copy of the Joi schema provided to `Felicity.entityFor()` above\n\nconsole.log(validationResult);\n/*\n{\n    success: false,\n    errors : [\n        {\n            \"message\": \"\\\"key2\\\" must contain at least 3 items\",\n            \"path\": [ \"key2\" ],\n            \"type\": \"array.min\",\n            \"context\": {\n                \"limit\": 3,\n                \"value\": [],\n                \"key\": \"key2\",\n                \"label\": \"key2\"\n            }\n        },\n        // ...\n    ]\n}\n*/\n```\n\n### Testing Usage\nAdditionally, Felicity can be used to randomly generate valid examples from either your [Felicity Models](#model-management) or directly from a Joi schema:\n```Javascript\nconst randomModelValue = FelicityModelConstructor.example(); // built in by `Felicity.entityFor()`\n/*\n{\n    key1: '2iwf8af2v4n',\n    key2:[\n        '077750a4-6e6d-4b74-84e2-cd34de80e95b',\n        '1a8eb515-72f6-4007-aa73-a33cd4c9accb',\n        'c9939d71-0790-417a-b615-6448ca95c30b'\n    ],\n    key3: { innerKey: 3.8538257114788257 }\n}\n*/\n\n// directly from Joi schemas:\nconst stringSchema = Joi.string().pattern(/[a-c]{3}-[d-f]{3}-[0-9]{4}/);\nconst sampleString = Felicity.example(stringSchema);\n// sampleString === 'caa-eff-5144'\n\nconst objectSchema = Joi.object().keys({\n    id      : Joi.string().guid(),\n    username: Joi.string().min(6).alphanum(),\n    numbers : Joi.array().items(Joi.number().min(1))\n});\nconst sampleObject = Felicity.example(objectSchema);\n/*\nsampleObject\n{\n    id: '0e740417-1708-4035-a495-6bccce560583',\n    username: '4dKp2lHj',\n    numbers: [ 1.0849635479971766 ]\n}\n*/\n```\n### Node.js version compatibility\nPlease note that Felicity follows [Node.js LTS support schedules](https://nodejs.org/en/about/releases/) as well as Joi Node.js version support.\n\nBeginning with Felicity@6.0.0, only Node.js versions 12 and above will be supported.\n\n## API\n\nFor full usage documentation, see the [API Reference](https://github.com/xogroup/felicity/blob/master/API.md).\n\n## Contributing\n\nWe love community and contributions! Please check out our [guidelines](https://github.com/xogroup/felicity/blob/master/.github/CONTRIBUTING.md) before making any PRs.\n\n## Setting up for development\n\nGetting yourself setup and bootstrapped is easy.  Use the following commands after you clone down.\n\n```\nnpm install \u0026\u0026 npm test\n```\n\n## Joi features not yet supported\n\nSome Joi schema options are not yet fully supported. Most unsupported features should not cause errors, but may be disregarded by Felicity or may result in behavior other than that documented in the Joi api.\n\nA feature is considered Felicity-supported when it is explicitly covered in tests on both `entityFor` (and associated instance methods) and `example`.\n\n- Function\n  - `ref`\n- Array\n  - `unique`\n- Object\n  - `requiredKeys`\n  - `optionalKeys`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxogroup%2Ffelicity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxogroup%2Ffelicity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxogroup%2Ffelicity/lists"}