{"id":16226246,"url":"https://github.com/ghostdevv/dashargs","last_synced_at":"2025-03-19T13:30:31.859Z","repository":{"id":42498595,"uuid":"272231711","full_name":"ghostdevv/dashargs","owner":"ghostdevv","description":"Simple package for parsing command line style arguments","archived":true,"fork":false,"pushed_at":"2023-10-19T09:18:19.000Z","size":498,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"stable","last_synced_at":"2025-03-17T07:11:23.229Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghostdevv.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"ghostdevv","patreon":"onlyspaceghost","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://ghostdev.xyz/donate"}},"created_at":"2020-06-14T15:39:54.000Z","updated_at":"2025-02-16T19:25:41.000Z","dependencies_parsed_at":"2024-06-19T06:11:40.473Z","dependency_job_id":"fb197611-1fff-4353-8b85-e0c2698200df","html_url":"https://github.com/ghostdevv/dashargs","commit_stats":null,"previous_names":["ghoststools/dashargs"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdevv%2Fdashargs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdevv%2Fdashargs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdevv%2Fdashargs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdevv%2Fdashargs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghostdevv","download_url":"https://codeload.github.com/ghostdevv/dashargs/tar.gz/refs/heads/stable","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244434670,"owners_count":20452230,"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-10T12:48:34.380Z","updated_at":"2025-03-19T13:30:31.604Z","avatar_url":"https://github.com/ghostdevv.png","language":"JavaScript","readme":"# DashArgs\n\n[![](https://img.shields.io/npm/v/dashargs?label=Latest%20Version\u0026style=for-the-badge\u0026logo=npm\u0026color=informational)](https://www.npmjs.com/package/dashargs)\n[![](https://img.shields.io/static/v1?label=Project%20Creator\u0026message=GHOST\u0026color=informational\u0026style=for-the-badge)](https://ghostdev.xyz)\n[![](https://img.shields.io/github/actions/workflow/status/ghoststools/dashargs/ci.yml?style=for-the-badge)](https://github.com/ghoststools/dashargs)\n[![](https://img.shields.io/static/v1?label=\u0026message=A%20GHOSTs%20Tools%20Project\u0026color=informational\u0026style=for-the-badge)](https://github.com/ghoststools)\n\nSimple package for parsing command line style arguments.\n\n## Requirements\n\n```\nNodeJS \u003e= v12.x\n```\n\n# Install\n\n```\nnpm install dashargs\n```\n\n# Setup\n\nCJS\n\n```js\nconst dash = require('dashargs');\n```\n\nESM\n\n```ts\nimport { parse, config, strip } from 'dashargs';\n```\n\n# Command Syntax\n\n```\n# Arguments:\n    Arguments have the structure of this:\n        -key \u003cvalue\u003e\n    Arguments with a value of more than one word must be wrapped in quotes:\n        -key '\u003cmulti word value\u003e'\n        or\n        -key \"\u003cmulti word value\u003e\"\n\n# Flags:\n    Flags are one character long and have the structure of this:\n        -a\n    Flags are stackable and when joined together all get parsed as individuals\n        -abc\n        is the same as\n        -a -b -c\n\n# Compound Flags:\n    Compound flags are the same as flags but are parsed differently:\n        --a\n    They can be multiple characters long as they aren't split\n        --abc -\u003e { abc: true }\n```\n\n# Parse a string\n\n`dash.parse(string, options)`\u003cbr\u003e\nThe options is an object and has the same points shown below in the config section, these will take priority over the set config, leave blank to use the ones set in the config\n\n```js\nconst dash = require('dashargs');\n\nlet command = 'setup -title \"New Project\" -desc \"Example project\"'; // Example command\nconst args = dash.parse(command);\n\nargs; // { title: 'New Project', desc: 'Example project' }\n```\n\n# Argv shortcut\n\nIf you want to parse the arguments on `process.argv` dashargs includes a shortcut method to do this: `dash.argv(options)`\n\n```js\nconst dash = require('dashargs');\n\n// Let's say the command was node . --dev\nconst args = dash.argv();\n\nargs; // { dev: true }\n```\n\n# Global Config\n\n`dash.config(options)`\u003cbr\u003e\nYou are able to set the default config used for every dashargs method. You just provide a object with the key being the method name, for exmaple:\n\n```js\nconst dash = require('dashargs');\n\ndash.config({\n    parse: {\n        unique: true,\n        typeCoerce: false,\n    },\n    strip: {\n        removeWhitespace: true,\n    },\n});\n```\n\nThe above will update the config used by the methods you choose, if you don't provide a option or a method then it will remain the default ones. The options you can provide above can be found by the methods in other points of the documentaion\n\n# Strip\n\n`dash.strip(string, options)`\n\n```js\nconst statement = 'Hello -ab world, I --c am -b a a test -d \"h\"!';\n\nconst parsed = dash.strip(statement, {\n    removeWhitespace: true,\n    removeFlags: true,\n    removeArgs: true,\n});\n\nconsole.log(parsed); // Hello I am a test!\n```\n\n`removeWhitespace`: Remove whitespaces\u003cbr\u003e\n`removeFlags`: If false then flags will be ignored\u003cbr\u003e\n`removeArgs`: If false then args will be ignored\n\n# Methods on parsed args\n\nThere are a few methods that can be done on the result from `dash.parse()` (The DashArgs class)\u003cbr\u003e\n\n-   ## Has\n\n    `dash.parse(string, options).has(key)`\n\n    ```js\n    const statement = '-hello world';\n\n    const parsed = dash.strip(statement, {\n        removeWhitespace: true,\n        removeFlags: true,\n        removeArgs: true,\n    });\n\n    console.log(parsed.has('hello')); // true\n    ```\n\n    ```js\n    // Check if it has any one of the supplied keys\n    const statement = '-a b -c d';\n\n    const parsed = dash.strip(statement, {\n        removeWhitespace: true,\n        removeFlags: true,\n        removeArgs: true,\n    });\n\n    console.log(parsed.has('x', 'a')); // true\n    ```\n\n-   ## Get\n\n    `dash.parse(string, options).get(key)`\n\n    ```js\n    const statement = '-hello world';\n\n    const parsed = dash.strip(statement, {\n        removeWhitespace: true,\n        removeFlags: true,\n        removeArgs: true,\n    });\n\n    console.log(parsed.get('hello')); // world\n    ```\n\n-   ## Array\n\n    `dash.parse(string, options).array()`\n\n    ```js\n    const statement = '-hello world';\n\n    const parsed = dash.strip(statement, {\n        removeWhitespace: true,\n        removeFlags: true,\n        removeArgs: true,\n    });\n\n    console.log(parsed.array()); // [{ key: 'hello', value: 'world', raw: '-hello world' }]\n    ```\n\n# FAQ\n\n-   ## Quote Escaping\n\n    In arguments it's possible to escape quotes, for example `-a \"b \\\" c\"`. Due to JavaScript seeing the `\\\"` as escaped, dashargs doesn't see the `\\` just `\"` therefore you must escape the `\\`, for example `-a \"b \\\\\" c\"`\n\n-   ## Custom Prefixes\n\n    Custom prefixes are possible with dashargs, on all methods, just pass in a prefix option with your desired prefix, however, you must be careful when doing this as certain prefixes such as `\"` will not work correctly and create unexpected behaviors, therefore they are not recommened.\n\n-   ## Examples\n\n    You are able to view examples in the examples directory of the project which can be found [here](https://github.com/ghoststools/dashargs/tree/master/examples)\n\n-   ## Other import methods\n\n    You are able to use a es import for node such as:\n\n    ```js\n    import dash from 'dashargs';\n    ```\n\n    and for typescript:\n\n    ```js\n    import * as dash from 'dashargs';\n    ```\n\n-   ## Support\n    -   Message me on discord: `GHOST#7524`\u003cbr\u003e\n    -   Join the [discord](https://discord.gg/2Vd4wAjJnm)\u003cbr\u003e\n    -   Create a issue on the [github](https://github.com/ghoststools/dashargs)\n","funding_links":["https://github.com/sponsors/ghostdevv","https://patreon.com/onlyspaceghost","https://ghostdev.xyz/donate"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghostdevv%2Fdashargs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghostdevv%2Fdashargs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghostdevv%2Fdashargs/lists"}