Coder Social home page Coder Social logo

compile-template's Introduction

@anikghosh256/compile-template

Build and Test NPM version NPM

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 string
  • lowercase(string) - Converts a string to lowercase
  • uppercase(string) - Converts a string to uppercase
  • pluralize(string) - Change the word to its plural
  • singularize(string) - Change the word to its singular
  • capPluralize(string) - capitalize + pluralize
  • capSingularize(string) - capitalize + singularize
  • time() - return timestamp

Notes

  • You can't provide whitespace in the function name, so capitalize (name) won't work. You can use capitalize(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.

compile-template's People

Contributors

anikghosh256 avatar

Watchers

 avatar  avatar

compile-template's Issues

Add some basic functions.

Example:

/*
* Math related
* /
math() // for mathematic operations. ex: math( 1 + a) where 'a' is a user define variable. 

/*
* String related
* /
uppercase() //  ex: uppercase('hi') -> 'HI'
lowercase() // ex: lowercase('hI') -> 'hi'
word() // ex: word('hi') -> 'Hi'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.