{"id":18361710,"url":"https://github.com/paldepind/functionize","last_synced_at":"2025-04-06T14:32:00.749Z","repository":{"id":29203705,"uuid":"32735041","full_name":"paldepind/functionize","owner":"paldepind","description":"A library which aids in making any JavaScript library more functional.","archived":false,"fork":false,"pushed_at":"2015-03-31T19:52:11.000Z","size":164,"stargazers_count":49,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-22T01:51:13.929Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/paldepind.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-03-23T13:53:04.000Z","updated_at":"2024-02-25T15:31:56.000Z","dependencies_parsed_at":"2022-08-17T20:05:19.216Z","dependency_job_id":null,"html_url":"https://github.com/paldepind/functionize","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paldepind%2Ffunctionize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paldepind%2Ffunctionize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paldepind%2Ffunctionize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paldepind%2Ffunctionize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paldepind","download_url":"https://codeload.github.com/paldepind/functionize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247496016,"owners_count":20948148,"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-11-05T22:35:14.524Z","updated_at":"2025-04-06T14:31:55.735Z","avatar_url":"https://github.com/paldepind.png","language":"JavaScript","readme":"# functionize\nA collection of functions which aids in making non-functional libraries\nfunctional.\n\n_Note_: functionize is currently in an early stage. If you have ideas or a\ndifferent vision about how such a library should be, please share them.\n\n# Background\n\nfunctionize is based on the idea that an ideal function should\nusually satisfy the following requirements.\n\n* Be curried, i.e. return a partial applied version of itself when called with\n  too few arguments.\n* Have a fixed arity (i.e take a constant amount of arguments).\n* Take any data it operates on as its last argument. This discourages the use\n  of functions that operate on a bound context (`this`).\n\nUnfortunately the above ideas are not shared by the majority of the JavaScript\ncommunity thus the need for functionize.\n\n# Goals\n\n* Make it easy and concise to convert any library into one that adheres to the above\n  criteria as much as possible.\n* Facilitate sharing and reuse of such library conversions.\n* Take the conversion burden of other functional libraries, making them more\n  focused in scope.\n\n# How it works\n\nfunctionize tries to be as unfancy as possible. And instead of writing actual\nconfiguration you pass the library to be transformed through a series of\ncomposed functions. This achieves simplicity and flexibility.\n\n# Examples\n\n## Converting String\n\nThis is a simple conversion of the standard String methods in JavaScript\n\n```javascript\nvar converter = fz.pipe([\n  fz.omit(['anchor', 'big', 'blink', 'bold', 'fixed', 'fontcolor',\n           'fontsize', 'italics', 'link', 'small', 'strike', 'sub', 'sup']),\n  fz.methods, fz.map(fz.fnInvoker),\n  fz.mapTo({\n    slice: {sliceFrom: [fz.apply(fz._, [fz._, undefined])],\n            sliceTo: [fz.apply(fz._, [undefined])]},\n    concat: {concat: [fz.rearg([1, 0])]},\n    toUpperCase: {uppercase: []},\n  }),\n]);\nvar S = converter(String.prototype);\n```\n\nIt can be used like this\n\n```javascript\n// Slicing\nvar sliceFrom6 = S.slice(6); // functions are curried\nsliceFrom6(8, 'abcdefghijklm'); // 'gh'\nS.sliceTo(4, 'abcdefghijklm'); // 'abcd'\n\nS.trim(' horse  '); // 'horse'\nS.uppercase('foobar'); // 'FOOBAR'\nS.concat('foo', 'bar'); // 'foobar'\n\n```\n\n## Converting Array\n\n```javascript\nvar converter = fz.pipe([\n  fz.methods, fz.map(fz.fnInvoker),\n  fz.to({\n    sortBy: [fz.prop('sort')],\n    sort: [fz.prop('sort'), fz.apply(fz._, [undefined])],\n  }),\n]);\nvar A = converter(Array.prototype);\n```\n\nIt can be used like this\n\n```javascript\nvar a = [3, 8, 4];\nA.sort(a); // [3, 4, 8]\nvar ns = [3, 8, 4];\nvar square = A.map(function(x) { return x*x; }); // [9, 64, 16]\n```\n\n# API\n\nFor better documentation see the source and/or the tests.\n\n## curryN(arity, fn)\n\nReturn a curried function with arity `arity` that calls `fn` when it has\nrecieved all its arguments.\n\n## map(fn, obj)\n\nMaps a function over an _object_(not an array). The mapper function recieves\nboth the object value and key.\n\n## filter(fn, obj)\n\nMaps a function over an object and returns an object with only the keys whose\nproperties satisfies the predicate function.\n\n## arity(fn)\n\nReturns the arity of the passed function.\n\n## invoker(arity, methodName)\n\nReturns a functions that applies the named method to an object.\n\n## fnInvoker(fn, methodName)\n\nLike `invoker`, but extracts its arity from `fn`.\n\n## methods(obj)\n\nReturns an object with all the objects on `obj`.\n\n## mapFields(properties, fn, obj)\n\nFor each property in `propeties` it takes that property from `obj` passes it\nthrough `fn` and returns an object with the keys overwritten by the result of\n`fn`.\n\n```javascript\nvar obj = {a: 1, bunch: 2, of: 3, properties: 4};\nvar newObj = fz.mapFields(['bunch', 'of'], function(x) { return x + 3; }, obj);\nnewObj; // {a: 1, bunch: 5, of: 3, properties: 7}\n```\n\n## rearg(newOrder, fn)\n\nRearranges the arguments of a function.\n\n```javascript\nfunction f(a, b, c) {\n  return a + b + c;\n}\nvar g = fz.rearg([2, 0, 1], fn);\ng('a', 'b', 'c'); // 'bca'\n```\n\n## flip(fn)\n\nReturns a function equivalent to `fn` but with the order of its two first\narguments reversed.\n\n_Note_: `flip` is excactly the same as `rearg([1, 0])`. Its removal is considered.\n\n## pipe(fns)\n\nCompose, left to right. I.e: `pipe(f, g, h)(x)` is the same as\n`h(g(f(x)))`.\n\n## apply(fn, arr)\n\nCalls `fn` with the arguments specified in `arr`.\n\n## omit(keys, obj)\n\nReturns `obj` without the keys mentioned in `keys`.\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaldepind%2Ffunctionize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaldepind%2Ffunctionize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaldepind%2Ffunctionize/lists"}