Modules@robinpath/path
path

@robinpath/path

0.1.2Node.jsPublic

Path 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.join to perform this operation
  • Resolve a sequence of paths into an absolute path -- Use path.resolve to perform this operation
  • Get the directory name of a path -- Use path.dirname to perform this operation
  • Get the last portion of a path (filename) -- Use path.basename to perform this operation
  • Get the file extension of a path -- Use path.extname to perform this operation

Quick Reference

FunctionDescriptionReturns
joinJoin path segments into a single pathThe joined path string
resolveResolve a sequence of paths into an absolute pathThe resolved absolute path
dirnameGet the directory name of a pathThe directory portion of the path
basenameGet the last portion of a path (filename)The last portion of the path
extnameGet the file extension of a pathThe extension of the file including the dot
normalizeNormalize a path, resolving '..' and '.' segmentsThe normalized path
isAbsoluteCheck whether a path is absoluteTrue if the path is absolute, false otherwise
relativeCompute the relative path from one path to anotherThe relative path from 'from' to 'to'
parseParse a path into an object with root, dir, base, ext, and nameAn object with root, dir, base, ext, and name properties
separatorGet the platform-specific path segment separatorThe 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"
ParameterTypeRequiredDescription
segmentsstringYesPath 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"
ParameterTypeRequiredDescription
segmentsstringYesPath 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"
ParameterTypeRequiredDescription
pathstringYesThe 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"
ParameterTypeRequiredDescription
pathstringYesThe file path
extstringNoOptional 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"
ParameterTypeRequiredDescription
pathstringYesThe file path

normalize

Normalize a path, resolving '..' and '.' segments

Module: path | Returns: string -- The normalized path

path.normalize "/usr/local/../bin"
ParameterTypeRequiredDescription
pathstringYesThe 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"
ParameterTypeRequiredDescription
pathstringYesThe 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"
ParameterTypeRequiredDescription
fromstringYesThe base path
tostringYesThe 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"
ParameterTypeRequiredDescription
pathstringYesThe 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
ParameterTypeRequiredDescription
(none)NoCall with no arguments

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(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)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/path

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size4.9 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities