{"id":18576093,"url":"https://github.com/thiagodp/split-cmd","last_synced_at":"2025-04-10T08:31:02.022Z","repository":{"id":46687649,"uuid":"136912733","full_name":"thiagodp/split-cmd","owner":"thiagodp","description":"💦Split a command into an array or an object for using with spawn or execa","archived":false,"fork":false,"pushed_at":"2023-12-21T02:01:12.000Z","size":159,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T19:02:17.786Z","etag":null,"topics":["args","argument","child-process","cli","command","exec","execa","node","nodejs","process","spawn","split"],"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/thiagodp.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":"2018-06-11T10:46:13.000Z","updated_at":"2021-09-30T00:06:07.000Z","dependencies_parsed_at":"2024-06-18T22:56:56.195Z","dependency_job_id":"de5106f2-b751-498e-8b9e-bf1f384cfdeb","html_url":"https://github.com/thiagodp/split-cmd","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":0.08333333333333337,"last_synced_commit":"89ca818dc86351f114ac2e67502ec51fd72fd016"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fsplit-cmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fsplit-cmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fsplit-cmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fsplit-cmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiagodp","download_url":"https://codeload.github.com/thiagodp/split-cmd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248012871,"owners_count":21033256,"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":["args","argument","child-process","cli","command","exec","execa","node","nodejs","process","spawn","split"],"created_at":"2024-11-06T23:23:33.404Z","updated_at":"2025-04-10T08:31:01.656Z","avatar_url":"https://github.com/thiagodp.png","language":"JavaScript","readme":"[![npm (tag)](https://img.shields.io/npm/v/split-cmd?color=green\u0026label=NPM\u0026style=for-the-badge)](https://github.com/thiagodp/split-cmd/releases)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/thiagodp/split-cmd/test.yml?style=for-the-badge)](https://github.com/thiagodp/split-cmd/actions)\n[![License](https://img.shields.io/npm/l/split-cmd.svg?style=for-the-badge\u0026color=green)](https://github.com/thiagodp/split-cmd/blob/master/LICENSE.txt)\n[![npm](https://img.shields.io/npm/dt/split-cmd?style=for-the-badge\u0026color=green)](https://www.npmjs.com/package/split-cmd)\n\n# split-cmd\n\n\u003e 💦 Split a command into an array or an object\n\nUseful for splitting a command to use with NodeJS' [child process](https://nodejs.org/api/child_process.html) methods, like [spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options), [exec](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback), and [execFile](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback), as well with libs like [execa](https://github.com/sindresorhus/execa).\n\n⚡ Just 0.4 KB uncompressed, no external dependencies.\n\n🎯 Version `1.1`+ works with NodeJS, DenoJS and browsers. JavaScript and TypeScript.\n\n## Installation\n\n```bash\nnpm i split-cmd\n```\n\n## Usage\n\n### Splitting into an array\n\n```js\nimport { split } from 'split-cmd';\n\nconst arr = split( 'git commit -m \"some message with spaces\"' );\n\nconsole.log( arr ); // [ \"git\", \"commit\", \"-m\", \"some message with spaces\" ]\n```\n\n### Splitting into an object\n\n```js\nimport { splitToObject } from 'split-cmd';\n\nconst obj = splitToObject( 'git commit -m \"some message with spaces\"' );\n\nconsole.log( obj.command ); // git\nconsole.log( obj.args ); // [ \"commit\", \"-m\", \"some message with spaces\" ]\n```\n\n### Using it with execa\n\n```js\nimport { splitToObject } from 'split-cmd';\nimport { execa } from 'execa';\n\n// Executing a single command\nconst obj = splitToObject( 'echo \"I see unicorns\"' );\nexeca( obj.command, obj.args )\n    .then( result =\u003e console.log( result.stdout ) ) // I see unicorns\n    .catch( error =\u003e console.log( error ) );\n\n// Executing multiple commands in batch\n[\n    'echo \"I see unicorns\"',\n    'mkdir foo',\n    'touch foo/bar.txt'\n]\n.map( s =\u003e splitToObject( s ) )\n.forEach( obj =\u003e {\n    execa( obj.command, obj.args )\n        .then( result =\u003e console.log( result.stdout ) )\n        .catch( error =\u003e console.log( error ) );\n} );\n```\n\n## API\n\n```js\n/**\n * Split a command into an array.\n *\n * @param {string} command Command to split.\n * @returns {Array}\n */\nsplit( command: string ): string[]\n\n/**\n * Split a command into an object with the attributes `command` and `args`.\n *\n *\n * @param {string} command Command to split.\n * @returns {object}\n */\nsplitToObject( command: string ): { command?: string, args?: string[] }\n```\n\n## License\n\nMIT © [Thiago Delgado Pinto](https://github.com/thiagodp)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fsplit-cmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiagodp%2Fsplit-cmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fsplit-cmd/lists"}