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:
yi_Xu
2021-04-28 15:32:25 -05:00
committed by GitHub
parent ff45a53422
commit fbdf27470c
3 changed files with 65 additions and 5 deletions

View File

@@ -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.
*