UNPKG

mine-h5-ui

Version:

一款轻量级、模块化基于 Vue3.x 的 H5 前端 UI 组件库 👍

203 lines (202 loc) 6.73 kB
import { DTCallback, LockedCallback, ThrottleBack, DebounceBack, LockedBack, FormatData, FormatTimeBack, CalculationBack } from './types'; /** * 变量类型判断 * @param { string } type - 需要判断的类型 * @param { any } value - 需要判断的值 * @returns { boolean } - 是否该类型 * @example * import { MeAPI } from 'mine-h5-ui' * * console.log(MeAPI.IsType('string', '123')) // 输出: true */ export declare const IsType: (type: string, value: unknown) => boolean; /** * 深拷贝变量-递归算法(recursive algorithm) * 支持 String,Number,boolean,null,undefined,Object,Array,Date,RegExp,Error 类型 * @param { any } arg - 需要深拷贝的变量 * @returns { any } - 拷贝完成的值 * @example * import { MeAPI } from 'mine-h5-ui' * * console.log(MeAPI.DeepCopyRA({ a: 1 })) // 输入: { a: 1 } */ export declare const DeepCopyRA: (arg: any) => any; /** * 判断是否是闰年 * @param { number } year - 能被4整除,不能被100整除,能被400整除;优先级:400>100>4 * @returns { boolean } - true:是闰年,false:不是闰年 * @example * import { MeAPI } from 'mine-h5-ui' * * cosnole.log(MeAPI.IsLeapyear(2020)) // 输出: true */ export declare const IsLeapyear: (num: number) => boolean; /** * 时间转换 * @param { string | Number | Date} [arg=new Date()] - 需要转换的时间 * @returns { FormatTimeBack } - 转换后的时间数据对象 * @returns { string } FormatTimeBack.Y - 年 * @returns { string } FormatTimeBack.M - 月 * @returns { string } FormatTimeBack.D - 日 * @returns { string } FormatTimeBack.w - 星期 * @returns { string } FormatTimeBack.h - 时 * @returns { string } FormatTimeBack.m - 分 * @returns { string } FormatTimeBack.s - 秒 * @returns { string } FormatTimeBack.date - 日期 * @returns { string } FormatTimeBack.time - 时间 * @returns { string } FormatTimeBack.datetime - 日期时间 * @example * import { MeAPI } from 'mine-h5-ui' * * console.log(MeAPI.FormatTime()) // 输出: { Y: '2021', M: '01', D: '01', w: '星期五', h: '00', m: '00', s: '00', date: '2021-01-01', time: '00:00:00', datetime: '2021-01-01 00:00:00' } */ export declare const FormatTime: (arg?: string | number | Date) => FormatTimeBack; /** * 倒时间计算 * @param { number } num - 需要转化的时间, ms * @param { string } [format="hh:mm:ss"] - 需要转化的时间, ms * @returns { FormatData } - 转换后的时间数据对象 * @returns { string } FormatData.DD - 日 * @returns { string } FormatData.hh - 时 * @returns { string } FormatData.mm - 分 * @returns { string } FormatData.ss - 秒 * @returns { string } FormatData.ms - 毫秒 * @example * import { MeAPI } from 'mine-h5-ui' * * console.log(MeAPI.CountDown(1000)) // 输出: { DD: '00', hh: '00', mm: '00', ss: '01', ms: '000' } */ export declare const CountDown: (num: number, format?: string) => Partial<FormatData>; /** * 节流 * @param { DTCallback } fn - 回调业务处理函数 * @param { number } [time=1000] - 定时器时间 * @returns { ThrottleBack } - 返回的 event 函数 * @example * import { MeAPI } from 'mine-h5-ui' * * const fn = () => console.log('节流') // 1s 后才会触发 * const throttle = MeAPI.Throttle(fn) * throttle() */ export declare const Throttle: (fn: DTCallback, time?: number) => ThrottleBack; /** * 防抖 * @param { DTCallback } fn - 回调业务处理函数 * @param { number } [time=300] - 定时器时间 * @returns { DebounceBack } - 返回的 event 函数 * @example * import { MeAPI } from 'mine-h5-ui' * * const fn = () => console.log('防抖') // 300ms 后才会触发 * const debounce = MeAPI.Debounce(fn) * debounce() */ export declare const Debounce: (fn: DTCallback, time?: number) => DebounceBack; /** * 锁定 * @param { LockedCallback } fn - 回调函数 * @param { number } [time=5000] - 超时自动关闭 * @returns { LockedBack } 返回函数 * @example * import { MeAPI } from 'mine-h5-ui' * * MeAPI.Locked(() => console.log('锁定')) // 5s 后才会触发 */ export declare const Locked: (fn: LockedCallback, time?: number) => LockedBack; /** * 加 0 补位 * @param { string } str - 原来拼接值 * @param { number } float1 - 第一个小数位数 * @param { number } float2 - 第二个小数位数 * @returns { string } - 加 0 补位之后的值 * @example * import { MeAPI } from 'mine-h5-ui' * * console.log(MeAPI.AddZero('1', 2, 3)) // 输出: 1.00 */ export declare const AddZero: (str: string, float1: number, float2: number) => string; /** * 加减乘除运算 * 使用方法:Calculation(0.1, 0.2).add(); * @param { number } num1 - 运算值 1 * @param { number } num2 - 运算值 2 * @returns { CalculationBack } - 运算方法 add subtract multiply divide * @example * import { MeAPI } from 'mine-h5-ui' * * console.log(MeAPI.Calculation(0.1, 0.2).add()) // 输出: 0.3 */ export declare const Calculation: (num1: number, num2: number) => CalculationBack; /** * 生成随机数 * @param { void } * @returns { string } 生成的随机数 * @example * import { MeAPI } from 'mine-h5-ui' * * console.log(MeAPI.GenerateRandom()) // 输出: 1612345678901 */ export declare const GenerateRandom: () => string; /** * 延迟器 * @param { number } [time=500] 延迟时间 * @returns { Promise<boolean> } Promise * @example * import { MeAPI } from 'mine-h5-ui' * * await MeAPI.Retarder() * console.log('延迟 500ms 后执行') */ export declare const Retarder: (time?: number) => Promise<boolean>; declare const _default: { /** * 变量类型判断 */ IsType: (type: string, value: unknown) => boolean; /** * 深拷贝变量 - 递归算法(recursive algorithm) */ DeepCopyRA: (arg: any) => any; /** * 判断是否是闰年 */ IsLeapyear: (num: number) => boolean; /** * 时间转换 */ FormatTime: (arg?: string | number | Date) => FormatTimeBack; /** * 倒计时 */ CountDown: (num: number, format?: string) => Partial<FormatData>; /** * 节流 */ Throttle: (fn: DTCallback, time?: number) => ThrottleBack; /** * 防抖 */ Debounce: (fn: DTCallback, time?: number) => DebounceBack; /** * 锁定 */ Locked: (fn: LockedCallback, time?: number) => LockedBack; /** * 加 0 补位 */ AddZero: (str: string, float1: number, float2: number) => string; /** * 加减乘除运算 */ Calculation: (num1: number, num2: number) => CalculationBack; /** * 生成随机数 */ GenerateRandom: () => string; /** * 延迟器 */ Retarder: (time?: number) => Promise<boolean>; }; export default _default;