{"id":21215780,"url":"https://github.com/betahuhn/action-input-parser","last_synced_at":"2026-03-16T07:08:19.398Z","repository":{"id":36959672,"uuid":"363400087","full_name":"BetaHuhn/action-input-parser","owner":"BetaHuhn","description":"🎬🛠️ Helper for parsing inputs in a GitHub Action","archived":false,"fork":false,"pushed_at":"2023-03-06T09:00:24.000Z","size":472,"stargazers_count":7,"open_issues_count":8,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T14:56:38.505Z","etag":null,"topics":["config-parser","github-action-helper","github-actions","github-actions-javascript","github-actions-typescript","nodejs"],"latest_commit_sha":null,"homepage":"https://mxis.ch","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/BetaHuhn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":{"ko_fi":"betahuhn","github":"betahuhn"}},"created_at":"2021-05-01T12:04:27.000Z","updated_at":"2024-04-10T07:34:03.000Z","dependencies_parsed_at":"2024-06-21T18:55:12.791Z","dependency_job_id":"c187d389-8b66-4832-81fa-7c05fdda096b","html_url":"https://github.com/BetaHuhn/action-input-parser","commit_stats":{"total_commits":188,"total_committers":3,"mean_commits":"62.666666666666664","dds":0.5106382978723405,"last_synced_commit":"a3727219a0ea8a4e5452efd6330b3bb3ac751203"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":"BetaHuhn/node-starter","purl":"pkg:github/BetaHuhn/action-input-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetaHuhn%2Faction-input-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetaHuhn%2Faction-input-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetaHuhn%2Faction-input-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetaHuhn%2Faction-input-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BetaHuhn","download_url":"https://codeload.github.com/BetaHuhn/action-input-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetaHuhn%2Faction-input-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264572972,"owners_count":23630379,"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":["config-parser","github-action-helper","github-actions","github-actions-javascript","github-actions-typescript","nodejs"],"created_at":"2024-11-20T21:45:10.639Z","updated_at":"2026-03-16T07:08:19.349Z","avatar_url":"https://github.com/BetaHuhn.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \n# Action Input Parser\n\n[![Node CI](https://github.com/BetaHuhn/action-input-parser/workflows/Node%20CI/badge.svg)](https://github.com/BetaHuhn/action-input-parser/actions?query=workflow%3A%22Node+CI%22) [![Release CI](https://github.com/BetaHuhn/action-input-parser/workflows/Release%20CI/badge.svg)](https://github.com/BetaHuhn/action-input-parser/actions?query=workflow%3A%22Release+CI%22) [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/BetaHuhn/action-input-parser/blob/master/LICENSE) ![David](https://img.shields.io/david/betahuhn/action-input-parser)\n\nHelper for parsing inputs in a GitHub Action\n\n\u003c/div\u003e\n\n## ⭐ Features\n\n- Similar API to [`core.getInput()`](https://github.com/actions/toolkit/tree/main/packages/core#inputsoutputs)\n- Parses [string, booleans, numbers and arrays](#types) to correct JS types\n- Supports [default values](#default-values) if no input was provided\n- Throws errors if input is set to [required](#required-inputs) and is missing\n- Uses local environment variables (and `.env` files) during [development](#development)\n- Specify a [custom function](#modify-the-parsed-input) for advanced parsing\n- Supports [array of keys](#key)\n\n## 🚀 Get started\n\nInstall [action-input-parser](https://github.com/BetaHuhn/action-input-parser) via npm:\n```shell\nnpm install action-input-parser\n```\n\n## 📚 Usage\n\nImport `action-input-parser` and use it like this:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput('name')\n```\n\n### Example\n\nLet's say you have the following workflow file (see [below](#development) on how to specify inputs during development):\n\n```yml\nuses: username/action\nwith:\n    names: |\n        Maximilian\n        Richard\n```\n\nPass an options object to the `getInput` function to specify the `array` type:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput('names', {\n    type: 'array'\n})\n\n// [ 'Maximilian', 'Richard' ]\n```\n\n[action-input-parser](https://github.com/BetaHuhn/action-input-parser) will parse the `names` input and return an array.\n\nSee below for [all options](#all-options) or checkout a few more [examples](#-examples).\n\n## ⚙️ Configuration\n\nYou can pass the following JavaScript object to `getInput` as the first or second parameter to tell [action-input-parser](https://github.com/BetaHuhn/action-input-parser) what to parse:\n\n```js\nconst options = {\n    key: 'names',\n    type: 'array',\n    default: [ 'maximilian' ]\n}\n\nparser.getInput(options)\n\n```\n\n### All options\n\nHere are all the options you can use and there default values:\n\n| Name | Description | Required | Default |\n| ------------- | ------------- | ------------- | ------------- |\n| `key` | The key of the input option (can also be an array of keys) | **Yes** | N/A |\n| `type` | The type of the input value (`string`/`boolean`/`number`/`array`) | **No** | `string` |\n| `required` | Specify if the input is required | **No** | false |\n| `default` | Specify a default value for the input | **No** | N/A |\n| `disableable` | Specify if the input should be able to be disabled by setting it to `false` | **No** | `false` |\n| `modifier` | A function which gets passed the parsed value as a parameter and returns another value  | **No** | N/A |\n\n### Key\n\nYou can either specify a single key as a string, or multiple keys as an array of strings.\n\n[See example](#multiple-keys)\n\n### Types\n\nYou can specify one of the following types which will determine how the input is parsed:\n\n- `string` - default type, the input value will only be trimmed\n- `boolean` - will parse a boolean based on the [yaml 1.2 specification](https://yaml.org/spec/1.2/spec.html#id2804923)\n- `number` - will convert the input to a number\n- `array` - will parse line or comma seperated values to an array\n\n\u003e Note: if the input can not be converted to the specifed type, an error is thrown\n\n[See example](#specify-a-type)\n\n### Required inputs\n\nWhen you set required to true and the input is not set, [action-input-parser](https://github.com/BetaHuhn/action-input-parser) will throw an error.\n\n[See example](#set-an-input-to-be-required)\n\n### Default values\n\nYou can specify a default value for the input which will be used when the input is not set.\n\n[See example](#specify-a-default-value)\n\n### Disableable input\n\nIf you have an input with a default value but you still want the user to be able to unset the input, set the `disableable` option to `true`.\n\nWhen the input is then set to `false`, [action-input-parser](https://github.com/BetaHuhn/action-input-parser) will return `undefined` instead of your default value.\n\n[See example](#disable-an-input)\n\n### Modifier function\n\nIf your input needs additional processing you can specify a function which will be passed the parsed input value.\n\n[See example](#modify-the-parsed-input)\n\n### Development\n\nIf you run your Action locally during development, you can set the inputs as environment variables or specify them in a `.env` file. [action-input-parser](https://github.com/BetaHuhn/action-input-parser) will use them as the inputs automatically.\n\n## 📖 Examples\n\nHere are some examples on how to use [action-input-parser](https://github.com/BetaHuhn/action-input-parser):\n\n### Basic example\n\nAction Workflow:\n\n```yml\nuses: username/action\nwith:\n    name: Maximilian\n```\n\nAction code:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput('name')\n\n// value -\u003e Maximilian\n```\n\nor \n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput({\n    key: 'name'\n})\n\n// value -\u003e Maximilian\n```\n\n### Specify a type\n\nAction Workflow:\n\n```yml\nuses: username/action\nwith:\n    dry_run: true\n```\n\nAction code:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput({ \n    key: 'dry_run',\n    type: 'boolean'\n})\n\n// Without setting the type to boolean, the value would have been 'true'\n```\n\n### Specify a default value\n\nAction code:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput({ \n    key: 'name',\n    default: 'Maximilian'\n})\n\n// If name is not set, Maximilian will be returned as the name\n```\n\n### Set an input to be required\n\nAction code:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput({\n    key: 'name',\n    required: true\n})\n\n// Will throw an error if name is not set\n```\n\n### Disable an input\n\nAction Workflow:\n\n```yml\nuses: username/action\nwith:\n    labels: false\n```\n\nAction code:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput({\n    key: 'labels', \n    default: [ 'merged', 'ready' ],\n    disableable: true\n})\n\n// Value will be undefined because labels was set to false\n```\n\n### Multiple Keys\n\nAction code:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput({ \n    key: [ 'GITHUB_TOKEN', 'GH_PAT' ]\n})\n\n// The first key takes precedence\n```\n\n### Modify the parsed input\n\nAction Workflow:\n\n```yml\nuses: username/action\nwith:\n    name: Maximilian\n```\n\nAction code:\n\n```js\nconst parser = require('action-input-parser')\n\nconst value = parser.getInput({\n    key: 'name',\n    modifier: (val) =\u003e {\n        return val.toLowerCase()\n    }\n})\n\n// Value will be maximilian\n```\n\n### Advanced example\n\nAction Workflow:\n\n```yml\nuses: username/action\nwith:\n    github_token: TOKEN\n    repository: username/reponame\n    labels: |\n        merged\n        ready\n```\n\nAction code:\n\n```js\nconst { getInput } = require('action-input-parser')\n\nconst config = {\n    githubToken: getInput({\n        key: 'github_token',\n        required: true\n    }),\n    repository: getInput({\n        key: 'repository',\n        modifier: (val) =\u003e {\n            const [user, repo] = val.split('/')\n            return { user, repo }\n        }\n    }),\n    labels: getInput({\n        key: 'labels',\n        type: 'array'\n    }),\n    dryRun: getInput({\n        key: 'dry_run',\n        type: 'boolean',\n        default: false\n    }),\n}\n\n// parsed config:\n{\n    githubToken: 'TOKEN',\n    repository: {\n        name: 'username',\n        repo: 'reponame'\n    },\n    labels: [ 'merged', 'ready' ],\n    dryRun: false\n}\n```\n\n## 💻 Development\n\nIssues and PRs are very welcome!\n\nThe actual source code of this library is in the `src` folder.\n\n- run `yarn lint` or `npm run lint` to run eslint.\n- run `yarn build` or `npm run build` to produce a compiled version in the `lib` folder.\n\n## ❔ About\n\nThis project was developed by me ([@betahuhn](https://github.com/BetaHuhn)) in my free time. If you want to support me:\n\n[![Donate via PayPal](https://img.shields.io/badge/paypal-donate-009cde.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=394RTSBEEEFEE)\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F81S2RK)\n\n## 📄 License\n\nCopyright 2021 Maximilian Schiller\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","funding_links":["https://ko-fi.com/betahuhn","https://github.com/sponsors/betahuhn","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=394RTSBEEEFEE","https://ko-fi.com/F1F81S2RK"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetahuhn%2Faction-input-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetahuhn%2Faction-input-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetahuhn%2Faction-input-parser/lists"}