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

hbs-ast-to-str

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hbs-ast-to-str

Converts Handlebars Abstract Syntax Tree (AST) back to template string.

  • 1.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Handlebars AST to Template String hbs-ast-to-str Project Icon

Description

This project converts a Converts Handlebars Abstract Syntax Tree (AST) back to template string with processing( optional).

Installation

npm install hbs-ast-to-str

Usage

with out any modification options

const {convertAstToString} = require('hbs-ast-to-str');
const ast = {
  /* Your Handlebars AST using Handlebars.parse(template_str)*/
};
const template = convertAstToString(ast);

with modification options

const {convertAstToString} = require('hbs-ast-to-str');

const ast = {
  /* Your Handlebars AST using Handlebars.parse(template_str)*/
};
const options: ModificationOptions = {
  helper: 'filter',
  paramType: HbsNodeTypes.SubExpression,
  paramPosition: 2,
  modifiers: [(d: string) => `'${d}'`],
};
const template = convertAstToString(ast, options);

API

convertAstToString(node: hbs.AST.Node | null, options: ModificationOptions): string

ModificationOptions Interface

The ModificationOptions interface is used to define a set of options for making modifications to a specific node or element in a Handlebars.js (Hbs) template. This interface is typically used in the context of custom Handlebars.js helpers or modifiers.

Interface Properties

  • helper: A string that specifies the name of the helper function. This property is optional and can be used to associate a modification with a particular helper.

  • paramType: An enumeration that represents the type of param that you want to modify. You can use HbsNodeType to specify the node type.

  • paramPosition: An integer that specifies the position of the parameter you want to modify. This is useful when dealing with helper parameters.

  • modifiers: An array of functions that define the modifications to be applied. Each function in the array should implement the logic for the modification.

Usage

Here's an example of how to use the ModificationOptions interface in TypeScript:

const options: ModificationOptions = {
  helper: 'customHelper',
  paramType: HbsNodeType.Block,
  paramPosition: 2,
  modifiers: [
    (parameterValue) => {
      // Implement your modification logic here.
      // Modify the 'parameterValue' as needed.
    },
    ...
  ],
};

Refer to spec file for more details.

License

MIT

Keywords

FAQs

Package last updated on 05 Nov 2023

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