How to use the prettier/src/language-yaml/printer-yaml.print function in prettier

To help you get started, we’ve selected a few prettier 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 mohsen1 / yawn-yaml / src / index.ts View on Github external
_.each(newJson, (value, key) => {
        // item is new
        if (_.isUndefined(json[key])) {
            let newValue = YAMLPrinter.print({ [key]: value });

            yaml = insertAfterNode(ast, newValue, yaml);
        }
    });
github mohsen1 / yawn-yaml / src / index.ts View on Github external
function cleanDump(value: string) {
    let yaml = YAMLPrinter.print(value).replace(/\n$/, '');

    if (os.EOL !== '\n') {
        yaml = yaml.replace(/\n/g, os.EOL);
    }

    return yaml;
}
github mohsen1 / yawn-yaml / src / index.ts View on Github external
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;