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

@mm-custom/method

v2.0.6

Published

方法库

Downloads

84

Readme

@mm-custom/Method

Common Libraries Of MaoMao

Method

2.0.5

/**
 * @function 下载文件
 * @version 2.0.5
 * @author mm
 * @param {Blob | string} data 文件数据
 * @param {string} [name='default'] 文件名称
 * @return void
 */
export declare const downloadFile: (data: Blob | string, name?: string) => void;

/**
 * @function 捕获视频帧
 * @version 2.0.5
 * @author mm
 * @param {HTMLVideoElement} video 视频DOM节点
 * @param {CaptureOptions?} options 捕获参数
 * @return void
 */
export declare const captureVideoFrame: (video: HTMLVideoElement, options?: CaptureOptions) => string;

2.0.1

/**
 * EventManager 类是一个基于 Map 和 Set 实现简单的事件管理器,用于事件的监听、移除、触发和清空
 */
export declare class EventManager<T> {
    /**
     * 添加事件监听
     * @param name 事件名称
     * @param listener 监听执行回调
     * @return 当前 EventManager 实例,支持链式调用
     */
    on(name: string, listener: Listener<T>): this;
    
    /**
     * 移除事件监听
     * @param name 事件名称
     * @param listener 要移除的监听执行回调
     * @return 当前 EventManager 实例,支持链式调用
     */
    off(name: string, listener: Listener<T>): this;
    
    /**
     * 添加一次性事件监听
     * @param name 事件名称
     * @param listener 一次性监听执行回调
     * @return 当前 EventManager 实例,支持链式调用
     */
    once(name: string, listener: Listener<T>): this;
    
    /**
     * 事件触发
     * @param name 事件名称
     * @param data 传递数据
     * @return 当前 EventManager 实例,支持链式调用
     */
    emit(name: string, data: T): this;
    
    /**
     * 清空事件的所有监听
     * @param name 事件名称
     * @return 当前 EventManager 实例,支持链式调用
     */
    clear(name?: string): this;
}

2.0.0

/**
 * @function 获取浏览器版本
 * @version 2.0.0
 * @author mm
 * @return {name: string, version: string} { name, version }
 */
export declare const browserVersion: () => {
  name: string;
  version: string;
};

/**
 * @function 首字母大写
 * @version 2.0.0
 * @author mm
 * @param {string} str 需要转换的字符串
 * @return {string}
 */
export declare const firstLetterUpperCase: (str: string) => string;

/**
 * @function 获取文件名的后缀
 * @version 2.0.0
 * @author mm
 * @param {string} fileName 文件名
 * @return {string}
 */
export declare const fileSuffix: (fileName: string) => string;

/**
 * @function blob二进制转Base64
 * @version 2.0.0
 * @author mm
 * @param {Blob} blob 二进制数据
 * @return {Promise}
 */
export declare const blobToBase64: (blob: Blob) => Promise<any>;

/**
 * @function 根据起始时间获取持续时间
 * @version 2.0.0
 * @author mm
 * @param {string} time 起始时间
 * @param {string} [format='hh:mm'] 输出格式(DD hh:mm:ss)
 * @return {string}
 */
export declare const timeToDuration: (time: string, format?: string) => string;

1.0.7

/**
 * @function 使用requestIdleCallback运行
 * @version 1.0.7
 * @author mm
 * @return {}
 * @param {Function} task
 * @param {Function} callback
 */
export declare const useIdleCallback: (task: Function, callback: Function) => void;
/**
 * @function 使用requestAnimationFrame运行
 * @version 1.0.7
 * @author mm
 * @return {}
 * @param {Function} task
 * @param {Function} callback
 */
export declare const useAnimationFrame: (task: Function, callback: Function) => void;
/**
 * @function 运行大量任务
 * @version 1.0.7
 * @author mm
 * @return {}
 * @param {Function} task
 * @param {'requestIdleCallback' | 'requestAnimationFrame'} type
 */
export declare const runNumerousTasks: (task: Function, type?: 'requestIdleCallback' | 'requestAnimationFrame') => Promise<any>;

