path
import { … } from 'zidane-ui'ui/src/path.ts
Functions#
basenameFunction#
The last segment of a path (/ or `` separated); trailing separators are ignored.
function basename(path: string): stringParameters
| Name | Type | Description |
|---|---|---|
| path | string | A file or folder path. |
Returns
stringcompactPathFunction#
Truncate a filesystem path for display so the most useful segments (the last few) stay readable while the start collapses to an ellipsis.
/Users/yaelguilloux/Code/agent/zidane → /…/agent/zidane
Deliberately NOT core's compactPath (zidane/chat/pure): core's rule is
~-substitution against $HOME, which a browser cannot read. Middle-segment
collapse keeps the meaningful tail intact in a narrow sidebar. Falls back
to a hard right-tail truncation when even the last segment overflows.
function compactPath(path: string, maxChars?: number): stringParameters
| Name | Type | Default | Description |
|---|---|---|---|
| path | string | The path to shorten. | |
| maxChars? | number | 38 | The longest result (default 38). |
Returns
stringformatPathForCwdFunction#
A project path as seen from cwd. A behavioral fork of core's
zidane/chat/path-display.ts: a file above the cwd shows as an absolute
path anchored at the project root, never a ../-prefixed relative, and
nothing here imports node:path.
- An absolute
projectRelativePathpasses through unchanged. - A file at or below
cwd→ a POSIX relative path (no./prefix);cwditself →.. - A file above
cwdor in a sibling tree → the absolute path.
function formatPathForCwd(
projectRelativePath: string,
projectRoot: string,
cwd: string,
): stringParameters
| Name | Type | Description |
|---|---|---|
| projectRelativePath | string | The path, relative to |
| projectRoot | string | The project's root folder. |
| cwd | string | The folder the path is shown from. |
Returns
stringsplitPathFunction#
a/b/c.ts → { dir: 'a/b', base: 'c.ts' }; dir is '' at the top level. For /-separated workspace paths.
function splitPath(path: string): { base: string; dir: string }Parameters
| Name | Type | Description |
|---|---|---|
| path | string | A |
Returns
{ base: string; dir: string }tildePathFunction#
path with a leading home folder shown as ~: /Users/ada/code/app →
~/code/app, /Users/ada → ~. Anything else (another user's folder,
/Users/adam, a relative path) comes back unchanged. For display only:
never pass the result to anything that reads the disk.
function tildePath(path: string, home: string | null | undefined): stringParameters
| Name | Type | Description |
|---|---|---|
| path | string | The path. |
| home | string | null | undefined | The home folder of the machine the path is on. Absent or empty: |
Returns
stringtildeTextFunction#
text with each path in it under home shown as ~ (in /Users/ada/x →
in ~/x): only where the home folder starts a path (the line's start,
after a space, a quote or a bracket) and ends at a path boundary. For
display only.
function tildeText(text: string, home: string | null | undefined): stringParameters
| Name | Type | Description |
|---|---|---|
| text | string | A line that may hold paths. |
| home | string | null | undefined | The home folder of the machine the paths are on. Absent or empty: |
Returns
string