slash

Converts Windows backslash paths to forward-slash paths in JavaScript.

Library
npm
v5.1.0
340stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity0
Maintenance20
Community68
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture75
Code Quality80
Innovation85
Learning Curve45

slash is a tiny, single-purpose npm package from Sindre Sorhus that converts Windows backslash file paths (foo\bar) into forward-slash paths (foo/bar). It exists because Node.js’s path module intentionally returns backslash-separated paths on Windows, which breaks code that expects POSIX-style forward slashes — for example glob matchers, URL builders, or generated import specifiers.

The package is a single exported function with no runtime dependencies, distributed as native ESM with bundled TypeScript types. It correctly leaves Windows extended-length paths (prefixed with \\?\) untouched, since those can’t safely be slash-converted. At roughly 140 million weekly downloads, it’s a foundational piece of the Node.js tooling ecosystem, used internally by build tools, bundlers, and testing frameworks that need path strings to be consistent across operating systems.

What You Get

  • A single default-exported slash(path) function that converts any Windows backslash path to a forward-slash path.
  • Extended-length path detection (\\?\ prefix) so those paths are left untouched instead of being incorrectly rewritten.
  • Zero runtime dependencies and a single-file, sub-kilobyte footprint.
  • Native ESM distribution with bundled TypeScript type definitions (index.d.ts).

Common Use Cases

  • Normalizing file paths before writing them into a build manifest, JSON output, or generated report so they read consistently on any OS.
  • Making path strings deterministic across Windows, macOS, and Linux CI runners for snapshot or golden-file testing.
  • Preparing path strings for libraries that require forward slashes (such as glob matchers) when the paths originated from Node’s path.join.
  • Generating consistent import/require specifiers from filesystem paths in codegen or bundler tooling, regardless of the host OS.

Under The Hood

Architecture The package is a single-file ES module (index.js) with no internal layering — one default-exported function receives a path string, checks for the Windows extended-length prefix (\\?\) via String.startsWith, and either returns the path unchanged or replaces every backslash with a forward slash via a global regex replace. There is no separation of concerns beyond that single conditional branch, no dependency injection, and nothing to break if an abstraction changed, since there is no abstraction beyond the function itself — index.d.ts mirrors this with one typed signature and an embedded usage example.

Tech Stack Distributed as native ESM only ("type": "module", a single exports field pointing at index.js) with bundled TypeScript declarations, and no build or bundling step transforms the shipped code. It carries zero runtime dependencies. Development tooling is xo (an opinionated ESLint preset) for linting, ava for behavioral tests, and tsd for compile-time type-signature tests, all run through one npm test script and exercised on a Node 14/16/18 matrix in GitHub Actions.

Code Quality The test suite covers both the primary conversion behavior (including a Unicode path segment) and the extended-length path edge case via ava, xo enforces a strict lint baseline as part of the same test run, and tsd verifies the public type declaration against a dedicated type-test file so the exported type signature is checked in CI rather than only documented in the README. Error handling isn’t really applicable given the function has no failure modes on the string input it expects, and naming is minimal and clear throughout. CI runs the full lint/test/type-check suite on every push and pull request across three Node versions.

API Design The public surface is a single function taking one required string argument and returning one string — about as low-friction and discoverable as an API gets, with no options object or class to instantiate. The type declaration’s docblock includes a runnable usage example mirroring the README, so editors surface working sample code on hover. The one rough edge for consumers is that it’s ESM-only, with no CommonJS entry point, so CommonJS callers need a dynamic import() or a bundler.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search