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

litequery

v0.2.1

Published

Lightweight JavaScript DOM manipulation, inspired by jQuery and jqlite, but runs using rollup-compiled, babel transpiled ES6 code.

Downloads

76

Readme

LiteQuery

Lightweight JavaScript DOM manipulation, inspired by jQuery and jqlite, but runs using rollup-compiled, babel transpiled ES6 code.

But why?

I wanted an easy wrapper for document.querySelector and querySelector all that mimics the behaviour of jQuery but is still lightweight, manageable and easy to develop.

How do I get going...

...really fast?

Include the following snippet in your HTML:

<script src="https://unpkg.com/litequery/dist/litequery.min.js"></script>

Then you can start using it, it'll be attached as the global variable litequery().

...the proper way?

  • Make sure you have NodeJS & NPM installed (or Yarn, if you prefer that)
  • Use npm i litequery --save in your project folder
  • Import node_modules/litequery/dist/litequery.min.js in your project, such as:
import litequery from 'litequery';

litequery('div.container').html('Hello World!');

Is it chainable?

Yes.

import lq from 'litequery';

lq('div').addClass('test').html('asdf');

works just as you would expect. Some functions do however return variables, such as hasClass('test') returns a boolean. So those functions break the chain.

What does it do?

import lq from 'litequery';

// Attributes
lq('img#myImg').attr('alt'); // Returns the "alt" text attribute, <img alt="hai"> - result "hai".
lq('img#myImg').attr('alt', 'This is better'); // Sets the "alt" attribute to "This is better".

// Classes
lq('div#myDiv').hasClass('selected'); // Do all the selected elements have the class specified? (returns Boolean)
lq('div#myDiv').dedupClass(); // Deduplicates all classes on all affected elements.
lq('div#myDiv').addClass('highlight'); // Just like jQuery! Add a class to a div.
lq('div#myDiv').removeClass('posh'); // div#myDiv is just not *that* classy after this.
lq('div#myDiv').toggleClass('active'); // Toggle a class

// Content manipulation
lq('#content').html('<h1>Wowza</h1>'); // Set the HTML of #content to "<h1>Wowza</h1>".
var content = lq('#content').html(); // Return #content's innerHTML as a string.

// Events (pretty basic and might not fire accurately at the moment, feel free to contribute)
lq('#hammer').on('touchstart', function(event) {
  event.preventDefault(); // Can't touch this
});

// Window events
lq().on('resize', function(event) {
  console.log('Awh lag');
});

lq().trigger('resize'); // Trigger resize on window

// Selection
lq('li').single(); // Get the first li item, expects it to be a single element. Warns if multiple selected, but still returns the first.
lq('li').first(); // Get the first matched li item.
lq('li').last(); // Get the last matched li item.
lq('li').parent(); // Get the parent of the first matched item.
lq('ul').children(); // Return the children of all selected objects
lq('li').eq(0); // Get the first matched li item. By index, zero-based.
lq('ul').find('div'); // Traverse the DOM down from UL and select ALL DIVs in each UL.
lq('ul').closest('div'); // Traverse the DOM up from UL and select the first DIV for each UL.

// Advanced selection
lq('li').filter(function(item) {
  return item.html(); === 'lol'; // Filter and return all li items containing the world "lol".
});

lq('li').get(); // Returns a NodeList of all matched li elements.
lq('li').get(0); // Returns a specific, non-litequery wrapped element (node) by index, zero-based.

// Apply something to all items using their actual node or element rather than the litequery wrapped one.
lq('.item').apply(function (item) {
  item.innerHTML = '';
  item.setAttribute('src', '../../test.jpg');
});

// Do something to each and every item, but with a litequery wrapped object.
lq('.item').each(function(item) {
  if (item.hasClass('onclear')) {
    item.html('');
  }
});

// Modify styles
lq('.item').css('background', 'red'); // Turns the background red, same as document.querySelector('.item').style.background = 'red';
lq('.item').css('background'); // Returns 'red'

Is this... tested?

Yes. Test are in the tests folder and run by mocha using npm run test.

Happy coding!

If you want to contribute, please do so. Feel free to add pull requests and likewise.