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

pinak-html

v1.0.0

Published

Effortlessly convert HTML into virtual nodes with our versatile parsing library, empowering seamless DOM manipulation in your applications.

Downloads

3

Readme

pinak-html

Welcome to the official documentation for pinak-html! This parsing library seamlessly converts HTML into virtual nodes, providing powerful DOM manipulation capabilities for your applications.

Introduction

pinak-html is a JavaScript library designed for parsing and converting HTML into virtual nodes (JavaScript objects). While originally developed for PinakJs, it is also compatible with other frameworks, such as ReactJs, that require virtual nodes. The library's syntax closely resembles JSX, with the only difference being the use of JavaScript template syntax instead of curly braces for expressions.

<div id={10}>Hello {'World'}</div>

// Equivalent with this library
htm`<div id=${10}>hello ${'World'}</div>`

Installation

  • Install pinak-html using your preferred package manager. Open your terminal and run:

    # using npm
    npm install pinak-html
    
    # using pnpm
    pnpm add pinak-html
  • Or use CDN, if you need to use it directly in the broowser. For Local project download it directly from CDN links.

    <!-- This'll created `PinakHtml` global variable. -->
    <script src="https://cdn.jsdelivr.net/npm/pinak-html"></script>
    
    <!-- Or you nedd any specific version -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

Features

  • Efficient creation of virtual nodes from HTML strings.
  • Lightweight and optimized for performance.
  • MIT licensed for flexibility in usage.

Getting Started

To start using pinak-html, follow these steps:

  1. Import the library:

    Import the library into your project like this:

    import PinakHtml from 'pinak-html';

    If you are using CDNs then PinakHtml will be available library.

  2. Create instance

    Create an instance of PinakHtml by providing a node builder function and, if needed, a directive builder function (useful for PinakJs).

    const html = PinakHtml(
        (name, props, children) => ({ name, props, children }), 
        (name, value, ...rest) => ({ name, value, rest })
    )
    
    // If using Pinakjs
    import { use, h } from 'pinak'
    
    const html = PinakHtml(h, use)
  3. Parsing Html

    Now use the html function to parse HTML from a string.

    const result = html`<div>Hi! From Pinak.</div>`
    console.log(result)
    
    // {
    //     type: 'div',
    //     props: null,
    //     children: "Hi! From Pinak."
    // }

    It is not necessary to write a single-root HTML; this library can parse multi-root HTML as well.

    const result = html`<h1>Hi!</h1><span> From Pinak.</span>`
    console.log(result)
    
    // [
    //     {
    //         type: 'h1',
    //         props: null,
    //         children: "Hi!"
    //     },
    //     {
    //         type: 'span',
    //         props: null,
    //         children: " From Pinak."
    //     }
    // ]

    Like JSX, JavaScript expressions can be used in the HTML.

    const result = html`<h1>Count: ${100}</h1>`
    console.log(result)
    
    // {
    //     type: 'h1',
    //     props: null,
    //     children: 'Count: 100'
    // }
    
    /* or */
    const dummyFn = () => {}
    const result = html`<${dummyFn}>Count: ${dummyFn}<//>`
    console.log(result)
    
    // {
    //     type: () => {},
    //     props: null,
    //     children: [
    //         'Count: ',
    //         () => {}
    //     ]
    // }

    HTML elements also have props.

    const result = html`<h1 name="h1" id=${10} other />`
    console.log(result)
    
    // {
    //     type: 'h1',
    //     props: {
    //         name: 'h1',
    //         id: 10,
    //         other: true
    //     },
    //     children: null
    // }

    If you are using PinakJs ], directives can be used as follows.

    html`<div use:input="value" ></div>`
    
    html`<div use:${countFn} ></div>`
    
    html`<div use:${countFn}="value" ></div>`
    
    html`<div use:input=${countFn} ></div>`
    
    html`<div use:input></div>`
    
    html`<div use:input:opt1:opt2=${countFn} ></div>`

Contribution

Contributions to pinak-html are welcome! If you have any bug fixes, improvements, or new features to propose, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Implement your changes and ensure all tests pass.
  4. Submit a pull request describing your changes and their purpose.

License

pinak-html is released under the MIT license. For more information, please refer to the LICENSE file.


Thank you for choosing pinak-html! If you have any questions or need assistance, feel free to reach out via email or by opening an issue on the GitHub repository. We hope this library enhances the reactivity of your JavaScript applications. Happy coding!