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

node:url

مساعدات ⁦URL⁩ القديمة في ⁦Node.js⁩ وإعادة تصدير ⁦URL⁩ وفق ⁦WHATWG⁩

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

توفر ⁦node:url⁩ مساعدات ⁦URL⁩ القديمة في ⁦Node⁩ إلى جانب المُنشئين العامين ⁦URL⁩ و ⁦URLSearchParams⁩.

const url = require("node:url");
const parsed = url.parse("https://user:pw@example.com:8080/a?x=1#h", true);
parsed.host;    // "example.com:8080"
parsed.query.x; // "1"

url.resolve("https://example.com/a/b/c", "../x");
// "https://example.com/a/x"
المساعدالنتيجة
parse(value, parseQueryString?, slashesDenoteHost?)كائن ⁦UrlObject⁩ قديم؛ وتصبح المفاتيح المكررة المحلَّلة مصفوفات.
format(value)سلسلة مبنية من كائن قديم أو من ⁦URL⁩ وفق ⁦WHATWG⁩.
resolve(from, to)سلسلة ⁦URL⁩ محلولة.
resolveObject(from, to)كائن قديم محلول.
domainToASCII() / domainToUnicode()تحويل ⁦IDN⁩.
fileURLToPath() / pathToFileURL()التحويل بين عنوان ⁦URL⁩ لملف والمسار المطلق.
urlToHttpOptions()خيارات لواجهات طلبات ⁦HTTP⁩ في ⁦Node⁩.

‏⁦url.URL === globalThis.URL⁩ و ⁦url.URLSearchParams === globalThis.URLSearchParams⁩. وينبغي للشيفرة الجديدة تفضيل مُنشئات ⁦WHATWG⁩ هذه على المحلّل القديم.

انظر أيضًا

Reference

Status: Full · 40 of 42 suite tests pass (95.2%) · since 1.1.0

Exports

ExportKindStatusNotes
parse()functionFullParses a URL string into a UrlObject (legacy API)
format()functionFullFormats a URL object or WHATWG URL back into a string
resolve()functionFullResolves a target URL relative to a base URL (legacy API)
URLpropertyFullThe WHATWG URL class (same as global URL)
URLSearchParamspropertyFullThe WHATWG URLSearchParams class (same as global URLSearchParams)
domainToASCII()functionFullConverts a Unicode domain name to its ASCII (Punycode) representation
domainToUnicode()functionFullConverts an ASCII (Punycode) domain name to Unicode
fileURLToPath()functionFullConverts a file: URL to a filesystem path string
pathToFileURL()functionFullConverts an absolute filesystem path to a file: URL
urlToHttpOptions()functionFullReturns an object with URL components suitable for use with http.request()
resolveObject()functionFullResolves a relative URL against a source URL object, similar to a browser resolving an anchor tag

Tests: node-api node:url: 40 pass, 2 fail, 0 error, 3 skipped. Failing: test-whatwg-url-custom-inspect.js, test-whatwg-url-custom-parsing.js.

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