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

daima-standard-api

v1.0.6

Published

袋马网络通信协议-标准版

Readme

袋马网络通信协议-标准版

介绍

Node.js 袋马网络通信协议

软件架构

软件架构说明

安装教程

npm install daima-standard-api --save

使用说明

  1. Node中使用
// 自定义接口配置
import config from './config/index';
// 自定义Cache实例
import cache from './config/cache';
// 引入袋马网络通信包
import App from 'daima-standard-api/dist';

// 定义应用实例
const DM = App(config, cache);

// 定义全局通用Request方法
const request = function (url, options, callback) {
  // 回调方法
  callback = Object.assign({
    success: e => console.log('success', e),  // 成功
    fail: e => console.log('fail', e),        // 失败
    complete: e => console.log('complete', e) // 完成
  }, callback);
  // 请求选项
  options = Object.assign({
    method: 'GET', // 请求方式,支持GET、POST、PUT、HEAD、PATCH、DELETE
    body: {}, // 请求的 body 信息,支持Object、FormData、URLSearchParams
    beforeRequest: e => { // 请求前事件
      // console.log('beforeRequest', e);
      return e; // 强制返回e,否则引起fetch异常
    },
    afterRequest: e => { // 请求后事件
      // console.log('afterRequest', e);
      return e;// 强制返回e,否则引起后续的链式方法异常
    },
    exception: e => console.warn(e), // 异常处理
  }, options);
  return ( new ( DM.Request ) ).sendRaytheonRequest(url, options, callback);
};

try {
  request('/app.v1.user/login', {
    method: 'POST',
    body: {username: 'admin', password: 'admin'},
    headers: {"Content-Type": "application/x-www-form-urlencoded"}
  }, {
    success(e) {
      DM.Helper.token = e.data;
    }
  });
} catch ( e ) {
  console.log(e.name + ": " + e.message);
} finally {
  console.log('网络请求测试结束')
}                                                                                                           } );
  1. Html中使用
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>DaiMa-Standard-API</title>
    <link rel="shortcut icon" href="../public/favicon.ico" type="image/x-icon">
    <link type="text/css" rel="stylesheet" href="../public/style.css">
</head>
<body>
<div class="demo">
    <ul>
        <li>
            <button data-id="1"><span>POST</span><small>app.v1.user/login</small><label>登陆</label></button>
        </li>
        <li>
            <button data-id="2"><span>DELETE</span><small>app.v1.user/logout</small><label>退出</label></button>
        </li>
        <li>
            <button data-id="3"><span>HEAD</span><small>app.v1.demo/head</small></button>
        </li>
        <li>
            <button data-id="4"><span>GET</span><small>app.v1.demo/get</small></button>
        </li>
        <li>
            <button data-id="5"><span>POST</span><small>app.v1.demo/post</small></button>
        </li>
        <li>
            <button data-id="6"><span>PUT</span><small>app.v1.demo/put</small></button>
        </li>
        <li>
            <button data-id="7"><span>PATCH</span><small>app.v1.demo/patch</small></button>
        </li>
        <li>
            <button data-id="8"><span>DELETE</span><small>app.v1.demo/delete</small></button>
        </li>
        <li>
            <label>单文件上传
                <input data-id="9" type="file" data-url="app.v1.demo/fileUpload">
            </label>
        </li>
        <li>
            <label>多文件上传
                <input data-id="10" type="file" data-url="app.v1.demo/multiFileUpload" multiple="multiple">
            </label>
        </li>
    </ul>
</div>
<script type="text/javascript" src="../public/jquery.js"></script>
<script type="text/javascript">
  ( function (window, $) {
    $(function () {
      // 接口配置
      const config = window.DaimaStandardApi.__config;
      // 缓存类实例
      const cache = window.DaimaStandardApi.__cache;
      // 袋码SDK方法
      const DM = window.DaimaStandardApi.default(config, cache);
      // 定义全局通用Request方法
      const request = function (url, options, callback) {
        // 回调方法
        callback = Object.assign({
          success: e => console.log('success', e),  // 成功
          fail: e => console.log('fail', e),        // 失败
          complete: e => console.log('complete', e) // 完成
        }, callback);
        // 请求选项
        options = Object.assign({
          method: 'GET', // 请求方式,支持GET、POST、PUT、HEAD、PATCH、DELETE
          body: {}, // 请求的 body 信息,支持Object、FormData、URLSearchParams
          beforeRequest: e => { // 请求前事件
            console.log('beforeRequest', e);
            return e; // 强制返回e,否则引起fetch异常
          },
          afterRequest: e => { // 请求后事件
            console.log('afterRequest', e);
            return e;// 强制返回e,否则引起后续的链式方法异常
          },
          exception: e => console.warn(e), // 异常处理
        }, options);
        return ( new ( DM.Request ) ).sendRaytheonRequest(url, options, callback);
      };

      // Demo按钮点击事件
      $('button:button').click(function () {
        let data = {}, headers = {"Content-Type": "application/x-www-form-urlencoded"};
        const id = $(this).data('id'), method = $(this).find('span').text(), url = $(this).find('small').text(), callback = {};
        switch ( id ) {
          case 1: // 登录
            data = {username: 'admin', password: 'admin'};
            callback.success = e => DM.Helper.token = e.data;
            break;
          case 2: // 退出
            headers = {"Content-Type": "application/json"};
            break;
          case 3:
            data = {notice: 'HelloKitty'};
            break;
          case 4:
            break;
          case 5:
            headers = {"Content-Type": "application/json"};
            data = {name: '大黑'};
            break;
          case 6:
            headers = {"Content-Type": "application/json"};
            data = {};
            break;
          case 7:
            data = {};
            break;
          case 8:
            data = new URLSearchParams('?name=小黄&age=2');
            break;
        }
        request(url, {method: method, body: data, headers: headers}, callback);
      });

      // Demo文件上传事件
      $('input:file').change(function (e) {
          const id = $(this).data('id'), url = $(this).data('url'), data = new FormData(), method = 'POST',
            headers = {"Content-Type": "multipart/form-data"};
          switch ( id ) {
            case 9: // 单文件上传
              data.append('file', e.currentTarget.files[ 0 ]);
              break;
            case 10: // 多文件上传
              let i = 0;
              for ( let v of e.currentTarget.files ) {
                console.log(v);
                data.append('file_' + i, v);
                i ++;
              }
              data.append('name', '王小二');
              break;
          }
          request(url, {method: method, body: data, headers: headers});
        }
      );
    })
  } )(window, jQuery);
</script>
<--! 引入build目录下bundle.js文件 -->
<script type="text/javascript" src="./bundle.js?c5421d57f488d29ad184"></script>
<--! 引入自定义配置文件 -->
<script type="text/javascript" src="./config.js?c5421d57f488d29ad184"></script>
</body>
</html>

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

码云特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. 码云官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
  4. GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
  5. 码云官方提供的使用手册 https://gitee.com/help
  6. 码云封面人物是一档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/