Change order of parameters
After giving this function more thought, I have come the realization that the order of parameters is not correct. In particular, we need to decouple the start path from the interpretation of a leading dot (.) segment.
For most use cases, there's no distinction between an unanchored path (e.g., dir/file
) and one that begins with a dot segment (e.g., ./dir/file
). We want to cater to that use case for the casual user, but still offer the option to allow a leading dot segment to carry special meaning (such as relative to the location of the current file, like Node's require
function).
Here's the new order I'd like to propose:
path, start = '~+', dot = '.'
By default, we use dot as the start path to prepend to an unanchored path, then interpret the dot character as the current working directory. This allows both dir/file
and ./dir/file
to be resolved relative to the current working directory by default when using expandPath(path)
, just like Node's path.resolve
function.
To change the start path for both scenarios, you'd use expandPath(path, '.', '/custom/start/path')
. But to assign different meanings, you'd use expandPath(path, '~+', '/custom/dot/path')
.
The start
parameter can be .
, ~
, ~+
, or an absolute path. The dot
parameter can be ~
, ~+
, or an absolute path.