{"id":23651364,"url":"https://github.com/damiancipolat/documenting_js_functions","last_synced_at":"2026-05-09T16:38:48.501Z","repository":{"id":139319253,"uuid":"226561294","full_name":"damiancipolat/Documenting_js_functions","owner":"damiancipolat","description":"This repository was created to show anothers JS developers a way of how to document javascript functions at the moment to start coding.","archived":false,"fork":false,"pushed_at":"2019-12-08T04:53:49.000Z","size":276,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-11T05:38:48.444Z","etag":null,"topics":["amazon","functional-programming","functional-programming-examples","js","node"],"latest_commit_sha":null,"homepage":"","language":null,"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/damiancipolat.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-07T18:54:00.000Z","updated_at":"2019-12-20T14:26:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"f283b6ba-b4b2-4237-9035-ce13cff889e8","html_url":"https://github.com/damiancipolat/Documenting_js_functions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/damiancipolat/Documenting_js_functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FDocumenting_js_functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FDocumenting_js_functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FDocumenting_js_functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FDocumenting_js_functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damiancipolat","download_url":"https://codeload.github.com/damiancipolat/Documenting_js_functions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FDocumenting_js_functions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006350,"owners_count":26084086,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["amazon","functional-programming","functional-programming-examples","js","node"],"created_at":"2024-12-28T16:37:18.545Z","updated_at":"2025-10-11T05:38:49.319Z","avatar_url":"https://github.com/damiancipolat.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/damiancipolat/Functional_programming_in_JS/blob/master/doc/fp.png?raw=true\" width=\"125px\" align=\"right\" /\u003e\n\n# Documenting functions in javascript\nThe idea of this repository is to continue with the last 2 projects that I raised on functional programming in js.\n\n## But why?\nFor some time I have been dedicated to javascript and I see that there is still no standard on how developers should document what data should be passed as parameters. Although JS is not a typed language, somehow we have to specify what data is sent in each parameter.\n\n**Currently:** Currently this is one of my functions, I have started working with this format.\n\n```js\n/*\n  Receive currency code and return money simbol.\n  Params\n    currency : string\n  Return\n    string\n*/\nconst getSymbol = (currency)=\u003e{\n\n  switch(currency){\n    case 'ARS':\n      return '$';\n    case 'USD':\n      return 'U$S';\n    default:\n      return '$';\n  }\n  \n}\n```\n\n**New format:** I'm moving to this new format.\n\n```js\n/*\n  Receive currency code and return money simbol.\n  getSymbol:: string → string\n*/\nconst getSymbol = (currency)=\u003e{...}\n```\n\n## Solution - Type Signatures\nThese type notations are a **meta language** called Type Signatures, defines the inputs and outputs for the function, sometimes including the number of arguments, the types of arguments and order of arguments contained by a function.\n\nType Signatures are based on Hindley-Milner Type system as a standard type system which is also followed by ML-influenced languages, including Haskell.\n\n**Some examples:**\n```js\n// length :: String → Number\nconst length = s =\u003e s.length;\n\n// length :: [Number] → Number\nconst length = arr =\u003e arr.length;\n\n// join :: (String, [String]) → String\nconst join = (separator, arr) =\u003e arr.join(separator)\n```\n\n## Code examples:\nThe sections are divided in **One parameter** / **Multiple parameters** / **High order functions**.\n\n### One parameter:\nExamples using 1 parameter as input and one flat return data, **f(x) = y**.\n\n- STRING - f(String) = Number:\n```js\n//length :: String → Number\nconst length = (a)=\u003ea.length;\n```\n\n- NUMBER - f(Number) = Number:\n```js\n//increase :: Number → Number\nconst increase = value =\u003e value+10;\n```\n\n- BOOLEAN - f(Bool) = Bool.\n```js\n//inverse :: Bool → Bool\nconst inverse = value =\u003e !value;\n```\n\n- ARRAY - f([x]) = Number.\n```js\n//length :: [a] → Number\nconst length = list =\u003e list.length;\n\n//length :: [string] → Number\nconst length = list =\u003e list.length;\n\n//length :: [Number] → Number\nconst length = list =\u003e list.length;\n```\n\n- DATE - f(date) = Bool.\n```js\n//expire :: Date → Bool\nconst expire = expireDate =\u003e new Date()\u003c=expireDate;\n```\n\n- FUNCTION - f(g([a])) = [b].\n```js\n//map :: (a → b) → [a] → [b]\nconst map = fn =\u003e arr =\u003e arr.map(fn)\n```\n\n- ANY - f(*) = b.\n```js\n//isNull :: * → Bool.\nconst isNull = obj =\u003e !!obj;\n```\n\n- OBJECT - f(object) = String.\n\n**Generic format**\n```js\n//map :: object → string\nconst toJson = obj =\u003e JSON.stringify(obj);\n```\n\n**Custom format**\n```js\n//map :: {name:String, age: Number} → string\nconst toJson = people =\u003e JSON.stringify(people);\n```\n\n**Array of objects**\n```js\n//map :: [{name:String, age: Number}] → [string]\nconst encode = people =\u003e people.map(p=\u003ebtoa(p));\n```\n\n### Multiple parameters:\nExamples using 2 parameters as input and one flat return data, **f(x,y) = z**.\n\n- STRING:\n```js\n// join :: (String, [String]) → String\nconst join = (separator, arr) =\u003e arr.join(separator)\n```\n\n- Number - f(x,y) ) = z.\n```js\n// sum :: (Number, Number) → Number\nconst sum = (x,y) =\u003e x+y;\n```\n\n- Array - f([a],b) = c.\n```js\n//concat :: [*],string → string\nconst concat = (list,char) =\u003e list.join(char).\n```\n\n### High order parameters:\nWhen a function is passed as parameter, we wrap it’s signature in a parentheses to present a more meaningful overall Type Signature. f(g(x)) = y\n\n```js\n// addOneToAll :: ((Number → Number),[Number]) → [Number]\nconst addOneToAll = (addOne = x=\u003ex+1 , arr) =\u003e arr.map(addOne)\n```\n\n## Using in real world JS\nExamples converting functions, comments signature.\n\n**Example 1**\n\nBefore, code example.\n```js\n/*\n  Receive two arrays with field, analyze both parameters and return the situation.\n  Params\n    flowFields   : {fields:[],onboarding_vu:string,document_attached:string}\n    clientFields : {fields:[],onboarding_vu:string,document_attached:string}\n  Return\n    [string] : required fields\n*/\nconst underAge = birth =\u003e !birth || (birth \u0026\u0026 moment().diff(birth, 'years')) \u003c 18;\n```\n\nAfter, code example using the meta lenguage notation.\n```js\n/*\n  Receive two arrays with field, analyze both parameters and return the situation.\n  underAge :: date → bool\n*/\nconst underAge = birth =\u003e !birth || (birth \u0026\u0026 moment().diff(birth, 'years')) \u003c 18;\n```\n\n**Example 2**\n\nBefore, code example.\n```js\n/*\n  GET a file from S3 bucket.\n  Params \n    S3 : aws s3 instance,\n    params : {Bucket:'xxxx',Key:'xxxx'}\n  Return\n    promise\n*/\nconst getFile = (s3,params) =\u003e s3.getObject(params).promise();\n```\n\nAfter, code example using the meta lenguage notation.\n```js\n/*\n  GET a file from S3 bucket.\n  getFile :: object, {Bucket:string, Key:string} → promise\n*/\nconst getFile = (s3,params) =\u003e s3.getObject(params).promise();\n```\n\n## Readings:\n- https://medium.com/hackernoon/function-type-signatures-in-javascript-5c698c1e9801\n- https://github.com/ramda/ramda/wiki/Type-Signatures\n- https://ramdajs.com/docs/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamiancipolat%2Fdocumenting_js_functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamiancipolat%2Fdocumenting_js_functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamiancipolat%2Fdocumenting_js_functions/lists"}