Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

template-file

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

template-file

🔀 Replace {{ variables }} in all your files

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

template-file

🔀 Replace {{ variables }} in all your files

Build status

Use variables to replace template strings in any type of file.

⚠️ NOTE: As of right now, only shallow values can be used in files. We know this sucks, and there’s an open issue for it. However, we believe in releasing early and often.

Usage

template-file <dataFile> <sourceGlob> <destination>

Arguments

  • data - Data file in JSON; used to replace variables in source files
  • sourceGlob - Files to process; see glob for syntax
  • destination - Destination directory where processed files go

Examples

ℹ️ TIP: Remember to place single quotes around your arguments (if they contain asterisks, question marks, etc.) to keep your shell from expanding globs before template-file gets to consume them.

Just handle one file:

template-file data.json template.txt build/

Compile all .abc files in src/ to build/:

template-file stuff.json 'src/**/*.abc' build/

API

const { renderString, renderTemplateFile } = require('template-file')

const data = {
  company: "GS&F",
  adjective: "cool"
}

// Replace variables in string
renderString('{{ company }} is {{ adjective }}.', data) // 'GS&F is cool.'

// Replace variables in a file
renderTemplateFile('/path/to/file', data)
  .then(renderedString => console.log(renderedString)) // same as above, but from file

Install

With either Yarn or npm installed, run one of the following:

# If using Yarn, add to project:
yarn add template-file

# ...or install globally to use anywhere:
yarn global add template-file

# If using npm, add to project:
npm install --save template-file

# ...or install globally to use anywhere:
npm install --global template-file

License

MIT

FAQs

Package last updated on 05 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc