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

lh-work-tools

v1.0.4

Published

### 安装 ``` npm install lh-work-tools --save ```

Downloads

2

Readme

公共hooks方法;

安装

npm install lh-work-tools --save

使用方法

1.引入

import { common, crypto } form "lh-work-tools";

2. 库方法

2.1 common 通用

import { commom } form "lh-work-tools";
import type { InfoType, FormChcekColumnType, CompressImageType, ListConvertTreeType, TreeType, LazyImgType } from "lh-work-tools";
/**
 * 防抖 (一定时间内只执行最后一次)
 * @param func 回调函数
 * @param time 毫秒
 */
export declare const debounce: <F extends (...args: any[]) => any>(func: F, time?: number) => (...args: Parameters<F>) => void;
/**
 * 节流 (一定时间内只执行一次)
 * @param func 回调函数
 * @param time 毫秒
 */
export declare const throttling: <F extends (...args: any[]) => any>(func: F, time?: number) => (...args: Parameters<F>) => void;
/**
 * 设置localStorage
 * @param key 唯一标识
 * @param value 存储值
 * @param keyHex 秘钥
 */
export declare const setLocalStorage: (key: string, value: any, keyHex: string) => boolean;
/**
 * 获取localStorage
 * @param key 唯一标识
 * @param keyHex 秘钥
 */
export declare const getLocalStorage: (key: string, keyHex: string) => string | null;
/**
 * 设置sessionStorage
 * @param key 唯一标识
 * @param value 存储值
 * @param keyHex 秘钥
 */
export declare const setSessionStorage: (key: string, value: any, keyHex: string) => boolean;
/**
 * 获取sessionStorage
 * @param key 唯一标识
 * @param keyHex 秘钥
 */
export declare const getSessionStorage: (key: string, keyHex: string) => string | null;
/**
 * 是否移动端
 */
export declare const isMobile: () => boolean;
/**
 * 复制文本
 * @param text 复制的字符串
 */
export declare const copyText: (text: string) => void;
/**
 * 获取url中指定参数
 */
export declare const getUrlParams: <T = unknown>() => T;
/**
 * 表单校验
 * @param data 表单对象数据
 * @param column 校验的结构列
 */
export declare const formChcek: (data: Record<string, any>, column: FormChcekColumnType[]) => Promise<string>;
/**
 * 根据索引遍历查询对象值
 * @param obj 数据对象 如:{info: data: {num: 1}}
 * @param indexText 对象索引值 如: "info.data.num"
 */
export declare const findObjectIndexValue: (obj: Record<string, any>, indexText: string) => any;
/**
 * 深拷贝
 */
export declare const deepClone: (origin: any, hashMap?: WeakMap<object, any>) => any;
/**
 * 获取文件名后缀
 * @param filedName 文件名称
 */
export declare const getSuffixName: (fileName: string) => string;
/**
 * 图片操作
 */
export declare const images: {
    /**
     * 图片压缩
     */
    compressImage({ imgFile, maxPx, quality, maxSize, types, }: CompressImageType): Promise<InfoType<string>>;
    /**
     * 图片懒加载
     */
    lazyImage({ el, loadingImgUrl, errorImgUrl }: LazyImgType): void;
};
/**
 * 数组操作
 */
export declare const array: {
    /**
     * 数组根据某字段进行排序
     * @param list 数组对象
     * @param filedName 排序字段名
     * @param sort 排序方式:asc正序,desc倒序
     */
    arraySort<T = unknown>(list: T[], filedName: string, sort?: string): T[];
    /**
     * 数组分页
     * @param list 数组对象
     * @param page 页数
     * @param num  每页数量
     */
    arrayPage<T_1 = unknown>(list: T_1[], page?: number, num?: number): T_1[];
    /**
     * 数组按页数分组返回
     * @param list 数组对象
     * @param num  每页数量
     */
    arrayGroup<T_2 = unknown>(list: T_2[], num?: number): T_2[][];
    /**
     * 列表转换树形数据
     * @param {array} list 			数据
     * @param {string} pidName 		父id字段名,默认:pid
     * @param {string} idName 		id字段名,默认:id
     * @param {string} labelName	名称的字段名,默认:label
     * @param {int} pid 			父id,默认:0
     */
    listConvertTree({ list, pidName, idName, labelName, pid }: ListConvertTreeType): TreeType[];
};
/**
 * 时间/日期操作
 */
