On this page

    M

    path.normalize

    History
    path.normalize(path): string
    Attributes
    path:string
    Returns:string

    The path.normalize() method normalizes the given path, resolving '..' and '.' segments.

    When multiple, sequential path segment separation characters are found (e.g. / on POSIX and either \ or / on Windows), they are replaced by a single instance of the platform-specific path segment separator (/ on POSIX and \ on Windows). Trailing separators are preserved.

    If the path is a zero-length string, '.' is returned, representing the current working directory.

    On POSIX, the types of normalization applied by this function do not strictly adhere to the POSIX specification. For example, this function will replace two leading forward slashes with a single slash as if it was a regular absolute path, whereas a few POSIX systems assign special meaning to paths beginning with exactly two forward slashes. Similarly, other substitutions performed by this function, such as removing .. segments, may change how the underlying system resolves the path.

    For example, on POSIX:

    path.normalize('/foo/bar//baz/asdf/quux/..');
    // Returns: '/foo/bar/baz/asdf'

    On Windows:

    path.normalize('C:\\temp\\\\foo\\bar\\..\\');
    // Returns: 'C:\\temp\\foo\\'

    Since Windows recognizes multiple path separators, both separators will be replaced by instances of the Windows preferred separator (\):

    path.win32.normalize('C:////temp\\\\/\\/\\/foo/bar');
    // Returns: 'C:\\temp\\foo\\bar'

    A TypeError is thrown if path is not a string.