@@ -48,6 +48,7 @@ const {
48
48
String,
49
49
StringPrototypeEndsWith,
50
50
StringPrototypeIncludes,
51
+ StringPrototypeIndexOf,
51
52
StringPrototypeSlice,
52
53
StringPrototypeSplit,
53
54
StringPrototypeStartsWith,
@@ -939,23 +940,53 @@ const genericNodeError = hideStackFrames(function genericNodeError(message, erro
939
940
* @returns {string }
940
941
*/
941
942
function determineSpecificType ( value ) {
942
- if ( value == null ) {
943
- return '' + value ;
943
+ if ( value === null ) {
944
+ return 'null' ;
945
+ } else if ( value === undefined ) {
946
+ return 'undefined' ;
944
947
}
945
- if ( typeof value === 'function' && value . name ) {
946
- return `function ${ value . name } ` ;
947
- }
948
- if ( typeof value === 'object' ) {
949
- if ( value . constructor ?. name ) {
950
- return `an instance of ${ value . constructor . name } ` ;
951
- }
952
- return `${ lazyInternalUtilInspect ( ) . inspect ( value , { depth : - 1 } ) } ` ;
953
- }
954
- let inspected = lazyInternalUtilInspect ( )
955
- . inspect ( value , { colors : false } ) ;
956
- if ( inspected . length > 28 ) { inspected = `${ StringPrototypeSlice ( inspected , 0 , 25 ) } ...` ; }
957
948
958
- return `type ${ typeof value } (${ inspected } )` ;
949
+ const type = typeof value ;
950
+
951
+ switch ( type ) {
952
+ case 'bigint' :
953
+ return `type bigint (${ value } n)` ;
954
+ case 'number' :
955
+ if ( value === 0 ) {
956
+ return 1 / value === - Infinity ? 'type number (-0)' : 'type number (0)' ;
957
+ } else if ( value !== value ) { // eslint-disable-line no-self-compare
958
+ return 'type number (NaN)' ;
959
+ } else if ( value === Infinity ) {
960
+ return 'type number (Infinity)' ;
961
+ } else if ( value === - Infinity ) {
962
+ return 'type number (-Infinity)' ;
963
+ }
964
+ return `type number (${ value } )` ;
965
+ case 'boolean' :
966
+ return value ? 'type boolean (true)' : 'type boolean (false)' ;
967
+ case 'symbol' :
968
+ return `type symbol (${ String ( value ) } )` ;
969
+ case 'function' :
970
+ return `function ${ value . name } ` ;
971
+ case 'object' :
972
+ if ( value . constructor && 'name' in value . constructor ) {
973
+ return `an instance of ${ value . constructor . name } ` ;
974
+ }
975
+ return `${ lazyInternalUtilInspect ( ) . inspect ( value , { depth : - 1 } ) } ` ;
976
+ case 'string' :
977
+ value . length > 28 && ( value = `${ StringPrototypeSlice ( value , 0 , 25 ) } ...` ) ;
978
+ if ( StringPrototypeIndexOf ( value , "'" ) === - 1 ) {
979
+ return `type string ('${ value } ')` ;
980
+ }
981
+ return `type string (${ JSONStringify ( value ) } )` ;
982
+ default :
983
+ value = lazyInternalUtilInspect ( ) . inspect ( value , { colors : false } ) ;
984
+ if ( value . length > 28 ) {
985
+ value = `${ StringPrototypeSlice ( value , 0 , 25 ) } ...` ;
986
+ }
987
+
988
+ return `type ${ type } (${ value } )` ;
989
+ }
959
990
}
960
991
961
992
/**
0 commit comments