Skip to content

tiveor/scg

Repository files navigation

SCG a Random Library for Generators
Build Status npm version

Installation

npm install @tiveor/scg

Basic usage

const { StringHelper } = require('@tiveor/scg');
const replaced = StringHelper.replace('This is a {{test}}', '{{test}}', 'joke');
// replaced = "This is a joke"

TemplateBuilder usage

const { TemplateBuilder, TEMPLATE_HANDLERS } = require('@tiveor/scg');

const ejsBuilder = new TemplateBuilder(TEMPLATE_HANDLERS.EJS);
ejsBuilder
  .render('This is a <%= test %>', {
    test: 'joke'
  })
  .then((replaced) => {
    // replaced = "This is a joke"
  });

const pugBuilder = new TemplateBuilder(TEMPLATE_HANDLERS.PUG);
pugBuilder
  .render('This is a #{test}', {
    test: 'joke'
  })
  .then((replaced) => {
    // replaced = "This is a joke"
  });

const handlebarsBuilder = new TemplateBuilder(TEMPLATE_HANDLERS.HANDLEBARS);
handlebarsBuilder
  .render('This is a {{test}}', {
    test: 'joke'
  })
  .then((replaced) => {
    // replaced = "This is a joke"
  });

Example

node example/index.js

For more information about templates visit the official documentation for each one: