3.0.0 • Published 2 years ago

@pxxtech/unit-conversion v3.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@scumon/unit-conversion

NPM version NPM downloads

一些简单的单位转换,比如:长度、质量、时间等。

下载

yarn add @scumon/unit-conversion -S

使用

import { g_kg } from "@scumon/unit-conversion";

g_kg(1000); // => 1

全局配置

import { config } from "@scumon/unit-conversion";

// 计算发生错误希望返回什么
config.error = "--";

// 所有结果统一配置,具体参考BigNumber文档
config.formatResult = (BigNumber) => {
  return BigNumber.toFixed(2);
};

拓展

import { expand, processing } from "@scumon/unit-conversion";

expand.x_y = (value: any, config: any) => {
  return processing(
    value,
    (BigNumber: any) => BigNumber.multipliedBy(1000000),
    config
  );
};