{"id":38746998,"url":"https://github.com/arnaugomez/easy-constructor","last_synced_at":"2026-01-17T11:46:55.237Z","repository":{"id":260664617,"uuid":"882006069","full_name":"arnaugomez/easy-constructor","owner":"arnaugomez","description":"JavaScript class constructors, without the boilerplate.","archived":false,"fork":false,"pushed_at":"2025-01-29T13:57:34.000Z","size":1315,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T14:58:30.003Z","etag":null,"topics":["class","constructor","javascript","object-oriented-programming","oop","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/easy-constructor","language":"TypeScript","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/arnaugomez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-01T17:19:36.000Z","updated_at":"2025-01-29T13:57:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"491482df-498d-4afb-b930-0ea9edd3781c","html_url":"https://github.com/arnaugomez/easy-constructor","commit_stats":null,"previous_names":["arnaugomez/easy-constructor"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/arnaugomez/easy-constructor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnaugomez%2Feasy-constructor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnaugomez%2Feasy-constructor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnaugomez%2Feasy-constructor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnaugomez%2Feasy-constructor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnaugomez","download_url":"https://codeload.github.com/arnaugomez/easy-constructor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnaugomez%2Feasy-constructor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28508456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T10:25:30.148Z","status":"ssl_error","status_checked_at":"2026-01-17T10:25:29.718Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["class","constructor","javascript","object-oriented-programming","oop","typescript"],"created_at":"2026-01-17T11:46:54.592Z","updated_at":"2026-01-17T11:46:55.221Z","avatar_url":"https://github.com/arnaugomez.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"logo.webp\" width=\"200px\" align=\"center\" alt=\"Easy Constructor logo\" /\u003e\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eEasy Constructor\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eJavaScript class constructors without the boilerplate\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003c!-- prettier-ignore-start --\u003e\n\t\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n\t\u003ca href=\"#contributors\" target=\"_blank\"\u003e\u003cimg alt=\"👪 All Contributors: 2\" src=\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-2-21bb42.svg\" /\u003e\u003c/a\u003e\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\t\u003c!-- prettier-ignore-end --\u003e\n\t\u003ca href=\"https://github.com/arnaugomez/easy-constructor/blob/main/.github/CODE_OF_CONDUCT.md\" target=\"_blank\"\u003e\u003cimg alt=\"🤝 Code of Conduct: Kept\" src=\"https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://codecov.io/gh/arnaugomez/easy-constructor\" target=\"_blank\"\u003e\u003cimg alt=\"🧪 Coverage\" src=\"https://img.shields.io/codecov/c/github/arnaugomez/easy-constructor?label=%F0%9F%A7%AA%20coverage\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/arnaugomez/easy-constructor/blob/main/LICENSE.md\" target=\"_blank\"\u003e\u003cimg alt=\"📝 License: MIT\" src=\"https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg\"\u003e\u003c/a\u003e\n\t\u003ca href=\"http://npmjs.com/package/easy-constructor\"\u003e\u003cimg alt=\"📦 npm version\" src=\"https://img.shields.io/npm/v/easy-constructor?color=21bb42\u0026label=%F0%9F%93%A6%20npm\" /\u003e\u003c/a\u003e\n\t\u003cimg alt=\"💪 TypeScript: Strict\" src=\"https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg\" /\u003e\n\u003c/p\u003e\n\nWrite JavaScript class constructors in a single line of code.\n\n- Fully type-safe: TypeScript inference that feels like magic :mage:\n- Write classes in half the code == half the bugs :bug: == half the bundle size :package:\n- No more positional arguments. Enjoy named arguments :love_letter:\n\nLet me show you an example. :point_down:\n\n```ts\n// Before\n\nclass ExampleClass {\n  property1: string;\n  property2: number;\n  property3: boolean;\n  property4: string;\n\n  // So much boilerplate!\n  constructor(\n    property1: string,\n    property2: number,\n    property3: boolean,\n    property4: string,\n  ) {\n    // Feels like I'm writing the same thing twice.\n    this.property1 = property1;\n    this.property2 = property2;\n    this.property3 = property3;\n    this.property4 = property4;\n  }\n}\n\n// So many positional arguments. I can't remember what they are!\nconst exampleInstance = new ExampleClass(\"Hello\", 42, true, \"World\");\n```\n\n```ts\n// After\n\nimport { easyConstructor } from \"easy-constructor\";\n\nclass ExampleClass {\n  property1!: string;\n  property2!: number;\n  property3!: boolean;\n  property4!: string;\n\n  // Just one line!\n  static create = easyConstructor(ExampleClass);\n}\n\n// Named arguments! 🎉\nconst exampleInstance = ExampleClass.create({\n  property1: \"Hello\",\n  property2: 42,\n  property3: true,\n  property4: \"World\",\n});\n```\n\n## Installation\n\n```shell\nnpm i easy-constructor\n```\n\n## Advanced usage\n\n### Optional fields and default values\n\nThe `easyConstructor` function treats all class fields as required by default. To make them optional, add them in the `optional` array.\n\n```ts\nimport { easyConstructor } from \"easy-constructor\";\n\nclass ExampleClass {\n  property1!: string;\n  property2!: number;\n  property3?: boolean;\n  property4: string = \"default\";\n\n  static create = easyConstructor(ExampleClass, {\n    optional: [\"property3\", \"property4\"],\n  });\n}\nconst exampleInstance = ExampleClass.create({\n  property1: \"Hello\",\n  property2: 42,\n});\n```\n\nTypeScript will infer the property names and provide auto-completion.\n\n### Omit variables and custom constructor\n\nYou can combine `easyConstructor` with a custom constructor, if you need to initialize some variables with custom logic.\n\nTo exclude variables from the easy constructor, use the `omit` array.\n\n```ts\nclass ExampleClass {\n  property1!: string;\n  property2!: number;\n  property3!: boolean;\n  property4: number;\n\n  static create = easyConstructor(ExampleClass, {\n    omit: [\"property4\"],\n  });\n\n  // Custom constructor\n  constructor(property4: string) {\n    this.property4 = property4 * 2;\n  }\n}\n\nconst exampleInstance = ExampleClass.create(\n  // Easy constructor arguments\n  {\n    property1: \"Hello\",\n    property2: 42,\n    property3: true,\n  },\n  // Custom constructor arguments\n  100,\n);\n```\n\n### Getters and setters\n\nEasy Constructor works with getters and setters too.\n\n```ts\nclass ExampleClass {\n  property1!: string;\n\n  get property2() {\n    return this.property1.length;\n  }\n\n  static create = easyConstructor(ExampleClass, {\n    // Omit getter and setter properties\n    // from the easy constructor\n    omit: [\"property2\"],\n  });\n}\n\nconst exampleInstance = ExampleClass.create({\n  property1: \"Hello\",\n});\n```\n\n### Limitations\n\nDoes not support inheritance.\n\nType inference only works with public fields.\n\nThe properties from the easy constructor are assigned after the custom constructor is called. This means that the custom constructor can't access the properties of the easy constructor.\n\n### When should I (not) use Easy Constructor? :thinking:\n\nEasy Constructor is simple, lightweight, and designed to do one thing very well: remove boilerplate from class constructors.\n\nIt is designed to replace 99% of the constructors in your app, where you are just assigning arguments to properties. However, if you have a very complex constructor, with hefty initialization logic, you should stick to the traditional constructor or use a factory function.\n\n## Contributors\n\n\u003c!-- spellchecker: disable --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/arnaugomez\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/66358043?v=4?s=100\" width=\"100px;\" alt=\"Arnau Gómez Farell\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eArnau Gómez Farell\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/arnaugomez/easy-constructor/commits?author=arnaugomez\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#content-arnaugomez\" title=\"Content\"\u003e🖋\u003c/a\u003e \u003ca href=\"https://github.com/arnaugomez/easy-constructor/commits?author=arnaugomez\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#ideas-arnaugomez\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#infra-arnaugomez\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"#maintenance-arnaugomez\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"#projectManagement-arnaugomez\" title=\"Project Management\"\u003e📆\u003c/a\u003e \u003ca href=\"#tool-arnaugomez\" title=\"Tools\"\u003e🔧\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"http://www.joshuakgoldberg.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/3335181?v=4?s=100\" width=\"100px;\" alt=\"Josh Goldberg ✨\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJosh Goldberg ✨\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#tool-JoshuaKGoldberg\" title=\"Tools\"\u003e🔧\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n## Meme gallery\n\nMemes related to easy-constructor. Express the pain of creating class constructors in vanilla JavaScript. Want to contribute a meme? Open a PR!\n\n\u003ca href=\"https://imgflip.com/i/998kqi\"\u003e\u003cimg src=\"https://i.imgflip.com/998kqi.jpg\" title=\"made at imgflip.com\"/\u003e\u003c/a\u003e\u003cdiv\u003e\u003ca href=\"https://imgflip.com/memegenerator\"\u003efrom Imgflip Meme Generator\u003c/a\u003e\u003c/div\u003e\n\n\u003ca href=\"https://imgflip.com/i/998l3l\"\u003e\u003cimg src=\"https://i.imgflip.com/998l3l.jpg\" title=\"made at imgflip.com\"/\u003e\u003c/a\u003e\u003cdiv\u003e\u003ca href=\"https://imgflip.com/memegenerator\"\u003efrom Imgflip Meme Generator\u003c/a\u003e\u003c/div\u003e\n\n\u003ca href=\"https://imgflip.com/i/998kfa\"\u003e\u003cimg src=\"https://i.imgflip.com/998kfa.jpg\" title=\"made at imgflip.com\"/\u003e\u003c/a\u003e\u003cdiv\u003e\u003ca href=\"https://imgflip.com/memegenerator\"\u003efrom Imgflip Meme Generator\u003c/a\u003e\u003c/div\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\u003c!-- spellchecker: enable --\u003e\n\n\u003c!-- You can remove this notice if you don't want it 🙂 no worries! --\u003e\n\n\u003e 💙 This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnaugomez%2Feasy-constructor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnaugomez%2Feasy-constructor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnaugomez%2Feasy-constructor/lists"}