← All procedures

optional.getOr

This function gives the present value, or `fallback`.

CLI
Package
@procedures/optional · README
Path
["optional","getOr"]
CLI
mark optional getOr --o <object | object> --fallback <any>
As data
{"$proc":["optional","getOr"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/optional/register"; // registers its procedures

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

From the command line

$ mark optional getOr --o <object | object> --fallback <any>

As data, in a program

{
  "$proc": ["optional", "getOr"],
  "input": { "o": "<o>", "fallback": "<fallback>" }
}

Input

FieldTypeRequiredDefaultDescription
oobject | objectyes
fallbackanyyes

Output

The schema does not list fields (any).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "o": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "tag": {
                "type": "string",
                "const": "none"
              }
            },
            "required": [
              "tag"
            ],
            "additionalProperties": {}
          },
          {
            "type": "object",
            "properties": {
              "tag": {
                "type": "string",
                "const": "some"
              },
              "value": {}
            },
            "required": [
              "tag",
              "value"
            ],
            "additionalProperties": {}
          }
        ]
      },
      "fallback": {}
    },
    "required": [
      "o",
      "fallback"
    ],
    "additionalProperties": false
  },
  "output": {}
}