diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-04-20 19:30:28 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-04-20 19:30:28 +0200 |
| commit | e371c801fed71bb73bc7c027e3de5ad2a6116673 (patch) | |
| tree | e6818b34fed4723d8c44d71f8c6d1a68e44c4c8d /src/lib/path.lua | |
| parent | 47a5607a691a576928896f21bcf563c011dc64e5 (diff) | |
Diffstat (limited to 'src/lib/path.lua')
| -rw-r--r-- | src/lib/path.lua | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/path.lua b/src/lib/path.lua index a0be1e5..925f017 100644 --- a/src/lib/path.lua +++ b/src/lib/path.lua @@ -8,6 +8,7 @@ function Path:new(p) p = p:gsub("/$", "") p = p:gsub("^%./", "") p = p:gsub("/[^/]+/%.%.", "") + p = p:gsub("^[^/]+/%.%./", "") local path = { segments = p:split('/'), @@ -126,6 +127,18 @@ function Path:remove(opts) pipe:close() end +function Path:is_parent_of(child) + return tostring(child):starts_with(tostring(self)) +end + +function Path:relative_to_parent(path) + if not path:is_parent_of(self) then + return nil + end + + return Path:new(tostring(self):sub(#tostring(path) + 2)) +end + return { tests = { function() |