1
1
'use strict'
2
2
3
3
const bufferModule = require ( 'buffer' )
4
- const { kResistStopPropagation, SymbolDispose } = require ( './primordials' )
4
+ const { format, inspect } = require ( './util/inspect' )
5
+ const {
6
+ codes : { ERR_INVALID_ARG_TYPE }
7
+ } = require ( './errors' )
8
+ const { kResistStopPropagation, AggregateError, SymbolDispose } = require ( './primordials' )
5
9
const AbortSignal = globalThis . AbortSignal || require ( 'abort-controller' ) . AbortSignal
6
10
const AbortController = globalThis . AbortController || require ( 'abort-controller' ) . AbortController
7
11
const AsyncFunction = Object . getPrototypeOf ( async function ( ) { } ) . constructor
@@ -28,22 +32,6 @@ const validateFunction = (value, name) => {
28
32
throw new ERR_INVALID_ARG_TYPE ( name , 'Function' , value )
29
33
}
30
34
}
31
-
32
- // This is a simplified version of AggregateError
33
- class AggregateError extends Error {
34
- constructor ( errors ) {
35
- if ( ! Array . isArray ( errors ) ) {
36
- throw new TypeError ( `Expected input to be an Array, got ${ typeof errors } ` )
37
- }
38
- let message = ''
39
- for ( let i = 0 ; i < errors . length ; i ++ ) {
40
- message += ` ${ errors [ i ] . stack } \n`
41
- }
42
- super ( message )
43
- this . name = 'AggregateError'
44
- this . errors = errors
45
- }
46
- }
47
35
module . exports = {
48
36
AggregateError,
49
37
kEmptyObject : Object . freeze ( { } ) ,
@@ -85,50 +73,8 @@ module.exports = {
85
73
debuglog ( ) {
86
74
return function ( ) { }
87
75
} ,
88
- format ( format , ...args ) {
89
- // Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
90
- return format . replace ( / % ( [ s d i f j ] ) / g, function ( ...[ _unused , type ] ) {
91
- const replacement = args . shift ( )
92
- if ( type === 'f' ) {
93
- return replacement . toFixed ( 6 )
94
- } else if ( type === 'j' ) {
95
- return JSON . stringify ( replacement )
96
- } else if ( type === 's' && typeof replacement === 'object' ) {
97
- const ctor = replacement . constructor !== Object ? replacement . constructor . name : ''
98
- return `${ ctor } {}` . trim ( )
99
- } else {
100
- return replacement . toString ( )
101
- }
102
- } )
103
- } ,
104
- inspect ( value ) {
105
- // Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
106
- switch ( typeof value ) {
107
- case 'string' :
108
- if ( value . includes ( "'" ) ) {
109
- if ( ! value . includes ( '"' ) ) {
110
- return `"${ value } "`
111
- } else if ( ! value . includes ( '`' ) && ! value . includes ( '${' ) ) {
112
- return `\`${ value } \``
113
- }
114
- }
115
- return `'${ value } '`
116
- case 'number' :
117
- if ( isNaN ( value ) ) {
118
- return 'NaN'
119
- } else if ( Object . is ( value , - 0 ) ) {
120
- return String ( value )
121
- }
122
- return value
123
- case 'bigint' :
124
- return `${ String ( value ) } n`
125
- case 'boolean' :
126
- case 'undefined' :
127
- return String ( value )
128
- case 'object' :
129
- return '{}'
130
- }
131
- } ,
76
+ format,
77
+ inspect,
132
78
types : {
133
79
isAsyncFunction ( fn ) {
134
80
return fn instanceof AsyncFunction
0 commit comments