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

pyrsmk-quark

v2.2.1

Published

Another micro-framework

Downloads

4

Readme

quark 2.2.1

Quark is a small javascript library that aims to let you compose your own framework from scratch. It brings a different syntax than the other frameworks which is a lot more intuitive and browser-friendly.

Quark is an alternative to Ender without all the building process and a lot of overhead.

Installation

npm install pyrsmk-quark
bower install pyrsmk-quark

As Ender, you'll need to install third-party libraries to add ajax, animations, etc... But it has a basic support for readiness, node selection and creation.

Quick examples

var $ = quark.$,
	$$ = quark.$$;
$('.foo .bar').data('state', 'ok');
$$('.comments').css('background', 'red');

Note that data() and css() methods are available by installing quarky, a good companion for quark.

Basics

Unlike jQuery-like libraries, each node is wrapped by quark and all methods (like css()) are available. Even into the methods themselves (like on() in quarky). But you can access to the base node with :

var node = $('.foo').node;

If you need to verify if a node has already been wrapped or not, you can test for :

if('quarked' in somenode) {
	// the node is wrapped
}

Quark has a heavy fault tolerance when searched nodes do not exist. Imagine, you have some blog comments that are not there for any reason, then that line won't crash anything :

$('.comments').css('color', 'green');

Readiness

Quark implements a basic ready function that should work in most browsers :

$(function() {
	// Run some tasks when the DOM is ready
});

Selecting nodes

$() will return one wrapped node.

$$() will return a list of wrapped. A forEach() method has been added to iterate over the nodes.

$$('.comments').forEach(function(index) {
	// index is the index of the current node in the list
	console.log(index);
	// the this keyword points to the current node
	this.css('background', 'red');
});

If you want to retrieve an array of nodes instead of an array of wrapped nodes, set true as second argument (really useful when some library expects an array of nodes) :

var nodes = $$('.comments', true);

Creating nodes

You can create on node by calling $(). The returned node is wrapped as well :

$('body').append($('<div>'));

You can create several nodes too :

var nodes = $$('<div>1</div><div>2</div><div>3</div>');

nodes.css('display', 'inline');

$('body').append(nodes);

Calling node methods

Quark is shipped with two base methods : findOne() and findAll().

// Find only one .bar node in .foo nodes
$('.foo').findOne('.bar');
// Find all .bar nodes in .foo nodes
$('.foo').findAll('.bar');

Calling node methods on $$() will apply the method to each node, as expected. But note that if the method is returning a value then $$() will return an array of all returned values. Per example :

// Return an array of all .bar nodes found in each .foo node
$$('.foo').findAll('.bar');

Writing extensions

Writing extensions is simple, you just have to write code like the example below and release your library on NPM with a quark tag (so it can easily be found).

Here's the API :

  • $._whenReady(function) : takes a function that verifies if the DOM is ready or not
  • $._selectNode(selector) : takes a function to select one node
  • $._selectNodes(selector) : takes a function to select several nodes
  • $._createNode(html) : takes a function to create one node
  • $._createNodes(html) : takes a function to create several nodes
  • $._nodeMethods : is an object and accepts new methods that will be appended to nodes by quark

Example

Here's a full example, based on quarky, nut, domReady, morpheus and qwest. First, we configure our framework :

var $ = quark.$,
	$$ = quark.$$;

// Set the selector engine
$._selectNode = function(selector) {
	return nut(selector)[0];
};
$._selectNodes = nut;

// Set the ready function
$._whenReady = domready;

// Add animation methods
$._nodeMethods.animate = function(options) {
    return morpheus(this.node, options);
};
$._nodeMethods.fadeIn = function(duration, func) {
	var node = this;
    return morpheus(this.node, {
        duration : duration,
        opacity  : 1,
        complete : function() {
			func.call(node);
		}
    });
};
$._nodeMethods.fadeOut = function(duration, func) {
	var node = this;
    return morpheus(this.node, {
        duration : duration,
        opacity  : 0,
        complete : function() {
			func.call(node);
		}
    });
};

// Add an ajax method to the front object
$.ajax = qwest;

Now that the framework is set, we can use it :

// When the DOM is ready
$(function() {
    // Animate images in .foo containers
	this.on('click', function() {
		this.findAll('img').fadeIn();
	});
    // Run a GET ajax request
    $.ajax.get('example.com')
          .then(function(xhr, response) {
              $('#info').html(response);
          });
});

License

Quark is published under the MIT license.