← All procedures

optional.toSentinel

This function changes an optional into the sentinel form: an absent value becomes `sentinel`.

CLI
Package
@procedures/optional · README
Path
["optional","toSentinel"]
CLI
mark optional toSentinel --o <object | object> --sentinel <any>
As data
{"$proc":["optional","toSentinel"],"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","toSentinel"], { o: "<o>", sentinel: "<sentinel>" });
console.log(JSON.stringify(result));

From the command line

$ mark optional toSentinel --o <object | object> --sentinel <any>

As data, in a program

{
  "$proc": ["optional", "toSentinel"],
  "input": { "o": "<o>", "sentinel": "<sentinel>" }
}

Input

FieldTypeRequiredDefaultDescription
oobject | objectyes
sentinelanyyes

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": {}
          }
        ]
      },
      "sentinel": {}
    },
    "required": [
      "o",
      "sentinel"
    ],
    "additionalProperties": false
  },
  "output": {}
}