quantity.tryParseUnit
This function gives the unit of a spelling, or undefined when the spelling names no unit.
CLI- Package
- @procedures/quantity · README
- Path
["quantity","tryParseUnit"]- CLI
mark quantity tryParseUnit --spelling <string>- As data
{"$proc":["quantity","tryParseUnit"],"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","tryParseUnit"], { spelling: "<spelling>" });
console.log(JSON.stringify(result));From the command line
$ mark quantity tryParseUnit --spelling <string>
As data, in a program
{
"$proc": ["quantity", "tryParseUnit"],
"input": { "spelling": "<spelling>" }
}Input
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
spelling | string | yes |
Output
The schema does not list fields (object | null).
JSON Schemas
{
"input": {
"type": "object",
"properties": {
"spelling": {
"type": "string"
}
},
"required": [
"spelling"
],
"additionalProperties": false
},
"output": {
"anyOf": [
{
"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": {}
},
{
"type": "null"
}
]
}
}