export function registerTypeFunctions()

in packages/sqrl/src/function/TypeFunctions.ts [40:110]


export function registerTypeFunctions(instance: StdlibRegistry) {
  instance.save(int, {
    args: [AT.any],
    pure: true,
    allowSqrlObjects: true,
    argstring: "value",
    docstring: "Returns the integer value of the given input value",
  });

  instance.save(SqrlObject.isTruthy, {
    name: "bool",
    args: [AT.any],
    allowSqrlObjects: true,
    pure: true,
    argstring: "value",
    docstring: "Returns the boolean value of the given input value",
  });

  instance.save(float, {
    args: [AT.any],
    pure: true,
    allowSqrlObjects: true,
    argstring: "value",
    docstring: "Returns the floating point value of the given input value",
  });

  instance.save(
    function list(...values) {
      return values;
    },
    {
      allowSqrlObjects: true,
      pure: true,
      argstring: "value[, ...]",
      docstring: "Returns a list of the provided values",
    }
  );

  instance.save(
    function str(value) {
      if (Array.isArray(value)) {
        return "[array]";
      } else if (typeof value === "object") {
        return "[object]";
      } else if (typeof value === "undefined") {
        // @todo: We should ensure this doesn't happen, but log the string to reduce confusion
        return "[undefined]";
      } else {
        return value.toString();
      }
    },
    {
      args: [AT.any],
      pure: true,
      argstring: "value",
      docstring: "Creates a string representation of the given value",
    }
  );

  instance.save(
    function basic(value) {
      return value;
    },
    {
      args: [AT.any],
      pure: true,
      argstring: "value",
      docstring: "Returns the basic representation of the given value",
    }
  );
}