-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4281bc0
commit 434aea0
Showing
13 changed files
with
203 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict' | ||
|
||
/* | ||
This file is a reduced and adapted version of the main lib/internal/util/inspect.js file defined at | ||
https://github.com/nodejs/node/blob/main/lib/internal/util/inspect.js | ||
Don't try to replace with the original file and keep it up to date with the upstream file. | ||
*/ | ||
module.exports = { | ||
format(format, ...args) { | ||
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args | ||
return format.replace(/%([sdifj])/g, function (...[_unused, type]) { | ||
const replacement = args.shift() | ||
if (type === 'f') { | ||
return replacement.toFixed(6) | ||
} else if (type === 'j') { | ||
return JSON.stringify(replacement) | ||
} else if (type === 's' && typeof replacement === 'object') { | ||
const ctor = replacement.constructor !== Object ? replacement.constructor.name : '' | ||
return `${ctor} {}`.trim() | ||
} else { | ||
return replacement.toString() | ||
} | ||
}) | ||
}, | ||
inspect(value) { | ||
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options | ||
switch (typeof value) { | ||
case 'string': | ||
if (value.includes("'")) { | ||
if (!value.includes('"')) { | ||
return `"${value}"` | ||
} else if (!value.includes('`') && !value.includes('${')) { | ||
return `\`${value}\`` | ||
} | ||
} | ||
return `'${value}'` | ||
case 'number': | ||
if (isNaN(value)) { | ||
return 'NaN' | ||
} else if (Object.is(value, -0)) { | ||
return String(value) | ||
} | ||
return value | ||
case 'bigint': | ||
return `${String(value)}n` | ||
case 'boolean': | ||
case 'undefined': | ||
return String(value) | ||
case 'object': | ||
return '{}' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.