mirror of
https://github.com/actions/toolkit
synced 2025-05-09 16:43:02 +00:00
feat(core): add getBooleanInput function (#725)
* feat(core): add getBooleanInput function * docs(core): update readme * test(core): update the core.test.ts
This commit is contained in:
parent
ff45a53422
commit
fbdf27470c
3 changed files with 65 additions and 5 deletions
|
@ -91,6 +91,28 @@ export function getInput(name: string, options?: InputOptions): string {
|
|||
return val.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
|
||||
* Support boolean input list: `true | True | TRUE | false | False | FALSE` .
|
||||
* The return value is also in boolean type.
|
||||
* ref: https://yaml.org/spec/1.2/spec.html#id2804923
|
||||
*
|
||||
* @param name name of the input to get
|
||||
* @param options optional. See InputOptions.
|
||||
* @returns boolean
|
||||
*/
|
||||
export function getBooleanInput(name: string, options?: InputOptions): boolean {
|
||||
const trueValue = ['true', 'True', 'TRUE']
|
||||
const falseValue = ['false', 'False', 'FALSE']
|
||||
const val = getInput(name, options)
|
||||
if (trueValue.includes(val)) return true
|
||||
if (falseValue.includes(val)) return false
|
||||
throw new TypeError(
|
||||
`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
|
||||
`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of an output.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue