* Conditional execution based on a condition * @input condition - Boolean condition to evaluate * @param thenAction - Action to execute if condition is true * @returns Result of thenAction if condition is true, otherwise input * @example * $c.string('/anime/123').ifThen($c => $c.urlAb
(
ctx: ChibiCtx,
input: Input,
thenAction: Then,
)
| 50 | * $c.string('/anime/123').ifThen($c => $c.urlAbsolute().return().run()).boolean(false) |
| 51 | */ |
| 52 | ifThen<Input, Then extends ($c: ChibiGenerator<Input>) => ChibiJson<any>>( |
| 53 | ctx: ChibiCtx, |
| 54 | input: Input, |
| 55 | thenAction: Then, |
| 56 | ): CT.UnwrapJson<ReturnType<Then>> | Input { |
| 57 | if (input) { |
| 58 | return ctx.isAsync() |
| 59 | ? (ctx.runAsync(thenAction as any, input) as any) |
| 60 | : ctx.run(thenAction as any, input); |
| 61 | } |
| 62 | return input; |
| 63 | }, |
| 64 | |
| 65 | /** |
| 66 | * If the input is falsy stop further execution and return the result of returnAction |