{"id":25837271,"url":"https://github.com/devtin/duckfficer","last_synced_at":"2025-03-01T02:48:07.183Z","repository":{"id":40290869,"uuid":"228456718","full_name":"devtin/duckfficer","owner":"devtin","description":"Zero-dependencies light-weight library for modeling, validating and sanitizing data 🦆 🐵 👁","archived":false,"fork":false,"pushed_at":"2023-01-07T04:27:43.000Z","size":4233,"stargazers_count":3,"open_issues_count":8,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T15:36:26.608Z","etag":null,"topics":["coercion","data","duck-typing","json","parsing","schema","validation"],"latest_commit_sha":null,"homepage":"https://devtin.github.io/duckfficer","language":"HTML","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/devtin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":["https://www.paypal.me/devtin"]}},"created_at":"2019-12-16T19:09:59.000Z","updated_at":"2021-09-27T17:21:38.000Z","dependencies_parsed_at":"2023-02-06T11:46:39.925Z","dependency_job_id":null,"html_url":"https://github.com/devtin/duckfficer","commit_stats":null,"previous_names":["devtin/schema-validator"],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fduckfficer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fduckfficer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fduckfficer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fduckfficer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devtin","download_url":"https://codeload.github.com/devtin/duckfficer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241309091,"owners_count":19941726,"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":["coercion","data","duck-typing","json","parsing","schema","validation"],"created_at":"2025-03-01T02:48:06.641Z","updated_at":"2025-03-01T02:48:07.171Z","avatar_url":"https://github.com/devtin.png","language":"HTML","funding_links":["https://www.paypal.me/devtin"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg align=\"center\" width=\"480\" src=\"https://repository-images.githubusercontent.com/228456718/f4767e00-61e6-11ea-964a-7b02d8dcb48f\"/\u003e\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\u003ch1 align=\"center\"\u003educkfficer\u003c/h1\u003e\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/duckfficer\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/duckfficer.svg\" alt=\"Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://htmlpreview.github.io/?https://github.com/devtin/duckfficer/blob/master/coverage/lcov-report/index.html\"\u003e\u003cimg src=\"https://img.shields.io/badge/coverage-99%25-green\" alt=\"Coverage 99%\"\u003e\u003c/a\u003e\n\u003ca href=\"/test/features\"\u003e\u003cimg src=\"https://github.com/devtin/duckfficer/workflows/test/badge.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-brightgreen.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nZero-dependencies, light-weight library (~4.6KB minified + gzipped)\u003cbr\u003e\nfor modeling, validating \u0026 sanitizing data\n\u003c/p\u003e\n\n## Manifesto\n\nPerforming duck-type validation and data sanitation is not what I came to this world for... I want a utility helping me\nsimplify that task.\n\nThis utility must:\n\n- Check whether certain value has the shape of a predefined schema-type\n- When a given value does not match the schema, it must offer a full report of what is wrong with the given\n  value vs what the schema is expecting! (see: [https://duckfficer.js.org/#/guide?id=error-handling-and-lifecycle](https://duckfficer.js.org/#/guide?id=error-handling-and-lifecycle))\n- Be easy to extend and share schemas within each other (see: [https://duckfficer.js.org/#/guide?id=nesting-schemas](https://duckfficer.js.org/#/guide?id=nesting-schemas))\n- Provide a built-in set of types for most common usages (see: [https://duckfficer.js.org/#/types](https://duckfficer.js.org/#/types))\n- Allow custom types as well as a cast and transform hooks (see: [https://duckfficer.js.org/#/types?id=custom](https://duckfficer.js.org/#/types?id=custom))\n\n\nLet's put hands on it!\n\n**Index**\n\n- [Installation](#installation)\n- [About](#about)\n- [At a glance](#at-a-glance)\n- [Documentation](https://devtin.github.io/duckfficer)\n\n## Installation\n\n```sh\n$ npm i duckfficer\n# or\n$ yarn add duckfficer\n```\n\n## At-a-glance\n\n```js\nconst { Schema } = require('duckfficer')\n\n// lets create a schema first\nconst User = new Schema({\n  firstName: String,\n  lastName: String,\n  get fullName () {\n    return this.firstName + ' ' + this.lastName\n  },\n  dob: Date,\n  contact: {\n    phoneNumber: {\n      type: Number,\n      autoCast: true // transforms String that look like a number into a Number\n    },\n    emails: {\n      default () {\n        return []\n      },\n      type: Array,\n      arraySchema: {\n        type: String,\n        regex: [/^[a-z0-9._]+@[a-z0-9-]+\\.[a-z]{2,}$/, '{ value } is not a valid e-mail address']\n      }\n    }\n  }\n})\n\nUser.parse({\n  firstName: 'Fulano de Tal',\n  contact: {\n    emails: ['fulanito']\n  }\n})\n  .catch(err =\u003e {\n    console.log(err.message) // =\u003e Data is not valid\n    console.log(err.errors.length) // =\u003e 4\n    console.log(err.errors[0].message) // =\u003e Property lastName is required\n    console.log(err.errors[0].field.fullPath) // =\u003e lastName\n    console.log(err.errors[1].message) // =\u003e Property dob is required\n    console.log(err.errors[1].field.fullPath) // =\u003e dob\n    console.log(err.errors[2].message) // =\u003e Property contact.phoneNumber is required\n    console.log(err.errors[2].field.fullPath) // =\u003e contact.phoneNumber\n    console.log(err.errors[3].message) // =\u003e fulanito is not a valid e-mail address\n    console.log(err.errors[3].field.fullPath) // =\u003e contact.emails.0\n  })\n\nUser.parse({\n  firstName: 'Fulano',\n  lastName: 'de Tal',\n  dob: '1/1/2020',\n  contact: {\n    phoneNumber: '3051234567',\n    emails: [\n      'personal@email.com',\n      'work@email.com'\n    ]\n  }\n})\n  .then(obj =\u003e {\n    console.log(obj.dob instanceof Date) // =\u003e true\n    console.log(typeof obj.contact.phoneNumber) // =\u003e number\n    console.log(obj) // =\u003e\n    /*\n      {\n        firstName: 'Fulano',\n        lastName: 'de Tal',\n        dob: 2020-01-01T05:00:00.000Z,\n        contact: {\n          phoneNumber: 3051234567,\n          emails: [ 'personal@email.com', 'work@email.com' ]\n        }\n      }\n    */\n  })\n```\n\n\n[Read the documentation](https://devtin.github.io/duckfficer)\n\n* * *\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\n\u0026copy; 2019-2020 Martin Rafael \u003ctin@devtin.io\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevtin%2Fduckfficer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevtin%2Fduckfficer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevtin%2Fduckfficer/lists"}