← All procedures

quantity.formatOnScale

This function prints an amount on a scale: "512 B", "1.5 KiB", "3.5 ms", "1.25 s", "2 min 5 s". It rounds the amount in a step before it compares the amount with the next step. Thus 1,048,575 B gives "1 MiB", not "1,024 KiB".

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

From the command line

$ mark quantity formatOnScale --amount <object> --scale <object>

As data, in a program

{
  "$proc": ["quantity", "formatOnScale"],
  "input": { "amount": {}, "scale": {} }
}

Input

FieldTypeRequiredDefaultDescription
amountobjectyes
scaleobjectyes

Output

The schema does not list fields (string).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "amount": {
        "type": "object",
        "properties": {
          "value": {
            "type": "number"
          },
          "unit": {
            "type": "string"
          }
        },
        "required": [
          "value",
          "unit"
        ],
        "additionalProperties": {}
      },
      "scale": {
        "type": "object",
        "properties": {
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "unit": {
                  "type": "string",
                  "description": "The unit of the step. The text shows its symbol, so the text reads back as the same amount."
                },
                "digits": {
                  "type": "number",
                  "description": "This number is the most decimal places (the default is 2)."
                },
                "significant": {
                  "type": "number",
                  "description": "This number is the significant digits. The decimal places then shrink as the number grows, but stay at most `digits`: with 2, the text is \"0.42\", \"3.5\" and \"120\"."
                },
                "fixed": {
                  "type": "boolean",
                  "description": "This option always shows `digits` decimal places: \"1.0\", not \"1\"."
                }
              },
              "required": [
                "unit"
              ],
              "additionalProperties": {}
            }
          },
          "compound": {
            "type": "object",
            "properties": {
              "units": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "The units of the compound, from the largest to the smallest."
              },
              "parts": {
                "type": "number",
                "description": "This number is the most units that the text names (the default is all). The smallest of them is rounded."
              }
            },
            "required": [
              "units"
            ],
            "additionalProperties": {}
          }
        },
        "required": [
          "steps"
        ],
        "additionalProperties": {}
      }
    },
    "required": [
      "amount",
      "scale"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "string"
  }
}