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

vite-plugin-free-mock

v0.1.9

Published

<br> <p align='center'> <a href="https://github.com/itmanyong/vite-plugin-free-mock"><img src="https://files.catbox.moe/n3j1k5.png" /></a> </p> <h1 align='center'>VITE-PLUGIN-FREE-MOCK</h1> <p align='center'><em>快速的 模拟 API 数据</em></p> <p align='cent

Downloads

4

Readme

⛲ 特性

  • 🌴 完全正则化的 URL,借助regexparam轻松定制各类 URL 需求

  • 🌱 自定义 URL 前缀/后缀、请求类型、延时模拟、状态码

  • 🍊 自定义虚拟数据库,搭载 mockjs 轻松模拟数据库数据

  • 🍖 支持 query、params、body、headers 等参数自动解析,自动化响应参数

  • 🌊 日志、全局参数、模块参数多级别优先配置

  • ✨ 内置 mockjs 全部功能

  • 🍜 内置多级别请求/响应拦截器

  • 🥤 内置多种不同 content-type 类型 send 方法

  • 🌿 完全控制的 req/res 随意组装个性化需求响应

  • ♨️ TypeScript 支持~~

🏋️ 安装

pnpm 用户(推荐)

pnpm i vite-plugin-free-mock -D

yarn 用户

pnpm add vite-plugin-free-mock -D

💎 插件配置

# vite.config.js
import { defineConfig } from 'vite';
# 导入插件
import vitePluginApiMock from 'vite-plugin-free-mock';
# 导入插件配置(根据你的配置)
import pluginConfig from './mock/createFreeMock'
export default defineConfig({
    plugins:[
        # 配置到插件列表中(顺序无关)
        vitePluginApiMock(pluginConfig),
        # ...otherPlugins,
    ],
    # ...otherViteConfig
})

⛷️ 参数定义

  • 插件顶层选项---vitePluginFreeMockOptions
{
  # 接口模块配置数组
  apis?: array,
  # 虚拟数据库生成配置
  db?: object,
  # 全局级别默认参数
  global?: object,
  # 开发环境是否开启插件功能
  devMock?: boolean,
  # 生产环境是否开启插件功能
  prodMock?: boolean,
  # 显示请求|响应日志
  logger?: boolean,
}
  • 接口模块选项---apis/item
{
  # 前缀,位于全局前缀后面 -> global.prefix + module.prefix
  prefix?: string,
  # 后缀,若存在全局suffix不生效
  suffix?: string,
  # 接口类型,若存在全局method不生效
  method?: get|post|put|patch|delete|options|head|trace,
  # 延时毫秒,若存在全局timeout不生效
  timeout?: number,
  # 状态码,若存在全局statusCode不生效
  statusCode?: number,
  # 严格模式,若存在全局strict不生效
  strict?: boolean,
  # 自定义参数对象,与全局meta会进行merge
  meta?: object,
  # 返回数据格式,若存在全局responseType不生效
  responseType?: html|text|xml|jpeg|gif|png|formData|xhtml|dataXml|atomXml|json|pdf|word|stream|form,
  # 模块级别请求拦截,全局请求拦截后触发,api = 当前触发接口
  handlerRequest?:  (ctx, api, _options) => any,
  # 模块级别响应拦截,全局响应拦截前触发,api = 当前触发接口
  handlerResponse?:  (ctx, api, _options) => any,
  # 模块接口配置
  apis?:array,
}
  • 接口选项---apis/item
{
  # 接口URL,使用regexparam解析,自动生成pattern
  url?: string,
  # 接口URL正则,显式设置则url无效
  pattern?: RegExp,
  # 接口路径参数params的字段名称集,根据url自动生成,设置pattern也可不配置
  keys?: string[],
  # 接口类型,优先级最高
  method?: get|post|put|patch|delete|options|head|trace,
  # 延时毫秒,优先级最高
  timeout?: number,
  # 状态码,优先级最高
  statusCode?: number,
  # 严格模式,优先级最高
  strict?: boolean,
  # 返回数据格式,优先级最高
  responseType?: html|text|xml|jpeg|gif|png|formData|xhtml|dataXml|atomXml|json|pdf|word|stream|form,
  # 接口response返回函数,ctx = 内部方法,包含req,res等,db = 虚拟数据数据,_options = 最终的插件配置
  render?: (ctx, db, _options) => void,
}
  • 虚拟数据库选项---db
{
  # 第一种:直接设置值
  keyName:object|any[],
  # 第二种:通过函数返回值
  keyName:({mockjs})=>any[]|object
  # tips
  # 返回的数据值都会被mockjs.mock()进行处理一次
}
  • 全局默认参数选项--global
{
  # 全局前缀,默认''
  prefix?: string,
  # 全局后缀,默认'',
  suffix?: string,
  # 全局请求类型,默认get
  method?: get|post|put|patch|delete|options|head|trace,
  # 全局延时毫秒,默认1024*1
  timeout?: number,
  # 全局状态码,默认200
  statusCode?: number,
  # 严格模式,默认false
  strict?: boolean,
  # 全局自定义参数对象,默认null
  meta?: object,
  # 全局返回数据类型,默认json
  responseType?: html|text|xml|jpeg|gif|png|formData|xhtml|dataXml|atomXml|json|pdf|word|stream|form,
  # 全局请求拦截,最先触发,api = 当前触发接口
  handlerRequest?:  (ctx, api, _options) => any,
  # 全局响应拦截,最后触发触发,api = 当前触发接口
  handlerResponse?:  (ctx, api, _options) => any,
}

👀 使用

🗜️ 案例

react-demo

📅 计划

  • 根据虚拟数据库自动生成规范的 API(可定制规范???)
  • 生产环境支持???
  • 支持API级别的拦截???
  • 补全单测~~~~~