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

mockquery

v0.2.6

Published

A Simple NodeJS jQuery Substitute

Downloads

23

Readme

MockQuery - A Simple NodeJS jQuery Substitute

Mockquery is a simple jQuery substitute for NodeJS, meant to be used on the server-side.

This is similar to cheerio, but is implemented specifically for covalent's use cases. That means it's currently a limited mock and doesn't cover full jQuery's API (nor the selectors yet).

Installation

npm install mockquery

Usage

You can create the $ object via loading an HTML fragment.

var mockquery = require('mockquery')

var $ = mockquery.load('<div>an html fragment</div>');

The html fragment currently needs to be based on XHTML rules; i.e. the underlying parser for mockquery doesn't try to parse everyday html's. This is due to mockquery's goal is for server-side template generation. This can change in the future.

You can also directly load from a file with either readFile (async) or readFileSync method.

// default async method
mockquery.readFile(<filePath>, function(err, $) {
  if (err) {
   ...
  } else {
    // use $ as the jQuery object.
  }
});

// sync method
$ = mockquery.readFileSync(<filePath>);

Document Object Model

mockquery provides a very limited DOM to keep things light, and just enough to support the mutators that makes sense for the server-side. Use $ for manipulation rather than DOM methods, since it's not a goal to be DOM-compliant.

Document Object

Once the document is loaded, the document object is available as $.document. This is a very limited document object. You generally do not want to directly manipulate it as a DOM object. Instead - use $ for manipulation.

Element Object

The Element object is likewise limited, and designed for template use (i.e. modifying attributes and children elements). You are likely to hold onto references of them, but use $ for manipulation.

getJSON and postJSON

Both $.getJSON and $.postJSON are available, and they are stubbed out, since for template generation you likely not want to prepopulate data that's supposed to be pulled from the client-side.

Supported Selectors

Since this is developed to support covalent it means that currently the selector supported are based on the need of covalent. This can be improved in the future if there are needs.

You can pass element or document objects into $ - the same way as in jQuery.

$(<element>)
$(<document>)

Likewise - you can also use element tags.

$('body')
$('div')

Class and ID also work.

$('.class')
$('#id')

Attributes also work.

$('[href]')

You can also create more elements via passing in a html fragment.

$('<div>a html fragment</div>')

Supported jQuery Methods

Data Methods

$(<selector>).data(<key>)

$(<selector>).data(<key>, <val>)

.data() works the same as jQuery.data(). You can use it to hold complex object (it won't be serialized into string; this is the same behavior as jQuery.

Attribute Methods

$(<selector>).attr(<key>)

$(<selector>).attr(<key>, <val>)

$(<selector>.removeAttr(<key>)

CSS Methods

$(<selector>).addClass(<class>)

$(<selector>).removeClass(<class>)

$(<selector>.css(<key>)

$(<selector>).css(<key>, <val>)

$(<selector>).css(<object>)

innerHTML and Child Elements Methods

$(<selector>).html()

$(<selector>).html('<div>another fragment</div>')

$(<selector>).children()

$(<selector>).append(<element>)

$(<element>).appendTo(<selector>)

$(<selector>).prepend(<element>)

$(<selector>).after(<element>)

$(<selector>).detach()

$(<selector>).remove()

$(<selector>).empty()

$(<selector>).clone()

Subsequent Selector Methods

$(<selector>).add(<selector>, <context>)

$(<selector>).filter(<selector_2>)

$(<selector>).has(<selector_2>)

$(<selector>).not(<selector>)

Event Methods

Events are all stubbed, like .getJSON and .postJSON.

$(<selector>).bind(<event>, ...) // does nothing

$(<selector>).unbind(<event>, ...) // does nothing

$(<selector>).on(<event>, ...) // does nothing

Helper Methods

$(<selector>).index()

$(<selector>).toArray()

$(<selector>).val()