josdejong/mathjs

Removing user-defined units

Open

#2,081 建立於 2021年1月13日

在 GitHub 查看
 (8 留言) (1 反應) (0 負責人)JavaScript (1,298 fork)batch import
featurehelp wanted

倉庫指標

Star
 (13,832 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Is there a way to remove user-defined units? I create units for currency conversion using:

math.createUnit('USD', {aliases: ['usd']})

var rates = currencyRates //Rates in json format
Object.keys(rates).map((currency) => {
    math.createUnit(rates[currency].code, {
        definition: math.unit(rates[currency].inverseRate + 'USD'),
        aliases: [rates[currency].code.toLowerCase()]
    }, {
        override: true
    })
})

But if I no longer want to use currencies, is there a way to remove them without creating a new mathjs instance (in my case without refreshing browser window)? If not, may I suggest introducing a math.removeUnit() method?

貢獻者指南