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

nathi

v1.1.2

Published

A lightweight custom JavaScript library to create and manipulate HTML elements.

Downloads

5

Readme

Nathi JavaScript Library

Nathi is a simple custom JavaScript library that provides a collection of utility methods for DOM manipulation and event handling.

Installation

Use the following command to install the library via npm:

Using npm

Install the package using npm:

npm install nathi

To use the library, include it in your project and create a new instance:

const NathiLib = require("nathi");
const nathiLib = new NathiLib();

ES6

import NathiLib from "nathi";
const nathiLib = new NathiLib();

Using script tag

For browser usage, include the bundled file in your HTML:

<script src="node_modules/nathi/dist/nathiLib.bundle.js"></script>
<script>
  const nathiLib = new NathiLib();
</script>

API Reference

createHTMLElement(tagName, attributes, textContent);

Create an HTML element with given attibutes and text content.

  • tagName (string): The tag name of the element to create.
  • attributes (object): An object containing the attributes and their values.
  • textContent (string, optional): The text content for the element.

Returns the created HTML element.

Examle:

const button = nathiLib.createHTMLElement(
  "button",
  { id: "myButton", class: "btn" },
  "Click me"
);
appendChildren(parent, childrenArray);

Append an array of children to a parent element.

  • parent (HTMLelement): The parent element to which the children will be appended.
  • childrenArray (Array): An array of HTML elements to append to the parent.
addClass(element, className);

Add a class to the specified element.

  • element (HTMLElement): the element to which the class will be added.
  • className (string): The name of the class to too.
removeClass(element, className);
  • element (HTMLElement): The element from which the class will be removed.
  • className (string): The name of the class to remove.
on(selectorOrElement, eventName, callback);

Adds an event listener to the specified element or element found by the provided CSS selector.

  • selectorOrElement (string | HTMLElement): The CSS selector string or DOM element to which the event listener should be added.
  • eventName (string): The name of the event to listen for.
  • callback (Function): The function to be called when the event occurs.
const nathiLib = new NathiLib();

// Using a CSS selector string
nathiLib.on("#example", "click", () => {
  console.log("Element clicked");
});

// Using a DOM element
nathiLib.on(document.getElementById("example"), "click", () => {
  console.log("Element clicked");
});

Project Structure

The nathi library has been organized using a separation of concerns approach, with each method placed in its own file inside the src folder. The index.js file imports and exports these methods as part of the NathiLib class. This structure makes it easier to maintain and add new features.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.