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

proto-component

v0.0.4

Published

This is a very minimal tool to split your HTML into pieces and inject them as if they were components.

Downloads

3

Readme

ProtoComponent

TL;DR

This is a very minimal tool to split your HTML into pieces and inject them as if they were components.

Motivation

Let's say you get tasked with making a HTML (and its stylesheet) as a scaffold for a new dashboard and it end up looking amazing with its main section, the surrounding layout, menus, navbars, etc., all the goodies.

Now you want to create another HTML that showcases the same but with a different main content. So you make a copy of the previous HTML and replace the main section.

Now someone points out that the menu should have two or three more items in it... so... do you make the same change in both HTMLs?... what if you already have 10 copies with different main contents?

The first and not bad at all solution is to migrate to Angular, VueJS, React or some other similar framework, but that's a lot of code, work and configuration for simple HTML scaffold that will most likely get chopped off into pieces and integrated into a framework.

So, at this point you want to be able to inject common of HTML pieces as if they were components, but you don't want the headache of configuring a big framework... well, here is where ProtoComponent comes in.

Installation with NPM

To install it use this command:

npm install proto-component

Then add this at the of your <body> tag.

<script src="node_modules/proto-component/dist/proto-component.min.js"></script>

Direct Use

If you don't even use NPM, you can just simply download one of these links:

And then simply added it as:

<script src="proto-component.min.js"></script>

Example

Supposed Structure

For this examples we're going to suppose this list of assets:

  • /
    • _proto/
      • footer.html
      • menu.html
    • index.html

Index Example

This is an example of a html file using ProtoComponent:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example</title>

    <link rel="stylesheet" href="https://bootswatch.com/4/pulse/bootstrap.min.css">
</head>

<body>
    <proto-component proto="menu"></proto-component>

    <div class="container pt-3">
        <div class="row">
            <div class="col">
                <div class="card">
                    <div class="card-header">Title</div>

                    <div class="card-body">
                        Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni sapiente rerum quo voluptatum sit
                        architecto, cumque corrupti. Veritatis, in voluptatum.
                    </div>
                </div>
            </div>
        </div>

        <proto-component proto="footer.html"></proto-component>
    </div>

    <script src="https://bootswatch.com/_vendor/jquery/dist/jquery.min.js"></script>
    <script src="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

    <script src="node_modules/proto-component/dist/proto-component.min.js"></script>
</body>

</html>

This example uses the great Bootswatch, please visit their page (Disclaimer: We are not associated with Bootswatch).

Other Pieces

menu.html

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01"
        aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarColor01">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="#">Home
                    <span class="sr-only">(current)</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Features</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
                    aria-expanded="false">Dropdown</a>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="#">Action</a>
                    <a class="dropdown-item" href="#">Another action</a>
                    <a class="dropdown-item" href="#">Something else here</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#">Separated link</a>
                </div>
            </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="text" placeholder="Search">
            <button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
        </form>
    </div>
</nav>

footer.html

<hr class="mt-5" />

<div class="row">
    <div class="col text-center">
        This is a footer!
    </div>
</div>

Proto Configuration

If you don't like the name of the folder _proto you can simply change it doing this:

<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- . . . -->
    </head>
    <body>
        <proto-config>
            {
            "sources": "my-directory"
            }
        </proto-config>

        <!-- . . . -->

        <script src="node_modules/proto-component/dist/proto-component.min.js"></script>
    </body>
</html>

You could also use a file for you configuration doing something like this:

<proto-config src="my-conf.json"></proto-config>

Assets

proto-config also allows you to quickly list the list of CSS and JS files you want to add, for example, you can replace this:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example</title>

    <link rel="stylesheet" href="https://bootswatch.com/4/pulse/bootstrap.min.css">
</head>

<body>
   <!-- ... -->

    <script src="https://bootswatch.com/_vendor/jquery/dist/jquery.min.js"></script>
    <script src="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

    <script src="node_modules/proto-component/dist/proto-component.min.js"></script>
</body>

</html>

With this:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example</title>
</head>

<body>
    <proto-config>
        {
            "scripts": [
                "https://bootswatch.com/_vendor/jquery/dist/jquery.min.js",
                "https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.bundle.min.js"
            ],
            "styles": [
                "https://bootswatch.com/4/pulse/bootstrap.min.css"
            ]
        }
    </proto-config>

    <!-- ... -->

    <script src="node_modules/proto-component/dist/proto-component.min.js"></script>
</body>

</html>