# smart-handlebars

> 'smart-handlebars' is a powerful Handlebars templating extension that enhances your frontend development capabilities. It extends the standard Handlebars functionality with a suite of additional functions, making it a versatile tool for web developers. Wi

Latest version **1.0.7** (published 2025-06-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install smart-handlebars
pnpm add smart-handlebars
yarn add smart-handlebars
bun add smart-handlebars
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

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

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2025-06-25 |
| First published | 2023-10-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Viral Dudhat |
| Maintainers | viral.dudhat |
| Keywords | handlebars functions, templating extensions, mathematical operations, rounding, text transformations, averaging, number formatting, case conversion, percentage calculations, frontend utilities |

## Links

- npm: https://www.npmjs.com/package/smart-handlebars
- npm.io page: https://npm.io/package/smart-handlebars

## Dependencies (1)

- [handlebars](https://npm.io/package/handlebars.md) ^4.7.8

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2025-06-25
- 1.0.6 — 2025-06-25
- 1.0.5 — 2024-10-23
- 1.0.4 — 2024-03-12
- 1.0.3 — 2023-10-12
- 1.0.2 — 2023-10-12
- 1.0.1 — 2023-10-12
- 1.0.0 — 2023-10-12

## README

# smart-handlebars

This npm package provides a collection of useful Handlebars.js helpers to perform common operations in your templates. These helpers can be used to simplify and enhance your Handlebars templates.

## Installation

You can install the package using npm:

```bash
npm install smart-handlebars
```

# Usage

To use the provided helpers in your Handlebars templates, first, import the package:

## Helper Functions

### Addition

**Description:** Adds the value to the variable in the template context.

**Syntax:**

```html
{{addition key val}}
```

**Example:**

```html
{{addition "total" 10}}
```

This will add 10 to the "total" variable in the template context.

### Subtraction

Description: Subtracts the value from the variable in the template context.

**Syntax:**

```html
{{subtraction key val}}
```

**Example:**

```html
{{subtraction "balance" 5}}
```

This will subtract 5 from the "balance" variable in the template context.

### Round

Description: Rounds a number to the nearest integer.

**Syntax:**

```html
{{round val}}
```

**Example:**

```html
{{round 3.7}}
```

This will round 3.7 to 4

### Ceil

Description: Rounds a number up to the nearest integer.

**Syntax:**

```html
{{ceil val}}
```

**Example:**

```html
{{ceil 2.3}}
```

This will round 2.3 up to 3.

### Floor

Description: Rounds a number down to the nearest integer.

**Syntax:**

```html
{{floor val}}
```

**Example:**

```html
{{floor 4.8}}
```

This will round 4.8 down to 4.

### Percentage

Description: Calculates the percentage of parVal relative to totVal.
**Syntax:**

```html
{{percentage parVal totVal}}
```

**Example:**

```html
{{percentage 25 100}}
```

This will calculate the percentage of 25 relative to 100, resulting in 25%.

### toFixed

Description: Formats a number to a fixed number of decimal places.
**Syntax:**

```html
{{toFixed val num}}
```

**Example:**

```html
{{toFixed 3.14159 2}}
```

This will format 3.14159 to two decimal places, resulting in "3.14".

### toUpperCase

Description: Converts a string to uppercase.
**Syntax:**

```html
{{toUpperCase str}}
```

**Example:**

```html
{{toUpperCase "Hello World"}}
```

This will convert "Hello World" to "HELLO WORLD".

### toLowerCase

Description: Converts a string to lowercase.
**Syntax:**

```html
{{toLowerCase str}}
```

**Example:**

```html
{{toLowerCase "Hello World"}}
```

This will convert "Hello World" to "hello world".

### Avg

Description: Calculates the average of a sum of values.
**Syntax:**

```html
{{avg sum len}}
```

**Example:**

```html
{{avg 30 5}}
```

This will calculate the average of 30 (sum) and 5 (len), resulting in 6.

### getNumberSuffix

Description: Returns the appropriate suffix for a given number (e.g., "st", "nd", "rd", or "th").
**Syntax:**

```html
{{getNumberSuffix number}}
```

**Example:**

```html
{{getNumberSuffix 21}}
```

This will return "st" as the suffix for the number 21.

### inc

Description: Increments the given value by 1.

**Syntax:**

```html
{{inc value}}
```

**Example:**

```html
{{inc 5}}
```

This will increment the value 5 by 1, resulting in 6.

### ifCond

Description: Allows you to create conditional statements in your Handlebars templates. It compares two values using various operators and executes the appropriate block of code based on the comparison result.

**Syntax:**

```html
{{#ifCond v1 operator v2}}
<!-- Code to execute when the condition is true -->
{{else}}
<!-- Code to execute when the condition is false -->
{{/ifCond}}
```

**Example:**
Equal (==) Operator

```html
{{#ifCond 5 '==' 5}} The values are equal. {{else}} The values are not equal. {{/ifCond}}
```

This will output: "The values are equal."
Not Equal (!=) Operator

```html
{{#ifCond 5 '!=' 3}} The values are not equal. {{else}} The values are equal. {{/ifCond}}
```

This will output: "The values are not equal."

You can use various operators, including ==, ===, !=, !==, <, <=, >, >=, &&, and ||, to create different conditional statements in your templates.

-- With these descriptions and usage examples, users of your npm package will have a clear understanding of how to use each helper function in their HTML templates.

### inWords

Description: Converts a number into words representation.

**Syntax:**

```html
{{inWords num}}
```

**Example:**

```html
{{inWords 12345}}
```

This will convert the number 12345 into "Twelve Thousand Three Hundred Forty-Five Only".

# `stringReplace` Handlebars Helper

## Overview

The `stringReplace` helper is a custom Handlebars function that replaces all occurrences of a specific substring within a given string with another substring. This can be especially useful when dynamically manipulating text inside templates.

## Usage

### Syntax

```handlebars
{{stringReplace str strToReplace replaceWith}}
```

**Example:**

```html
{{stringReplace 'Hello Handlebars' 'Handlebars' 'World'}}
```

# `resolveNestedTemplate` Handlebars Helper

## Overview

The `resolveNestedTemplate` helper is a custom Handlebars function that compiles and renders a string containing Handlebars syntax inside another template. This is especially useful when your data includes template strings that need to be evaluated with the current context.

## Usage

### Syntax

```handlebars
{{{resolveNestedTemplate templateString}}}
```

**Example:**

### Input

```{{!-- content = "Hello, {{name}}" --}}
<html>
  <body>{{{resolveNestedTemplate content}}}</body>
</html>
```

### Context

```{
  "name": "Smartsense",
  "content": "Hello, {{name}}"
}
```

### Output

```
<html>
  <body>Hello, Smartsense</body>
</html>
Output
```

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