/**
 * @function 经纬度:十进制转换为度分秒
 * @version 1.0.7
 * @author mm
 * @param {number} data 十进制经纬度
 * @param {DegreeOption} option
 * @param {number} option.number=2 保留位数
 * @param {string | 'object'} option.format 返回格式:'D°M′S″ */
export declare const formatDegree: (data: number, option?: DegreeOption) => string | Degree;

/**
 * @function 经纬度数组:十进制转换为度分秒
 * @version 1.0.7
 * @author mm
 * @param {number[]} data 十进制经纬度
 * @param {DegreeOption} option
 * @param {number} option.number=2 保留位数
 * @param {string | 'object'} option.format 返回格式:'D°M′S″ */
export declare const formatDegreeArray: (data: [number, number], option?: DegreeOption) => [string | Degree, string | Degree];

/**
 * @function 经纬度:度分秒转换为十进制
 * @version 1.0.7
 * @author mm
 * @param {string} data 度分秒经纬度
 * @param {number} number=2 保留数字
 * */
export declare const formatDecimal: (data: string, number?: number) => number;

1.0.0

/**
 * @function 根据数据返回相应的类型
 * @version 1.0.0
 * @author mm
 * @param {any} data 需要判断的数据
 * @param {boolean?} upper 是否大写
 * @returns {string}
 */
export declare const returnType: (data: any, upper?: boolean) => string;

/**
 * @function 判断数据类型是否正确
 * @version 1.0.0
 * @author mm
 * @param {any} data 需要判断的数据
 * @param {TypeName} type 预判的数据类型
 * @returns {boolean}
 */
export declare const judgeType: (data: any, type: TypeName) => boolean;

/**
 * @function 转换数据
 * @version 1.0.0
 * @author mm
 * @param {any} data 需要判断的数据
 * @returns {BaseType}
 */
export declare const transformValue: (data: any) => BaseType | null;

/**
 * @function 设置 SessionStorage
 * @version 1.0.0
 * @author mm
 * @param {object|array|string} param 设置的参数名|参数
 * @param {BaseType} val 设置的参数值
 */
export declare const setSession: (param: string | object | ObjectType[], val: BaseType) => void;

/**
 * @function 获取 SessionStorage
 * @version 3.0.2
 * @author mm
 * @param {string} name 获取的参数名
 * @return {BaseType}
 */
export declare const getSession: (name: string) => BaseType | null;

/**
 * @function 移除 SessionStorage
 * @version 1.0.0
 * @author mm
 * @param {string|string[]} name <all> 移除的参数名
 */
export declare const removeSession: (name: string | string[]) => void;

/**
 * @function 防抖函数
 * @version 1.0.0
 * @author mm
 * @param {callback} fn 需要防抖的函数
 * @param {number} [delay=40] 防抖延迟时间
 * @param {boolean} [immediate=false] 是否立即执行
 * @return {function}
 */
export declare const debounce: (fn: Function, delay?: number, immediate?: boolean) => Function;

/**
 * @function 节流函数
 * @version 1.0.0
 * @author mm
 * @param {callback} fn 需要节流的函数
 * @param {number} [wait=40] 节流等待时间
 * @param {boolean?} [immediate=false] 是否立即执行
 * @return {function}
 */
export declare const throttle: (fn: Function, wait?: number, immediate?: boolean) => Function;

/**
 * @function 下划线转驼峰
 * @version 1.0.0
 * @author mm
 * @param {string} str 目标字符串
 * @return {string}
 */
export declare const lineToHump: (str: string) => string;

/**
 * @function 驼峰转下划线
 * @version 1.0.0
 * @author mm
 * @param {string} str 目标字符串
 * @return {string}
 */
export declare const humpToLine: (str: string) => string;

/**
 * @function 点转驼峰
 * @version 1.0.0
 * @author mm
 * @param {string} str 目标字符串
 * @return {string}
 */
export declare const pointToHump: (str: string) => string;

/**
 * @function 驼峰转点
 * @version 1.0.0
 * @author mm
 * @param {string} str 目标字符串
 * @return {string}
 */
