Registry / devops / js-hcl-parser

js-hcl-parser

JSON →
library1.0.1jsnpmunverified

The `js-hcl-parser` package provides a fully functional JavaScript parser for HashiCorp Configuration Language (HCL), enabling seamless conversion between HCL syntax and JSON objects. Currently stable at version 1.0.1, its primary differentiator is its genesis: the JavaScript code is generated directly from the official HashiCorp HCL Go repository using `gopherjs`. This approach aims to ensure high fidelity and compatibility with the canonical HCL specification, making it a reliable choice for projects needing to interact with HCL configurations in a JavaScript environment. The library offers both parsing HCL strings into JSON and stringifying JSON back into HCL, catering to diverse configuration management needs. Release cadence is not explicitly stated but typically follows updates or major changes in the upstream HCL Go library.

npm install js-hcl-parser
INSTALL
IMPORT
SIG · JS-HCL-PARSER
J
js-hcl-parser
devopsjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HCL
import HCL from 'js-hcl-parser'
const HCL = require('js-hcl-parser')
The README examples use CommonJS `require`, but ESM `import` is the recommended modern approach for this default export.
HCL.parse
import HCL from 'js-hcl-parser'; const parsed = HCL.parse(hclString);
import { parse } from 'js-hcl-parser'
The `parse` function is a method of the default-exported `HCL` object, not a named export from the package root.
HCL.stringify
import HCL from 'js-hcl-parser'; const hclOutput = HCL.stringify(jsonObject);
import { stringify } from 'js-hcl-parser'
The `stringify` function is a method of the default-exported `HCL` object, not a named export from the package root.

Demonstrates how to parse an HCL string into a JavaScript object and how to stringify a JSON string back into HCL format.

import HCL from 'js-hcl-parser'; // Example HCL input string const hclInput = ` scale { from = 72 to = 24 } `; // Example JSON input object (or string representation) const jsonInput = ` { "scale": { "from": 72, "to": 72 } } `; // Parse HCL to a JavaScript object console.log('Parsed HCL:', HCL.parse(hclInput)); // Expected output: { scale: { from: 72, to: 24 } } // Stringify a JSON string to HCL format // Note: stringify expects a JSON string, not a JS object directly. console.log('Stringified JSON:', HCL.stringify(jsonInput)); /* Expected output (formatting may vary slightly): scale { from = 72 to = 72 } */
Debug
Known issues

No known issues recorded.

Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
js-hcl-parser — npm install js-hcl-parser · libregistry