normalize-path
Normalize Windows and POSIX file path slashes to unix-style forward slashes
Repository Health
Technical Analysis
normalize-path is a tiny, single-function utility that converts backslashes to forward slashes, condenses repeated slashes, and strips trailing slashes (optionally) in a file path string. It correctly handles Windows UNC and long-path prefixes so paths remain valid after normalization on path.parse(). Because consistent, cross-platform path strings are a recurring need in build tools and file watchers, it’s a foundational dependency used internally by projects like chokidar and anymatch, and by extension a large share of the Node.js file-watching and glob-matching ecosystem.
What You Get
- A single
normalizePath(path, stripTrailing)function with no dependencies - Conversion of Windows backslashes to forward slashes while preserving win32 UNC/long-path prefixes correctly
- Automatic condensing of repeated slashes into one
- Optional trailing-slash stripping via the second
stripTrailingargument (defaults to stripping)
Common Use Cases
- Normalizing file paths inside file-watching libraries (e.g. chokidar) so glob patterns match consistently across platforms
- Ensuring cache keys or generated identifiers derived from file paths are identical on Windows and POSIX systems
- Sanitizing user- or config-supplied path strings before passing them to glob-matching libraries like anymatch or micromatch
- Preprocessing paths in build tools and bundlers before comparing or storing them
Under The Hood
Architecture - The entire library is one exported function in index.js (about 30 lines): it type-checks the input, short-circuits for the root path (/ or \) and single-character paths, detects the win32 UNC/long-path prefix pattern (\\?\ or \\.\) and preserves it as //, then splits the remaining path on any run of / or \ via a single regex, optionally drops a trailing empty segment, and rejoins with /. Tech Stack - Plain, dependency-free CommonJS JavaScript with no build step; bower.json indicates it once also targeted Bower-based front-end distribution alongside npm. Code Quality - test.js (87 lines) exercises root paths, repeated slashes, Windows-style paths, UNC/long-path prefixes, and the stripTrailing flag using Mocha/assert-style tests; the function throws a TypeError for non-string input, giving a clear contract despite the tiny surface area. API Design - A single function with a positional boolean second argument (stripTrailing, default true) keeps the call site terse; this is also its main ergonomic limitation for callers who want to combine it with other flags, though its narrow single-purpose scope is a deliberate design choice reflected in its README.md positioning as a focused building block for other tools like chokidar and anymatch.
Used by 3 apps in this directory
Amplication
Developer Tools · AI Code Assistants · Automation
Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.
Kibana
Analytics · Monitoring
Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.
TinaCMS
CMS
An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.