Skip to main content

filterPath() function

Replaces non-alphanumeric characters with dashes to make paths comply with file system names.

Signature​

export declare function filterPath(input: string, platformDetector?: PlatformDetector): string;

Parameters​

Parameter

Type

Description

input

string

A path candidate.

platformDetector

PlatformDetector

(Optional) The platform detector instance to use. Defaults to a new PlatformDetector instance.

Returns​

string

A validated path.

Remarks​

This function sanitizes strings to be safely used as file or folder names by removing or replacing problematic characters that could cause issues across different file systems.

Platform-specific processing:

  • Windows: Preserves backslashes (\\) and colons (:) for drive letters and path separators (e.g., C:\\path\\to\\file). Replaces all other non-alphanumeric characters with dashes.
  • POSIX (Linux, macOS): Preserves forward slashes (/) for path separators. Replaces all other non-alphanumeric characters with dashes.

Post-processing: After character replacement, consecutive dashes are collapsed to a single dash to avoid excessive dashes from adjacent special characters (e.g., "foo--bar" becomes "foo-bar").

Common use cases include sanitizing build configuration names, user-provided identifiers, and template-generated path components.


Generated via tsdoc2docusaurus 1.3.2 by API Extractor/Documenter 7.57.2.