@robinpath/path
0.1.2Node.jsPublicPath manipulation utilities for joining, resolving, and parsing file paths
Path
Path manipulation utilities for joining, resolving, and parsing file paths
Package: @robinpath/path | Category: Utility | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the path module when you need to:
- Join path segments into a single path -- Use
path.jointo perform this operation - Resolve a sequence of paths into an absolute path -- Use
path.resolveto perform this operation - Get the directory name of a path -- Use
path.dirnameto perform this operation - Get the last portion of a path (filename) -- Use
path.basenameto perform this operation - Get the file extension of a path -- Use
path.extnameto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
join | Join path segments into a single path | The joined path string |
resolve | Resolve a sequence of paths into an absolute path | The resolved absolute path |
dirname | Get the directory name of a path | The directory portion of the path |
basename | Get the last portion of a path (filename) | The last portion of the path |
extname | Get the file extension of a path | The extension of the file including the dot |
normalize | Normalize a path, resolving '..' and '.' segments | The normalized path |
isAbsolute | Check whether a path is absolute | True if the path is absolute, false otherwise |
relative | Compute the relative path from one path to another | The relative path from 'from' to 'to' |
parse | Parse a path into an object with root, dir, base, ext, and name | An object with root, dir, base, ext, and name properties |
separator | Get the platform-specific path segment separator | The OS path separator (/ on POSIX, \ on Windows) |
Functions
join
Join path segments into a single path
Module: path | Returns: string -- The joined path string
path.join "/usr" "local" "bin"
| Parameter | Type | Required | Description |
|---|---|---|---|
segments | string | Yes | Path segments to join |
resolve
Resolve a sequence of paths into an absolute path
Module: path | Returns: string -- The resolved absolute path
path.resolve "src" "index.ts"
| Parameter | Type | Required | Description |
|---|---|---|---|
segments | string | Yes | Path segments to resolve |
dirname
Get the directory name of a path
Module: path | Returns: string -- The directory portion of the path
path.dirname "/usr/local/bin/node"
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | The file path |
basename
Get the last portion of a path (filename)
Module: path | Returns: string -- The last portion of the path
path.basename "/usr/local/bin/node"
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | The file path |
ext | string | No | Optional extension to remove from the result |
extname
Get the file extension of a path
Module: path | Returns: string -- The extension of the file including the dot
path.extname "index.html"
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | The file path |
normalize
Normalize a path, resolving '..' and '.' segments
Module: path | Returns: string -- The normalized path
path.normalize "/usr/local/../bin"
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | The path to normalize |
isAbsolute
Check whether a path is absolute
Module: path | Returns: boolean -- True if the path is absolute, false otherwise
path.isAbsolute "/usr/local"
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | The path to check |
relative
Compute the relative path from one path to another
Module: path | Returns: string -- The relative path from 'from' to 'to'
path.relative "/usr/local" "/usr/local/bin/node"
| Parameter | Type | Required | Description |
|---|---|---|---|
from | string | Yes | The base path |
to | string | Yes | The target path |
parse
Parse a path into an object with root, dir, base, ext, and name
Module: path | Returns: object -- An object with root, dir, base, ext, and name properties
path.parse "/home/user/file.txt"
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | The path to parse |
separator
Get the platform-specific path segment separator
Module: path | Returns: string -- The OS path separator (/ on POSIX, \ on Windows)
path.separator
| Parameter | Type | Required | Description |
|---|---|---|---|
| (none) | No | Call with no arguments |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
| (standard errors) | Check function parameters and authentication |
@desc "Join and validate result"
do
set $result as path.join "/usr" "local" "bin"
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. Multi-step Path workflow
Chain multiple path operations together.
@desc "Join, resolve, and more"
do
set $r_join as path.join "/usr" "local" "bin"
set $r_resolve as path.resolve "src" "index.ts"
set $r_dirname as path.dirname "/usr/local/bin/node"
print "All operations complete"
enddo
2. Safe join with validation
Check results before proceeding.
@desc "Join and validate result"
do
set $result as path.join "/usr" "local" "bin"
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.2 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/path
