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

hcl2-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hcl2-parser

HCL v2 parser for JavaScript

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

HCL v2 parser for JS

This is a HCL version 2 parser for JavaScript, there are several other JS parsers for HCL but none that support the newer HCL v2 syntax

It wraps the very helpful tmccombs/hcl2json and calls the convert package in order to parse HCL input strings to JSON strings. The Go code in parser.go is converted to JS using GopherJS

TypeScript definitions are included

Reference

The module exports the following functions:

function parseToString(input: string): string
function parseToObject(input: string): any

Usage

Install as normal with NPM

npm install hcl2-parser

Importing into your project

// Good old fashioned Node.js CommonJS require
const hcl = require("hcl2-parser")

// Import with ES6 or TypeScript
import * as hcl = from "hcl2-parser"

Simple example of usage

const hcl = require("hcl2-parser")

const hclString = `
# Create a resource group
variable "azureRegion" {
  type = string
  default = "uksouth"
}
resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = var.azureRegion
}
`

// Parse into a JSON string
stringResult = hcl.parseToString(hclString)
console.log(stringResult)

// Parse into an object, the actual result is in array index 0 for reasons I don't understand
objectResult = hcl.parseToObject(hclString)
console.log(objectResult[0].resource.azurerm_resource_group)

Keywords

FAQs

Package last updated on 07 May 2021

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