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 🙏

© 2025 – Pkg Stats / Ryan Hefner

yuki-mock

v1.0.8

Published

基于 node-express-mock 封装

Readme

yuki-mock

You can install professor level

install

$ npm install yuki-mock -D

OR

$ yarn add yuki-mock -D

running

// package.json

"scripts": {
    "mock:dev": "yuki-mock dev",
    "mock:start": "yuki-mock start"
} 

// cmd

npx yuki-mock start | npx yuki-mock dev

// 可在根目录添加 mock.config.js 修改端口号及协议等 默认8888 // mock.config.js

module.exports = {
    local: {
        open: true,
        port: 8888
    },
    // http:{
    //     open:false,
    //     port:80
    // },
    // https:{
    //     open:false,
    //     port:443
    // }
}

随机函数方法

handleRandom:

  • 生成随机数
  • @param {number} n
  • @returns number

randomArrayText:

  • @param {array} textArr 字符串数据模板
  • @param {number} nums 次数
  • @returns array

splitText:

  • @param {string} text 文本
  • @param {*} separator 分隔符

uuid:

  • 随机uuid
  • @returns string

randomText:

  • @param {array} textArr 字符串数据模板
  • @returns string

randomNumber:

  • @param {number} maxNumber 随机最大的数值
  • @returns number

randomEnum:

  • @param {array} enums 枚举模板数组
  • @returns number

randomBoolean:

  • 随机布尔值

randomObject:

  • @param {array} textArr 字符串模板数组
  • @param {object} payload 生成的对象类型
  • @param {function} createRandomData 创建随机数据方法
  • @returns string | number | array

createRandomData:

  • @param {array} textArr 字符串模板数组
  • @param {object} objType 生成的对象类型
  • @param {number} nums 生成多少个
  • @returns array
    module.exports = {
        handleRandom, // 生成随机数
        randomArrayText, // 生成随机字符串数组
        splitText, // 根据不同分隔符分割文本成数组
        uuid, //随机uuid
        randomText, // 随机字符串
        randomNumber, // 随机数字
        randomEnum, // 随机枚举值
        randomBoolean, // 随机布尔值
        randomObject, // 随机对象
        createRandomData // 生成随机数据方法
    }

Example:

在自己项目根目录创建mock(该名称必须为mock)文件夹,再创建文件夹,该文件夹名称为路由接口,比如v2(任意) , 再创建接口文件,比如test.js(名称随意, 除common, 该文件可做统一拦截)
// mock/v2/test.js   postman访问 http://localhost:8888/v2/test

const express = require("express")
const router = express.Router()
const {createRandomData, randomObject} = require('yuki-mock')
router.get("/", (req, res, next) => {
    const textArr = ['只要你爱', '我愿', '我就全给', '给你百合花般的唇', '给你常青藤般的臂']
    const data = createRandomData(textArr, {
        id: {
            type: 'uuid'
        },
        name: {
            type: 'string',
            template: textArr
        },
        number: {
            type: 'number',
            count: 10
        },
        status: {
            type: 'enum',
            template: [10, 20, 30, 40]
        },
        bl: {
            type: 'boolean'
        },
        tag: {
            type: 'array',
            template: textArr,
            count: 3
        },
        obj: {
            type: 'object',
            template: textArr,
            payload: {
                id: {
                    type: 'uuid'
                },
                number: {
                    type: 'number',
                    count: 10
                }
            }
        },
        data: {
            type: 'randomData',
            template: textArr,
            payload: {
                id: {
                    type: 'uuid'
                },
                name: {
                    type: 'string',
                    template: textArr
                },
                number: {
                    type: 'number',
                    count: 10
                }
            },
            count: 10
        }
    }, 100)
    res.send({err: 0, msg: "tools", array: data, object: randomObject(textArr, {
        id: {
            type: 'uuid'
        },
        name: {
            type: 'string',
            template: textArr
        },
        number: {
            type: 'number',
            count: 10
        }
    })})
})

module.exports = router