Socket
Book a DemoInstallSign in
Socket

smart-template-injector

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-template-injector

You can process an template injecting stretches of anything with an context object.

0.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

smart-template-injector

You can process an template injecting stretches of anything with an context object.

Usage

npm install smart-template-injector

Selectors

You can use basically on pattern to select inject tag:

  • /*inject:*/

After of : you can put the property name of the object what you want to use.

Simple example

var smartTemplateInjector = require('smart-template-injector');

var template = ""
	+ "/*inject:libs*/\n"
	+ "\n"
	+ "var smartSomeFunction = {\n"
	+ "	someFunction: SomeFunction\n"
	+ "};\n"
	+ "\n"
	+ "module.exports = smartSomeFunction;\n"
	+ "\n"
	+ "function SomeFunction() {\n"
	+ "	console.log('All right.');\n"
	+ "};\n"
	+ "\n"
	+ "/*inject:function*/\n";

var obj = {
	libs: "var path = path || require('path');\nvar fs = fs || require('fs');",
	function: "function AnotherFunction() {\n	console.log('All ok.');\n};"
};  

console.log(smartTemplateInjector.inject(template, obj));
  

Anyway we can go more deep and complex

var smartTemplateInjector = require('smart-template-injector');

var template = ""
	+ "/*inject:module.libs*/\n"
	+ "\n"
	+ "var smartSomeFunction = {\n"
	+ "	someFunction: SomeFunction\n"
	+ "};\n"
	+ "\n"
	+ "module.exports = smartSomeFunction;\n"
	+ "\n"
	+ "function SomeFunction() {\n"
	+ "	console.log('All right.');\n"
	+ "};\n"
	+ "\n"
	+ "/*inject:module.function*/\n";

var obj = {
	module: {
		libs: "var path = path || require('path');\nvar fs = fs || require('fs');",
		function: "function AnotherFunction() {\n	console.log('All ok.');\n};"
	}
};  

console.log(smartTemplateInjector.inject(template, obj));
  

News

0.0.1 Project start. 0.0.2 Fix inject function to respect line breaks.

Danke

Keywords

template

FAQs

Package last updated on 11 May 2016

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.