MCPcopy Index your code
hub / github.com/MALSync/MALSync / ifThen

Function ifThen

src/chibiScript/functions/controlFlowFunctions.ts:52–63  ·  view source on GitHub ↗

* 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,
  )

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

isAsyncMethod · 0.80
runAsyncMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected