@anikghosh256/compile-template
v1.4.0
Published
Minimal templates for Node.js
Downloads
67
Maintainers
Readme
@anikghosh256/compile-template
Minimal templates for Node.js
Installation
npm install @anikghosh256/compile-template
Usage
const compile = require('@anikghosh256/compile-template');
const compiled = compile('filedir/filename.ct', { name: 'John' }); // filepath and variables
Full example
├── root
│ ├── index.js
│ └── template.ct # template file you can use any extension
// index.js
const compile = require('@anikghosh256/compile-template');
const compiled = compile('template.ct', { name: 'John' }); // you can pass file content as third argument
console.log(compiled); // you can also write to a file or do whatever you want with the compiled template
<!-- template.ct -->
<h1>Hello, ${name}!</h1>
<h2>How are you? ${capitalize(name)}</h2>
<h3>Lowercase: ${lowercase(name)}</h3>
<!-- output -->
<h1>Hello, John!</h1>
<h2>How are you? John</h2>
<h3>Lowercase: john</h3>
Functions
capitalize(string)
- Capitalizes the first letter of a stringlowercase(string)
- Converts a string to lowercaseuppercase(string)
- Converts a string to uppercasepluralize(string)
- Change the word to its pluralsingularize(string)
- Change the word to its singularcapPluralize(string)
- capitalize + pluralizecapSingularize(string)
- capitalize + singularizetime()
- return timestamp
Notes
- You can't provide whitespace in the function name, so
capitalize (name)
won't work. You can usecapitalize(name)
instead. ${ name}
won't work. You can use ${name} instead.- You can use any extension for the template file, but it's recommended to use
.ct
for compile-template files.