← All procedures

quantity.format

This function prints an amount: "$1,234.56", "$500/mo", "7,875 s", "34.5%", "72°F", "12 reps", "∞ s".

CLI
Package
@procedures/quantity · README
Path
["quantity","format"]
CLI
mark quantity format --amount <object | object | object>
As data
{"$proc":["quantity","format"],"input":{}}

Use it

In TypeScript

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

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

From the command line

$ mark quantity format --amount <object | object | object>

As data, in a program

{ "$proc": ["quantity", "format"], "input": { "amount": "<amount>" } }

Input

FieldTypeRequiredDefaultDescription
amountobject | object | objectyes
optionsobjectno

Output

The schema does not list fields (string).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "amount": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "value": {
                "type": "number"
              },
              "unit": {
                "type": "string"
              }
            },
            "required": [
              "value",
              "unit"
            ],
            "additionalProperties": {}
          },
          {
            "type": "object",
            "properties": {
              "value": {
                "type": "string",
                "const": "infinite"
              },
              "unit": {
                "type": "string"
              }
            },
            "required": [
              "value",
              "unit"
            ],
            "additionalProperties": {}
          },
          {
            "type": "object",
            "properties": {
              "unknown": {
                "type": "string"
              },
              "unit": {
                "type": "string"
              }
            },
            "required": [
              "unknown"
            ],
            "additionalProperties": {}
          }
        ]
      },
      "options": {
        "type": "object",
        "properties": {
          "digits": {
            "type": "number",
            "description": "This number is the most decimal places to show (the default is 2). Money shows exactly this many when it is given. Otherwise money shows its cents only when it has cents: $400, $42.49."
          },
          "signed": {
            "type": "boolean",
            "description": "This option shows a + on a positive amount, for changes."
          }
        },
        "additionalProperties": {}
      }
    },
    "required": [
      "amount"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "string"
  }
}