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 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-ecarx-interface

v1.0.9

Published

[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][down

Readme

egg-ecarx-interface

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-ecarx-interface --save

Usage

// {app_root}/config/plugin.js
exports.interface = {
  enable: true,
  package: 'egg-ecarx-interface',
};

// {app_root}/app.js
module.exports = app => {
  app.status = app.config.interface
};

Configuration

// {app_root}/config/config.default.js
// 如果觉得对象太大,自行 exports.interface = require('path/to/interface.js|json')
exports.interface = {
  locale: true, //是否 对message进行国际化处理
  success: true, //是否 输出success字段
  codeField: 'code', //配置错误码的字段名
  messageField: 'message', // 配合错误内容的字段名
  defaultSuccess: 'success', 默认成功的status
  defaultFail: 'fail', //默认失败的status
  status: {
    success: {
      success: true,
      code: 200,
      message: 'success',
    },

    fail: {
      success: false,
      code: 400,
      message: 'fail',
    },

    not_found: {
      success: false,
      code: 404,
      message: '%s not found',
    },

    invalid_param: {
      success: false,
      code: 422,
      message: 'params error %s',
    },

    server_error: {
      success: false,
      code: 500,
      message: 'server error %s',
    }
  }
};

Use

@method ctx.success(data, message)
@args
    - data  返回值里里的data
    - message 成功输出语句, 默认'success'

@example
    ctx.success()
    ctx.success({msg: '成功内容对象'})
    ctx.success({msg: '成功内容对象'}, '成功提示语句')
{
  "success": true,
  "code": 200,
  "message": "成功语句",
  "data": {
    "msg": "成功内容对象"
  }
}

@method ctx.fail(status, data, ...message)
@args
    - status 错误对象,默认 app.status.fail
    - data  返回值里里的data, 如果data是string, 会被当做是message, 请分装成 obj/array
    - ...message 错误输出语句, 和 status的message进行合并处理,合并规则如下
     如果 status 的 message 是非字符串模板,则会进行替换message,如 ctx.fail(app.status.fail, '操作错误') => 'fail' + "操作错误' => '操作错误'
     如果 status 的 message 是字符串模板,则会进行模板拼接,如 ctx.fail(app.status.not_found, '某数据') => '%s not found' + "某数据' => '某数据 not found'

@example
    ctx.fail(app.status.fail, '错误message')
    ctx.fail(app.status.fail, {msg: '错误内容对象'})
    ctx.fail(app.status.fail, {msg: '错误内容对象'}, '错误message')
    //如果是不是字符串模板
        app.status.notmuban = {code:1001, message: 'muban muban'}
        ctx.fail(app.status.notmuban, '错误message') => "错误message"
    //如果是字符串模板
        app.status.muban = {code:1001, message: 'muban %s muban'}
        ctx.fail(app.status.muban, '错误message') => "muban 错误message muban"
    //如果 locale=true 需要国际化
        app.status.muban = {code:1001, message: 'muban %s muban'}
        国际化配置 zh-CN.js 里 'muban %s muban': '模板 %s 模板'
        ctx.fail(app.status.muban, '错误message') => "模板 错误message 模板"

国际化

如果 locale: true 开启了国际化,用户的 message 和 status里的 message 都会先 国际化后,再进行拼接,比如上面的例子
   //如果目标语言是 zh-CN
   //zh-CN.js
   module.exports = {
     'fail': '失败',
     '%s not found': '%s不存在'
   };

   ctx.fail(app.status.not_found, '某数据') => '%s not found' + "某数据' => 国际化 => '%s不存在' + "某数据' =>'某数据不存在'