Skip to content

path

import { … } from 'zidane-ui'ui/src/path.ts

Functions#

basenameFunction#

The last segment of a path (/ or `` separated); trailing separators are ignored.

TypeScript
function basename(path: string): string
Parameters
NameTypeDescription
pathstring

A file or folder path.

string

ui/src/path.ts:14

compactPathFunction#

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.

TypeScript
function compactPath(path: string, maxChars?: number): string
Parameters
NameTypeDefaultDescription
pathstring

The path to shorten.

maxChars?number38

The longest result (default 38).

string

ui/src/path.ts:47

formatPathForCwdFunction#

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 projectRelativePath passes through unchanged.
  • A file at or below cwd → a POSIX relative path (no ./ prefix); cwd itself → ..
  • A file above cwd or in a sibling tree → the absolute path.
TypeScript
function formatPathForCwd(
  projectRelativePath: string,
  projectRoot: string,
  cwd: string,
): string
Parameters
NameTypeDescription
projectRelativePathstring

The path, relative to projectRoot (or absolute).

projectRootstring

The project's root folder.

cwdstring

The folder the path is shown from.

string

ui/src/path.ts:86

splitPathFunction#

a/b/c.ts → { dir: 'a/b', base: 'c.ts' }; dir is '' at the top level. For /-separated workspace paths.

TypeScript
function splitPath(path: string): { base: string; dir: string }
Parameters
NameTypeDescription
pathstring

A /-separated path.

{ base: string; dir: string }

ui/src/path.ts:28

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.

TypeScript
function tildePath(path: string, home: string | null | undefined): string
Parameters
NameTypeDescription
pathstring

The path.

homestring | null | undefined

The home folder of the machine the path is on. Absent or empty: path unchanged.

string

ui/src/path.ts:178

tildeTextFunction#

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.

TypeScript
function tildeText(text: string, home: string | null | undefined): string
Parameters
NameTypeDescription
textstring

A line that may hold paths.

homestring | null | undefined

The home folder of the machine the paths are on. Absent or empty: text unchanged.

string

ui/src/path.ts:194