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

carbonium

v1.2.4

Published

One kilobyte library for easy DOM manipulation

Downloads

38

Readme

CodeQL Coverage Status Socket Badge CodeFactor Quality Gate Status Size npm version GitHub

Carbonium

One kilobyte library for easy DOM manipulation

With carbonium, you can call $(selector) and the result can be accessed as both an DOM element and an array of matched elements. DOM element operations are applied to all matched elements.

Examples

To set the left CSS property of all elements with the class indent to 40 pixels:

$(".indent").style.left = "40px";

To add the class important to all div's with "priority" as content:

$("div")
  .filter((el) => el.textContent == "priority")
  .classList.add("important");

You can use carbonium to create elements:

const error = $("<div class='error'>An error has occured!</div>")[0];

Installation

npm install --save-dev carbonium

Now you can import carbonium:

import { $ } from "carbonium";

If you don't want to install or use a bundler like webpack or rollup.js, you can import carbonium like this:

const { $ } = await import(
  "https://cdn.jsdelivr.net/npm/carbonium@1/dist/bundle.min.js"
);

API

Select elements

$(selector [, parentNode])

Parameters

| Name | Type | Description | | ---------- | ------------------------------ | -------------------------------------------------------------------------- | | selector | string | Selector to select elements | | parentNode | Document | Element (optional) | Document or element in which to apply the selector, defaults to document |

Returns

An array of the matched elements, which can also be accessed as a single element.

Create element

$(html [, parentNode])

Parameters

| Name | Type | Description | | ---------- | ------------------------------ | -------------------------------------------------------------------------- | | html | string | HTML of element to create, starting with "<" | | parentNode | Document | Element (optional) | Document or element in which to apply the selector, defaults to document |

Returns

An array with one created element.

TypeScript

If you use TypeScript, it's good to know Carbonium is written in TypeScript and provides all typings. You can use generics to declare a specific type of element, for example HTMLInputElement to make the disabled property available:

$<HTMLInputElement>("input, select, button").disabled = true;

Why?

You might find most frameworks are quite bulky and bad for performance (1). On the other side, you might find using native DOM and writing document.querySelectorAll(selector) each time you want to do some DOM operations to become tedious. You can write your own helper function, but that only takes part of the pain away.

Carbonium seeks to find the sweet spot between using a framework and using the native DOM.

jQuery

Isn't this just jQuery and isn't that obsolete and bad practice?

No. Carbonium doesn't have the disadvantages of jQuery:

  1. Carbonium is very small: just around one kilobyte.
  2. There's no new API to learn, carbonium provides only standard DOM API's.

Browser support

Carbonium is supported by all modern browsers. It is tested to work on desktop and mobile with Firefox 79, Chrome 84, Safari 13 and Edge 84. It should work with all browsers supporting Proxy, see Can I use Proxy for support tables.

Name

Carbonium is the Latin name for carbon. Carbon has two forms (allotropes): graphite and diamond. Just like this library, in which the result presents itself both as one element and as a list of elements.

Photo CC BY-SA 3.0

License

Copyright 2023 Edwin Martin and released under the MIT license.