{"id":13527401,"url":"https://github.com/dpup/node-flags","last_synced_at":"2025-04-10T03:50:22.180Z","repository":{"id":57237843,"uuid":"1523812","full_name":"dpup/node-flags","owner":"dpup","description":"Flag handling library for node.js.","archived":false,"fork":false,"pushed_at":"2025-01-28T15:00:36.000Z","size":108,"stargazers_count":27,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-03T02:09:18.061Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/dpup.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":"2011-03-25T01:38:01.000Z","updated_at":"2025-01-28T15:00:42.000Z","dependencies_parsed_at":"2024-10-26T21:18:07.684Z","dependency_job_id":"955b359a-f2cd-49bf-b30d-db98539d4945","html_url":"https://github.com/dpup/node-flags","commit_stats":{"total_commits":36,"total_committers":5,"mean_commits":7.2,"dds":"0.16666666666666663","last_synced_commit":"2e5259e4416542f38c04324212a57d83b1729b51"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpup%2Fnode-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpup%2Fnode-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpup%2Fnode-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpup%2Fnode-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpup","download_url":"https://codeload.github.com/dpup/node-flags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154999,"owners_count":21056542,"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-08-01T06:01:47.279Z","updated_at":"2025-04-10T03:50:22.154Z","avatar_url":"https://github.com/dpup.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Node-Flags\n\nA flexible and easy-to-use command-line flag parsing library for Node.js applications.\n\n[![npm version](https://badge.fury.io/js/flg.svg)](https://badge.fury.io/js/flg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- Define flags across multiple files\n- Support for various data types (string, boolean, integer, number, string list, multi-string)\n- Easy-to-use API for defining and accessing flags\n- Customizable flag validation\n- Built-in help text generation\n\n## Installation\n\nInstall using your favorite package manager:\n\n```bash\nnpm install flg\n# or\nyarn add flg\n# or\npnpm add flg\n```\n\n\u003e ⚠️ _**Important Notice**_: This npm package was formerly known as `flags` and has been renamed to `flg`. Starting from version `3.0.0`, all updates will be published under this new package name.\n\u003e\n\u003e Migrate from `flags` to `flg` at your convenience to ensure you receive upcoming releases and avoid the deprecation notice of the previous name.\n\u003e\n\u003e _See [below](#package-name-update) for details and migration steps._\n\n## Usage\n\nHere's a quick example of how to use Node-Flags:\n\n```javascript\nimport * as flags from \"flg\";\n\n// Define flags\nflags.defineString(\"name\", \"Anonymous\", \"Your name\");\nflags.defineInteger(\"age\", 21, \"Your age in years\");\nflags.defineNumber(\"height\", 1.8, \"Your height in meters\");\nflags.defineStringList(\"pets\", [], \"List of your pets\");\nflags.defineMultiString(\"hobby\", [], \"Your hobbies\");\n\n// Parse command-line arguments\nflags.parse();\n\n// Access flag values\nconst info = [\n  `Name: ${flags.get(\"name\")}`,\n  `Age: ${flags.get(\"age\")}`,\n  `Height: ${flags.get(\"height\")}m`,\n  `Pets: ${flags.get(\"pets\").join(\", \")}`,\n  `Hobbies:\\n  ${flags.get(\"hobby\").join(\"\\n  \")}`,\n];\n\nconsole.log(info.join(\"\\n\"));\n```\n\nRun your script with flags:\n\n```bash\nnode example.js --name=\"John Doe\" --age=30 --height=1.75 --pets=dog,cat --hobby=reading --hobby=gaming\n```\n\n## Defining Flags\n\nNode-Flags provides several methods to define flags:\n\n- `defineString(name, defaultValue, description)`\n- `defineBoolean(name, defaultValue, description)`\n- `defineInteger(name, defaultValue, description)`\n- `defineNumber(name, defaultValue, description)`\n- `defineStringList(name, defaultValue, description)`\n- `defineMultiString(name, defaultValue, description)`\n\nEach method returns a `Flag` object that allows further configuration:\n\n```javascript\nflags\n  .defineString(\"api-key\")\n  .setDefault(\"your-default-key\")\n  .setDescription(\"API key for authentication\")\n  .setValidator((value) =\u003e {\n    if (value.length \u003c 10) {\n      throw new Error(\"API key must be at least 10 characters long\");\n    }\n  })\n  .setSecret(true);\n```\n\n## Passing Flags\n\n- Use double dashes for flag names: `--flagname`\n- Separate values with an equal sign or space: `--flagname=value` or `--flagname value`\n- Quote complex string values: `--message=\"Hello, World!\"`\n- Use `--` to separate flags from additional arguments: `--flag1 value1 -- arg1 arg2`\n\n## Querying Flag Values\n\nAccess flag values using `flags.get(flagName)` or `flags.FLAGS.flagName.get()`.\n\nFlag objects also provide properties like `name`, `defaultValue`, `currentValue`, and `isSet`.\n\n## Help Text\n\nNode-Flags automatically generates help text. Access it by running your script with the `--help` flag.\n\n## Testing\n\nFor testing, you can pass predefined arguments to `flags.parse()`:\n\n```javascript\nflags.parse([\"--flag1\", \"--noflag2\", \"--flag3=value\"]);\n```\n\nReset flags between test cases:\n\n```javascript\nflags.reset();\n```\n\n## Package name update\n\nThe original release of `flags` version `0.2.2` has been republished as `flg` version `3.0.0`. This change was made to ensure consistency and avoid potential naming conflicts.\n\nAll existing releases under the original `flags` name are still intact, so existing applications will not break.\n\nMigrate to `flg` to ensure you receive future releases.\n\n#### Migration Guide\n\nTo upgrade your project to use the new `flg` package:\n\n1. Uninstall the old `flags` package:\n\n   ```bash\n    npm uninstall flags\n   ```\n\n2. Install the new `flg` package:\n\n   ```bash\n    npm install flg\n   ```\n\n3. Update all references in your code from `flags` to `flg`:\n\n   ```js\n   // before\n   import * as flags from \"flags\";\n\n   // after\n   import * as flags from \"flg\";\n   ```\n\n#### Versioning\n\nThe new versioning starts from `3.0.0` to reflect the continuity of the `flags` package while aligning with semantic versioning best practices.\n\n#### Release history\n\n| Version                                                    | Date                     |\n| ---------------------------------------------------------- | ------------------------ |\n| [flg@3.0.0](https://www.npmjs.com/package/flg/v/3.0.0)     | _New name going forward_ |\n| [flags@0.2.2](https://www.npmjs.com/package/flags/v/0.2.2) | 2024-09-16T17:32:20.498Z |\n| [flags@0.2.1](https://www.npmjs.com/package/flags/v/0.2.1) | 2024-09-14T00:38:28.225Z |\n| [flags@0.2.0](https://www.npmjs.com/package/flags/v/0.2.0) | 2024-09-13T23:04:51.567Z |\n| [flags@0.1.3](https://www.npmjs.com/package/flags/v/0.1.3) | 2015-02-27T02:29:55.285Z |\n| [flags@0.1.2](https://www.npmjs.com/package/flags/v/0.1.2) | 2014-04-18T01:55:57.093Z |\n| [flags@0.1.1](https://www.npmjs.com/package/flags/v/0.1.1) | 2011-11-02T19:53:15.783Z |\n| [flags@0.1.0](https://www.npmjs.com/package/flags/v/0.1.0) | 2011-04-04T14:58:55.383Z |\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpup%2Fnode-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpup%2Fnode-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpup%2Fnode-flags/lists"}