readDurationFromConfig()
Home > @backstage/config
> readDurationFromConfig
Reads a duration from config.
Signature:
function readDurationFromConfig(config: Config, options?: {
key?: string;
}): HumanDuration;
Parameters
Parameter |
Type |
Description |
---|---|---|
config |
A configuration object | |
options |
{ key?: string; } |
(Optional) |
A duration object
Remarks
The supported formats are:
- A string in the format of '1d', '2 seconds' etc. as supported by the
ms
library. - A standard ISO formatted duration string, e.g. 'P2DT6H' or 'PT1M'. - An object with individual units (in plural) as keys, e.g.{ days: 2, hours: 6 }
.
The string forms are naturally only supported if the options.key
argument is passed, since a Config
argument always represents an object by its nature.
This does not support optionality; if you want to support optional durations, you need to first check the presence of the target with config.has(...)
and then call this function.