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

infuser

v0.0.3

Published

If you're looking for an easy way to extract or update dynamic content within static files, this library has got you covered! With `getSlots`, you can quickly extract the content of slots or placeholders within your files. And with `updateSlots`, you can

Downloads

8

Readme

infuser

If you're looking for an easy way to extract or update dynamic content within static files, this library has got you covered! With getSlots, you can quickly extract the content of slots or placeholders within your files. And with updateSlots, you can effortlessly replace the content of these slots with new content. Say goodbye to the hassle of manually updating static files with dynamic content. Let infuser do the heavy lifting for you and streamline your workflow like never before!

Installation

Yarn

yarn add infuser  

NPM

npm install infuser --save  

Use

Node

import { updateFile, SlotUpdate } from "infuser";

const filePath = "./example.html";
const updates: Array<SlotUpdate> = [
  {
    slotName: "header",
    newContent: "<h1>New header content</h1>",
  },
  {
    slotName: "footer",
    newContent: "<p>New footer content</p>",
  },
];

updateFile(filePath, updates)
  .then(() => {
    console.log("File successfully updated");
  })
  .catch((error) => {
    console.error("An error occurred:", error);
  });

File structure

Infuser library uses special comments to identify slots in a file. Here's an example of how the file should look like:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- infuser start my-header -->
    <h1>Original header content</h1>
    <!-- infuser end my-header -->

    <div>
      <p>Content not inside a slot remains unchanged.</p>
    </div>

    <!-- infuser start my-footer -->
    <p>Original footer content</p>
    <!-- infuser end my-footer -->
  </body>
</html>

In this example, there are two slots: header and footer. When the updateFile function is called, the content between <!-- infuser start header --> and <!-- infuser end header -->, and <!-- infuser start footer --> and <!-- infuser end footer --> will be replaced with the new content specified in the updates array.

Infuser supports some common file formats out of the box, and you can specify the comment style for files it does not recognize.

Notice

This library is open source software released under the MIT license. See the LICENSE file for more information. This code is provided as-is, without any warranty or guarantee of any kind. Use at your own risk. I cannot be held responsible for any issues or damages that may arise from the use of this code. However, I have done my best to ensure that it is well-written and thoroughly tested, and I am always open to feedback and suggestions for improvement. Thank you for your understanding. I hope you enjoy using it and find it useful in your projects. If you have any questions or feedback, please don't hesitate to reach out.