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

insert-file-content

v0.0.1

Published

Replace custom tokens and lines by file content

Readme

insert-file-content

insert-file-content (ifc) replace custom tokens and regular expression lines by file content.

Installation

As dependency

npm install insert-file-content

As dev dependency

npm install insert-file-content -D

Use from cmd line or install globally

npm install insert-file-content -g

Configuration

configuration can be set via config file, cmd line paramaters or ifc.ifcSync function parameters or combination of any.

Configuration options

srcDir : Source directory path for files to be replaced. If relative path (starts with ./ or ../), its always relative to where ifc process is started. Defaults to "./src".

outDir : Output directory path for files to be output after replac. If relative path (starts with ./ or ../), its always relative to where ifc process is started. Defaults to "./out".

tokens: Tokens to be replaced with file content. All files inside srcDir are searched for tokens and replaced with respective file content. Result files are placed under outDir. Tokens are provided as name:value format as shown below.

  tokens: {
    'token': 'file path'
  }

Example: 

  tokens: {
    '<!-- header here -->': './templates/header.html',
    'version-number': './templates/version.txt',
    '<!-- body here -->': './body.html',
    '<!-- inner header here -->': '../others/inner-header.html',
    '<!-- footer here -->': '/usr/templates/footer.html'
  },

Each token is replaced with respective file content provided in path. If relative path (starts with ./ or ../), its always relative to where ifc process is started. If template file contains matched tokens, template content is replaced with file content recursively. Defaults to {}.

lineRegExp : If source file content line matches regular expression, line is replaced with file content matching regular expression. This helps to provide both token and file path inside source file. Defaults to "".

Example: lineRegExp: 'filename=(.*.html)'

In Below html source file, lines 7 and 10 matches above regular expression and gets replaced with file path returned by regular expression (.*.html). In below case, line 7 gets replaced with file contents "./templates/body.html" and line 10 gets replaced with contents of "./templates/others/footer.html"

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<!-- filename=./templates/body.html -->
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<!-- filename=./templates/others/footer.html -->
</body>
</html>

config : Path to config file. If you wish to set configuration options from file, path to config file to read from. Config file should set all configuration options in json format. Defaults to "./ifc.json".

fileEncoding : File encoding format to use when reading files. Defaults to "utf8".

cleanOutDir : Delete outDir if exist on start. If true, outDir is deleted on start and re-created to output replaced files. See outDir configuration options for more details. Defaults to false

Example configuration file.

{
  cleanOutDir: false,
  config: "./ifc.json",
  fileEncoding: "utf8",
  lineRegExp: "filename=(.*.html)",
  outDir: "./out",
  srcDir: "./src",
  tokens: {
    '<!-- header here -->': './templates/header.html',
    'version-number': './templates/version.txt',
    '<!-- body here -->': './body.html',
    '<!-- inner header here -->': '../others/inner-header.html',
    '<!-- footer here -->': '/usr/templates/footer.html'
  },
}

USAGE:

As node source

const ifc = require('insert-file-content');
ifc.ifcSync({
  srcDir: './input',
  outDir: './output',
  tokens: {
    '<!-- header here -->': './templates/header.html',
    '<!-- body here -->': './templates/body.html',
    'version-number': './templates/version.txt',
    '<!-- inner header here -->': './templates/others/inner-header.html',
    '<!-- footer here -->': './templates/footer.html'
  },
  lineRegExp: 'filename=(.*.html)',
  cleanOutDir: true,
  config: './config.json'
});

From command line

ifc -h
Usage: ifc [options]

Options:
  -v, --version              output the version number
  -c, --config <config>      Config file path
  -e, --encoding <encoding>  File encoding when reading files to replace
  -l, --line <line>          Line regular expression
  -o, --out <out>            Output directory where files are saved after insert
  -s, --src <src>            Source directory where files to be inserted
  -t, --tokens <tokens>      Tokens to replace
  -C, --clean [clean]        Delete out directory if already exist before inserting file content (default: false)
  -h, --help                 output usage information

Cmd Example:

ifc -c ./config.json -e utf-8 --line 'filename=(.*.html)' -o ./outdir -s ./srcdir -t '<!-- header here -->:./templates/header.html,<!-- body here -->:./templates/body.html'