1.1.7 • Published 3 months ago

lh-hooks v1.1.7

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

公共hooks方法;

安装

npm install lh-hooks --save

使用方法

1.引入

import { common, crypto } form "lh-hooks";

2. 库方法

2.1 common 通用

imprort { commom } form "lh-hooks";
import type { InfoType, FormChcekColumnType, CompressImageType, ListConvertTreeType, TreeType, LazyImgType } from "lh-hooks";
/**
 * 防抖 (一定时间内只执行最后一次)
 * @param func 回调函数
 * @param time 毫秒
 */
export declare const debounce: (func: Function, time?: number) => (...value: any) => void;
/**
 * 节流 (一定时间内只执行一次)
 * @param func 回调函数
 * @param time 毫秒
 */
export declare const throttling: (func: Function, time?: number) => (...value: any) => 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 time 时间戳/s
     * @param format 时间输出格式,默认:Y-m-d H:i:s
     */
    timeConvertDate(time: number, format?: string): string;
    /**
     * 日期转时间戳
     * @param date 日期
     */
    dateConvertTime(date: string): number;
    /**
     * 获取前后某天日期
     * @param n 前n天或后n天,负数=前n天,正数=后n天,0=当天,默认=0
     * @param format 时间输出格式,默认:Y-m-d H:i:s
     */
    getSomeDayDate(n?: number, format?: string): string;
    /**
     * 获取前后某月的某一天
     * @param nMonth 前后月份 0=当月,1=下月,-1=上月
     * @param nDay 某一天,默认第一天,0=最后一天
     * @param format 时间输出格式,默认:Y-m-d H:i:s
     */
    getSomeMonthDayDate(nMonth: number, nDay?: number, format?: string): 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加解密

imprort { crypto } form "lh-hooks";
/**
 * 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;
1.1.7

3 months ago

1.1.1

12 months ago

1.1.6

12 months ago

1.1.5

12 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago