UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

38 lines (37 loc) 1.05 kB
/** * Copyright Super iPaaS Integration LLC, an IBM Company 2024 */ import yaml from 'js-yaml'; import { parseDocument, stringify } from "yaml"; import { ERROR_PROCESSING_YAML_FILE } from '../../constants/message-constants.js'; const readYaml = (input) => { return yaml.load(input); }; const readMultiYaml = (fileName, input) => { try { return yaml.loadAll(input); } catch (error) { throw new Error(`${ERROR_PROCESSING_YAML_FILE} ${fileName}: Invalid Yaml`); } }; const convertToYAMLString = (input) => { return yaml.dump(input); }; const parseYamlContent = (content) => { try { return parseDocument(content); } catch (error) { throw new Error("Failed to parse YAML content."); } }; const convertParsedYmlToString = (yamlDoc) => { try { return stringify(yamlDoc); } catch (error) { throw new Error("Failed to convert YAML document to string."); } }; export { readYaml, convertToYAMLString, readMultiYaml, parseYamlContent, convertParsedYmlToString };