jeremyfa / yaml.js

Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to use stringify() to fmt file context to '|-' ?

Cloudzp opened this issue · comments

my code:

import  YAML from 'yamljs'
let yaml = YAML.stringify(this.value,4);
console.log(yaml)

this.value :

{
    "apiVersion": "v1",
    "items": [
        {
            "apiVersion": "v1",
            "data": {
                "app.conf": "estnautorender = false\ncopyrequestbody = true"
            },
            "kind": "ConfigMap"
        }
    ],
    "kind": "List",
    "metadata": {
        "resourceVersion": "",
        "selfLink": ""
    }
}

expect:

# by www.bejson.com 
apiVersion: v1
items:
- apiVersion: v1
  data:
    app.conf: |-
      estnautorender = false
      copyrequestbody = true
  kind: ConfigMap
kind: List
metadata: {resourceVersion: '', selfLink: ''}

got :

apiVersion: v1
items:
- apiVersion: v1
  data:
    app.conf:  "estnautorender = false\ncopyrequestbody = true"
  kind: ConfigMap
kind: List
metadata: {resourceVersion: '', selfLink: ''}

Hi, the output you get is valid but dumping multiline strings with | is not supported at the moment.

ok , thank you very much! 👍