Codes in the following example uses POSIX path but it automatically use Windows
path on Windows. Use methods under posix or win32 object instead to handle
non platform specific path like:
Return the last portion of a path. Trailing directory separators are ignored.
import{ basename }from"https://deno.land/std@0.144.0/path/mod.ts";const p =basename("./deno/std/path/mod.ts");console.log(p);// "mod.ts"
dirname
Return the directory name of a path.
import{ dirname }from"https://deno.land/std@0.144.0/path/mod.ts";const p =dirname("./deno/std/path/mod.ts");console.log(p);// "./deno/std/path"
extname
Return the extension of the path.
import{ extname }from"https://deno.land/std@0.144.0/path/mod.ts";const p =extname("./deno/std/path/mod.ts");console.log(p);// ".ts"
format
Generate a path from FormatInputPathObject object.
import{ format }from"https://deno.land/std@0.144.0/path/mod.ts";const p =format({
root:"/",
dir:"/home/user/dir",
ext:".html",
name:"index",});console.log(p);// "/home/user/dir/index.html"
fromFileUrl
Converts a file URL to a path string.
import{ fromFileUrl }from"https://deno.land/std@0.144.0/path/mod.ts";const p =fromFileUrl("file:///home/foo");console.log(p);// "/home/foo"
import{ toNamespacedPath }from"https://deno.land/std@0.144.0/path/mod.ts";const p =toNamespacedPath("/home/foo");console.log(p);// "/home/foo"
common
Determines the common path from a set of paths, using an optional separator,
which defaults to the OS default separator.
import{ common }from"https://deno.land/std@0.144.0/path/mod.ts";const p =common(["./deno/std/path/mod.ts","./deno/std/fs/mod.ts",]);console.log(p);// "./deno/std/"
globToRegExp
Generate a regex based on glob pattern and options This was meant to be using
the fs.walk function but can be used anywhere else.
import{ globToRegExp }from"https://deno.land/std@0.144.0/path/glob.ts";globToRegExp("foo/**/*.json",{
extended:true,
globstar:true,
caseInsensitive:false,});// returns the regex to find all .json files in the folder foo.