export declare const humpToPoint: (str: string) => string;

/**
 * @function 字符串切割
 * @version 1.0.0
 * @author mm
 * @param {string} str 字符串
 * @param {string} [mark=" "] 切割符号,默认为空格字符串
 * @param {number?} returnIndex 返回切割的数组下标,默认返回切割的数组
 * @return {string|string[]}
 */
export declare const stringSplit: (str: string, mark?: string, returnIndex?: number) => string | string[];

/**
 * @function 根据格式字符串生产想要的字符串
 * @version 1.0.0
 * @author mm
 * @param {string} format 输出格式 (YYYY-MM-DD hh:mm:ss)
 * @param {Record<string, string>} params 参数对象,需要包含输出格式中规定的参数
 * @return {string}
 */
export declare const formatToString: (format: string, params: Record<string, string>) => string;

/**
 * @function 深拷贝
 * @version 1.0.0
 * @author mm
 * @param {object|array} target 目标对象
 * @return {object|array}
 */
export declare const deepClone: (target: Record<string, any> | any[]) => Record<string, any> | any[] | BaseType;

/**
 * @function 深替换
 * @version 1.0.0
 * @author mm
 * @param {object|array} target 目标对象
 * @param {object|array} replace 替换对象
 * @return {object|array}
 */
export declare const deepReplace: (target: Record<string, any> | any[], replace: Record<string, any> | any[]) => Record<string, any> | any[];

/**
 * @function 随机生成整数
 * @version 1.0.0
 * @author mm
 * @param {number} min 最小值
 * @param {number} max 最大值
 * @param {number} [number=1] 需要产生的个数,必须为正整数
 * @return {number|number[]}
 */
export declare const randomNumber: (min: number, max: number, number?: number) => number | number[];

/**
 * @function 保留小数,默认两位
 * @version 1.0.0
 * @author mm
 * @param {number} decimal 小数
 * @param {number} number=2 保留位数
 * @return {number}
 */
export declare const keepDecimal: (decimal: number, number?: number) => number;

/**
 * @function 时间戳或者中国标准时间格式化
 * @version 1.0.0
 * @author mm
 * @param {(number|Date)?} timestamp 时间戳或者中国标准时间
 * @param {string} [format='YYYY-MM-DD'] 输出格式 (YYYY-MM-DD hh:mm:ss)
 * @return {string}
 */
export declare const timestampFormat: (timestamp?: number | Date, format?: string) => string;

/**
 * @function 毫秒格式化
 * @version 1.0.0
 * @author mm
 * @param {number} time 毫秒数
 * @param {string} [format='hh:mm'] 输出格式(DD hh:mm:ss)
 * @return {string}
 */
export declare const millisecondFormat: (time: number, format?: string) => string;

interface DMSFormat {
  type: 'DMS';
  decimal: number | string;
  number: number;
  format: 'object' | string;
}
interface DECFormat {
  type: 'DEC';
  degree: number | string;
  minute: number | string;
  second: number | string;
  number: number;
}
/**
 * @function 经纬度十进制及度分秒转换
 * @version 1.0.0
 * @author mm
 * @param {DMSFormat | DECFormat} params 参数
 */
export declare const lonLatConversion: (params: DMSFormat | DECFormat) => string | number | {
  degree: number;
  minute: number;
  second: number;
};

/** @module Other */
/**
 * @function 根据当前分辨率计算大小
 * @version 1.0.0
 * @author mm
 * @param {number} size 想要计算的大小
 * @param {number} [base=1920] 计算的基础数值
 * @return {number}
 */
export declare const remToPx: (size: number, base?: number) => number;

/**
 * @function 字节大小转换
 * @version 1.0.0
 * @author mm
 * @param {number} [bytes=0] 字节
 * @return {string}
 */
export declare const bytesToSize: (bytes?: number) => string;

/**
 * @function 判断是否为JSON格式
 * @version 1.0.0
 * @author mm
 * @param {any} val 需要判断的值
 * @return {boolean}
 */
export declare const isJSON: (val: any) => boolean;