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

include-by-tag

v0.0.5

Published

Include files by tag asynchronously

Readme

Include by tag

Library to include a file(s) within another file. It will not work on circular imports due to recursive strategy.

For example we have some configuration hierarchy of JSON configuration files:

config
├── main.json
├── entries.json
├── colors.json
└── templates
    ├── number.json
    ├── string.json
    └── boolean.json

With content

main.json

{
    "name": "ibt",
    "date": "2000-01-01T00:00+02:00",
    "entries": "!include entries.json",
    "templates": "!include templates/*.json"
}

entries.json

{
    "actions": [ "To be", "Not to be" ],
    "colors": "!include colors.json"
}

colors.json

[
    { "name": "black", "type": "boolean" },
    { "name": "white", "type": "boolean" },
    { "name": "red", "type": "number" },
    { "name": "blue", "type": "string" },
    { "name": "green", "type": "string" }
]

number.json

{
    "name": "number",
    "prop": "Final countdown"
}

string.json

{
    "name": "string",
    "prop": "A word is enough to the wise"
}

boolean.json

{
    "name": "boolean",
    "prop": "Bisected world"
}

And if we will reading main.json config we can asynchronously read included files:

main.json ->| entries.json ->| colors.json ->|
            |         boolean.json         ->|
            |         number.json          ->|
            |         string.json          ->|

-------------------------------------------->| Full config

Final JSON will look like:

{
    "name": "ibt",
    "date": "2000-01-01T00:00+02:00",
    "entries": {
        "actions": [ "To be", "Not to be" ],
        "colors": [
            { "name": "black", "type": "boolean" },
            { "name": "white", "type": "boolean" },
            { "name": "red", "type": "number" },
            { "name": "blue", "type": "string" },
            { "name": "green", "type": "string" }
        ]
    },
    "templates": [
        { "name": "boolean", "prop": "Bisected world" },
        { "name": "number", "prop": "Final countdown" },
        { "name": "string", "prop": "A word is enough to the wise" }

    ]
}

Usage

const IBT = require('include-by-tag');
const yaml = require('js-yaml');

const options = {
    parser: { parse: yaml.safeLoad },
    includeTag: '!Include'
};

const ibt = new IBT(options);

ibt.read('/etc/superapp/config.yml', '/usr/lib/superapp/config.yml')
    .then(config => {
        console.log(config);
    });

~include~ string recognize globs. All globs interpreted like array. So value !include tests/*.json and file tests/first.json with content { "first": "test" } will be recognized as

{
  "tests": [{ "first": "test" }]
}

Included files are sorted alphabetically.

API

new IBT(options);

Options
  • parser (Object, default: JSON): Any object that has .parse method. It must return parsed Object. For example, to use YAML parser options must look like { parser: { parse: require('js-yaml').safeLoad }}
  • includeTag (String, default: !include): Tag for include. Filepath followed by tag, ex. !include ext/file.json

Methods

ibt.read(filepath, [...filepath])

read() is a primary method to read file includes. If method call with multiple filepaths, it will be merged after full files reading and composing like Object.assign(parsedFile0, parsedFile1, ...). Method return promise, with object as argument.