انتقل إلى المحتوى

مرجع واجهة ⁦node:console⁩

توابع ⁦console⁩ والتنسيق ونسخ ⁦Console⁩ المخصّصة

في هذه الصفحة
Open in ChatGPTOpen in Claude

يعيد ⁦require("node:console")⁩ و⁦globalThis.console⁩ الكائن نفسه. وتصدّر الوحدة أيضًا ⁦Console⁩ للكتابة إلى تدفقات مخصّصة.

import console, { Console } from "node:console";

console.log("value=%d", 2);
console.table([{ a: 1, b: "x" }]);

const custom = new Console(process.stdout, process.stderr);
custom.warn("written to stderr");

التوابع المعتادة متاحة: ⁦log⁩ و⁦info⁩ و⁦warn⁩ و⁦error⁩ و⁦debug⁩ و⁦dir⁩ و⁦trace⁩ و⁦table⁩ و⁦assert⁩ و⁦clear⁩، والعدّادات والمجموعات والمؤقتات. ويدعم التنسيق ⁦%s⁩ و⁦%d⁩ و⁦%i⁩ و⁦%f⁩ و⁦%j⁩ و⁦%o⁩ و⁦%O⁩ و⁦%%⁩.

يدعم ⁦console.table⁩ المصفوفات والكائنات ويعرض جدول ⁦ASCII⁩. أما التباعد والمحاذاة فيه فيحددهما التنفيذ؛ فلا تحلّل النص المعروض.

استبدال ⁦process.stdout.write⁩ أو ⁦process.stderr.write⁩ يعترض أيضًا مخرجات ⁦console⁩ العامة المقابلة.

Reference

Status: Partial · 20 of 21 suite tests pass (95.2%) · since 1.1.0

Exports

ExportKindStatusNotes
log()functionFullPrints to stdout with newline
info()functionFullAlias for log()
warn()functionFullPrints to stderr with newline
error()functionFullPrints to stderr with newline
debug()functionFullPrints to stdout with newline
trace()functionFullPrints to stderr the string ‘Trace: ’ followed by a stack trace
dir()functionFullUses util.inspect() on obj and prints the resulting string to stdout
dirxml()functionFullAlias for log()
table()functionFullPrints a table representation of the data
clear()functionFullClears the console (when possible)
count()functionFullMaintains an internal counter and outputs the number of times count() has been called with the given label
countReset()functionFullResets the internal counter for the given label
group()functionFullIncreases indentation of subsequent lines by spaces for grouping
groupCollapsed()functionFullAlias for group()
groupEnd()functionFullDecreases indentation of subsequent lines by spaces for grouping
time()functionFullStarts a timer with a given label
timeEnd()functionFullStops a timer and prints elapsed time
timeLog()functionFullPrints the elapsed time for a running timer without stopping it
assert()functionFullWrites an error message to the console if the assertion is false

Not implemented

context, createTask, profile, profileEnd, timeStamp.

Tests: node-api node:console: 20 pass, 1 fail, 0 error, 1 skipped. Failing: test-console-issue-43095.js.

هل كانت هذه الصفحة مفيدة؟