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 🙏

© 2026 – Pkg Stats / Ryan Hefner

containsjs

v0.1.6

Published

ContainsJS

Readme

ContainsJS

ContainsJS is a tool to help create HTML using include. This means you can include any .html file inside your main html page. Helps you to reuse your code on other pages.

  • Create your HTML snippets  - Instantiate ContainsJS and pass your views folder's path as parameter
  • Include any .html to your pages.

Dependencies

ContainJS needs jQuery in your project to work.

Installation

There's two ways of using ContainsJS

NPM

On Windows
$ cd into_your_app_root_folder
$ mkdir views
$ npm install contain -s
$ move /node_modules/constainsjs/contains.js /public/scripts/
On Linux/Mac
$ cd into_your_app_root_folder
$ mkdir views
$ npm install contain -s
$ mv /node_modules/constainsjs/contains.js /public/scripts/

CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/contains.js"></script>

In your HTML

<head>
    <!-- Your jQuery Import goes here -->
    <script src="/scripts/contains.js"></script>
</head>

Usage

After you've included Contain in your project, open your main JS file. Instantiate ContainsJS document.ready.

$(document).ready(() => {
    // -> "/views/" is the path of the views folder we created.
    // Must contain / before and after the folder path.
    var contains = new ContainsJS('/views/'); 
    contains.include('header.html');
});

In your main HTML file, use the <contains> tag.

<body>
    <contains view="header"></contains>
</body>

Note that inside <contains> the name of the file you used inside your JS, is the same as the one in HTML, apart from the .html which is not necessary in HTML.

Inside your views folder, create a header.html file.

<div>
    <nav>
        <ul>
            <li><a href="http://npmjs.org/packages/containsjs">Contain</a></li>
        </ul>
    </nav>
</div>

Using JS with your view.

If you want to include new script to your views, instantiate like this:

containjs.include('test.html', ['./test.js', './test2.js']);

Where the second parameter is a scripts array. Specify the path only from the views folder you defined. Example: Files test.js and test2.js inside /views folder.

Or even scripts from other sources

containjs.include('test.html', ['https://www.script.com/script']);

You can also run inline scripts in your HTML

<div>
    <nav>
        <ul>
            <li><a href="http://npmjs.org/packages/containsjs">Contain</a></li>
        </ul>
    </nav>
</div>
<script>alert("Hello, I'm working!")</script>

Include function with Promise

If you need synchronous including of your code, use the Promise in the function.

contains.include("header.html", [".header.js"]).then(() => {
        // Now your HTML is included.
});

Custom Variables inside HTML

If you want to use custom variables inside your HTML, you can do so by doing like this:

containjs.include('teste.html',['./teste.js'], {name: 'Bob'});

Where the third parameter is a object with the same name you will specify on your HTML.

And to access it on your HTML:

<div>
    <nav>
        <ul>
            <li><a href="http://npmjs.org/packages/containsjs">Contain</a></li>
            <p>$name</p>
        </ul>
    </nav>
</div>
<script>alert("Hello $name, I'm working!")</script>

Add the same variable with a $ in front of it.

Append Elements

There's two ways to append elements to your included HTML.

With raw elements

contains.append("table.html", "<tr>Test</tr>")

Or with another view

contains.append("table.html", null, "table-element.html", {name: "Test", age: "18"}).then(() => {
    // Now your HTML is included.
}) 

The function takes 4 parameters, if you are using the raw element, you only need to pass your view, and the element to be included.

If you want to include another view to it, you need to pass your view, null, the path to the other view and optionally a attributes object to be included.

Extras

You can also hide/show your views programmatically.

You don't need to use show on your newly created <contains></contains>. The show function can be used for transitions for example.

    contains.show('header.html');
    contains.hide('footer.html');

Notes

   You can include as many tags you want, and you only need to instantiate each one, only one time.

    <contains view="header"></contains>
    <contains view="body"></contains>
    <contains view="footer"></contains>
    $(document).ready(() => {
    var contains = new ContainsJS('/views/'); 
    contains.include('header.html');
    contains.include('body.html');
    contains.include('footer.html');
});

Licence

MIT

Edison Cury Neto