Skip to content

Use Scalar.source when serialising numerical values #660

@eemeli

Description

@eemeli

By default, numerical values (!!int and !!float) are represented using the native JS Number, which has limits to the precision and absolute value of what it can represent before overflowing:

import { parseDocument } from 'yaml'

const doc = parseDocument('gitsha: 61e9540')
doc.get('gitsha', true)
Scalar {
  value: Infinity,
  range: [ 8, 15, 15 ],
  source: '61e9540',
  type: 'PLAIN',
  format: 'EXP'
}

Note, however, that we already retain the string source of the value. When serialising the above, we should make use of it, so that we don't end up with:

gitsha: .inf

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions