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

printscout

v2.0.3

Published

Simple, cross-browser print event listeners (before and after) with no dependencies

Downloads

695

Readme

PrintScout

Simple, cross-browser print event listeners (before and after) with no dependencies

Table of contents

Usage

// ES2015
import PrintScout from 'printscout';

// CommonJS
const PrintScout = require('printscout').default;

// script
const PrintScout = window.PrintScout;

// create a new scout
const scout = new PrintScout();

// add listeners in a traditional way
const beforePrintHandler = () => {
  console.log('I fire before print render');
};

scout.on('beforeprint', beforePrintHandler);

// or you can do it dynamically, the handler you passed is returned when added,
// either with the shorthand methods or the standard ones
const afterPrintHandler = scout.after(() => {
  console.log('I fire after print render');
});

// and remove them as you would any other listener
scout.off('beforeprint', beforePrintHandler);

// or with the convenience function attached to the handler returned from adding it
afterPrintHandler.off();

API

on

scout.on(eventName: string, handler: function): function

Adds the handler to the list of handlers that will fire when the specific eventName is called. The valid eventName values are beforeprint, before (shorthand for beforeprint), afterprint, and after (shorthand for afterprint).

const scout = new PrintScout();

const handler = scout.on('afterprint', event => console.log(event));

Additionally, the handler passed receives an additional off method attached to it, which will remove the listener when called directly.

handler.off(); // will no longer log the event

off

scout.off([eventName: string[, handler: function]]): void

Removes the handler from the list of handlers that will fire when the specific eventName is dispatched. If no handler is passed, then all handlers for a given eventName are removed. If no eventName is passed, then all handlers are removed. The valid eventName values are the same as for on.

const scout = new PrintScout();

const handler = scout.on('beforeprint', console.log('about to print...'));
...
scout.off('beforeprint', handler);

after

scout.after(handler: function): function

Shorthand method for on with the eventName set to afterprint. Like on, returns the handler passed.

const scout = new PrintScout();

const handler = scout.after(event => console.log(event));

before

scout.before(handler: function): function

Shorthand method for on with the eventName set to beforeprint. Like on, returns the handler passed.

const scout = new PrintScout();

const handler = scout.before(event => console.log(event));

Browser support

  • Chrome (all versions)
  • Firefox (all versions)
  • Edge (all versions)
  • Opera 15+
  • IE 9+
  • Safari 6+
  • iOS 8+
  • Android 4+

Development

Standard stuff, clone the repo and npm install dependencies. The npm scripts available:

  • build => run webpack to build development dist file with NODE_ENV=development
  • build:minified => run webpack to build production dist file with NODE_ENV=production
  • dev => run webpack dev server to run example app / playground
  • dist => runs build and build-minified
  • lint => run ESLint against all files in the src folder
  • prepublish => runs compile-for-publish
  • prepublish:compile => run lint, test:coverage, transpile:es, transpile:lib, dist
  • test => run AVA test functions with NODE_ENV=test
  • test:coverage => run test but with nyc for coverage checker
  • test:watch => run test, but with persistent watcher
  • transpile:lib => run babel against all files in src to create files in lib
  • transpile:es => run babel against all files in src to create files in es, preserving ES2015 modules (for pkg.module)