Skip to content

Files

Latest commit

f12ad21 · Jun 4, 2022

History

History
39 lines (30 loc) · 1.99 KB

ts-lib-convert.md

File metadata and controls

39 lines (30 loc) · 1.99 KB

convert string to number

This example demonstrates how to convert to number to a string (and string to a number). The function will return "succeeded" and both if-statements will use the inferred type in their comparison. Open in playground

export const main = asl.deploy.asStateMachine(async () => {
  const num = asl.convert.stringToNumber("42");
  if (num === 42) {
    const str = asl.convert.numberToString(num);
    if (str === "42") {
      return "succeeded";
    }
  }
  throw new Error("failed");
});

convert string to boolean

This example demonstrates how to convert to boolean to a string (and string to a boolean). The function will return "succeeded" and both if-statements will use the inferred type in their comparison. Open in playground

export const main = asl.deploy.asStateMachine(async () => {
  const bool = asl.convert.stringToBoolean("true");
  if (bool === true) {
    const str = asl.convert.booleanToString(bool);
    if (str === "true") {
      return "succeeded";
    }
  }
  throw new Error("failed");
});