{"id":17130039,"url":"https://github.com/serkanyersen/kwargsjs","last_synced_at":"2025-07-29T05:32:32.558Z","repository":{"id":8977352,"uuid":"10721752","full_name":"serkanyersen/kwargsjs","owner":"serkanyersen","description":"Smart python like argument management for javascript","archived":false,"fork":false,"pushed_at":"2014-11-24T21:29:42.000Z","size":198,"stargazers_count":114,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-04T23:07:18.936Z","etag":null,"topics":["javascript","keyword-arguments","python","syntactic-sugar","utilities"],"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/serkanyersen.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":"2013-06-16T15:24:46.000Z","updated_at":"2024-08-13T18:56:03.000Z","dependencies_parsed_at":"2022-09-10T03:23:34.670Z","dependency_job_id":null,"html_url":"https://github.com/serkanyersen/kwargsjs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/serkanyersen/kwargsjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkanyersen%2Fkwargsjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkanyersen%2Fkwargsjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkanyersen%2Fkwargsjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkanyersen%2Fkwargsjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serkanyersen","download_url":"https://codeload.github.com/serkanyersen/kwargsjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkanyersen%2Fkwargsjs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267633670,"owners_count":24118777,"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-07-29T02:00:12.549Z","response_time":2574,"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":["javascript","keyword-arguments","python","syntactic-sugar","utilities"],"created_at":"2024-10-14T19:11:18.582Z","updated_at":"2025-07-29T05:32:32.518Z","avatar_url":"https://github.com/serkanyersen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Keyword arguments for Javascript. Similar to python's kwargs\n\nThis little tool gives you the ability to use keyword arguments support for your functions. So you can either specify\neach argument as you wish or use the arguments regularly. In fact you can do both at the same time.\n\nAnother feature is to have the ability to set default values for your function arguments without changing or adding\nany code to your function.\n\n[![Build Status](https://travis-ci.org/serkanyersen/kwargsjs.png?branch=master)](https://travis-ci.org/serkanyersen/kwargsjs)\n\n## Usage\nJust include the script on your site. That's it. When included it will add a new method called `kwargs` to Function\nprototype and you can use it like this:\n\n```javascript\nvar functionName = function(arg1, arg2){\n    // code\n}.kwargs([defaults]);\n```\n### With node.js\nYou can install it with npm\n```bash\nnpm install kwargsjs\n```\nand include it on your scripts\n```javascript\nvar kwargs = require('kwargsjs');\nvar functionName = kwargs(function(arg1, arg2){\n    // code\n}, [defaults]);\n// or using function prototype\nvar functionName = function(arg1, arg2){\n    // code\n}.kwargs([defaults]);\n```\n\n## Examples\nJust write your function as you would normally, and don't worry about the arguments size. just call `.kwargs()`\nand rest will be handled.\n\n```javascript\nvar test = function(arg1, arg2, arg3){\n    // Your code\n}.kwargs();\n```\n\nNow, if you want you can pass all arguments in a single object and they all will be mapped to their correct places\n\n```javascript\ntest({\n    arg3: 'val3',\n    arg1: 'val1',\n    arg2: 'val2'\n});\n```\n\nYou can also use your function like you would normally use\n\n```javascript\ntest('val1', 'val2', 'val3');\n```\n\nthe best part is that you can do both\n\n```javascript\ntest('val1', {\n    arg3: 'val3',\n    arg1: 'val1',\n});\n```\n\n### Using Default values for arguments\n\nLet's say we have this function that says Hello to a given name.\n\n```javascript\nvar greeting = function(name){\n    return \"Hello \" + name;\n};\ngreeting('Frank'); // -\u003e Hello Frank\n```\nIf no name is given, we want it to return \"Hello World\", usually you would have to add conditions to your\nfunction and check for existence of `name` argument. kwargs automatically handles that for you.\n\n```javascript\nvar greeting = function(name){\n    return \"Hello \" + name;\n}.kwargs({name: 'World'}); // Set a default value for your argument and\n                           // it will be used when this argument is empty\n// Here are the results\ngreeting('Frank'); // -\u003e Hello Frank\ngreeting(); // -\u003e Hello World\n```\n\n## A real example\nLet's say we have a function that receives a lot of arguments and generates a name with prefixes and suffixes when\nprovided.\n\n```javascript\nvar name = function(firstName, lastName, middleName, prefix, suffix){\n    var name = [];\n    if(prefix){\n        name.push(prefix);\n    }\n    name.push(firstName);\n    if(middleName){\n        name.push(middleName);\n    }\n    name.push(lastName);\n    if(suffix){\n        name.push(suffix);\n    }\n    return name.join(' ');\n}.kwargs();\n```\nNow, when we want create a name with only a suffix, all we have to do is to provide the name and suffix. You can only\npass required arguments without changing anything on your function code.\n\n```javascript\nname('John', 'Doe', { suffix:'Ph.D.' });\n// -\u003e John Doe Ph.D.\nname('Max', 'Fightmaster', { prefix: 'Staff Sgt.' })\n// -\u003e Staff Sgt. Max Fightmaster\nname('Isaac', 'Newton', { prefix: 'Sir', suffix: 'PRS MP'});\n// -\u003e Sir Isaac Newton PRS MP\n```\n\n## Warnings\n\n#### Name Mangling\n\nSome javascript minifiers such as UglifyJS are using a technique called **mangling** which shortens the code by changing\nthe argument and variable names in your function, this feature might break `kwargs` because it relies on these names.\nYou can either disable this feature on your minifier or define your argument names as reserved words in\n[mangle options](https://github.com/mishoo/UglifyJS2#mangler-options)\n\n-----\n\n#### Kwargs argument and reguler object arguments\n\nIf last argument passed is an object, code assumes it's a `kwargs` object, if your function accepts objects as arguments\nyou should be careful about this, here is an example.\n\n```javascript\n// in both cases, `anObject` argument will be interpreted as `kwargs` object and be ignored\nmyFunc(anObject);\nmyFunc('val', anObject);\n```\n\nto avoid this problem you have two solutions\n\n```javascript\nmyFunc(anObject, {}); // passing last argument as an empty object\n// or using the options method and passing your object in kwargs\nmyFunc({\n  arg1: anObject\n});\n```\n\n## LICENSE\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserkanyersen%2Fkwargsjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserkanyersen%2Fkwargsjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserkanyersen%2Fkwargsjs/lists"}