{"id":51590586,"url":"https://github.com/bentimor/decraft","last_synced_at":"2026-07-11T14:03:10.423Z","repository":{"id":168951575,"uuid":"644754049","full_name":"BenTimor/Decraft","owner":"BenTimor","description":"Craft TypeScript decorators easily","archived":false,"fork":false,"pushed_at":"2023-05-24T08:50:12.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-07T08:09:37.887Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenTimor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-05-24T07:29:27.000Z","updated_at":"2023-05-30T07:37:38.000Z","dependencies_parsed_at":"2023-05-28T07:15:17.107Z","dependency_job_id":null,"html_url":"https://github.com/BenTimor/Decraft","commit_stats":null,"previous_names":["bentimor/decraft"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BenTimor/Decraft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenTimor%2FDecraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenTimor%2FDecraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenTimor%2FDecraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenTimor%2FDecraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenTimor","download_url":"https://codeload.github.com/BenTimor/Decraft/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenTimor%2FDecraft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35364269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-11T02:00:05.354Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2026-07-11T14:03:09.522Z","updated_at":"2026-07-11T14:03:10.418Z","avatar_url":"https://github.com/BenTimor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Decraft - Smart TypeScript Decorators\n\nDecraft is a user-friendly npm package that simplifies the creation of TypeScript decorators, significantly enhancing their power and readability. With Decraft, crafting intuitive and efficient decorators is a streamlined and enjoyable experience.\n\n## Starting from the end - How does you use the decorators?\n\nLets say that we created a decorator named `@myDecorator`. Those are all of the ways that we can use **the same decorator**.\n\nWe don't need to create a new decorator for each case, we can just use the same one for all of those cases.\n\n### @myDecorator\n\nThe classic way to use decorators. Just put it above a class method.\n\n```typescript\nclass MyClass {\n\t@myDecorator\n\tfunc(...params) {\n\t\t// code\n\t}\n}\n```\n\n### @myDecorator(...args)\n\nWe can also pass arguments to our decorator.\n\n```typescript\nclass MyClass {\n\t@myDecorator(...args)\n\tfunc(...params) {\n\t\t// code\n\t}\n}\n```\n\n### myDecorator(func, args)\n\n\u003e Whooho, This is not a decorator!\n\nYou are right. But one of the issues with decorators is that we can't use them in some cases. For example for callbacks or functions outside of a class.\n\nSo with decraft, we allow you to use some hacks.\n\n```typescript\nconst func = myDecorator((...params) =\u003e {\n\t// code\n}, ...args);\n``` \n\nor another example:\n```typescript\nfunction _func(...params) {\n  // code\n}\n\nconst func = myDecorator(_func, ...args)\n```\n\n### myDecorator(...args)(func)\n\nWe allow also a different approach for readability.\n\n```typescript\nconst func = myDecorator(...args)((...params) =\u003e {\n\t// code\n});\n```\n\n## How to create a decorator?\n\nIt's pretty straightforward. We call the `decorator` function and pass as a generic a list of types that will be used for the decorator arguments.\n\nThen we pass a callback which will be called each time we create the function (or the object it exists in). \n\nIt may also return a function, and this function will **replace** the function that the decorator is used on.\n\n```typescript\nconst  myDecorator  =  decorator\u003c[...DecoratorParamsTypes]\u003e((func, decoratorParams) =\u003e {\n\t// The function that we return here will replace the function that it's being used on\n\treturn (...args:  any[]) =\u003e {\n\t\t// We're doing nothing, just calling the function\n\t\treturn  func(...args);\n\t};\n\n\t// If we prefer, we can also return nothing and the decorator function will not replace the function that it's being used on\n});\n```\n\n## Our best practices\n\n1. We still have several type issues, so we recommend to check that you really got the params you wanted to get.\n2. Don't return a function with different type that the one you got. TypeScript not updating the function types right now when using this decorator.\n3. When using decorator as a function like this: `myDecorator(func, ...args)` or `myDecorator(...args)(func)` you should set a type to the variable it's assigned to. We return `any` right now as a type.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbentimor%2Fdecraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbentimor%2Fdecraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbentimor%2Fdecraft/lists"}