Skip to content

dumping is formating custom type wrong #576

Closed
@rubendmatos1985

Description

@rubendmatos1985
const yaml = require("js-yaml")

class Test {
  constructor(id) {
    this.id = id
  }
  id

  get Id() {
    return this.id
  }
  async fetchData() {
    console.log("get async data")
  }
}



var customtagYamlType = new yaml.Type("!mapInfo", {
  kind: "scalar",
  resolve: () => true,
  construct: (id) => new Test(id),
  instanceOf: Test,
  represent: (customTag) => customTag.id,
})

const obj = {
  name: 'some',
  data:{
    content:[
      {
        value: new Test("1")
      }
    ]
  }
}


const schema = yaml.Schema.create([customtagYamlType])

const result = yaml.dump(obj, { schema })
console.log(result)

/* the output is 
data:
  content:
  - value: !<!mapInfo> '1'

-----------------------------------------
i am expecting like in the documentation
data:
  content:
  - value: !mapInfo  '1'



node version v12.14.1
  

*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions