{"id":13518922,"url":"https://github.com/mako-taco/DecorateThis","last_synced_at":"2025-03-31T11:30:59.238Z","repository":{"id":32509387,"uuid":"36090401","full_name":"mako-taco/DecorateThis","owner":"mako-taco","description":"JS Decorators library","archived":false,"fork":false,"pushed_at":"2015-06-08T23:05:21.000Z","size":383,"stargazers_count":537,"open_issues_count":3,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-08T03:16:42.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mako-taco.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}},"created_at":"2015-05-22T19:07:46.000Z","updated_at":"2025-02-11T03:26:50.000Z","dependencies_parsed_at":"2022-09-05T09:00:54.595Z","dependency_job_id":null,"html_url":"https://github.com/mako-taco/DecorateThis","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mako-taco%2FDecorateThis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mako-taco%2FDecorateThis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mako-taco%2FDecorateThis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mako-taco%2FDecorateThis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mako-taco","download_url":"https://codeload.github.com/mako-taco/DecorateThis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246461555,"owners_count":20781346,"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":[],"created_at":"2024-08-01T05:01:50.842Z","updated_at":"2025-03-31T11:30:58.968Z","avatar_url":"https://github.com/mako-taco.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# DecorateThis\nSimple, vanilla JS type checking through ES7 decorators\n...and a few other decorators, to boot.\n\n- [Installation](#incorporating-in-your-project)\n- [Changelog](/docs/CHANGELOG.md)\n- Documentation\n  - [Type validation](#type-validation)\n    - [param](#type-validation)\n    - [returns](#type-validation)\n    - [promises](#promises)\n    - [Validating Complex Types](/docs/TYPE_VALIDATOR_API.md)\n  - [memoize](#memoization)\n  - [debounce](#debouncing)\n  - [curry](#currying)\n  - [configurable](#property-descriptors)\n  - [writable](#property-descriptors)\n  - [enumerable](#property-descriptors)\n\nIf you like this project, be sure to check out [FluxThis](https://github.com/addthis/FluxThis), the immutable Flux framework by [AddThis](http://www.addthis.com).\n\n[![npm version](https://badge.fury.io/js/decorate-this.svg)](http://badge.fury.io/js/decorate-this)\n[![Build Status](https://travis-ci.org/mako-taco/DecorateThis.svg?branch=master)](https://travis-ci.org/mako-taco/DecorateThis)\n\n# Type Validation\nThrow errors when unexpected types are provided or returned from class or object\nfunctions. For more details, see the [Type Validator API](/docs/TYPE_VALIDATOR_API.md).\n```js\nimport {param, returns} from 'decorate-this';\n\nclass Point {\n    constructor() {\n        this.x = 0;\n        this.y = 0;\n    }\n\n    // The first param of this method takes a Point, and will throw\n    // a type error if a non-Point is passed\n    @param(Point)\n    // The method returns a Number. If it doesn't, a type error will\n    // be thrown before the value is returned.\n    @returns(Number)\n    distanceTo(point) {\n        let squaredDistance = (point.x - this.x) ** 2 +\n            (point.y - this.y) ** 2;\n\n        return Math.sqrt(squaredDistance);\n    }\n\n    // Two number args, no return value\n    @param(Number)\n    @param(Number)\n    addToDimensions(x, y) {\n        this.x += x;\n        this.y += y;\n    }\n}\n```\n\n# Memoization\nAutomatically memoize functions for greater efficiency\n```js\nimport memoize from 'decorate-this';\nlet obj = {\n    // Results of the function are stored in a map, which maps arguments\n    // to the function's result. This expensive func is only run a single\n    // time for a given a/b pair.\n    @memoize\n    expensiveFunc(a, b) {\n        return Math.sin(Math.sqrt(a ** b));\n    }\n};\n```\n\n# Property descriptors\n```js\nimport {enumerable, writable, configurable} from 'decorate-this';\n\nclass T {\n    @configurable(false)\n    @enumerable(false)\n    @writable(false)\n    hiddenMethod() {\n        /* ... */\n    }\n}\n```\n\n# Currying\nBuild up long argument lists with currying\n```js\nlet obj = {\n    @curry\n    curriedAdd(a, b, c) {\n        return a + b + c;\n    }\n}\n\nlet addToFive = obj.curriedAdd(5);   // Function\nlet addToFiveAndThree = addToFive(3);  // Function\nlet sum = addToFiveAndThree(7);      // 15\n```\n\n# Debouncing\nRate-limit expensive or frequently called functions\n\n```js\nlet obj = {\n    @debounce(500) // call after 500ms of no further calls\n    debouncedFn(event) {\n        console.log(event.clientX, event.clientY);\n    }\n}\n```\n\n# Promises\nSimilar to `returns`, but validates the fulfillment value of a promise\n```js\nlet obj = {\n    @promises(ArrayOf(Number))\n    getPoints() {\n        return new Promise(resolve =\u003e {\n            setTimeout(() =\u003e resolve([1, 2, 3]), 5000);\n        });\n    }\n}\n```\n\n# Incorporating in your project\n```\nnpm install decorate-this\n```\n\n- Build your project with Babel\n- Enable stage 1 (experimental) features\n- Profit\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmako-taco%2FDecorateThis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmako-taco%2FDecorateThis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmako-taco%2FDecorateThis/lists"}