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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lianhr12/business-tools

v1.1.0

Published

Business development common tools and methods encapsulation collection

Readme

business-tools

npm LICENSE MIT

业务开发常用工具方法封装集合,业务开发过程中,会经常用到日期格式化url参数转对象浏览器类型判断节流函数等常用函数,为避免不同项目多次复制粘贴的麻烦,这里统一封装,并发布到npm,以提高开发效率。

注意:工具库依赖于浏览器运行环境,不可直接使用到nodejs环境,否则部分方法会直接报错

安装使用

使用npm或者yarn快速安装

npm install @lianhr12/business-tools -S
yarn add @lianhr12/business-tools -S

根据模块使用工具库,下面简单举例: ES Module

import businessTool from '@lianhr12/business-tools';
// 获取系统信息
const os = businessTool.getOSInfo();

CommonJS

const businessTool = require('@lianhr12/business-tools');
// 获取系统信息
const os = businessTool.getOSInfo();

浏览器,需要下载dist目录下的business-tools.umd.js文件,并页面引用

<script src="business-tools.umd.js"></script>
<script>
    var OS = businessTool.getOSInfo();
</script>

推荐使用方法

// 为减少文件体积,推荐按需引入使用到方法
import { getOSInfo } from '@lianhr12/business-tools';
// 获取系统信息
const os = getOSInfo();

API文档

Cookie

  • 根据name读取Cookie    function getCookieByName(name: string): string;
  • 根据name删除Cookie   removeCookiesByName(name: string): void;
  • 添加Cookie   function setCookie(name: string, value: string

Device

  • 根据UA信息获取浏览器信息   function getBrowserInfo(): IBrowserInfo [name: string; version: string]
  • 获取操作系统类型    getOSInfo(): string

DOM

  • 判断元素是否包含指定class   hasClass(el: Element, className: string): boolean;
  • 为元素添加class    function addClass(el: Element, className: string): void;
  • 删除元素指定的className    function removeClass(el: Element, className: string): void;
  • 获取滚动条距顶部的距离    function getScrollTop(): number;
  • 设置滚动条距顶部的距离    setScrollTop(value: any): number;
  • 在${duration}时间内,滚动条平滑滚动到${to}指定位置   function scrollTo(to: number, duration: number): void;

Helper

  • 根据键盘keycode获得键名    function getKeyName(keycode: any): any;

Object

  • 判断obj是否为空    isEmptyObject(obj: any): boolean;
  • 深拷贝,支持常见类型    function deepClone(values: any): any;

Random

  • 生成指定范围[min, max]的随机数    randomNum(min: number, max: number): number;
  • 随机生成颜色 function randomColor(): string;

Regexp

  • 判断是否为16进制颜色,rgb 或 rgba   function isColor(str: string): boolean;
  • 判断是否为邮箱地址    isEmail(str: string): boolean;
  • 判断是否为身份证号   function isIdCard(str: string): boolean;
  • 判断是否为手机号    function isPhoneNum(str: string): boolean;
  • 判断是否为URL地址    function isUrl(str: string): boolean;

String

  • 现金额转大写    digitUppercase(n: number): string;
  • 手机号隐私处理(中间四位数隐藏)   function replacePhoneNum(phone: string): string;
  • 去除首尾空格处理,trim(' test ')   function trim(str: string): string;

Support

  • 判断浏览器是否支持webP格式图片  function hasSupportWebP(): boolean;

Time

  • 格式化${startTime}距现在的已过时间   formatPassTime(startTime: number): string;
  • 格式化现在距${endTime}的剩余时间    function formatRemainTime(endTime: number): string;
  • 是否为闰年    isLeapYear(year: number): boolean;
  • 判断是否为同一天    function isSameDay(date1: Date, date2?: Date): boolean;
  • 获取指定日期月份的总天数    function monthDays(time: Date): number;
  • ${startTime - endTime}的剩余时间,startTime大于endTime时,均返回0。    function timeLeft(startTime: Date | string, endTime: Date | string): { d: number; h: number; m: number; s: number; } | undefined;

URL

  • url query参数字符转对象   function parseQueryString(url?: string): {};
  • 对象序列化为url query参数字符    function stringfyQueryString(obj: any): string;