Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_.each(newJson, (value, key) => {
// item is new
if (_.isUndefined(json[key])) {
let newValue = YAMLPrinter.print({ [key]: value });
yaml = insertAfterNode(ast, newValue, yaml);
}
});
function cleanDump(value: string) {
let yaml = YAMLPrinter.print(value).replace(/\n$/, '');
if (os.EOL !== '\n') {
yaml = yaml.replace(/\n/g, os.EOL);
}
return yaml;
}
function updateSeq(ast: Node, newJson: any, yaml: string) {
let values = JSYAML.load(YAMLPrinter.print(ast));
if (values === undefined || !_.isArray(values)) return yaml;
let min = Math.min(values.length, newJson.length);
if (values.length > min) {
for (let i = values.length - 1; i >= min; --i) {
yaml = removeArrayElement(ast.value[i], yaml);
}
} else if (newJson.length > min) {
yaml = insertAfterNode(ast, cleanDump(newJson.slice(min)), yaml);
}
for (let i = min - 1; i >= 0; --i) {
yaml = changeArrayElement(ast.value[i], cleanDump(newJson[i]), yaml);
}
return yaml;