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

mocking-service

v1.0.1

Published

mock data service

Downloads

7

Readme

express-mock

mock API data for express

Setup


npm install express-mocking
var mocking = require('express-mocking')({
    mockConfig: {
      '/mockArray': {
        'data': [{
                  id: 'string',
                  name: 'string',
                  content: 'string',
                  obj: {
                    id: 'string',
                  },
              }],
        'recordSize': 'data.size=10', // 说明是data数组,size=10,该字段不生成mock数据
        'errCode': 0,
        'errMsg': "成功",
      },
      '/mockObject': {
        'data': {
          id: 'string',
          name: 'string', 
          content: 'string',
        },
        'testVar': 'int',
        'errCode': 0,
        'errMsg': "成功",
      },
      '/mockStringArray': {
        'data': ['string'],
        'totalCount': '30',
        'recordSize': 'data.size=11', // 说明是data数组,size=11,该字段不生成mock数据
        'errCode': 0,
        'errMsg': "成功",
      },
      '/mockIntArray': {
        'data': ['int'],
        'totalCount': '30',
        'recordSize': 'data.size=16', // 说明是data数组,size=16,该字段不生成mock数据
        'errCode': 0,
        'errMsg': "成功",
      },
    }
});

app.use(mocking);

options

mockConfig

e.g.
mockConfig: {
  '/mockArray': {
    'data': [{
      id: 'id',
      name: 'string',
      content: 'string',
      date: 'date-time',
      timestamp: 'timestamp',
      obj: {
        id: 'id',
      },
    }],
    'recordSize': 'data.size=10', // 说明是data数组,size=10,该字段不生成mock数据
    'errCode': 0,
    'errMsg': "成功",
  },
}
生成数据:

'/mockArray':

{
  data: [{
    id: "ed8b4cc47ebc44b88604bd88ed8b00d9",
    name: "理睛活阳界等改面紧且却过小怕轻实信望五东等并党了师睛治起以多后八上海们赶意各怕变病准您也的科指识从建识家够清两上此更上最队千呢出将面睡像1七用产认书每当而很",
    content: "直爬色眼么过轻有识见女您情生雪的有认样命青亲师黑义话究赶往底叫群往响进等条爬工天拿北光又现者不士刻难阳别治情点3子孩些无多年里唱色跟步立场送经样实6关名",
    timestamp: 1557661601135,
    date: "2019-05-12 19:46",
    obj: {
      id: "b070ec5e63e44a66a67242cbd6495ddf"
    }
  }, {
    id: "fd8c9bfb1acf435a924a194427cdc589",
    name: "年声不块夜拿多应路习来常水什往本化决问小使很究",
    content: "花死放气听看马许过打色确便群了整内志阵全新拉科分变得件快父气但必父但里近业是坐给爷让师年今而全石很那究自觉未土倒哪思四流年些意想成于中够底确转接向兴下解争间有服连",
    timestamp: 1557661610135,
    date: "2019-05-01 13:46",
    obj: {
      id: "a1879399a3ba481fa24f78f97ff0f4b5"
    }
  }],
  errCode: 0,
  errMsg: "成功"
}
注意

data为对象数组或者普通数组的时候,需要指定数组长度,指定方式为定义一个同级的key,该value以data.size=开头,其中data便是命名一致即可。 若需要字符串数组,如下即可:

  key: ['string'], //int型数组即['int']
  size: 'key.size=10'
}