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

@iitrend/mock-server

v1.6.5

Published

IITrend Mock Server.

Downloads

6

Readme

mock-server

接口模拟数据-服务器

使用/启动方法

const MockServer = require('@iitrend/mock-server')
// 建议在业务代码编译完成之前启动
new MockServer({
    mockPort: 8810
})

核心 API

new MockServer(config)

启动一个 Server 监听接受请求,并交由 @iitrend/mock-server/core 处理并生成模拟数据。

参数

config

// 以下为默认参数
{
    // 自动启动服务
    autoStart: true,

    // server
    mockHost: 'localhost',
    mockPort: 8810,

    // 配置非json文件指向(匹配中的使用使用js加载方式)
    mockData: {
        'static/static-config': true
    },
    // 默认为项目根目录下的 => 'mock/src/’
    mockDataPath: path.join(process.cwd(), 'mock/src/'),

    // 接口请求延迟(取区间随机值)
    mockDelays: [0, 300],

    // express app headers
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': '*',
        'Access-Control-Allow-Methods': '*',
        'Content-Type': 'application/json;charset=utf-8'
    }

    // Mock.Random.extend
    // mockExtends: {},

    // http://localhost:8810/WHActs/Api/index.php/Client/Home/showIndex => 'Client/Home/showIndex'
    // parseMockFile: (url = '') => url.replace(/\?\S*/ig, '').split('/').slice(-3).join('/')
}

目录结构

mock/src/**/*.json

# 例如请求接口:Client/Home/showIndex
文件及目录:mock/src/Client/Home/showIndex.json
{
    "user": "@first()",
    "nickname": "@cname()",
    "realname": "@cname()",
    "firm_name": "广州@ctitle(2,5)有限公司",
    "dept_name": "@ctitle(2,5)部",
    "sex|1-2": 1,
    "birthday": "@timestamp()",
    "intro": "@ctitle(5,10)",
    "area": "@province()",
    "target_step_list": [2000, 4000, 6000, 8000, 10000, 12000],
    "target_step_n|+1": [2000, 4000, 6000, 8000, 10000, 12000],
    "step_n|10000-20000": 10000,
    "step_today|10000-20000": 10000,
    "cal_n|10000-20000": 10000,
    "cal_today|1000-2000": 10000,
    "icon": "@imageFix(50x50)",
    "firm_icon": "@imageFix(200x100)",
    "phone": "@phone()",
    "addr": {
        "id|+1": 1,
        "name": "@cname()",
        "addr": "@province()@city()@county()@ctitle(1,3)街@integer(1,2000)号",
        "phone": "@phone()"
    },
    "weight|50000-100000": 70000,
    "height|100-240": 1
}