mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
* func: User url rules to scape non alphanumeric values in hcl variables * docs: add changelog * func: unscape flags before returning * use JSON.stringify instead of bespoke value quoting to handle in-value-multi-line cases --------- Co-authored-by: Phil Renaud <phil@riotindustries.com>
26 lines
552 B
JavaScript
26 lines
552 B
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
// @ts-check
|
|
|
|
/**
|
|
* Convert a JSON object to an HCL string.
|
|
*
|
|
* @param {Object} obj - The JSON object to convert.
|
|
* @returns {string} The HCL string representation of the JSON object.
|
|
*/
|
|
export default function jsonToHcl(obj) {
|
|
const hclLines = [];
|
|
|
|
for (const key in obj) {
|
|
const value = obj[key];
|
|
const hclValue = typeof value === 'string' ? JSON.stringify(value) : value;
|
|
|
|
hclLines.push(`${key}=${hclValue}\n`);
|
|
}
|
|
|
|
return hclLines.join('\n');
|
|
}
|