← All procedures

client.coerce

Coerce value to specified type

browsernot registered
Package
@procedures/client · README
Path
["client","coerce"]
CLI
Not a mark command: it is not in the default registry.
As data
{"$proc":["client","coerce"],"input":{}}
Tags
core, type

Try it in the Composer →

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY, allCoreProcedures } from "@procedures/client";

for (const procedure of allCoreProcedures) {
  if (!PROCEDURE_REGISTRY.has(procedure.path)) PROCEDURE_REGISTRY.register(procedure);
}

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["client","coerce"], { to: "<to>" });
console.log(JSON.stringify(result));

As data, in a program

{ "$proc": ["client", "coerce"], "input": { "to": "<to>" } }

Input

FieldTypeRequired
valueunknownno
to"string" | "number" | "boolean" | "array"yes

Output

The schema does not list fields (any).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "value": {
        "description": "The value"
      },
      "to": {
        "type": "string",
        "enum": [
          "string",
          "number",
          "boolean",
          "array"
        ],
        "description": "The type to convert to: string, number, boolean or array"
      }
    },
    "required": [
      "to"
    ]
  },
  "output": {
    "description": "The value in the target type"
  }
}