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

@alexcarpe/kquery

v1.0.7

Published

Kquery is an awesome library that allow you to do magic with your DOM

Downloads

27

Readme

Goal

What's better than jQuery? 👉 kQuery 👈

The goal of this repository is to build a simplified jQuery-like capable library, called 🎤 kQuery.


Table of contents

Usage

import kQuery from 'kquery';

kQuery('.item')
  .replaceWith(kQuery('.itemReplacement'))
  .style({
    color: '#000',
  });

This gets all the DOM elements matching the CSS selector .item, replaces them with all the elements matching .itemReplacement, and then changes the CSS color property of the DOM element.

API

The API to implement is very similar to the jQuery API.

kQuery(cssSelectorString)

Select matching elements on the page.

  • Reads a CSS selector string
  • Returns a kQuery collection (kCollection or collection in this assignment)

Example

<div class="item">Hello</div>
<div class="item">World!</div>
const kCollection = kQuery('.item');

Result

kCollection now contains the elements matching the CSS selector .item.

kCollection.replaceWith(kCollection)

  • Replaces the current collection with another one
  • Returns the new collection

Example

<div class="item">Some</div>
<div class="item">Item</div>

<span class="itemReplacement">Hello</span>
<span class="itemReplacement">World!</span>
kQuery('.item').replaceWith(kQuery('.itemReplacement'));

DOM result

<span class="itemReplacement">Hello</span>
<span class="itemReplacement">World!</span>

kCollection.style(Object)

  • Updates the style of the current collection
  • Returns the current collection

Example

<div class="item">Hello World!</div>
kQuery('.item').style({ color: 'red' });

Result

Hello World! is now displayed in red color.

kCollection.remove()

  • Removes the current collection from the DOM
  • Returns an empty collection to allow the chain of commands to continue

Example

<div class="item">Some</div>
<div class="item">Item</div>
<div>Hello World!</div>
kQuery('.item').remove();

DOM result

<div>Hello World!</div>

kCollection.find(cssSelectorString)

  • Searches the current collection for matching elements and replaces the current collection
  • Returns the new collection

Example

<div class="item">Hello <span>World!</span></div>
<div class="item">World! <span>Hello</span></div>
const kCollection = kQuery('.item').find('span');

Result

kCollection contains two spawn elements.

kCollection.get()

  • Returns an Array of all DOM elements in the kCollection

After this call, the kQuery chain ends since you get a regular Array and not a kCollection.

Example

<div class="item">Hello</div>
<div class="item">World!</div>
const domElements = kQuery('.item').get();

Result

domElements contains an array of DOM elements with two elements.

kCollection.getCurrentCssSelector()

  • Returns a string which reppresent the concatenations of all chain css selectors.

Example

const cssSelector = kQuery('.item').find('span').getCurrentCssSelector();

Result

cssSelector contains .item span.