{"id":22021585,"url":"https://github.com/lamansky/trim-apply","last_synced_at":"2026-05-06T07:41:05.024Z","repository":{"id":57379917,"uuid":"118335088","full_name":"lamansky/trim-apply","owner":"lamansky","description":"[Node.js] Drops undefined arguments from the end of a function call.","archived":false,"fork":false,"pushed_at":"2019-10-12T09:58:27.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T17:22:03.479Z","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/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-21T13:00:19.000Z","updated_at":"2020-07-30T12:49:04.000Z","dependencies_parsed_at":"2022-09-06T05:01:32.619Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/trim-apply","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Ftrim-apply","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Ftrim-apply/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Ftrim-apply/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Ftrim-apply/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/trim-apply/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245085097,"owners_count":20558332,"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-30T06:13:07.571Z","updated_at":"2026-05-06T07:41:04.988Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trim-apply\n\nDrops undefined arguments from the end of a function call.\n\nUseful if you’re forwarding arguments from one function to another, but the second function has behavior which is affected by the presence of an explicit `undefined` argument.\n\nAccepts an array of arguments, just like [`Function.prototype.apply()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply). If you want to provide an argument list instead, use the [`trim-call`](https://github.com/lamansky/trim-call) module.\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 5.0.0 or above.\n\n```bash\nnpm i trim-apply\n```\n\n## API\n\nThe module exports a function (`trimApply()`) that has one other function attached to it as a method (`trimApply.new()`).\n\n### `trimApply()`\n\n#### Parameters\n\n1. `fn` (function): The function to call.\n2. `thisArg` (any): The value of `this` while the function is being called.\n3. `args` (array): The arguments for the function call. Any `undefined` arguments at the end will be dropped.\n\n#### Return Value\n\nThe return value of `fn` when called with `thisArg` and `args`.\n\n### `trimApply.new()`\n\n#### Parameters\n\n1. `Cls` (class): The class whose constructor you want to call.\n2. `args` (array): The arguments for the constructor call. Any `undefined` arguments at the end will be dropped.\n\n#### Return Value\n\nA new instance of `Cls` constructed with `args`.\n\n## Examples\n\n```javascript\nconst trimApply = require('trim-apply')\n\nf1('test')\n\nfunction f1 (a, b) {\n  trimApply(f2, this, [a, b])\n}\n\nfunction f2 () {\n  arguments.length // 1\n}\n```\n\nBecause of `trimApply()`, the `f2()` function only receives one argument.\n\nHere is the above example repeated _without_ `trimApply()`:\n\n```javascript\nf1('test')\n\nfunction f1 (a, b) {\n  f2.apply(this, [a, b])\n}\n\nfunction f2 () {\n  arguments.length // 2\n}\n```\n\nWithout `trimApply()`, the undefined `b` argument of `f1()` becomes an explicit second argument for `f2()`.\n\n## Related\n\n* [trim-call](https://github.com/lamansky/trim-call)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Ftrim-apply","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Ftrim-apply","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Ftrim-apply/lists"}