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

eyepatch

v0.1.5

Published

A library of notification based objects

Downloads

19

Readme

eyepatch

A library of notification based objects

Installation

npm install eyepatch --save

Why?

Sometimes you just want to know when something happens without the need of checking it yourself. You just want to be notified when the change happens.

Who?

Just me myself and I, in my free time

Features

  • Events - Simple or parametrized.
  • ConditionalEvent - Simple or parametrized.
  • GlobalEvent - To broadcast events globally
  • ObservableCollection - notifies you when something changes.
  • ObservableDictionary - Works with keys as an object and not only strings and numbers. Notifies on changes. Works simply adding non enumerable property as the key id. This doesn't affect the JSON.stringify method nor the for in loop.

Languages

The library is written in TypeScript but you can use in both in TypeScript and JavaScript

Usage examples in TypeScript

Using parametrized event:
var event = new EventT<number>();

event.on((_num: number) => console.log('The number ' + _num + ' was raised'));

event.raise(15);
Using conditional event
var conditionalEvent = new ConditionalEventT<number>();

conditionalEvent.on(
  (_num) => console.log('The number ' + _num + ' is positive'),
  (_num) => _num > 0
  );

conditionalEvent.raise(-1); // Will not be logged
conditionalEvent.raise(12); // Will be logged
Using global event
const globalEvent1 = new GlobalEvent();

globalEvent1.on('some event name', (_num: number) => console.log('The number ' + _num + ' was raised'));

// In some other place
const globalEvent2 = new GlobalEvent();
globalEvent2.raise('some event name', 123); // Will log: "The number 123 was raised"
Raising safely in case one of the registrations throws an error
var event = new Event();

event.on(() => throw 'some error');
event.on(() => console.log('I still want to log'));

event.raiseSafe();
Using ObservableCollection
var collection = new ObservableCollection<number>();

var items:number[] = collection.items;

collection.itemsChanged.on(
  (_args: IItemsChangedEventArgs<number>) => {
    console.log('Added items: ' + _args.added);
    console.log('Removed items: ' + _args.removed);
  });

collection.add(2);
collection.addRange([1,2,3,4,5,6,7,8,9]);

collection.removeMatching(2);
collection.removeMatchingRange([5,6]);
collection.removeAtIndex(0);
collection.removeAtIndices([0,1]);

var size: number = collection.size;

var has7: boolean = collection.contains(7);

collection.clear();
Using ObservableDictionary
var dictionary = new ObservableDictionary<Obejct, Object>();

dictionary.itemsChanged.on(
  _args => {
    console.log('Added key value pairs: ' + _args.added);
    console.log('Removed key value pairs: ' + _args.removed);
  });

var key = { someProp: 1 };
var value = {};
dictionary.add(key, value);

// Be aware: containsKey will work only on keys instances that are inside the dictionary
var containsKey: boolean = dictionary.containsKey(key);
var containsValue: boolean = dictionary.containsValue(value);

// Be aware: getValueByKey will work only on keys instances that are inside the dictionary
var valueByKey: Object = dictionary.getValueByKey(key);

var size: number = dictionary.size;

var keys: Object[] = dictionary.keys;
var values: Object[] = dictionary.values;
var keysAndValues: IKeyValue<Object, Object>[] = dictionary.keysAndValues;

// Be aware: removing will work only on keys instances that are inside the dictionary
dictionary.remove(key);

// If you don't have the instance you can search it:
var foundKey = dictionary.findKey(_ => _.someProp === 1);
dictionary.containsKey(foundKey);
dictionary.getValueByKey(foundKey);
dictionary.remove(foundKey);

dictionary.clear();

Whats next?

Have fun and feel free to use, comment, request, and contribute. I'll keep adding stuff from time to time