* Determine the specific type of a value for type-mismatch errors. * @param {*} value * @returns {string}
(value)
| 1006 | * @returns {string} |
| 1007 | */ |
| 1008 | function determineSpecificType(value) { |
| 1009 | if (value === null) { |
| 1010 | return 'null'; |
| 1011 | } else if (value === undefined) { |
| 1012 | return 'undefined'; |
| 1013 | } |
| 1014 | |
| 1015 | const type = typeof value; |
| 1016 | |
| 1017 | switch (type) { |
| 1018 | case 'bigint': |
| 1019 | return `type bigint (${value}n)`; |
| 1020 | case 'number': |
| 1021 | if (value === 0) { |
| 1022 | return 1 / value === -Infinity ? 'type number (-0)' : 'type number (0)'; |
| 1023 | } else if (value !== value) { // eslint-disable-line no-self-compare |
| 1024 | return 'type number (NaN)'; |
| 1025 | } else if (value === Infinity) { |
| 1026 | return 'type number (Infinity)'; |
| 1027 | } else if (value === -Infinity) { |
| 1028 | return 'type number (-Infinity)'; |
| 1029 | } |
| 1030 | return `type number (${value})`; |
| 1031 | case 'boolean': |
| 1032 | return value ? 'type boolean (true)' : 'type boolean (false)'; |
| 1033 | case 'symbol': |
| 1034 | return `type symbol (${String(value)})`; |
| 1035 | case 'function': |
| 1036 | return `function ${value.name}`; |
| 1037 | case 'object': |
| 1038 | if (value.constructor && 'name' in value.constructor) { |
| 1039 | return `an instance of ${value.constructor.name}`; |
| 1040 | } |
| 1041 | return `${lazyInternalUtilInspect().inspect(value, { depth: -1 })}`; |
| 1042 | case 'string': |
| 1043 | value.length > 28 && (value = `${StringPrototypeSlice(value, 0, 25)}...`); |
| 1044 | if (StringPrototypeIndexOf(value, "'") === -1) { |
| 1045 | return `type string ('${value}')`; |
| 1046 | } |
| 1047 | return `type string (${JSONStringify(value)})`; |
| 1048 | default: |
| 1049 | value = lazyInternalUtilInspect().inspect(value, { colors: false }); |
| 1050 | if (value.length > 28) { |
| 1051 | value = `${StringPrototypeSlice(value, 0, 25)}...`; |
| 1052 | } |
| 1053 | |
| 1054 | return `type ${type} (${value})`; |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * Create a list string in the form like 'A and B' or 'A, B, ..., and Z'. |
no test coverage detected
searching dependent graphs…