How to use the js-yaml.safeDump function in js-yaml

To help you get started, we’ve selected a few js-yaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moleculerjs / awesome-moleculer / generate-modules-site.js View on Github external
async function main() {
	try {
		// Load module files
		const payload = await readFile(MODULES_PATH, { encoding: "utf8" });

		// Parse yaml payload
		const modules = yaml.safeLoad(payload, "utf8");

		// Transform into site acceptable format
		const siteModules = await transform(modules);

		// Store new file
		await writeFile(
			SITE_MODULES,
			yaml.safeDump(siteModules, { lineWidth: 500 })
		);
	} catch (error) {
		console.log(error);
		process.exit(1);
	}
}
github matrix-io / matrix-os / lib / service / application.js View on Github external
function updateConfigKey( options, cb ) {
    var configFile = Matrix.config.path.apps + '/' + options.name + '.matrix/config.yaml';
    var config = yaml.loadSafe( fs.readFileSync( configFile ) );
    if ( config.hasOwnProperty( 'configuration' ) ) {
    //FIXME: Depreciate this path
      console.warn( '`configuration` in app config', options );
      config.configuration[ options.key ] = options.value;
    } else {
    // this is the newness
      config.settings[ options.key ] = options.value;
    }
    var configJs = yaml.safeDump( config );
    fs.writeFile( configFile, configJs, cb );
  }
github Azure / vscode-kubernetes-tools / src / helm.authoring.ts View on Github external
return;
    }

    const template = yaml.safeLoad(resourceYaml);
    templatise(template);

    // TODO: offer a default
    const templateName = await context.host.showInputBox({ prompt: "Name for the new template" });
    if (!templateName) {
        return;
    }

    const templateFile = path.join(chart.path, "templates", templateName + ".yaml");
    // TODO: check if file already exists

    const templateYaml = yaml.safeDump(template);  // the parse-dump cycle can change the indentation of collections - is this an issue?
    const templateText = fixYamlValueQuoting(templateYaml);
    context.fs.writeFileSync(templateFile, templateText);

    await context.host.showDocument(vscode.Uri.file(templateFile));
}
github k3s-io / k3s / docs / getting-started-guides / coreos / azure / lib / cloud_config.js View on Github external
var write_cloud_config_from_object = function (data, output_file) {
  try {
    fs.writeFileSync(output_file, [
      '#cloud-config',
      yaml.safeDump(data),
    ].join("\n"));
    return output_file;
  } catch (e) {
    console.log(colors.red(e));
  }
};
github OfficeDev / office-js-snippets / config / helpers.ts View on Github external
export function getPrintableDetails(item: any, indent: number) {
    const details = jsyaml.safeDump(item, {
        indent: 4,
        lineWidth: -1,
        skipInvalid: true
    });

    return details.split('\n').map(line => new Array(indent).join(' ') + line).join('\n');
}
github openaddresses / openaddresses / migrate / index.js View on Github external
_(states).each(function(state, key) {
            fs.writeFile(path.join(dir, key + '.yaml'), yaml.safeDump(state));
            console.log('Exported ' + path.join(dir, key + '.yaml'));
        });
    })
github sezna / nps / src / bin-utils / initialize / index.js View on Github external
function dumpYAMLConfig(packageJsonPath, scripts) {
  const packageScriptsPath = resolve(
    dirname(packageJsonPath),
    './package-scripts.yml',
  )
  const fileContents = safeDump({scripts: structureScripts(scripts)})
  writeFileSync(packageScriptsPath, fileContents)

  return {packageJsonPath, packageScriptsPath}
}
github sigoden / htte / src / unit.js View on Github external
inspect({ req, res }) {
    let model = {
      name: this.name(),
      module: this.module(),
      api: this.api(),
      req: req || {},
      res: res || {}
    }
    return yaml.safeDump(model)
  }
github khalidx / resource-x / src / index.ts View on Github external
return tokens.reduce((combined, token) => {
      if (token.type === 'code' && token.text.length > 0) {
        if (token.lang === 'json') {
          return combined += `${yaml.safeDump(JSON.parse(token.text), { noRefs: true })}\n`
        }
        if (token.lang === 'yaml') {
          return combined += `${token.text}\n`
        }
      }
      return combined
    }, '')
  } catch (error) {
github benweet / stackedit / src / components / modals / FilePropertiesModal.vue View on Github external
properties[name] = this[name];
            hasChanged = true;
          } else if (properties[name]) {
            delete properties[name];
            hasChanged = true;
          }
        }
      });
      if (hasChanged) {
        if (Object.keys(extensions).length) {
          properties.extensions = extensions;
        } else {
          delete properties.extensions;
        }
        this.setYamlProperties(Object.keys(properties).length
          ? yaml.safeDump(properties)
          : '\n');
      }
    },
    setSimpleTab() {