{"id":20673163,"url":"https://github.com/javascipt/arget","last_synced_at":"2026-04-24T09:34:51.261Z","repository":{"id":57183524,"uuid":"80558069","full_name":"Javascipt/arget","owner":"Javascipt","description":":gear: Manipulate Function.arguments properly","archived":false,"fork":false,"pushed_at":"2017-02-04T11:10:58.000Z","size":75,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-18T10:02:15.790Z","etag":null,"topics":["arguments","function"],"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/Javascipt.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":"2017-01-31T20:15:48.000Z","updated_at":"2017-11-07T02:23:46.000Z","dependencies_parsed_at":"2022-08-23T01:21:02.034Z","dependency_job_id":null,"html_url":"https://github.com/Javascipt/arget","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javascipt%2Farget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javascipt%2Farget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javascipt%2Farget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javascipt%2Farget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Javascipt","download_url":"https://codeload.github.com/Javascipt/arget/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242900000,"owners_count":20203704,"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":["arguments","function"],"created_at":"2024-11-16T20:40:21.971Z","updated_at":"2026-04-24T09:34:46.238Z","avatar_url":"https://github.com/Javascipt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![Arget](logo.png)\n\n\u003e A JavaScript utility library to manipulate Function.arguments\n\n![Arget](https://api.travis-ci.org/Javascipt/arget.svg)\n\nA nice library to deal with most of arguments annoying usecases. A first Error object, a second optional argument or a last function as a callback... Arget helps solve all these issues in one line of code. Ex:\n\n```javascript\n  function fn () {\n    var args = arget(arguments);\n    \n    args.toArray(); // =\u003e [1, 'str', 2, true]\n    args.pick(Number); // =\u003e [1, 2]\n    args.match(null, Boolean, String); // =\u003e [1, true, 'str']\n  }\n\n  fn(1, 'str', 2, true);\n```\n\nSecond example :\n\n```javascript\n  function fn () {\n    var [foo, bar, foobar] = arget(arguments).match(null, null, Function);\n    console.log(foo, bar, foobar);\n  }\n\n  fn({}, () =\u003e {}); // ==\u003e {}, undefined, () =\u003e {}\n  fn({}, 'value', () =\u003e {}); // ==\u003e {}, 'value', () =\u003e {}\n```\n\n## Content\n\n\n- [Install](#install)\n- [Usage](#usage)\n- [Arget wrapper](#arget-wrapper)\n  - [.first( )](#first-)\n  - [.last( )](#last-)\n  - [.get( )](#get-)\n  - [.getRight( )](#getRight-)\n  - [.all( )](#all-)\n  - [.toArray( )](#toarray-)\n  - [.forEach( )](#foreach-)\n  - [.each( )](#each-)\n  - [.filter( )](#filter-)\n  - [.map( )](#map-)\n  - [.pick( )](#pick-)\n  - [.omit( )](#omit-)\n  - [.match( )](#match-)\n  - [.matchRight( )](#matchright-)\n  - [.length](#length)\n- [License](#license)\n\n## Install\n```\nnpm install --save arget\n```\n\n## Usage\nWhen requiring the arget module, you'll get a function that instanciates the [Arget wrapper](#arget-wrapper) using the arguments you are passing.\n```javascript\n  var arget = require('arget');\n\n  function fn () {\n    var wrapper = arget(arguments);\n  }\n```\n\u003e /!\\ arget instanciates the wrapper whether you pass arguments as argument to arget or not, but you need to keep in mind that there is a huge performance issue if you don't.\n\n## Arget wrapper\n\n### .first( )\n\nReturns the first argument\n\n```javascript\n  function fn () {\n    return arget(arguments).first();\n  }\n\n  fn(1, 2, 3, 4); // ==\u003e 1\n  fn(); // ==\u003e undefined\n```\n\n### .last( )\n\nReturns the last argument\n\n```javascript\n  function fn () {\n    return arget(arguments).last();\n  }\n\n  fn(1, 2, 3, 4); // ==\u003e 4\n  fn(); // ==\u003e undefined\n```\n\n### .get( )\n\n\u003e .get(position, [constructor = undefined])\n\nReturns element with the constructor and the position specified\n\n```javascript\n  function fn () {\n    return arget(arguments).get(1);\n  }\n\n  fn(true, 2, 3, 4); // ==\u003e 2\n  fn(); // ==\u003e undefined\n\n\n\n  function fn () {\n    return arget(arguments).get(1, Number);\n  }\n\n  fn(true, 2, 3, 4); // ==\u003e 3\n```\n### .getRight( )\n\n\u003e .getRight(position, [constructor = undefined])\n\nReturns element with the constructor and the position from the right specified\n\n```javascript\n  function fn () {\n    return arget(arguments).get(1);\n  }\n\n  fn(true, 2, 3, 4); // ==\u003e 3\n  fn(); // ==\u003e undefined\n\n\n\n  function fn () {\n    return arget(arguments).get(0, Number);\n  }\n\n  fn(true, 2, 3, 4); // ==\u003e 4\n```\n### .all( )\n\n\u003e .all([constructor = undefined])\n\nReturns elements with the constructor specified\n\n```javascript\n  function fn () {\n    return arget(arguments).all(Number);\n  }\n\n  fn(true, 2, 3, 4); // ==\u003e [2, 3, 4]\n  fn(); // ==\u003e []\n```\n### .toArray( )\n\nConverts arguments object to array\n\n```javascript\n  function fn () {\n    return arget(arguments).toArray();\n  }\n\n  fn(1, 2, 3, 4); // ==\u003e [1, 2, 3, 4]\n  fn(); // ==\u003e []\n```\n### .forEach( )\n\n\u003e  .forEach(iteratee)\n\nIterates over the arguments\n\n```javascript\n  function fn () {\n    arget(arguments).forEach(e =\u003e console.log(e));\n  }\n\n  fn(1, 2, 3, 4); // ==\u003e prints 1 2 3 4\n\n```\nThe `iteratee` takes 3 arguments :\n\n\u003e iteratee(item, index, array)\n\n- `item`  : The element\n- `index` : The element index on the arguments\n- `array` : The arguments as array\n\n```javascript\n  function fn () {\n    arget(arguments).forEach((item, index, array) =\u003e {\n      console.log(item, index, array)\n    });\n  }\n\n  fn(1, 2, 3);\n\n  // prints :\n  // 1 0 [1, 2, 3]\n  // 2 1 [1, 2, 3]\n  // 3 2 [1, 2, 3]\n\n```\n\n### .each( )\n\nAlias of [.forEach( )](#foreach)\n\n### .filter( )\n\n\u003e  .filter(predicate)\n\nReturns an array filtred depending on the returned value of the predicate for each item. The result contains items that the predicate returned a truthy value for.\n\n```javascript\n  function fn () {\n    return arget(arguments).filter(e =\u003e e != 3);\n  }\n\n  fn(1, 2, 3, 4); // ==\u003e 1 2 4\n\n```\n\nThe `predicate` takes 3 arguments :\n\n\u003e predicate(item, index, array)\n\n- `item`  : The element\n- `index` : The element index on the arguments\n- `array` : The arguments as array\n\n### .map( )\n\n\u003e  .map(predicate)\n\nReturns an array containing the result of the predicate for each element\n\n```javascript\n  function fn () {\n    return arget(arguments).map(e =\u003e e * 2);\n  }\n\n  fn(1, 2, 3, 4); // ==\u003e 2 4 6 8\n\n```\nThe `iteratee` takes 3 arguments :\n\n\u003e iteratee(item, index, array)\n\n- `item`  : The element\n- `index` : The element index on the arguments\n- `array` : The arguments as array\n\n### .pick( )\n\n\u003e  .pick(contructor[, constructor[, ...]])\n\nReturns an array of elements with the constructors specified\n\n```javascript\n  function fn () {\n    return arget(arguments).pick(Number)\n  }\n\n  fn(true, 1, 2, 'str'); // ==\u003e [1, 2]\n\n\n  function fn () {\n    return arget(arguments).pick(Number, String)\n  }\n\n  fn(true, 1, {}, 'str'); // ==\u003e [1, 'str']\n\n```\n\n### .omit( )\n\n\u003e  .omit(contructor[, constructor[, ...]])\n\nReturns an array of elements without those with the constructors specified\n\n```javascript\n  function fn () {\n    return arget(arguments).omit(Number)\n  }\n\n  fn(true, 1, 2, 'str'); // ==\u003e [true, 'str']\n\n\n  function fn () {\n    return arget(arguments).omit(Number, String)\n  }\n\n  fn(true, 1, {}, 'str'); // ==\u003e [true, {}]\n\n```\n### .match( )\n\n\u003e  .match(contructor[, constructor[, ...]])\n\nReturns an array of elements depending in the pattern of constructors specified.\nWhen a falsy value is given instead of a constructor, the position is filled with an elements not matched yet.\n\n```javascript\n  function fn () {\n    return arget(arguments).match(null, null, Function);\n  }\n\n  fn(1, () =\u003e {}); // ==\u003e [1, undefined, () =\u003e {}]\n  fn(1, 'value', () =\u003e {}); // ==\u003e [1, 'value', () =\u003e {}]\n\n\n\n  function fn () {\n    return arget(arguments).match(Array, null, Number, null, Function);\n  }\n\n  fn(1, 2, 3, () =\u003e {}, []) // ==\u003e [ [], 2, 1, 3, () =\u003e {} ]\n```\n\u003e /!\\ : Note that the match method starts first by putting the items with the constructors specified on their position, then it fills the falsy positions with the rest.\n\n### .matchRight( )\n\n\u003e  .matchRight(contructor[, constructor[, ...]])\n\nSimilar to [.match( )](#match-) but it loops **from right to left**.\n\nReturns an array of elements depending in the pattern of constructors specified. \nWhen a falsy value is given instead of a constructor, the position is filled with an elements not matched yet.\n\n```javascript\n  function fn () {\n    return arget(arguments).matchRight(null, null, Function);\n  }\n\n  fn(1, () =\u003e {}); // ==\u003e [undefined, 1, () =\u003e {}]\n  fn(1, 'value', () =\u003e {}); // ==\u003e [1, 'value', () =\u003e {}]\n\n\n\n  function fn () {\n    return arget(arguments).matchRight(Array, null, Number, null, Function);\n  }\n\n  fn(1, 2, 3, () =\u003e {}, []) // ==\u003e [ [], 1, 3, 2, () =\u003e {} ]\n```\n\u003e /!\\ : Note that the matchRight method starts first by putting the items with the constructors specified on their position, then it fills the falsy positions with the rest.\n\n### .length\n\nReturns the number of elements\n\n\n```javascript\n  function fn () {\n    return arget(arguments).length\n  }\n\n  fn(); // ==\u003e 0\n  fn(1, () =\u003e {}); // ==\u003e 2\n  fn(1, 'value', () =\u003e {}); // ==\u003e 3\n```\n\n## License\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavascipt%2Farget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavascipt%2Farget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavascipt%2Farget/lists"}