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

istanbul-widget

v1.9.1

Published

收集 istanbul 代码覆盖率的web小组件

Downloads

114

Readme

istanbul-widget

收集 istanbul 代码覆盖率的web小组件

如果你使用vite作为开发框架,推荐使用 vite-plugin-istanbul-widget

上手

方法一:使用 npm

npm install istanbul-widget
import { IstanbulWidget } from 'istanbul-widget'

const istanbulWidget = new IstanbulWidget({
  defaultPosition: {
    x: 0,
    y: 100,
  },
  plugin: {
    // 上报按钮
    report: {
      async onReport(coverage) {
        console.log('上报', coverage)
        // throw new Error('上报失败') // 你可以控制失败的逻辑
      },
    },
    // 设置插件
    setting: {
      requireReporter: true,
    },
    buttonGroup: [
      {
        text: '自定义按钮',
        onClick(...args) {
          console.log(...args)
        },
      },
    ],
  },
})

方法二:使用CDN直接插入到HTML

<script src="https://unpkg.com/istanbul-widget@latest/dist/istanbul-widget.min.js"></script>
<script>
  // 默认会挂载到 `window.IstanbulWidget` 上
  const istanbulWidget = new window.IstanbulWidget();
</script>

配置项

interface IstanbulWidgetOptions {
  /**
   * 主题色
   * @default 'dark'
   */
  theme?: 'light' | 'dark'
  /**
   * 挂载DOM
   * @default document.body
   */
  target?: string | HTMLElement
  /**
   * 按钮悬浮
   * @description false 则关闭悬浮
   */
  float?: {
    offsetX?: number
  } | false
  /**
   * 按钮默认位置
   * @default
   * ```js
   * { x: 0, y: 0 }
   * ```
   */
  defaultPosition?: {
    x?: number
    y?: number
  }

  /**
   * 控件就绪时回调
   */
  onReady?: () => void

  /**
   * 默认开启的插件
   */
  defaultPlugins?: ('setting' | 'buttonGroup')[]

  /**
   * 插件设置
   */
  plugin?: {
    /**
     * 上报插件(核心)
     */
    report: ReportOptions
    /**
     * 设置插件
     */
    setting?: SettingOptions
    /**
     * button组插件
     * @description 内置暴露了一组按钮插件,方便扩展
     */
    buttonGroup?: ButtonGroupOptions
  }
  /**
   * 插件顺序
   */
  pluginOrder?: (PluginName | string)[]
  /**
   * 打印调试信息
   * @default false
   */
  debug?: boolean
}

编写插件

支持 react插件 和 原生html+dom插件

import { IstanbulWidget } from 'istanbul-widget'
import { Button } from 'istanbul-widget/components'

function ReactPlugin() {
  return <Button size={'sm'}>this is react Plugin</Button>
}

// 自定义react插件
const reactPlugin = new IstanbulWidget.IstanbulWidgetReactPlugin('react_plugin', 'React Plugin', ReactPlugin)

reactPlugin.on('init', () => {
  console.log('react plugin inited')
})

// 自定义html插件
const htmlEl = document.createElement('div')
htmlEl.innerHTML = 'this is html plugin'
const htmlPlugin = new IstanbulWidget.IstanbulWidgetPlugin('html_plugin', 'HTML Plugin', htmlEl)

htmlPlugin.on('init', () => {
  console.log('html plugin inited')
})

const istanbulWidget = new IstanbulWidget({
  defaultPosition: {
    x: 0,
    y: 100,
  },
  plugin: {
    // 上报按钮
    report: {
      onReport(coverage) {
        console.log('上报', coverage)
        throw new Error('上报失败')
      },
    },
    // 设置插件
    setting: {
      requireReporter: true,
    },
    buttonGroup: [
      {
        text: '额外按钮 - 1',
        onClick() {
          console.log('1')
        },
      },
    ],
  },
})

istanbulWidget.addPlugin(reactPlugin)
istanbulWidget.addPlugin(htmlPlugin)

截图

入口按钮

入口

深色主题

深色主题

浅色主题

浅色主题