← All procedures

quantity.parseUnit

This function resolves a unit from its spelling. The spelling has symbols or their aliases, factors joined by `·` or `*`, and one `/` at most. All that follows the slash divides: "kcal/h·kg" is per hour per kilogram. A factor can have a power (`m^2`) and say what it counts (`{rep}`).

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

From the command line

$ mark quantity parseUnit --spelling <string>

As data, in a program

{
  "$proc": ["quantity", "parseUnit"],
  "input": { "spelling": "<spelling>" }
}

Input

FieldTypeRequiredDefaultDescription
spellingstringyes

Output

FieldTypeRequiredDefaultDescription
symbolstringyesThe symbol is its canonical spelling: the symbols of the atoms, `·` between factors, and one `/`.
componentsobject[]yes
vectorobjectyes
factorobjectyes
offsetobjectnoOnly a lone affine unit (°F, °C) has an offset. A compound of it is a difference.
kind"area" | "charge" | "count" | "current" | "data" | "data-rate" | "derived" | "energy" | "energy-price" | "frequency" | "length" | "level" | "mass" | "money" | "money-rate" | "power" | "ratio" | "resistance" | "specific-power" | "specific-volume-rate" | "speed" | "temperature" | "time" | "transfer-rate" | "voltage" | "volume"yes
countsobjectyesThe counts are what it counts, with exponents: bpm counts beats, and `{set}/wk` counts sets per week.
logbooleanyes
paramstringnoThe parameter is what its size changes with: a jiffy needs the HZ of the kernel.
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "spelling": {
        "type": "string"
      }
    },
    "required": [
      "spelling"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "object",
    "properties": {
      "symbol": {
        "type": "string",
        "description": "The symbol is its canonical spelling: the symbols of the atoms, `·` between factors, and one `/`."
      },
      "components": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "atom": {
              "type": "object",
              "properties": {
                "symbol": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "display": {
                  "type": "string",
                  "description": "This text is how it prints, where that is not its symbol: °F, µs."
                },
                "vector": {
                  "type": "object",
                  "properties": {
                    "time": {
                      "type": "number"
                    },
                    "length": {
                      "type": "number"
                    },
                    "mass": {
                      "type": "number"
                    },
                    "temperature": {
                      "type": "number"
                    },
                    "data": {
                      "type": "number"
                    },
                    "money": {
                      "type": "number"
                    },
                    "current": {
                      "type": "number"
                    }
                  },
                  "additionalProperties": {}
                },
                "factor": {
                  "type": "object",
                  "properties": {
                    "n": {
                      "type": "string",
                      "pattern": "^-?(0|[1-9][0-9]*)$",
                      "x-procedures-codec": "bigint"
                    },
                    "d": {
                      "type": "string",
                      "pattern": "^-?(0|[1-9][0-9]*)$",
                      "x-procedures-codec": "bigint"
                    }
                  },
                  "required": [
                    "n",
                    "d"
                  ],
                  "additionalProperties": {}
                },
                "offset": {
                  "type": "object",
                  "properties": {
                    "n": {
                      "type": "string",
                      "pattern": "^-?(0|[1-9][0-9]*)$",
                      "x-procedures-codec": "bigint"
                    },
                    "d": {
                      "type": "string",
                      "pattern": "^-?(0|[1-9][0-9]*)$",
                      "x-procedures-codec": "bigint"
                    }
                  },
                  "required": [
                    "n",
                    "d"
                  ],
                  "additionalProperties": {},
                  "description": "An affine unit (a temperature) has an offset: base = (value + offset) × factor."
                },
                "log": {
                  "type": "boolean",
                  "const": true,
                  "description": "A logarithmic level converts only to itself, and it averages by energy."
                },
                "counts": {
                  "type": "string",
                  "description": "This name is what it counts, when it is a count of something: a GT is 10⁹ transfers, a bpm counts beats."
                },
                "percent": {
                  "type": "boolean",
                  "const": true,
                  "description": "A percentage makes a unit with no dimension a ratio."
                },
                "param": {
                  "type": "string",
                  "const": "hz",
                  "description": "Its size changes with the system that it measures: a jiffy is 1/HZ seconds."
                },
                "decimals": {
                  "type": "number",
                  "description": "An amount keeps this many decimal places: money keeps the cent."
                },
                "aliases": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "symbol",
                "name",
                "vector",
                "factor"
              ],
              "additionalProperties": {}
            },
            "annotation": {
              "type": "string",
              "description": "The annotation `{rep}` counts reps, and `%{1RM}` is a percentage of a one-rep max."
            },
            "exponent": {
              "type": "number",
              "description": "The exponent has a sign: what follows the slash divides."
            }
          },
          "required": [
            "exponent"
          ],
          "additionalProperties": {}
        }
      },
      "vector": {
        "type": "object",
        "properties": {
          "time": {
            "type": "number"
          },
          "length": {
            "type": "number"
          },
          "mass": {
            "type": "number"
          },
          "temperature": {
            "type": "number"
          },
          "data": {
            "type": "number"
          },
          "money": {
            "type": "number"
          },
          "current": {
            "type": "number"
          }
        },
        "additionalProperties": {}
      },
      "factor": {
        "type": "object",
        "properties": {
          "n": {
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]*)$",
            "x-procedures-codec": "bigint"
          },
          "d": {
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]*)$",
            "x-procedures-codec": "bigint"
          }
        },
        "required": [
          "n",
          "d"
        ],
        "additionalProperties": {}
      },
      "offset": {
        "type": "object",
        "properties": {
          "n": {
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]*)$",
            "x-procedures-codec": "bigint"
          },
          "d": {
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]*)$",
            "x-procedures-codec": "bigint"
          }
        },
        "required": [
          "n",
          "d"
        ],
        "additionalProperties": {},
        "description": "Only a lone affine unit (°F, °C) has an offset. A compound of it is a difference."
      },
      "kind": {
        "type": "string",
        "enum": [
          "area",
          "charge",
          "count",
          "current",
          "data",
          "data-rate",
          "derived",
          "energy",
          "energy-price",
          "frequency",
          "length",
          "level",
          "mass",
          "money",
          "money-rate",
          "power",
          "ratio",
          "resistance",
          "specific-power",
          "specific-volume-rate",
          "speed",
          "temperature",
          "time",
          "transfer-rate",
          "voltage",
          "volume"
        ]
      },
      "counts": {
        "type": "object",
        "properties": {},
        "additionalProperties": {
          "type": "number"
        },
        "description": "The counts are what it counts, with exponents: bpm counts beats, and `{set}/wk` counts sets per week."
      },
      "log": {
        "type": "boolean"
      },
      "param": {
        "type": "string",
        "const": "hz",
        "description": "The parameter is what its size changes with: a jiffy needs the HZ of the kernel."
      }
    },
    "required": [
      "symbol",
      "components",
      "vector",
      "factor",
      "kind",
      "counts",
      "log"
    ],
    "additionalProperties": {}
  }
}