{"id":22814185,"url":"https://github.com/mamedul/objectpropvalidator","last_synced_at":"2026-04-28T20:07:50.900Z","repository":{"id":57312980,"uuid":"436016099","full_name":"mamedul/objectpropvalidator","owner":"mamedul","description":"simple and small fine object properties validation checker with suggestions","archived":false,"fork":false,"pushed_at":"2025-08-30T15:27:31.000Z","size":284,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-03T14:16:42.188Z","etag":null,"topics":["javascript","mamedul","momedul","object","object-properties","objectpropvalidator","validator"],"latest_commit_sha":null,"homepage":"https://mamedul.github.io/objectpropvalidator/","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/mamedul.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-07T20:23:51.000Z","updated_at":"2025-09-24T01:02:09.000Z","dependencies_parsed_at":"2022-09-20T23:11:50.616Z","dependency_job_id":null,"html_url":"https://github.com/mamedul/objectpropvalidator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/mamedul/objectpropvalidator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamedul%2Fobjectpropvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamedul%2Fobjectpropvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamedul%2Fobjectpropvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamedul%2Fobjectpropvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mamedul","download_url":"https://codeload.github.com/mamedul/objectpropvalidator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamedul%2Fobjectpropvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32396862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","mamedul","momedul","object","object-properties","objectpropvalidator","validator"],"created_at":"2024-12-12T13:07:31.269Z","updated_at":"2026-04-28T20:07:50.893Z","avatar_url":"https://github.com/mamedul.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# objectPropValidator: Simple, Recursive JavaScript Object Validation\n\n[![Version](https://img.shields.io/badge/version-2.0.1-blue.svg)](https://github.com/mamedul/objectpropvalidator)\n![visitors](https://visitor-badge.laobi.icu/badge?page_id=mamedul.objectpropvalidator)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Made with Love in Bangladesh](https://img.shields.io/badge/Made%20with%20%E2%9D%A4%EF%B8%8F%20in-Bangladesh-green.svg)](https://mamedul.github.io/)\n[![Hire Me](https://img.shields.io/badge/Hire%20Me-Available-brightgreen.svg)](https://mamedul.github.io/)\n\n\n**objectPropValidator** is a lightweight, zero-dependency JavaScript utility for validating object properties against a defined schema. It's designed to be simple, flexible, and powerful, allowing for recursive validation of nested objects with clear, helpful error messages.\n\nWhether you're validating API responses, configuration objects, or function arguments, this library ensures your data structure is correct without adding bloat to your project.\n\n---\n\n## Core Features\n\n* ✅ **Schema-Based Validation**: Define a clear and reusable schema for your objects.\n* recursi **Recursive/Nested Validation**: Effortlessly validate complex, nested object structures.\n* 💪 **Flexible Rules**: Check for property `type`, whether it's `required`, and add your own custom `validator` functions.\n* 🎯 **Specific Error Logging**: Get clear, actionable error messages in the console that pinpoint exactly what failed.\n* 🕊️ **Lightweight \u0026 Zero-Dependency**: Tiny footprint. No external libraries needed.\n* 🌐 **Universal Compatibility**: Works in modern browsers and Node.js environments.\n\n---\n\n## Installation\n\nYou can use `objectPropValidator` by directly including the script in your HTML.\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/mamedul/objectpropvalidator/src/objectpropvalidator.min.js\"\u003e\u003c/script\u003e\n```\n\nOr for `npm` installation\n\n```ssh\nnpm install objectpropvalidator\n```\n\n---\n\n## Quick Start: Basic Usage\n\nGetting started is simple. Just define a schema and create a validator function from it.\n\n1.  **Define a `schema`** that describes the expected structure of your object.\n2.  **Call `objectPropValidator(schema)`** to create a reusable validator function.\n3.  **Use the new function** to check your data object. It returns `true` or `false`.\n\n```javascript\n// 1. Define the validation schema\nconst userSchema = {\n  name: {\n    type: String,\n    required: true\n  },\n  email: {\n    type: String,\n    required: false // This property is optional\n  },\n  age: {\n    type: Number,\n    required: true,\n    // Add a custom validator function for more complex logic\n    validator(value) {\n      const isValid = value \u003e= 18;\n      if (!isValid) {\n        console.error(\"[Validation Error] User must be 18 or older.\");\n      }\n      return isValid;\n    }\n  }\n};\n\n// 2. Create a reusable validator function\nconst validateUser = objectPropValidator(userSchema);\n\n// 3. Test it with some data\nconst validUser = {\n  name: \"Mamedul Islam\",\n  age: 26\n};\n\nconst invalidUser = {\n  name: 12345, // Wrong type\n  // 'age' is missing\n};\n\nconsole.log(\"Is the first user valid?\", validateUser(validUser)); // true\n\nconsole.log(\"Is the second user valid?\", validateUser(invalidUser)); // false\n// Console will show:\n// [Validation Error] Invalid type for property 'name'. Expected 'String' but received 'Number'.\n// [Validation Error] Missing required property: 'age'\n```\n\n---\n\n## Advanced Usage\n\n### Nested Object Validation\n\nThe real power of `objectPropValidator` comes from its ability to handle nested objects recursively. Simply set the `validator` property to another validator instance.\n\n```javascript\n// Schema for a user object\nconst userValidator = objectPropValidator({\n  id: { type: Number, required: true },\n  username: { type: String, required: true }\n});\n\n// Schema for a blog post, which includes a nested 'author' object\nconst postSchema = {\n  title: {\n    type: String,\n    required: true\n  },\n  author: {\n    type: Object,\n    required: true,\n    validator: userValidator // Use the user validator here!\n  }\n};\n\nconst validatePost = objectPropValidator(postSchema);\n\nconst validPost = {\n  title: \"My First Post\",\n  author: {\n    id: 1,\n    username: \"mamedul\"\n  }\n};\n\nconst invalidPost = {\n    title: \"Another Post\",\n    author: {\n        id: \"2\" // Invalid type, should be Number\n    }\n};\n\nconsole.log(validatePost(validPost));   // true\nconsole.log(validatePost(invalidPost)); // false\n// Console will show:\n// [Validation Error] Invalid type for property 'id'. Expected 'Number' but received 'String'.\n```\n\n### Configuring Error Logs\n\nYou can pass a configuration object as the second argument to control how errors are logged.\n\n```javascript\nconst config = {\n  logLevel: 'warn' // Use console.warn instead of the default console.error\n};\n\nconst myValidator = objectPropValidator(mySchema, config);\n```\n\n* **`logLevel`**: Can be `'error'` (default), `'warn'`, or `'log'`.\n\n---\n\n## API Reference\n\n### `objectPropValidator(schema, [config])`\n\nCreates and returns a new validator function.\n\n* **`schema`** `(Object)`: An object where each key is a property to validate. The value is an object containing the validation rules.\n* **`config`** `(Object, optional)`: Configuration options.\n    * **`logLevel`** `(String)`: Sets the console logging method. Defaults to `'error'`.\n\n### Schema Rule Properties\n\nFor each property in your `schema`, you can define the following rules:\n\n* **`type`** `(Constructor | Array\u003cConstructor\u003e)`: The expected type (e.g., `String`, `Number`, `Object`, `Array`). You can also provide an array for multiple allowed types, like `[String, Number]`.\n* **`required`** `(Boolean)`: If `true`, the property must exist in the object being validated.\n* **`validator`** `(Function)`: A custom function that receives the property's value and should return `true` if valid, and `false` otherwise. This is also the mechanism for nested validation.\n\n---\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue on the [GitHub repository](https://github.com/mamedul/objectpropvalidator).\n\n---\n\n## License\n\nThis project is licensed under the **MIT License**. Copyright (c) 2022 by [**Mamedul Islam**](https://mamedul.github.io/).\n\nSee the [LICENSE](https://opensource.org/licenses/MIT) file for more details.\n\n---\n\n## Author \u0026 Hire Me\n\nThis project was created and is maintained by [**Mamedul Islam**](https://mamedul.github.io/).\n\n\nI am a passionate **web developer** with experience in creating interactive and user-friendly web components. I am currently *available for freelance projects* or full-time opportunities.\n\nI help businesses grow their online presence with custom web solutions. Specializing in **WordPress**, **WooCommerce**, and **Shopify**, I build modern, responsive, and high-performance websites.\n\n* **WhatsApp**: [message me](https://wa.me/8801847406830?text=Hi%2C%20I%27d%20like%20to%20hire%20you.)\n* **Portfolio**: [mamedul.github.io](https://mamedul.github.io/)\n* **GitHub**: [@mamedul](https://github.com/mamedul)\n* **LinkedIn**: [Connect with me!](https://www.linkedin.com/in/mamedul/)\n* **Twitter (X)**: [@mamedul](https://www.x.com/mamedul/)\n\n[![Hire Me](https://img.shields.io/badge/Hire%20Me-Available-brightgreen.svg)](https://mamedul.github.io/)\n\n---\n\n### Show Your Support\n\nIf you find this extension useful, please consider giving it a star on GitHub! Your support helps motivate further development and improvements.\n\n[![GitHub stars](https://img.shields.io/github/stars/mamedul/jquery-scrollpaging?style=for-the-badge)](https://github.com/mamedul/jquery-scrollpaging/stargazers) \u0026nbsp;\n\nIf you found this project helpful, give it a ⭐ on GitHub!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmamedul%2Fobjectpropvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmamedul%2Fobjectpropvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmamedul%2Fobjectpropvalidator/lists"}