Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hbs-dedent-helper

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hbs-dedent-helper

A simple handlebars helper to dedent blocks of text in handlebars.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.4K
decreased by-12.72%
Maintainers
1
Weekly downloads
 
Created
Source

Handlebars dedent helper

A simple handlebars helper to dedent blocks of text in handlebars.

Very often, when using block helpers our code would end up nested more than it should be. Which can be problematic for code-generators:

if (foo) {
    {{#each items}}
        console.log('{{.}}')
    {{/each}}
}

generates something like:

if (foo) {
        console.log('a');
        console.log('b');
}

This is visually unappealing. In addition, for indentation sensitve languages this can break the code.

To solve this we provide two helpers:

  1. dedent helper:

(Dedents a block of code by one level)

if (foo) {
    {{#each items}}
        {{#dedent}}
        console.log('{{.}}')
        {{/dedent}}
    {{/each}}
}

One level defaults to 4 spaces. But this is configurable through setLevelSize & setLevelChar:

import {setLevelSize} from "hbs-dedent-helper";

// Configure dedent helper to use 1 tab
setLevelSize(1);
setLevelChar('\\t');
  1. dedent-by helper provides more control:
if (foo) {
    {{#dedent-by 2 "level"}}
        {{#each items}}
            console.log('{{.}}')
        {{/each}}
    {{/dedent-by}}
}

We can also explicitly use tabs or spaces:

if (foo) {
    {{#dedent-by 8 "spaces"}}
        {{#each items}}
            console.log('{{.}}')
        {{/each}}
    {{/dedent-by}}
}
if (foo) {
    {{#dedent-by 2 "tabs"}}
        {{#each items}}
            console.log('{{.}}')
        {{/each}}
    {{/dedent-by}}
}

Installation

npm install --save handlebars hbs-dedent-helper

Registration

import {register} from "hbs-dedent-helper";

register();

FAQs

Package last updated on 12 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc