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

mu.js

v1.1.2

Published

µ is the new $

Downloads

130

Readme

µ.js is the new $

This package is top secret and should not be used by anybody under any circumstances.

  • Simplified HTTP request client. request
  • Tiny, fast, and elegant implementation of core jQuery designed specifically for the server. cheerio

Examples

/* Initialize jQuery on remote document */
let µ = require('mu.js')
µ('http://example.com/').then($ => {
	// $ = cheerio (jQuery)
	console.log(
		$('body').html()
	)
})
/* For options, use object passed to request module */
µ({
	url: 'http://example.com', 
	timeout: 5000, 
	strictSSL: true // require valid SSL
}).then($ => {
	console.log(
		$('title').text()
	)
})
/* From local file */
µ.fromFile('page.html').then($ => {
	console.log(
		$('title').text()
	)
})
/* From local file synchronously */
let $ = µ.fromFileSync('/var/www/index.html')
$('h2').each(function() { /* make text red in every <h2> */
	$(this).css('color', 'red')
})
/* From a string */
let $ = µ.fromString('<div><h2>Title of a document</h2><p>Description of a document.</p></div>') // does not even require <html></html>
$('div').html() /* <h2>Title of a document</h2><p>Description of a document.</p> */
/* Full document outerHTML*/
$.html()
/* Initialize jQuery on remote document synchronously */
const $ = µ.sync('http://reddit.com')
$('title').text() // reddit: the front page of the internet
/* Fetch worldnews headlines from Reddit */
µ('https://www.reddit.com/r/worldnews/').then($ => {
	$('p[class="title"]').each(function() {
		let a = $('a', $(this)) // every <a> in this <p>
		console.log({
			title: a.text(), 
			url: a.attr('href')
		})
	})
})
/* 
{
   "title": "Elon Musk's SpaceX Falcon 9 rocket blasts off to deliver human sperm to International Space Station for NASA testsstandard.co.uk",
   "url": "https://www.standard.co.uk/news/world/spacex-falcon-9-elon-musks-powerful-rocket-blasts-off-to-deliver-human-sperm-to-international-space-a3804171.html"
}
{
   "title": "Russia threatens sanctions over Latvian language in Latvian schoolsbbc.com",
   "url": "http://www.bbc.com/news/world-europe-43626368"
}
{
   "title": "Robert Mueller’s Russia probe reportedly rolled a witness, George Nader, who confirmed that Blackwater founder Erik Prince did indeed attempt to set up a secret backchannel between Trump and Russia in January 2017uproxx.com",
   "url": "https://uproxx.com/news/russian-met-erik-prince-backchannel-link-putin/"
}

... more
*/

Update: 30 october 2019

Added additional method sync for synchronous initialization. See example.

Update: 1 april 2018

Now includes 3 additional methods: fromFile, fromFileSync and fromString.

Update: 4 september 2018

Resolved instance of jQuery (cheerio) now includes reference to HTTP response, which in turn includes a reference to the HTTP request. This can be used for stuff like reading header information (Content-type, cache-control, ...) and detect redirect(s).

let url = 'http://example.com'
µ(url).then($ => {
	console.log($.response.headers)
	let destination = $.response.request.uri.href 
	if(destination != url)
		console.log(`we were redirected from ${url} to ${destination}`)
	
	// the rest of your $ code
})