-
Hi! Ran into this today, and it's unclear to me what the interpreted data type is and how could I guide the library to add those! I tested it on https://www.json2yaml.com, and the quote were preserved. Apologies if that's a known YAML behaviour! ❯ node
Welcome to Node.js v12.22.1.
> const yaml = require('yaml')
> console.log(yaml.stringify({time: "12:00"}))
time: 12:00
> console.log(yaml.stringify({time: "1200"}))
time: "1200" Happy to provide more context/examples if that's helpful! (Update: some context dependabot/dependabot-core#3615) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's because YAML.parse('time: 12:00')
> { time: '12:00' }
YAML.parse('time: 12:00', { version: '1.1' })
> { time: 720 }
YAML.parse('time: "12:00"', { version: '1.1' })
> { time: '12:00' }
YAML.stringify({ time: '12:00' })
> 'time: 12:00\n'
YAML.stringify({ time: '12:00' }, { version: '1.1' })
> 'time: "12:00"\n' The logic here is that unless otherwise specified, if it looks like a string could be written as a plain scalar, we do that. But if re-parsing that output string would consider it as having a different type in the current schema, the value gets quoted. Hence the quotes around |
Beta Was this translation helpful? Give feedback.
It's because
yaml
defaults to the "core" schema of YAML 1.2, which does not include sexagesimal numbers. If you're working with another YAML library that uses the YAML 1.1 schema, it might make good sense to use theversion: '1.1'
option:The logic here is that unless otherwise specified, if it looks like a string could be written as a plain scalar, we do that. But if re-parsing that output …