UNPKG

javascript-tool

Version:

使用TypeScript语言编写的JavaScript工具合集

124 lines (123 loc) 3.63 kB
declare type Value = string | number | boolean | any[] | Record<string, unknown>; declare type Return = null | string | number | boolean | any[] | Record<string, unknown>; declare type ForItem = any[] | Record<string, unknown>; interface ICookie { /** * 存值 * @param key 键,string类型 * @param value 对应的值,支持数组或者对象 */ setItem: (key: string, value: Value, maxAge?: number) => void; /** * 取值 * @param key 键,string类型 * @returns 有则返回,没有返回null */ getItem: (key: string) => Return; /** * 移除 * @param key 键,string类型 */ removeItem: (key: string) => void; /** * 是否存在 * @param key 键,string类型 * @returns true:存在 false:不存在 */ hasItem: (key: string) => boolean; /** * 清除所有值 */ clear: () => void; /** * 获取所有的key * @returns 一个由key组成的数组 */ keys: () => Array<string>; } interface Storage { /** * 存值 * @param key 键,string类型 * @param value 对应的值,支持数组或者对象 */ setItem: (key: string, value: Value) => void; /** * 取值 * @param key 键,string类型 * @returns 有则返回,没有返回null */ getItem: (key: string) => Return; /** * 移除 * @param key 键,string类型 */ removeItem: (key: string) => void; /** * 是否存在 * @param key 键,string类型 * @returns true:存在 false:不存在 */ hasItem: (key: string) => boolean; /** * 清除所有值 */ clear: () => void; /** * 获取所有的key * @returns 一个由key组成的数组 */ keys: () => Array<string>; } interface Platform { is: { desktop: boolean; mobile: boolean; ios: boolean; android: boolean; }; } interface IDate { /** * 比较两个时间大小 * @param d1 要比较的时间字符串(例:2021/12/24、2021-12-24、2021-12-24 12:12:12),必传; * @param d2 要比较的时间字符串(格式同d1),非必传;不传则取当前时间 * @returns true:d1 >= d2 false:d1 < d2 */ compareDate: (d1: string, d2?: string) => boolean; /** * 获取两个时间的差值毫秒数 * @param d1 时间字符串(例:2021/12/24、2021-12-24、2021-12-24 12:12:12),必传; * @param d2 时间字符串(格式同d1),非必传;不传则取当前时间 * @returns d1减去d2的时间毫秒数差值 */ dateDifference: (d1: string, d2?: string) => number; /** * 获取当前时间格式化后的时间字符串 * @param separator 分隔符(例如:- /) * @returns 当前时间格式化时间(例如:2020-12-24 12:12:12、2020/12/24 12:12:12) */ formatDate: (separator: string) => string; } interface Validate { /** * 邮箱验证 */ isEmail: (str: string) => boolean; /** * 11位手机号验证 */ isTel: (str: string) => boolean; /** * 身份证验证 */ isId: (str: string) => boolean; /** * 验证 * @param str 要验证的字符串 * @param reg 正则表达式 * @returns 一个布尔值 */ verification: (str: string, reg: RegExp) => boolean; } export { Value, Return, ICookie, Storage, ForItem, Platform, IDate, Validate };