3
3
ArrayPrototypeForEach,
4
4
ArrayPrototypeJoin,
5
5
ArrayPrototypePush,
6
+ DatePrototypeToISOString,
6
7
ObjectEntries,
7
8
RegExpPrototypeSymbolReplace,
8
9
RegExpPrototypeSymbolSplit,
@@ -125,24 +126,28 @@ function tapEscape(input) {
125
126
}
126
127
127
128
function jsToYaml ( indent , name , value , seen ) {
128
- if ( value === null || value === undefined ) {
129
+ if ( value === undefined ) {
129
130
return '' ;
130
131
}
131
132
132
- if ( typeof value !== 'object' ) {
133
- const prefix = `${ indent } ${ name } : ` ;
133
+ const prefix = `${ indent } ${ name } :` ;
134
+
135
+ if ( value === null ) {
136
+ return `${ prefix } ~\n` ;
137
+ }
134
138
139
+ if ( typeof value !== 'object' ) {
135
140
if ( typeof value !== 'string' ) {
136
- return `${ prefix } ${ inspectWithNoCustomRetry ( value , inspectOptions ) } \n` ;
141
+ return `${ prefix } ${ inspectWithNoCustomRetry ( value , inspectOptions ) } \n` ;
137
142
}
138
143
139
144
const lines = RegExpPrototypeSymbolSplit ( kLineBreakRegExp , value ) ;
140
145
141
146
if ( lines . length === 1 ) {
142
- return `${ prefix } ${ inspectWithNoCustomRetry ( value , inspectOptions ) } \n` ;
147
+ return `${ prefix } ${ inspectWithNoCustomRetry ( value , inspectOptions ) } \n` ;
143
148
}
144
149
145
- let str = `${ prefix } |-\n` ;
150
+ let str = `${ prefix } |-\n` ;
146
151
147
152
for ( let i = 0 ; i < lines . length ; i ++ ) {
148
153
str += `${ indent } ${ lines [ i ] } \n` ;
@@ -154,11 +159,16 @@ function jsToYaml(indent, name, value, seen) {
154
159
seen . add ( value ) ;
155
160
const entries = ObjectEntries ( value ) ;
156
161
const isErrorObj = isError ( value ) ;
157
- let result = '' ;
158
162
let propsIndent = indent ;
163
+ let result = '' ;
159
164
160
165
if ( name != null ) {
161
- result += `${ indent } ${ name } :\n` ;
166
+ result += prefix ;
167
+ if ( internalBinding ( 'types' ) . isDate ( value ) ) {
168
+ // YAML uses the ISO-8601 standard to express dates.
169
+ result += ' ' + DatePrototypeToISOString ( value ) ;
170
+ }
171
+ result += '\n' ;
162
172
propsIndent += ' ' ;
163
173
}
164
174
0 commit comments