npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cicctencent/util

v2.3.0

Published

jv utils library

Downloads

3

Readme

jv函数辅助库

包括:

  • math: 提供小数点精确的计算,加减乘除和取模
  • amount: 用于格式化金额数字为常用的金融需要的格式,如1,234.00
  • detect: 用于判断系统、平台和机型

使用文档可以暂时参考测试文件,位于源码的test目录下

安装

npm i -S @jv/util;

引用

import math from '@jv/util/math';

console.log(math.add(.002, .003));

amount

amount#toCurrency

转换为常用货币展示格式,按千分割数字,如:12345.67 => 12,345.67

import { toCurrency } from '@jv/util/amount';

// 默认两位小数
toCurrency(12345); // => 12,345.00
// 限制小数位数
toCurrency(12345, 3); // => 12,345.000
toCurrency(12345.1, 3); // => 12,345.100
toCurrency(12345, 0); // => 12,345
// 保留指定个小数时,遵循四舍五入原则
toCurrency(12345.618, 1); // => 12,345.6
toCurrency(12345.618, 2); // => 12,345.62
// 尽可能的去除末尾多余的0
toCurrency(12345, 3); // => 12,345.000
toCurrency(12345, 3, true); // => 12,345
toCurrency(12345.1, 3, true); // => 12,345.1
// 异常数据原样返回
toCurrency('--'); // => --

amount#toText

格式化大数为指定的单位,如:12345.67 => 1.23万

import { toText } from '@jv/util/amount';

// 自带万和亿两个档位的级别,默认2位小数
toText(123456789); // => 1.23亿
toText(12345); // => 12.35万
// 限制接受转换的起始金额
toText(12345); // => 1.23万
toText(12345, 2, { threshold: 100000 }); // => 12345.00
toText(123456, 2, { threshold: 100000 }); // => 12.35.00万
// 保留固定位数的小数(遵循四舍五入)
toText(123446789, 0); // => 1亿
toText(123446789, 3); // => 1.234亿
toText(123446789, 4); // => 1.2345亿
// 指定附加单位
toText(12345, 2, { unit: '手' }); // => 1.23万手
toText(12345, 2, { unit: '张' }); // => 1.23万张
// 尽可能的去除末尾多余的0
toText(100000); // => 10.00万
toText(100000, 2, { cut: true }); // => 10万
toText(101000, 3); // => 10.100万
toText(101000, 3, { cut: true }); // => 10.1万
// 如果原始数据是小数,则不能进行格式化
toText(12356.67); // => 12345.67
// allowDecimal=true,绕过小数不处理逻辑
toText(12356.67, 2, { allowDecimal: true }); // => 1.23万