{"id":19356872,"url":"https://github.com/alexfigliolia/decorators","last_synced_at":"2026-01-19T12:33:29.568Z","repository":{"id":252848907,"uuid":"841649175","full_name":"alexfigliolia/decorators","owner":"alexfigliolia","description":"A collection of useful decorators for every day programming","archived":false,"fork":false,"pushed_at":"2024-08-13T16:57:47.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-23T21:05:59.592Z","etag":null,"topics":["decorators"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@figliolia/decorators","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexfigliolia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-12T20:41:19.000Z","updated_at":"2024-08-13T16:57:50.000Z","dependencies_parsed_at":"2024-11-26T18:43:37.205Z","dependency_job_id":null,"html_url":"https://github.com/alexfigliolia/decorators","commit_stats":null,"previous_names":["alexfigliolia/decorators"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexfigliolia/decorators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdecorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdecorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdecorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdecorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexfigliolia","download_url":"https://codeload.github.com/alexfigliolia/decorators/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdecorators/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28567899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T08:53:44.001Z","status":"ssl_error","status_checked_at":"2026-01-19T08:52:40.245Z","response_time":67,"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":["decorators"],"created_at":"2024-11-10T07:05:43.914Z","updated_at":"2026-01-19T12:33:29.552Z","avatar_url":"https://github.com/alexfigliolia.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Decorators\nDecorators for everyday programming. \n\nIn this library you'll find a collection of useful shorthands for boosting productivity through the stage 3 Decorators API.\n\n## Installation\n```\nnpm i @figliolia/decorators\n# or \nyarn add @figliolia/decorators\n```\n\n## API\n\n1. [Bound](#bound)\n2. [Cache](#cache)\n3. [Debounce](#debounce)\n4. [Throttle](#throttle)\n5. [Animation Frame](#animation-frame)\n6. [Log Browser](#log-browser)\n7. [Log Server](#log-server)\n8. [Measure Browser](#measure-browser)\n9. [Measure Server](#measure-server)\n10. [Unsafe Chainable](#unsafe-chainable)\n\n### Bound\nImplicitely bind class methods to their instances\n```typescript\nimport { bound } from \"@figliolia/decorators\";\n\nclass MyClass {\n  private someField = \"value\";\n\n  @bound\n  public someMethod() {\n    return this.someField;\n  }\n}\n\nconst { someMethod } = new MyClass();\n// Works\nsomeMethod();\n```\n\n### Cache\nCache previous calls to a given method\n```typescript\nimport { cache } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @cache\n  public expensive(x: number, y: number) {\n    // Compute expensive value\n  }\n}\n\nconst instance = new MyClass();\n// computes on first execution\ninstance.expensive(1, 2);\n// reads from cache then onwards as long as arguments match\ninstance.expensive(1, 2);\n```\n\n### Debounce\nDebounces calls to a given method for a pre-determined duration\n```typescript\nimport { debounce } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @debounce(300)\n  public getData(query: string) {\n    void fetch(`/api/data?query=${query}`);\n  }\n}\n\nconst instance = new MyClass();\n// Invokes 300ms following the last call\nvoid instance.getData(\"searching for something\");\n```\n\n### Throttle\nThrottles calls to a given method for a pre-determined duration\n```typescript\nimport { throttle } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @throttle(300)\n  public getData(query: string) {\n    void fetch(`/api/data?query=${query}`);\n  }\n}\n\nconst instance = new MyClass();\n// Invokes immediately, then disables later calls for 300ms\nvoid instance.getData(\"searching for something\");\n```\n\n### Animation Frame\nInvokes the target method using calls to `requestAnimationFrame`\n```typescript\nimport { animationFrame } from \"@figliolia/decorators\";\n\nclass MyClass {\n  node: HTMLElement;\n  constructor(ID: string) {\n    this.node = document.getElementById(ID);\n  }\n\n  @animationFrame\n  public animate() {\n    const { translate } = this.node.style;\n    const current = parseInt(translate.slice(0, -2));\n    if(current === 100) {\n      return;\n    }\n    this.node.style.translate = `${current + 1}px`;\n    this.animate()\n  }\n}\n\nconst instance = new MyClass(\"elementID\");\n// animates an element's translateX property\ninstance.animate();\n```\n\n### Log Browser\nLogs invokation arguments and return values for a given method as long as the `NODE_ENV` is not `production`\n\nThis method will use native colorized logging (in chrome and firefox)\n```typescript\nimport { logBrowser } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @logBrowser\n  public async getData(query: string) {\n    return fetch(`/api/data?query=${query}`);\n  }\n}\n\nconst instance = new MyClass();\nvoid instance.getData(\"searching for something\");\n```\n\n### Log Server\nLogs invokation arguments and return values for a given method as long as the `NODE_ENV` is not `production`\n\nThis method will use [Chalk](\"https://www.npmjs.com/package/chalk\") for colorized logging\n```typescript\nimport { logServer } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @logServer\n  public async getData(query: string) {\n    return fetch(`/api/data?query=${query}`);\n  }\n}\n\nconst instance = new MyClass();\nvoid instance.getData(\"searching for something\");\n```\n\n### Measure Browser\nLogs the duration occupied by the target method at runtime\n```typescript\nimport { measureBrowser } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @measureBrowser\n  public expensive() {\n    for(let i = 0; i \u003c 1_000_000; i++) {\n\n    }\n  }\n}\n\nconst instance = new MyClass();\ninstance.expensive();\n```\n\n### Measure Server\nLogs the duration occupied by the target method at runtime\n```typescript\nimport { measureServer } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @measureServer\n  public expensive() {\n    for(let i = 0; i \u003c 1_000_000; i++) {\n\n    }\n  }\n}\n\nconst instance = new MyClass();\ninstance.expensive();\n```\n\n### Unsafe Chainable\nOverrides the return type of a given method, replacing it with the class instance\n```typescript\nimport { chainable } from \"@figliolia/decorators\";\n\nclass MyClass {\n  @chainable\n  public async method1() {\n    \n  }\n  @chainable\n  public async method2() {\n    \n  }\n}\n\nconst instance = new MyClass().method1().method(2);\n// instance = MyClass\n```\n\n## Stage 3 Decorator Proposal Vs. Experimental Decorators\nIf you're a typescript developer, the Experimental decorators API (found under the `experimentalDecorators` flag) has likely become familiar to you in recent years. While it's not far from the JavaScript [Stage 3 Proposal](https://github.com/tc39/proposal-decorators), there are significant syntactical mismatches between each decorators implementation that make interoperability impossible.\n\nTherefore, this library will not use TypeScript's experimental implementation, and instead favor JavaScript's Stage 3 Proposal. To read more on the Stage 3 proposal and where it varies from experimental decorators, I'd recommend [this article](https://2ality.com/2022/10/javascript-decorators.html).\n\n### Limitations\nTypescipt is limited in it's ability to transform types based on the presence of a decorator. This means, that if you modify argments or a return type in a decorator, Typescript will not know about it (yet). For the time-being (if you're a typescript user), I'd recommend not mutating method or property declarations in your decorators, and instead limit your usage functional transforms that maintain your application's type safety.\n\n### For JavaScript Users\nUsing this library without a syntax transform will not work any browser or node.js at the time of writing (August 12th, 2024). To ensure your code works smoothly across varying runtimes, check out the [Babel's Transform](https://babeljs.io/blog/2022/09/05/7.19.0#stage-3-decorators-14836) for Stage 3 Decorators.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfigliolia%2Fdecorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexfigliolia%2Fdecorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfigliolia%2Fdecorators/lists"}