query
On this page

normalizePath

lib.strings.normalizePath

Docs pulled from | This Revision | about 1 hour ago


Normalize path, removing extraneous /s

Inputs

s
1. Function argument

Type

normalizePath :: string -> string

Examples

lib.strings.normalizePath usage example

normalizePath "/a//b///c/"
=> "/a/b/c/"

Noogle detected

Implementation

The following is the current implementation of this function.

normalizePath = s:
    warnIf
      (isPath s)
      ''
        lib.strings.normalizePath: The argument (${toString s}) is a path value, but only strings are supported.
            Path values are always normalised in Nix, so there's no need to call this function on them.
            This function also copies the path to the Nix store and returns the store path, the same as "''${path}" will, which may not be what you want.
            This behavior is deprecated and will throw an error in the future.''
      (
        builtins.foldl'
          (x: y: if y == "/" && hasSuffix "/" x then x else x+y)
          ""
          (stringToCharacters s)
      );