GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — yaml/src/stringify/stringifyNumber.ts at main · eemeli/yaml

Expand file tree

/

stringifyNumber.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
33 lines (32 loc) · 968 Bytes
/

stringifyNumber.ts

Copy path

File metadata and controls

33 lines (32 loc) · 968 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { Scalar } from '../nodes/Scalar.ts'
export function stringifyNumber(
{ format, minFractionDigits, source, tag, value }: Scalar,
version: '1.1' | '1.2' = '1.2'
): string {
if (typeof value === 'bigint') return String(value)
const num = typeof value === 'number' ? value : Number(value)
if (!isFinite(num)) {
if (typeof value === 'number' && source) {
const source_ = version === '1.1' ? source.replace(/_/g, '') : source
if (parseFloat(source_) === num) return source
}
return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf'
}
let n = Object.is(value, -0) ? '-0' : JSON.stringify(value)
if (
!format &&
minFractionDigits &&
(!tag || tag === 'tag:yaml.org,2002:float') &&
/^-?\d/.test(n) &&
!n.includes('e')
) {
let i = n.indexOf('.')
if (i < 0) {
i = n.length
n += '.'
}
let d = minFractionDigits - (n.length - i - 1)
while (d-- > 0) n += '0'
}
return n
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.