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

psmitter

v1.0.0

Published

Usefull event emitter for Browser

Downloads

2

Readme

PSMITTER

Psmitter

js-standard-style

Actual version published on NPM npm module downloads per month

An usefull event emitter for the Browser

:runner: Migration

Check migration file to 1.0.0.

:cloud: Install

npm install psmitter --save

:fork_and_knife: Usage

You can use this module of many ways:

  • By minFile:
<!-- index.html -->
<script src="psmiter.min.js" type="text/javascript"></script>
// file.js
let myEmitter = new Psmitter()
  • By require
// file.js
const Psmitter = require('psmitter').Psmitter

let myEmitter = new Psmitter()
  • By webpack

Only add just with the others vendors files

// webpack.config.js
var vendors = [
  ...,
  'psmitter'
]
// file.js
let myEmitter = new Psmitter()

:memo: Documentation

on(event | [eventA, eventB], fn)

Register a listener for one or more events

Params
  • event | [eventA, eventB] - string|Array: Event name or array of events names
  • fn - function : Callback function

emit(event, data)

Dispatch a event

Params
  • event - string: Event name for dispatch
  • data - mixed: Data for send when the event is emitted.

once(event | [eventA, eventB], fn)

Register a listener that will be executed only once

Params
  • event | [eventA, eventB] - string|Array: Event name or array of events names
  • fn - function : Callback function

getEvents()

Get a list of event names in the current Psmitter instance

Return
  • array : The list of events names

getListeners(event)

Get a listeners list binded to determinate event

Params
  • event - string: Event name
Return
  • array : The list of listeners

countListeners(event)

Number of listeners registered to an event

Params
  • event - string: Event name
Return
  • number : Number of listeners registered

removeListener(event, fn)

Remove an listener of a determinate event

Params
  • event - string: Event name
  • fn - function : Callback function to remove

removeAllListeners(event)

Remove all listeners of a event

Params
  • event - string: Event name

removeLastListener(event)

Remove the last listener of an event

Params
  • event - string: Event name

hasSomeListener(event)

Check if exists almost one listener registered to a event

Params
  • event - string: Event name
Return
  • boolean : Return true if contains some listener, otherwise return false

:clipboard: Examples

If you need to emit and listen some data


// button[id="message"]
var button = document.getElementById('message')
button.addEventListener('click', function () {
  myEmitter.emit('message', 'hello world from Psmitter')
})

myEmitter.on('message', function (data) {
  console.log(data)
})

If you needs to remove and newly register an listener

index.html

<body>
  <input type="button" value="Remove listener" id="removeListener">
  <input type="button" value="Register Listener" id="registerListener">
  <div id="time"></div>
</body>

file.js

var time = document.getElementById('time')
var commonListener = function (data) {
  time.innerHTML = data
}

myEmitter.on('time', commonListener)

var removeButton = document.getElementById('removeListener')
removeButton.addEventListener('click', function () {
  myEmitter.removeListener('time', commonListener)
})

var registerButton = document.getElementById('registerListener')
registerButton.addEventListener('click', function () {
  myEmitter.on('time', commonListener)
})

setInterval(function () {
  myEmitter.emit('time', new Date())
}, 1000)

:rocket: How to contribute :smiley:

You have a improvement? or found a bug? See how to contribute

:tada: Where is this library used?

If you are using this library in one of your projects, add it in this list.

  • proyect name with link(Author) ---> description

:scroll: License

[MIT][license] © [Fernando Palacios]