Skip to content

Is this the only way to get valid units? #3181

Answered by dvd101x
AFZL210 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, I wouldn't say it's the only way. There might be many ways, but I would recommend exploring math.Unit.UNITS to find a way to match your specific needs.

I personally think the answer proposed at #3178 (comment) is very complete. Maybe you don't need all prefixes so you can skip some steps.

You could find similar solutions in various places in this project. Which might be useful to your needs.

  • mathjs/bin/cli.js

    Lines 123 to 152 in 02f195f

    const Unit = math.Unit
    for (const name in Unit.UNITS) {
    if (hasOwnProperty(Unit.UNITS, name)) {
    if (name.indexOf(keyword) === 0) {
    matches.push(name)
    }
    }
    }
    for (const name in Unit.PREFIXES) {
    if (

Replies: 1 comment 1 reply

Comment options

dvd101x
Apr 1, 2024
Collaborator Sponsor

You must be logged in to vote
1 reply
@AFZL210
Comment options

Answer selected by AFZL210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants