WardrikWorkspace.Path (wardrik_workspace v0.1.0-rc.1)

Copy Markdown

Paths and globs within a workspace.

A path names a file, as notes/today.md. normalize/1 drops . segments and repeated slashes. It refuses a path that:

  • starts with / or ~
  • contains a .. segment
  • contains a NUL or a backslash
  • is longer than 1,024 bytes

Folders are just path prefixes, so there's nothing to create.

A glob matches whole paths:

  • * - any characters within one folder.
  • ? - one character.
  • ** - any characters across folders.

For example, notes/*.md matches the Markdown files in notes, and **/*.md matches all of them.

Summary

Functions

Compiles glob to a regular expression.

Returns whether glob matches path.

Normalises path. Returns {:error, reason} if it isn't a valid path.

Functions

compile(glob)

@spec compile(String.t()) :: Regex.t()

Compiles glob to a regular expression.

match?(glob, path)

@spec match?(String.t(), String.t()) :: boolean()

Returns whether glob matches path.

normalize(path)

@spec normalize(term()) :: {:ok, String.t()} | {:error, String.t()}

Normalises path. Returns {:error, reason} if it isn't a valid path.