1.1.0 • Published 19 days ago

@godcount/unit-conversion v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
19 days ago

unit-conversion

  • 快捷的单位转换工具,对 Number 原型扩展,实现快速使用
  • 没有精度这东西

日志

  • 时间
  • 存储容量
  • 长度(公制、市制、英制)
  • 添加best,返回最佳值(字符串)
  • 添加配置
{
    // 单位大写
    bestUnitUpper: boolean;
    // 添加空格
    bestCenterSpace: boolean;
    // 保留小数位数
    bestFractionDigits: number;
}

导入

npm install @godcount/unit-conversion

用法

  • 只需要全局导入

导入例子

  • 导入全部
import "@godcount/unit-conversion";
  • 使用类
import { DurationUnit } from "@godcount/unit-conversion";
  • (typescript)全局类型提示
// tsconfig.json
{
  "compilerOptions": {
    "types": ["@godcount/unit-conversion"]
  }
}

使用例子

转换时间

  • 返回毫秒
const duration = 180;
duration.toDuration("s").ms;
duration.toDuration("s").min;
...

转换存储容量

  • 返回兆
const byte = 1024;
byte.toStorage("byte").m;

转换长度

  • 返回厘米、毫、码
const nm = 100;
nm.toLength("nm")
    .cm.toLength("cm")
    .hao.toLength("hao").yd;
1.1.0

19 days ago

1.0.1

6 months ago

1.0.0

6 months ago