josdejong/mathjs

Removing user-defined units

オープン

#2,081 opened on 2021/01/13

 (8 件のコメント) (1 件のリアクション) (0 人の担当者)JavaScript (1,314 件のフォーク)batch import
featurehelp wanted

Repository metrics

Stars
 (15,065 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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?

コントリビューターガイド