{"id":18817851,"url":"https://github.com/vitorluizc/uncouple","last_synced_at":"2025-04-13T23:25:22.827Z","repository":{"id":48034930,"uuid":"118147971","full_name":"VitorLuizC/uncouple","owner":"VitorLuizC","description":"📂 Uncouple constructors and classes methods into functions.","archived":false,"fork":false,"pushed_at":"2023-01-03T21:46:56.000Z","size":1120,"stargazers_count":14,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T17:05:31.716Z","etag":null,"topics":["functional-programming","javascript","uncouple"],"latest_commit_sha":null,"homepage":"","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/VitorLuizC.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":"2018-01-19T16:15:52.000Z","updated_at":"2023-03-17T15:18:57.000Z","dependencies_parsed_at":"2023-02-01T10:30:52.007Z","dependency_job_id":null,"html_url":"https://github.com/VitorLuizC/uncouple","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Funcouple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Funcouple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Funcouple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Funcouple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VitorLuizC","download_url":"https://codeload.github.com/VitorLuizC/uncouple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248795361,"owners_count":21162756,"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":["functional-programming","javascript","uncouple"],"created_at":"2024-11-08T00:13:39.862Z","updated_at":"2025-04-13T23:25:22.803Z","avatar_url":"https://github.com/VitorLuizC.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Uncouple\n\n[![Build Status](https://travis-ci.org/VitorLuizC/uncouple.svg?branch=master)](https://travis-ci.org/VitorLuizC/uncouple)\n[![License](https://badgen.net/github/license/VitorLuizC/uncouple)](./LICENSE)\n[![Install size](https://packagephobia.now.sh/badge?p=uncouple)](https://packagephobia.now.sh/result?p=uncouple)\n[![Library minified size](https://badgen.net/bundlephobia/min/uncouple)](https://bundlephobia.com/result?p=uncouple)\n[![Library minified + gzipped size](https://badgen.net/bundlephobia/minzip/uncouple)](https://bundlephobia.com/result?p=uncouple)\n\nUncouple constructors and classes methods into functions.\n\n## Installation\n\nThis library is published in the NPM registry and can be installed using any compatible package manager.\n\n```sh\nnpm install uncouple --save\n\n# For Yarn, use the command below.\nyarn add uncouple\n```\n\n### Installation from CDN\n\nThis module has an UMD bundle available through JSDelivr and Unpkg CDNs.\n\n```html\n\u003c!-- For UNPKG use the code below. --\u003e\n\u003cscript src=\"https://unpkg.com/uncouple\"\u003e\u003c/script\u003e\n\n\u003c!-- For JSDelivr use the code below. --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/uncouple\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  // UMD module is exposed through the \"uncouple\" global function.\n  console.log(uncouple);\n\n  var O = uncouple(Object);\n  var isFetchDefined = O.hasOwnProperty(window, 'fetch');\n\u003c/script\u003e\n```\n\n## Usage\n\nModule default exports uncouple function.\n\n`uncouple` receives a constructor or a class as argument and returns an object with its uncoupled methods.\n\n```js\nimport uncouple from 'uncouple';\n\nconst O = uncouple(Object);\n// =\u003e {\n//   hasOwnProperty: ƒ ()\n//   isPrototypeOf: ƒ ()\n//   propertyIsEnumerable: ƒ ()\n//   toLocaleString: ƒ ()\n//   toString: ƒ ()\n//   valueOf: ƒ ()\n// }\n\nconst hasFetch = O.hasOwnProperty(window, 'fetch');\n// =\u003e true\n```\n\nAll uncoupled methods receives an instance as first argument followed by method arguments.\n\n```js\nconst { trim, substr } = uncouple(String);\n\ntrim('   Okay    ');\n//=\u003e 'Okay'\n\nsubstr('ABCDEF', -3);\n//=\u003e 'CDF'\n```\n\nIt also works for Function constructors and classes.\n\n```js\nfunction User(name) {\n  this.name = name;\n}\n\nUser.prototype.getName = function() {\n  console.log(this.name);\n};\n\nconst { getName } = uncouple(User);\n\ngetName(new User('João'));\n//=\u003e 'João'\n\nclass Car {\n  speed = 0;\n\n  acelerate(speed) {\n    this.speed += speed;\n  }\n}\n\nconst { acelerate } = uncouple(Car);\n\nconst uno = new Car();\n\nacelerate(uno, 120);\nacelerate(uno, 60);\n\nuno.speed;\n//=\u003e 180\n```\n\n## Use cases\n\nYou can reuse methods with duck types, like Array.prototype.filter in a NodeList.\n\n```js\nconst { filter } = uncouple(Array);\n\nconst anchors = document.getElementsByTagName('a');\n//=\u003e NodeListOf\u003cHTMLAnchorElement\u003e\n\nconst isLink = anchor =\u003e /^https?:\\/\\//.test(anchor.href);\n\nconst links = filter(anchors, isLink);\n//=\u003e Array\u003cHTMLAnchorElement\u003e\n```\n\nCompositions and smart pipelines became pretty and readable with uncoupled methods.\n\n```js\nconst {\n  trim,\n  replace,\n  normalize,\n  toLocaleLowerCase\n} = uncouple(String);\n\n\" Olá, como vai  vocÊ?\"\n|\u003e normalize(#, 'NFKD')\n|\u003e replace(#, /[\\u0080-\\uF8FF]/g, '')\n|\u003e trim\n|\u003e replace(#, /\\s+/g, ' ')\n|\u003e toLocaleLowerCase\n//=\u003e 'ola, como vai voce?'\n\nconst normalize = compose(\n  toLocaleLowerCase,\n  (value) =\u003e replace(value, /\\s+/g, ' '),\n  trim,\n  (value) =\u003e replace(value, /[\\u0080-\\uF8FF]/g, '')\n  (value) =\u003e normalize(value, 'NFKD'),\n);\n\nnormalize(' Meu nome é Vitor   , meus bons')\n//=\u003e 'meu nome e vitor, meus bons'\n```\n\nWith `uncouple` you can call `Object` methods with `Object.create(null)`, which returns an empty object without prototype.\n\n```js\nconst user = Object.create(null);\n\nuser.name = '@VitorLuizC';\n\nuser.hasOwnProperty('name');\n//=\u003e throws TypeError: user.hasOwnProperty is not a function\n\nconst { hasOwnProperty: has } = uncouple(Object);\n\nhas(user, 'name');\n//=\u003e true\n```\n\n## License\n\nReleased under [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorluizc%2Funcouple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitorluizc%2Funcouple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorluizc%2Funcouple/lists"}