{"id":16482451,"url":"https://github.com/f/ufcs","last_synced_at":"2026-03-08T15:36:23.087Z","repository":{"id":25999393,"uuid":"29441850","full_name":"f/ufcs","owner":"f","description":"DLang's Universal Function Call Syntax port to JavaScript","archived":false,"fork":false,"pushed_at":"2016-03-07T10:33:10.000Z","size":172,"stargazers_count":43,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T17:08:12.747Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f.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-01-18T21:30:31.000Z","updated_at":"2024-10-25T13:21:29.000Z","dependencies_parsed_at":"2022-08-06T08:00:59.110Z","dependency_job_id":null,"html_url":"https://github.com/f/ufcs","commit_stats":null,"previous_names":["f/ufsc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fufcs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fufcs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fufcs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fufcs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f","download_url":"https://codeload.github.com/f/ufcs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757233,"owners_count":20505355,"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-10-11T13:10:47.059Z","updated_at":"2026-03-08T15:36:23.058Z","avatar_url":"https://github.com/f.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UFCS.js\nDLang's [Uniform Function Call Syntax (UFCS)][1] port to JavaScript\n\n\u003e It's mutates the `Object.prototype`, be careful when you are using it.\n\n## Install\n\n```\nnpm install ufcs\n```\n\n## Overview\n\nA free function can be called with a syntax that looks as if the function were a member function of its first parameter type.\n\nIdea is simple, result is awesome.\n```js\n// With UFCS, you can call this function ...\nfuncName ( firstParameter, [otherParameters...] )\n\n// ... like this.\nfirstParameter.funcName ( [otherParameters...] )\n```\n\n### Uniform Wrapper\n\nJust wrap the function and `ufcs` will handle rest.\n\n```js\nvar uniform = require('ufcs');\n\nuniform(add);\nfunction add(x, y) {\n  return x + y;\n}\n\nvar result = add(2, 3); //=\u003e 5\nvar result = (2).add(3); //=\u003e 5\n```\n\n### Chaining\n\nSince it mutates `Object.prototype` you can use it with every type. So, you can chain the function.\n\n```js\nvar result = add(2, 3).add(4).add(5); //=\u003e 2 + 3 + 4 + 5 = 14\n```\n\n## Examples\n\n```js\nuniform(add);\nfunction add(x, y) { return x + y; }\n\nuniform(remove);\nfunction remove(x, y) { return x - y; }\n\nuniform(multiply);\nfunction multiply(x, y) { return x * y; }\n\nuniform(divide);\nfunction divide(x, y) { return x / y; }\n\n(2).add(3).multiply(6).divide(2).remove(3).add(5).divide(5); //=\u003e 3.4,  It's ((((2 + 3) * 6) / 2) - 3 + 5) / 5\n```\n\n### Multiple Uniform\n\n```js\nfunction add(x, y) { return x + y; }\nfunction remove(x, y) { return x - y; }\nfunction multiply(x, y) { return x * y; }\nfunction divide(x, y) { return x / y; }\n\nuniform(add, remove, multiply, divide);\n\n(2).add(3).multiply(6).divide(2).remove(3).add(5).divide(5); //=\u003e 3.4,  It's ((((2 + 3) * 6) / 2) - 3 + 5) / 5\n```\n\nAlternative syntax:\n\n```js\nuniform(\n  function add(x, y) { return x + y; },\n  function remove(x, y) { return x - y; },\n  function multiply(x, y) { return x * y; },\n  function divide(x, y) { return x / y; }\n);\n```\n\n### Object Uniform\n\nNormally, it's not allowed to uniform an anonymous function, but in this case, you can. **Please do not use `this` in these functions.**\n\n```js\nvar Maths = {\n  add: function (x, y) { return x + y; },\n  remove: function (x, y) { return x - y; },\n  multiply: function (x, y) { return x * y; },\n  divide: function (x, y) { return x / y; }\n};\nuniform(Maths); // Uniform all the methods.\n\nadd(1, 2).divide(3); //=\u003e 1\n(1).add(2).divide(3); //=\u003e 1\n```\n\n## License\nMIT.\n\n[1]: http://dlang.org/function.html#pseudo-member\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fufcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff%2Fufcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fufcs/lists"}