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\\"Стандартні граничні випадки та перевірку аргументів описано в документації Node.js щодо path.
Reference
Status: Full · 16 of 16 suite tests pass (100.0%) · since 1.1.0
Exports
| Export | Kind | Status | Notes |
|---|---|---|---|
basename() | function | Full | Return the last portion of a path, optionally removing a suffix |
dirname() | function | Full | Return the directory name of a path |
extname() | function | Full | Return the extension of the path, from the last ’.’ to end of string |
format() | function | Full | Returns a path string from an object (the opposite of path.parse()) |
isAbsolute() | function | Full | Determines whether path is an absolute path |
join() | function | Full | Join all arguments together and normalize the resulting path |
normalize() | function | Full | Normalize a path, resolving ’..’ and ’.’ segments |
parse() | function | Full | Returns an object whose properties represent significant elements of the path |
relative() | function | Full | Returns the relative path from ‘from’ to ‘to’ |
resolve() | function | Full | Resolve a sequence of paths into an absolute path |
toNamespacedPath() | function | Full | Returns an equivalent namespace-prefixed path (Windows only; no-op on POSIX) |
matchesGlob() | function | Full | Returns true if the path matches the given glob pattern |
sep | property | Full | The platform-specific path segment separator |
delimiter | property | Full | The platform-specific path delimiter |
posix | property | Full | Provides access to POSIX specific implementations of the path methods |
win32 | property | Full | Provides access to Windows specific implementations of the path methods |
Tests: node-api node:path: 16 pass, 0 fail, 0 error, 1 skipped.