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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lmy-utils

v1.3.1

Published

utils for js/ts

Readme

1.3.1更新内容

  • 12.金额转大写
  • 13.运算精度丢失问题(两数的加减乘除,如需更近一步了解参考14)
  • 14.currency.js是一个轻量级的〜1kb JavaScript库,用于处理货币值。 它旨在解决javascript中的浮点问题。

用法

JavaScript

import { removeRepeat , ...rest } from 'lmy-utils'

TypeScript

import { removeRepeat , ...rest } from 'lmy-utils/index'

1.removeRepeat(数组对象去重)

removeRepeat (arr: Array<object>,attribute: string ,order: boolean = true)

let arr = [
  {
    name:'xiaoming',
    age:'12'
  },
  {
    name:'xiaohong',
    age:'12'
  }
]
removeRepeat(arr,'age');//[{name:'xiaoming',age:'12'}]

2.random(获取唯一字符串)不传参数默认21位

random(size:number) :string

random(22);
random(32);

3.timeMethod依赖day.js进行时间处理

timeMethod(date: string | number, format: boolean = true)

    timeMethod().today 获取当前时间不带时分秒
    timeMethod().todayComplete 获取当前时间带时分秒
    timeMethod().formatTime(date,format) 穿参数进行时间格式化,第一个参数时间戳,第二个参数布尔值,默认true,默认带时分秒
    timeMethod().exposeDayjs 暴露的dayjs可以根据需求使用

4.deepClone深拷贝

deepClone(obj: unknown):unknown

let arr = [1,2,3];
let newArr = deepClone(arr);
newArr[0] = 4;
console.log(arr,newArr);//[1,2,3]  [4,2,3]

5.debounce防抖

debounce(fn:Function, time:number = 1000)

6.throttle节流

throttle(fn:Function, time:number = 1000)

7.judgmentType判断任意数据的类型

judgmentType(data:unknown)

8.characterFrequency统计数组或字符串中出现字符的次数

characterFrequency(data: Array<string|number> | string )

characterFrequency([1,2,3,1,2,3]); //{ '1': 2, '2': 2, '3': 2 }
characterFrequency('12332'); //{ '1': 1, '2': 2, '3': 2 }

9.timeAround计算时间在N之前或在N之后(可传时间戳/可传时间格式的字符串[2022-12-12 or 2022-12-12 12:00:00])

timeAround(time: number | string)

timeAround("1663141162171");//xx秒之前
timeAround("2022-09-16 18:00:00");//xx秒之前

10.regularCheckFun正则校验

regularCheckFun(data:string | number,type:number,subclass?:string) data 需要校验的数据 type 需要校验的类型

  • 1.中国地区手机号 2.国内座机电话 3.邮箱地址 4.银行卡号 5.身份证号 6.中国邮政编码 7.密码校验(强:strong,中:in,弱:weak)
    • 密码校验

      强:最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符

      中:最少6位,字母+数字,字母+特殊字符,数字+特殊字符

      弱:最少6位,纯数字,纯字母,纯特殊字符

regularCheckFun(15939678299,1);//true
regularCheckFun('123456',7,'weak');//true
regularCheckFun('123456',7,'strong');//false
regularCheckFun('aA1@aaf12',7,'strong');//true

11.objToArrObj对象处理成数组对象

interface Person { [key:string]: unknown;} objToArrObj(obj:Person)

let obj = {a:1b:2,c:3}
objToArrObj(obj);//[ { a: 1 }, { b: 2 }, { c: 3 } ]

12.金额转大写

convertCurrency (money:number | string)

convertCurrency("120.12")//壹佰贰拾元壹角贰分
convertCurrency(520)//伍佰贰拾元整

13.运算精度丢失问题(两数的加减乘除,如需更近一步了解参考14)

type calculationType = string | number;

plus(arg1:calculationType, arg2:calculationType)加法 subtract(arg1:calculationType, arg2:calculationType)减法 multiply(arg1:calculationType, arg2:calculationType)乘法 divide(arg1:calculationType, arg2:calculationType)除法

calculation.plus(0.1,0.05);//0.15
calculation.subtract(0.1,0.05);//0.05
calculation.multiply(0.1,0.05);//0.005
calculation.divide(0.1,0.05);//2

14.currency.js

currency.js是一个轻量级的〜1kb JavaScript库,用于处理货币值。 它旨在解决javascript中的浮点问题。

currencyFun()

//其他用法参照官方文档正常使用
let currency = currencyFun();
let {value} = currency("$2.51").add(0.1).add(0.3);
console.log(value);//2.91