JSPM

template-insert

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q9633F
    • License MIT

    Create templates with placeholders and insert variables into the placeholders. Works with every text but was designed for HTML files.

    Package Exports

    • template-insert
    • template-insert/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (template-insert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    template-insert

    Create templates with placeholders and insert variables into the placeholders. Works with every text but was designed for HTML files.

    Install the package:

    npm install template-insert

    Replace placeholders without a file

       import {replaceContent} from "template-insert"
        
       const replacement = replaceContent("Normal text {{replaceme}} Normal text again",
         {
            replaceme: "Replaced Placeholder"
         }
        )
        
        //Result: 'Normal text Replaced Placeholder Normal text again'

    Replace placeholders from a file

       import {replaceContent} from "template-insert"
       import {readFileSync} from "fs"
       
       const content = readFileSync("./index.html", {encoding: "utf8"})
       const replacement = replaceContent(content,
         {
            replaceme: "Replaced Placeholder",
            replacemetoo: "Another Placeholder"
         }
        )