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

generator-mock-koa

v1.1.2

Published

使用koa结合mock,主要提供给前端开发人员的模拟数据测试,必要的时候,也可以用于代理转发

Downloads

2

Readme

generator-mock-koa

使用koa结合mock,主要提供给前端开发人员的模拟数据测试,必要的时候,也可以用于代理转发、和基于Koa开发新的系统

Installation

First, install Yeoman and generator-mock-koa using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-mock-koa

Then generate your new project:

yo mock-koa

1.1.2

实现了基础的功能,能够基于简单配置实现数据的mock 升级特性:构建完成后,会自动安装相关依赖,使用者只需要到根目录下执行 npm run mock-serve 就能开启mock服务了

Use

项目构建完成后,打开src/api,在这个页面下编写mock的接口,在该目录下的文件会自动处理,要求符合格式

案列:使用模板解析语法开发

import Mock from 'mockjs';

const data = Mock.mock({
  total: 100,
  'rows|10': [{
    id: '@guid',
    name: '@cname',
    'age|20-30': 23,
    'job|1': ['前端工程师', '后端工程师', 'UI工程师', '需求工程师']
  }]
});

export default {
  prefix: "/pattern",
  methods: {
    "GET /a": data,
    "GET /list": () => {
      return {
        code: 200,
        message: "success",
        data
      }
    },
    // 这里的 ctx ==> router.get(ctx);
    "/list2": (ctx) => {
      return {
        code: 200,
        message: "success",
        data: ctx.request.query
      }
    },
    "POST /form": () => {
      return {
        code: 200,
        message: "success",
        data: Mock.mock({ id: '@guid' })
      }
    }
  }
};

案列,使用原生Koa的开发模式

import Router from 'koa-router';
import Mock from 'mockjs';

/**
 * 案列,使用原生Koa的开发模式
 */

const router = new Router({
  prefix: '/user',
});

/**
 * 获取菜单列表
 */
router.get('/list', (ctx) => {
  const data = Mock.mock({
    total: 100,
    'rows|10': [{
      id: '@guid',
      name: '@cname',
      'age|20-30': 23,
      'job|1': ['前端工程师', '后端工程师', 'UI工程师', '需求工程师']
    }]
  });
  return {
    code: 200,
    message: "success",
    data
  }
});

export default router;

Getting To Know Yeoman

  • Yeoman has a heart of gold.
  • Yeoman is a person with feelings and opinions, but is very easy to work with.
  • Yeoman can be too opinionated at times but is easily convinced not to be.
  • Feel free to learn more about Yeoman.

License

MIT © mmyhs