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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zjlab-fe/util

v0.1.0

Published

支持多个文件同时下载

Downloads

113

Readme

API

下载文件

支持多个文件同时下载

/**
 * 下载文件
 * @param url {string} 文件url
 * @param openWindow {bool} 可选,是否是新开标签页下载
 * @param message {object} 可选,如果传入,需要传入antd或者antdv的message
 */
function downloadFile(url: string, openWindow?: boolean, message?: any): void;

提取文件类型

/**
 * 提取文件类型
 * @param filePath {string} 文件路径 or 文件url
 * @returns ext {string} 文件类型
 */
function getFileExt(filePath: string): string;

对object或者array进行trim操作

/**
 * 深度遍历,对于类型是字符串的value进行trim操作
 * @param obj 原始的数据
 * @returns newObj trim操作后的数据
 */
function trimObj<T>(obj: T): T;

iframe通信相关

通信类

/**
 * iframe通信类
 */
class IfmChannel {
    onMessageCallback: Record<string, any>;
    /**
     * 向iframe发送消息
     * @param ifmDom
     * @param type
     * @param data
     * @param callback
     */
    postMessageToIfm(ifmDom: HTMLIFrameElement, type: string, data?: any, callback?: (data: any) => void): void;
    /**
     * 向父窗口发送消息
     * @param type {string} 消息类型
     * @param data {any} 可选,发送的数据
     * @param callback {function} 可选,如果传入,表示等待消息回应,等同于onMessage(type, callback, true)
     */
    postMessage(type: string, data?: any, callback?: (data: any) => void): void;
    /**
     * 监听来自父窗口的消息 or 父窗口监听来自iframe的消息
     * @param type {string} 消息类型
     * @param callback {function} 消息处理函数
     * @param isOnce {boolean} 可选,表示消息处理函数是否是一次性的
     */
    onMessage(type: string, callback: (data: any) => void, isOnce?: boolean): void;
    /**
     * 销毁事件监听
     */
    destroy(): void;
}

// 使用
const ifmChannel = new IfmChannel();
// 给父窗口发送消息
ifmChannel.postMessage('messageType', {
  name: 'xxx',
  projectId: 'xxx'
});
// 监听来自父窗口的消息
ifmChannel.onMessage('messageType', (data: any) => {
  // ...
});

iframe嵌入,主应用相关api

/**
 * 主应用初始化,监听路由
 */
function mainAppInit(): void;

/**
 * 获取iframe的最终url
 * @param initUrl {string} iframe初始url
 * @returns
 */
function getIframeUrl(initUrl: string): string;

iframe嵌入,子应用相关api

interface SubAppInitData {
    token: string | undefined;
    userInfo: IUserInfo | null;
}


/**
 * 子应用初始化配置对象类型
 */
interface ISubAppInitConfig {
    /** 账号信息数据会存放在window[namespace]下,默认值是_subApp,默认会将账号信息数据同步到window._subApp下 */
    namespace: string;
}
/**
 * 子应用初始化
 * @param callback (data: SubAppInitData) => void) 可选,回调函数中会传回来自父窗口的账号信息
 * @param config {ISubAppInitConfig} 可选
 *
 */
function subAppInit(callback?: (data: SubAppInitData) => void, config?: ISubAppInitConfig): void;

interface IConfig {
    /** 账号关联的token存放在了window[authTokenNamespace]下,authTokenNamespace的默认值是_subApp,同subAppInit中的namespace */
    authTokenNamespace: string;
}
/**
 * 获取经过配置的axios实例
 * @param instanceConfig {IConfig} 实例化配置
 * @returns axios实例
 */
function getAxiosInstanceWithAuth(instanceConfig?: IConfig): import("axios").AxiosInstance;

账号信息类型定义

interface IUserInfo {
    /** 用户id */
    userId: string;
    /** 用户名 */
    userName: string;
    /** 邮箱 */
    email: string;
    /** 昵称 */
    nickName: string;
    /** 头像 */
    avatar: string;
    /** 所在组织名 */
    orgName: string;
    /** 所在组织code */
    orgCode: string;
    /** 所在组织id */
    orgId: string;
    /** 账号状态 */
    status: number;
    /** 用于组织内部的用户名称 */
    realName?: string;
    /** 根组织id,只有当前登录用户的用户信息才包含 */
    rootOrgId?: string;
}