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

egg-qingshu

v0.0.9

Published

青数自用模块

Downloads

2

Readme

Egg-qingshu 插件

启用插件

config/plugin.js 文件中声明启用插件:

exports.qingshu = {
  /** 是否启用插件,true 为启用,false 为禁用 */
  enable: true,

  /** 指定插件使用的包,请填写 'egg-load' */
  package: 'egg-qingshu',
};

配置方式

config/config.${env}.js文件配置插件:

自动挂载第三方模块至 Egg.js 框架上

forked from inlym/egg-load

config.qingshu = {
  /** 需要挂载的模块列表 */
  module: [
    /** 列表项支持对象(object)和字符串(string)两种形式 */
    {
      /** 需要挂载的 npm 包的包名,例如 axios,必填 */
      package: 'pkg1-name',

      /** 挂载的属性名,例如填 abc,该模块可以通过 app.abc 进行访问,默认为包名,选填 */
      name: 'abc',

      /** 是否禁用,默认为否,选填 */
      disabled: false,
    },

  /** 使用字符串形式只需要输入包名即可,其他属性按照默认属性自动设置 */
    'pkg2-name',
  ],

  /** 是否挂载到 app 上,默认开启 */
  app: true,

  /** 是否挂载到 agent 上,默认关闭 */
  agent: false,
}

示例

我们模拟以下这个使用场景,来演示如何配置和使用本插件:

发现 axios 和 only 两个模块的使用率非常高,于是准备将这两个模块挂载到框架上。

config/plugin.js 文件中声明启用插件:

exports.qingshu = {
  enable: true,
  package: 'egg-qingshu',
};

config/config.${env}.js文件配置插件(示例是一个典型的配置方式):

config.qingshu = {
  module: [
    {
      package: 'axios',
      name: 'req',
    },
    'only',
  ],
}

通过上述示例方式配置后,可以通过 app.res 访问 axios 模块,以及通过 app.only 访问 only 模块。

123pan 模块使用方法

首先config.default.js中配置

config.qingshu = {
    app: true,
    agent: false,
    pan123: {
        privateKey: 'privateKey',
        uid: 123,
        validDuration: 15 * 60 * 1000,
    },
};

使用

/**
     * 使用 pan123 对 URL 进行处理
     *
     * @param url 待处理的 URL
     * @param options 可选参数,用于配置 pan123 调用
     * - options.privateKey pan123 的私钥
     * - options.uid pan123 的用户 ID
     * - options.validDuration 链接的有效时长(秒)
     * - demo pan123('http://url/690211379', {
            privateKey: 'privateKey',
            uid: 123,
            validDuration: 15 * 60 * 1000,
        })
     * @returns 处理后的 URL
     * @throws 当 URL 为空时,抛出异常 'URL is required'
     * @throws 当配置参数无效时,抛出异常 'Invalid options provided. Ensure privateKey, uid, and validDuration are specified correctly.'
     */
    - 完整写法
const pan = await ctx.helper.pan123('http://url/690211379', {
            privateKey: 'privateKey',
            uid: 123,
            validDuration: 15 * 60 * 1000,
        });
        console.log(pan);

    - 简单写法
    const pan = await ctx.helper.pan123('http://url/690211379');
        console.log(pan);

统一错误处理

/**
     * 处理失败响应
     *
     * @param options 选项对象,默认为空对象
     * - options.infocode 自定义code
     * - options.message 自定义消息
     * @param errorCode HTTP状态码,默认为409
     * @param code 自定义状态码,默认为1
     * @returns 无返回值
     */
  - 完整写法
    ctx.helper.fail({infocode = 1, message = 'fail'},200,1);
  - 简单写法
    ctx.helper.fail('自定义错误信息')

统一成功处理

/**
     * 成功响应处理函数
     *
     * @param data 响应数据,默认为null
     * @param msg 响应消息对象,默认为空对象
     * - msg.infocode 自定义code
     * - msg.message 自定义消息
     * @param options 额外响应选项,默认为空对象
     * @param code 响应状态码,默认为0
     * @returns 无返回值,直接设置响应状态码和响应体
     */
    ctx.helper.success(data,{ infocode = 0, message = 'success' })
    - 完整写法
    ctx.helper.success(result, {
        infocode: 20002,
        message: '登陆成功!',
    },{
        token:token,
        time:new time()
    },0);
    - 简单写法
    ctx.helper.success(result)
    ctx.helper.success(data,'成功')