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

moohlah

v0.0.9

Published

Like JQuery, but works on more than DOM elements

Downloads

12

Readme

moohlah

JQuery like system for more than just the DOM

Install

npm install moohlah

Usage

Basic Usage

$ = require('moohlah')();

$.register('split',function(arg) {
 return this.split(arg);
});

$('blank plank').split(' ');
//results in ['blank','plank']

$(['blank','plank']).split('a');
//results in ['bl','nk','pl']

Just like in JQuery duplicates are removed.

How is this different than just using JQuery's $.fn.func = ...

The behind the scenes of JQuery is not as sophisticated as some might suspect. The result of every JQuery call producing a set with only unique elements is not actually a feature of JQuery. Jquery developers have just done a really good job writing each of the standard functions so that they only return sets. They have taken the hard way to develop JQuery making it more difficult for you to add on to it.

When we write a function for $.fn the this object we get for the function is really just the list we were working with on the outside. JQuery doesn't do anything to break the elements up for you, concatenate results, and remove duplicates and empty elements.

In JQuery the above function would have been properly written:

$.fn.split=function(arg) {
 var retr=[];
 this.toArray().forEach(function(item) {
  retr = retr.concat(item.split(arg));
 });
 return lodash.select(lodash.uniq(retr),function(item){return item;});
}

But in Moohlah it's just:

$.register('split',function(arg) {
 return this.split(arg);
});

or

$.register('split',String.prototype.split);

Many more JQuery like features are included and will be included as development continutes.

For example we can add element sets together.

$(['blank','plank']).add('flank stake').split(' ').split('a');

Multiple implementations in one program

The entire inspiration for moohlah is that JQuery is geared towards HTML elements and not for other kinds of objects we might work with in an environment like NodeJS.

Creating additional instances of the library whose configurations won't interfere is easy. As you may have recalled after we used require to load the module we called it as a function. We can do this as many times as we want to create set templates that operate distinctly.

var moohlah = require('moohlah'),
 $ = moohlah(),
 _ = moohlah();

We also can use this to preregister functions or store template configurations in separate files.

$ = moohlah(require('./peopleSets.js'));

_ = moohlah({split: function(arg) {return this.split(arg)}
            ,print: function() { console.log(this) }
          });

π = moohlah(function($) {
 $.register('parent',function () {return this.parentElement;});
 //registerDumb binds to the set rather than to each element in the set.
 $.registerDumb('first',function() {return $(this.toArray().split(0,1));});
}
  

Just for fun

The entire point of this module is to work with graphs. After all this is based on JQuery which works with a special kind of graph, the DOM, which is a simple example of a tree.

Here's a bit of fun:

function Person() {
 this.peopleIKnow;
}


$Bacon = moohlah();


$Bacon.register('peopleKnown',function() {
 return this.peopleIKnow;
}

$Bacon.registerDumb('contains',function(lookingFor) {
 return lodash.contains(this.toArray(),lookingFor);
});


function baconNumber(person) {
 var baconators = $Bacon(person),
  count=0;
  
 while(true) {
  ++c;
  baconators = baconators.peopleKnown();
  if(baconators.contains(kevinBacon)) {
   return c;
  }
 }
}