{"id":16641978,"url":"https://github.com/artskydj/hash-to-array","last_synced_at":"2025-04-05T01:25:47.561Z","repository":{"id":24938340,"uuid":"28355700","full_name":"ArtskydJ/hash-to-array","owner":"ArtskydJ","description":"Turns an arg hash into an array of arguments. Useful when running command line apps with child_process.","archived":false,"fork":false,"pushed_at":"2023-07-18T20:11:39.000Z","size":47,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T12:18:48.050Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArtskydJ.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2014-12-22T19:40:05.000Z","updated_at":"2023-03-07T20:59:28.000Z","dependencies_parsed_at":"2024-06-19T04:08:54.906Z","dependency_job_id":"531f1620-62a1-4fba-9743-ce84f85b174f","html_url":"https://github.com/ArtskydJ/hash-to-array","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fhash-to-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fhash-to-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fhash-to-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fhash-to-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtskydJ","download_url":"https://codeload.github.com/ArtskydJ/hash-to-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247273999,"owners_count":20912029,"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-10-12T07:48:28.504Z","updated_at":"2025-04-05T01:25:47.545Z","avatar_url":"https://github.com/ArtskydJ.png","language":"JavaScript","readme":"# hash-to-array\r\n\r\n[![Build Status](https://travis-ci.org/ArtskydJ/hash-to-array.svg)](https://travis-ci.org/ArtskydJ/hash-to-array)\r\n\r\nTurns an arg hash into an array of arguments. Useful when running command line apps with child_process.\r\n\r\nLike [minimist](https://github.com/substack/minimist) in reverse.\r\n\r\n# examples\r\n\r\nPlease note that these examples are not good real-world use-cases. There are much better ways of accomplishing what is shown in these examples!\r\n\r\nrm -rf dir:\r\n```node\r\nvar hashToArray = require('hash-to-array')\r\nvar spawn = require('child_process').spawn\r\n\r\nvar args = hashToArray({\r\n\tr: true,\r\n\tf: true,\r\n\t'/lolz/moar/lol': false\r\n}) //=\u003e [ '-r', '-f', '/lolz/moar/lol' ]\r\nspawn('rm', args)\r\n```\r\n\r\nmkdir -p dir:\r\n```node\r\nvar hashToArray = require('hash-to-array')\r\nvar spawn = require('child_process').spawn\r\n\r\nspawn('mkdir', hashToArray({p: true})) //=\u003e [ '-p' ]\r\n```\r\n\r\nbrowserify:\r\n```node\r\nvar hashToArray = require('hash-to-array')\r\nvar spawn = require('child_process').spawn\r\n\r\nvar args = hashToArray({\r\n\t'myModule.js': false,\r\n\td: true,\r\n\toutfile: './bundle.js'\r\n}) //=\u003e [ 'myModule.js', '-d', '--outfile', './bundle.js' ]\r\nspawn('browserify', args)\r\n```\r\n\r\n# usage\r\n\r\n## `var arr = hashToArray(hash)`\r\n\r\n- `hash` is a map of the input arguments and their corresponding values.\r\n\t- If it is already an array, it returns it.\r\n\t- If it is not an object, it stuffs it into an array. E.g. `7` -\u003e `[7]`\r\n- **Returns** `arr`.\r\n\r\n\u003c!-- js\r\nvar hashToArray = require('./')\r\n--\u003e\r\n\r\n```js\r\n// Objects are transformed into arrays\r\nhashToArray({ your: 'name' }) // =\u003e [ '--your', 'name' ]\r\nhashToArray({ hello: true })  // =\u003e [ '--hello' ]\r\nhashToArray({ hello: false })  // =\u003e [ 'hello' ]\r\nhashToArray({ 0: 8, 1: false, length: 2 }) // =\u003e [ '-0', 8, '1', '--length', 2 ]\r\n\r\n// Arrays are unmodified\r\nhashToArray([ '-o', 'two.txt' ]) // =\u003e [ '-o', 'two.txt' ]\r\n\r\n// Other things are stuffed into arrays\r\nhashToArray('hi there') // =\u003e [ 'hi there' ]\r\nhashToArray(17) // =\u003e [ 17 ]\r\n\r\nhashToArray({\r\n    username: 'joseph',\r\n    password: 'lolwut',\r\n    'debug-level': 12\r\n}) // =\u003e [ '--username', 'joseph', '--password', 'lolwut', '--debug-level', 12 ]\r\n```\r\n\r\nNote that boolean values do not get pushed to the array. They signify the presence of prepended dashes. (See examples.)\r\n\r\n# install\r\n\r\nWith [npm](https://nodejs.org/download) do:\r\n\r\n\tnpm install hash-to-array\r\n\r\n# license\r\n\r\n[MIT](https://choosealicense.com/licenses/mit/)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartskydj%2Fhash-to-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartskydj%2Fhash-to-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartskydj%2Fhash-to-array/lists"}