# @novigi/template-engine

> Zero dependency stand-alone general purpose template engine for super fast templating 🛠

Latest version **1.0.0-1** (published 2022-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @novigi/template-engine
pnpm add @novigi/template-engine
yarn add @novigi/template-engine
bun add @novigi/template-engine
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-1 |
| Published | 2022-11-04 |
| First published | 2022-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Novigi |
| Maintainers | buddhima, nov_user, madushak |

## Links

- npm: https://www.npmjs.com/package/@novigi/template-engine
- npm.io page: https://npm.io/package/@novigi/template-engine

## Recent versions

- 1.0.0-1 (latest) — 2022-11-04
- 1.0.0-0 — 2022-10-20

## README

![npm (scoped)](https://img.shields.io/npm/v/@novigi/template-engine) ![NPM](https://img.shields.io/npm/l/@novigi/template-engine) ![Statements](https://img.shields.io/badge/statements-100%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-100%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-100%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-100%25-brightgreen.svg?style=flat)
# @novigi/template-engine

Zero dependency stand-alone general purpose template engine for super fast templating 🛠

## 🐿 Features

- Supports nested obejects → `'${deeply.nested.objects.are.supported}'`
- Reusable templates → you can have the template in a varable!
- lightweight, error free and super fast templating
- Javascript template literals style

## 📦 Getting Started

1. Install the dependency
```
npm install @novigi/template-engine
```

2. Import the library
```
const lib = require('@novigi/template-engine');
```

## 📖 Documentation

<a name="module_template"></a>

## template
Templates enable fast rendering of the server-side data that needs to be passed to the application.The template engine replaces the variables in a template file with actual values, and displays this value to the client. This makes it easier to quickly build our application. This is the guideline of compile-time text rendering capability.

```js
const { template } = require('@novigi/template-engine')

template.render('We are from ${city}!', {city: 'Colombo'})  // We are from Colombo
// or simply
'We are from ${city}!'.render({city: 'Colombo'})            // We are from Colombo
```


* [template](#module_template)
    * _static_
        * [.render(templatedText, context)](#module_template.render) ⇒ <code>string</code>
    * _inner_
        * [~String](#external_String)
            * [.render(context)](#external_String+render) ⇒ <code>String</code>

<a name="module_template.render"></a>

### template.render(templatedText, context) ⇒ <code>string</code>
This function render a text, based on the templatedText and contextObject.

**Kind**: static method of [<code>template</code>](#module_template)  
**Returns**: <code>string</code> - rendered text  

| Param | Type | Description |
| --- | --- | --- |
| templatedText | <code>string</code> | templated text that needs to be replaced with context objects values |
| context | <code>object</code> | object that contains values for template |

**Example**  
```js
template.render('${city} is a coastal city', {city: 'Sydney'})  // Sydney is a coastal city

let ctx = {
 location: {
    city: {
      state: 'NSW'
    }
  }
}
template.render('${location.city.state} is the state!', ctx)   // NSW is the state!
```
<a name="external_String"></a>

### template~String
Extension methods to built in String object.

**Kind**: inner external of [<code>template</code>](#module_template)  
<a name="external_String+render"></a>

#### string.render(context) ⇒ <code>String</code>
Extension method to the String object to call `render()` method with context object.

**Kind**: instance method of [<code>String</code>](#external_String)  
**Returns**: <code>String</code> - rendered text  

| Param | Type | Description |
| --- | --- | --- |
| context | <code>object</code> | object that contains values for template |

**Example**  
```js
'We are from ${city}!'.render({city: 'Colombo'})   // We are from Colombo
```

_This is an auto generated file. Please don't make changes manually_

---
_Source: https://npm.io/package/@novigi/template-engine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
