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

an-adaptor

v1.0.4

Published

some adaptors can use for node middle layer

Readme

an-adaptor

Example

const Adaptor = require('an-adaptor');

const adaptor = new Adaptor({
  adaptorName: 'http',
  http: {
    url: 'https://api-m.mtime.cn/PageSubArea/HotPlayMovies.api'
  },
  apis: {
    GET_USERS: {
      adaptorName: 'http'
    }
  },
  validators: {
    GET_USERS: {
      reqData: {
        locationId: 'number'
      }
    }
  }
});

adaptor.dispatch(name, {
  params: {
    locationId: 365
  },
  valiReq: true
});

Usage

new Adaptor(options): options

apis <object>
  执行 dispatch 时使用的方法。
validatiors <object>
  验证请求和返回数据的参数。
adaptor <objcet>
  一些 adaptor 及其调用的名字
[adaptorName] <string>
  请求将会使用的 adaptor
[http] <object>
  参数同 api 中的 http
[mock] <object>
  参数同 api 中的 mock
[local] <object>
  参数同 api 中的 local
[redis] <object>
  参数同 api 中的 redis
[database] <object>
  参数同 api 中的 database
[schemas] <object>
  数据库需要的数据模型
[middlewares] <Array | Object>
  增加中间件,参数与 api 中的 middlewares 一致。

apis: api

middlewares

中间件

[enable] <boolean>
  是否会被执行,默认不执行
adaptor <string|array>
  在哪些 adaptor 中有效
priority <number>
  优先级
module <function(ctx, next)>
  中间件执行函数
adaptorName

请求方式

http

http 请求参数

http 参数数据格式参考: https://www.npmjs.com/package/axios#request-config
mock

mock 请求参数

total <number>
  当要 mock 一个数组时需传入请求数量。
data
  mock 数据格式。当需要一个数组时,在最外层加上[]。
  https://github.com/nuysoft/Mock/wiki/Syntax-Specification
local

local 本地请求参数

publicPath <string>
  本地数据的公共路径。建议传入一个绝对地址。
filePath <string>
  本地数据的文件路径。
func <function(resolve, reject)>
  本地数据请求函数。如果设置了这个参数,则忽略文件请求。
redis

redis 数据库请求参数

method <string>
  请求方法
dataType <string>
  redis 中的数据类型:'string' | 'list' | 'set' | 'hash' | 'sortSet'
host <string>
  redis 数据库主机名
port <number>
  redis 数据库端口名
params: key <string>
          要查询或添加的数据的 key
        [value]<object|string|number>
          要修改或添加的数据的 value
        [range] <array>
          查询 list/sortSet 数据时要给出的查询范围
        [index] <number>
          删除 list 数据时要给出的数据所在的位置
        params 参数也可在 dispatch 时传入。
database

数据库请求参数

method <string>
  请求方法
uri <string>
  数据库 uri
schemaName <string>
  schemas 中需要的 schema 名
collection <string>
  集合名
[options] <object>
  mongoose.connect 时候传入的参数
  http://mongoosejs.com/docs/connections.html#options
params:  data <object>
           查询方式/添加的数据
         [skip] <number>
           跳过多少数据查询
         [limit] <number>
           只查询多少数据
         [sort] <object>
           数据排序方式
         [update] <objcet>
           数据更新方式
         params 参数也可在 dispatch 时传入。
         (以上都是 mongoose 中的标准格式)

validators: validator

reqData

验证请求数据格式。 与 Mock.valid 格式一致。

resData

验证响应数据格式 与 Mock.valid 格式一致。

API

use

增加中间件。

app.use(middleware);
middleware <object|array>: [enable] <boolean>
                             是否会被执行,默认不执行
                           adaptor <string|array>
                             在哪些 adaptor 中有效
                           priority <number>
                             优先级
                           module <function(ctx, next)>
                             中间件执行函数

dispacth

向目标 adaptor 发起请求。

app.dispatch(name, options);
name <string>
  执行 api 的名字
[options]: [params] <object>
             请求的数据参数,也是要验证的数据参数。默认没有参数。
           [valiReq] <boolean|number>
             是否验证请求数据|给验证请求数据的中间件设置优先级。默认 false。
           [valiRes] <boolean|number>
             是否验证响应数据|给验证响应数据的中间件设置优先级。默认 false。

返回一个 Promise 对象:

adaptor.dispatch(name, options).then(ctx => {
    // ctx 中有 res、originalResponse、validator、api、http、mock、local、redis、database、params、schemas
}).catch(err => {
  // 一些处理错误的代码
});

推荐在 dispatch 中传递 params,便于参数共享。

作为 express 中间件

var Promise = require('bluebird');
var Adaptor = require('an-adaptor');
var express = require('express');
var app = Promise.promisifyAll(express());

app.use(Adaptor.express({
  adaptorName: 'http',
  http: {
    url: 'https://api-m.mtime.cn/PageSubArea/HotPlayMovies.api'
  },
  apis: {
    GET_DATA: {}
  }
}));

app.get('/', (req, res) => {
  req.dispatch('GET_DATA').then(ctx => {
    res.send(ctx.res);
  });
});

app.listenAsync(8000).then(() => {
  console.log('listen 8000');
}).catch(err => {
  console.log(err);
});

Adaptor.express 中传入与 Adaptor 相同的参数,req.dispatch 参数与 adaptor.dispatch 一致。