export declare const date: {
    /**
     * 将秒转换为时分秒
     * @param second 秒数
     */
    secondConvertTime(second: number): string;
    /**
     * 日期或时间戳格式化
     * @param (date | number) 日期 | 时间戳
     * @param format 时间输出格式,默认:Y-m-d H:i:s
     */
    dateFormatter(dates: Date | number, format?: string): string;
    /**
     * 日期转时间戳
     * @param date 日期 2023-08-08
     */
    dateConvertTime(date: string): number;
    /**
     * 获取前后某天日期
     * @param n 前n天或后n天,负数=前n天,正数=后n天,0=当天,默认=0
     * @param format 时间输出格式,默认:Y-m-d
     */
    getSomeDayDate(n?: number, format?: string): string;
    /**
     * 获取前后某月的某一天
     * @param nMonth 前后月份 0=当月,1=下月,-1=上月
     * @param nDay 某一天,默认第一天,0=最后一天
     * @param format 时间输出格式,默认:Y-m-d
     */
    getSomeMonthDayDate(nMonth: number, nDay?: number, format?: string): string;
    /**
     * 获取本周时间区间
     * @param format 时间输出格式,默认:Y-m-d H:i:s
     */
    getWeekDate(format?: string): {
        start: string;
        end: string;
    };
    /**
     * 获取本季度时间区间
     * @param format 时间输出格式,默认:Y-m-d H:i:s
     */
    getQuarterDate(format?: string): {
        start: string;
        end: string;
    };
};
/**
 * 金融类操作
 */
export declare const finance: {
    /**
     * 中文姓名验证
     * @param name 姓名
     */
    isChineseName(name: string, min?: number, max?: number): InfoType;
    /**
     * 金额验证
     * @param money 金额
     */
    isMoney(money: string): boolean;
    /**
     * 手机号验证
     * @param phone 手机号
     */
    isPhone(phone: string): boolean;
    /**
     * 是否是邮箱格式
     * @param email 邮箱地址
     */
    isEmail(email: string): boolean;
    /**
     * 是否是银行卡号
     * @param cardNumber 卡号
     */
    isBankCard(cardNumber: string): boolean;
    /**
     * 是否是身份证号
     * @param cardNumber 卡号(15 or 18位)
     */
    isIdCard(cardNumber: string): boolean;
    /**
     * 金额小写转为大写
     * @param amount 金额(最大支持到千亿)
     */
    amountToUpperCase(amount: string): InfoType<string>;
    /**
     * 姓名遮掩处理
     * @param name 姓名
     */
    nameCover(name: string): string;
    /**
     * 数字号码遮掩处理
     * @param number 数字号码
     * @param type 类型:手机号 | 身份证 | 银行卡
     */
    numberCover(number: string, type: "phone" | "idCard" | "bankCard"): string;
};

2.2 des加解密

import { crypto } form "lh-work-tools";
/**
 * DES加密
 * @param value 加密值
 * @param key 秘钥
 */
declare function enCryptoDES(value: any, key: string): string;
 /**
 * DES解密
 * @param value 解密值
 * @param key 秘钥
 */
declare function deCryptoDES(value: any, key: string): string;

2.3 随机数据

import { createRandomData } form "lh-work-tools";

/**
 * 生成随机数据
 * @param dataSchema 生成数据的结构
 * @param num 生成条数, 1=固定数量, '1-5'为范围随机
 */
export declare const createRandomData: (dataSchema: SchemaType[], num: number | string) => { list: Record<string, string | number>[], total: number };