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

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

معالجة مسارات ⁦POSIX⁩ و⁦Windows⁩

في هذه الصفحة
Open in ChatGPTOpen in Claude
import path from "node:path";

console.log(path.join("src", "app", "index.js"));
console.log(path.parse("archive.tar.gz"));
console.log(path.matchesGlob("src/a/b.js", "src/**/*.js")); // true

التوابع القياسية متاحة: ⁦basename⁩ و⁦dirname⁩ و⁦extname⁩ و⁦format⁩ و⁦isAbsolute⁩ و⁦join⁩ و⁦normalize⁩ و⁦parse⁩ و⁦relative⁩ و⁦resolve⁩ و⁦toNamespacedPath⁩ و⁦matchesGlob⁩.

يكشف ⁦path.posix⁩ و⁦path.win32⁩ نكهتين صريحتين على كل مضيف. ويتبع التصدير الافتراضي المضيف الحالي. وتتوفر فواصلهما بوصفها ⁦sep⁩ ومحددات قوائم المسارات بوصفها ⁦delimiter⁩.

يدعم ⁦matchesGlob⁩ أحرف البدل و⁦globstar⁩ وفئات الأحرف وبدائل الأقواس المعقوفة وأنماط ⁦extglob⁩. والاسم الأساسي الذي يبدأ بنقطة مثل ⁦.bashrc⁩ امتداده فارغ، والنقطة الأخيرة هي التي تحدد الامتداد متعدد الأجزاء.

path.parse(".bashrc").ext; // ""
path.parse("archive.tar.gz").ext; // ".gz"
path.win32.normalize("C:\\temp\\foo\\..\\"); // "C:\\temp\\"

راجع توثيق ⁦path⁩ في ⁦Node.js⁩ للحالات الحدّية القياسية والتحقق من الوسائط.

Reference

Status: Full · 16 of 16 suite tests pass (100.0%) · since 1.1.0

Exports

ExportKindStatusNotes
basename()functionFullReturn the last portion of a path, optionally removing a suffix
dirname()functionFullReturn the directory name of a path
extname()functionFullReturn the extension of the path, from the last ’.’ to end of string
format()functionFullReturns a path string from an object (the opposite of path.parse())
isAbsolute()functionFullDetermines whether path is an absolute path
join()functionFullJoin all arguments together and normalize the resulting path
normalize()functionFullNormalize a path, resolving ’..’ and ’.’ segments
parse()functionFullReturns an object whose properties represent significant elements of the path
relative()functionFullReturns the relative path from ‘from’ to ‘to’
resolve()functionFullResolve a sequence of paths into an absolute path
toNamespacedPath()functionFullReturns an equivalent namespace-prefixed path (Windows only; no-op on POSIX)
matchesGlob()functionFullReturns true if the path matches the given glob pattern
seppropertyFullThe platform-specific path segment separator
delimiterpropertyFullThe platform-specific path delimiter
posixpropertyFullProvides access to POSIX specific implementations of the path methods
win32propertyFullProvides access to Windows specific implementations of the path methods

Tests: node-api node:path: 16 pass, 0 fail, 0 error, 1 skipped.

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