| | |
| | | /** |
| | | * The `node:util` module supports the needs of Node.js internal APIs. Many of the |
| | | * utilities are useful for application and module developers as well. To access |
| | | * it: |
| | | * |
| | | * ```js |
| | | * import util from 'node:util'; |
| | | * ``` |
| | | * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/util.js) |
| | | */ |
| | | declare module "node:util" { |
| | | export * as types from "node:util/types"; |
| | | export type InspectStyle = |
| | |
| | | * Returns an array of call site objects containing the stack of |
| | | * the caller function. |
| | | * |
| | | * Unlike accessing an `error.stack`, the result returned from this API is not |
| | | * interfered with `Error.prepareStackTrace`. |
| | | * |
| | | * ```js |
| | | * import { getCallSites } from 'node:util'; |
| | | * |
| | |
| | | * console.log(`Function Name: ${callSite.functionName}`); |
| | | * console.log(`Script Name: ${callSite.scriptName}`); |
| | | * console.log(`Line Number: ${callSite.lineNumber}`); |
| | | * console.log(`Column Number: ${callSite.column}`); |
| | | * console.log(`Column Number: ${callSite.columnNumber}`); |
| | | * }); |
| | | * // CallSite 1: |
| | | * // Function Name: exampleFunction |
| | |
| | | * @legacy Use ES2015 class syntax and `extends` keyword instead. |
| | | */ |
| | | export function inherits(constructor: unknown, superConstructor: unknown): void; |
| | | /** |
| | | * The `util.convertProcessSignalToExitCode()` method converts a signal name to its |
| | | * corresponding POSIX exit code. Following the POSIX standard, the exit code |
| | | * for a process terminated by a signal is calculated as `128 + signal number`. |
| | | * |
| | | * If `signal` is not a valid signal name, then an error will be thrown. See |
| | | * [`signal(7)`](https://man7.org/linux/man-pages/man7/signal.7.html) for a list of valid signals. |
| | | * |
| | | * ```js |
| | | * import { convertProcessSignalToExitCode } from 'node:util'; |
| | | * |
| | | * console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15) |
| | | * console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9) |
| | | * ``` |
| | | * |
| | | * This is particularly useful when working with processes to determine |
| | | * the exit code based on the signal that terminated the process. |
| | | * @since v25.4.0 |
| | | * @param signal A signal name (e.g. `'SIGTERM'`) |
| | | * @returns The exit code corresponding to `signal` |
| | | */ |
| | | export function convertProcessSignalToExitCode(signal: NodeJS.Signals): number; |
| | | export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void; |
| | | export interface DebugLogger extends DebugLoggerFunction { |
| | | /** |
| | |
| | | * |
| | | * ```js |
| | | * import { debuglog } from 'node:util'; |
| | | * const log = debuglog('foo'); |
| | | * const log = debuglog('foo-bar'); |
| | | * |
| | | * log('hi there, it\'s foo-bar [%d]', 2333); |
| | | * ``` |
| | |
| | | */ |
| | | export function debuglog(section: string, callback?: (fn: DebugLoggerFunction) => void): DebugLogger; |
| | | export { debuglog as debug }; |
| | | export interface DeprecateOptions { |
| | | /** |
| | | * When false do not change the prototype of object |
| | | * while emitting the deprecation warning. |
| | | * @since v25.2.0 |
| | | * @default true |
| | | */ |
| | | modifyPrototype?: boolean | undefined; |
| | | } |
| | | /** |
| | | * The `util.deprecate()` method wraps `fn` (which may be a function or class) in |
| | | * such a way that it is marked as deprecated. |
| | |
| | | * @param code A deprecation code. See the `list of deprecated APIs` for a list of codes. |
| | | * @return The deprecated function wrapped to emit a warning. |
| | | */ |
| | | export function deprecate<T extends Function>(fn: T, msg: string, code?: string): T; |
| | | export function deprecate<T extends Function>(fn: T, msg: string, code?: string, options?: DeprecateOptions): T; |
| | | export interface IsDeepStrictEqualOptions { |
| | | /** |
| | | * If `true`, prototype and constructor |