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

blankscreen

v1.0.1

Published

BlankScreen

Downloads

5

Readme

README

白屏监控组件,支持多实例,默认支持全屏白屏监控,和 React 组件白屏监控。

USAGE

全局白屏监控

blankscreen 内置了全屏白屏监控,引入 blankscreen 后,只需要复写 onError, onSuccess 方法即可。

import BlankScreen from 'blankscreen';

BlankScreen.onError = function(err) {
  console.log('full-page blank screen', err);
};
BlankScreen.onSuccess = function(meta) {
  console.log('full-page OK', meta);
};

React 组件白屏监控

blankscreen 还内置了 React 组件,包含待检查的组件外部即可检查内部是否处于白屏状态。

import ReactBlankScreen from 'blankscreen/lib/react';

render() {
  return (
    <ReactBlankScreen
      rule-text={10}
      onError={this.onError}
      onSuccess={this.onSuccess}
      autoStart
    >
      <div></div>
    </ReactBlankScreen>
  );
}

如果组件需要异步检查,不设置 autoStart 或设置为 false,然后通过 ref 主动调用 start() 方法启动检查。

import ReactBlankScreen from 'blankscreen/lib/react';

componentDidMount() {
  setTimeout(() => {
    this.refs.blankscreen.start();
  }, 1000);
}

render() {
  return (
    <ReactBlankScreen
      ref="blankscreen"
      rule-text={10}
      onError={this.onError}
      onSuccess={this.onSuccess}
    >
      <div></div>
    </ReactBlankScreen>
  );
}

基础用法

import BaseBlankScreen from 'blankscreen/lib/base';

const bs = new BaseBlankScreen(element, {
  rule: {
    text: 0,
  },
  onError: err => console.error(err),
  onSuccess: meta => console.log(meta),
  autoStart: true,
})
bs.start();

白屏判定规则

| 文字\元素 | 有 | 无 | |-----------|----|----| | 有 | 黑 | 黑 | | 无 | 白 | 白 |

原则上,只通过是否有指定个数的『文字』来判定是否白屏, 子元素个数多少不作为判定条件,只作为附加信息。

注:

  • 黑:判定为不是白屏。
  • 白:判定为白屏。

API

BlankScreen(element, options)

  • {HTMLElement} element 监控的元素,如果是 React 元素,则是其子节点。
  • {Object} options 可选的选项配置。
    • {Number} rule-text: 白屏规则:有效文本(剔除无效空白符)最少个数,默认设置是 0。子节点有效文本少于或等于这个值,则认为是白屏。
    • {Function} onError: 最终判定为白屏时,会触发 onError
    • {Function} onSuccess: 页面开始正常渲染时,会触发 onSuccess
    • {Boolean} autoStart: 自动开始检查,默认 false。

.start()

开始检查白屏,白屏时间从此时开始计算。

.stop()

停止检查。超时(6s)或离开页面时自动停止检查。

注:终止后会判定是否白屏,得到判定结果后,不可再次启动检查。

.onError = err => {}

可复写的白屏处理函数。判定为白屏时会调用 onError 函数。

err:

  • state: 白屏状态。
    • timeout: 超时(6s)后判定为白屏。
    • stop: 离开页面时判定为白屏。
  • time: 首屏时间。
  • textLength: 白屏时的文字数量。
  • elemLength: 白屏时子元素数量。

.onSuccess = mata => {}

可复写的非白屏处理函数,最终判定为非白屏,会调用 onSuccess 函数。

meta:

  • state: 页面状态,固化为 "success"。
  • time: 首屏时间。

白屏检查状态机

状态机