slash

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

Library
npm
v5.1.0
339 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
56 /100 Fair
Development Activity 48
Maintenance 24
Community 72
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 75
Code Quality 80
Innovation 85
Learning Curve 45

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.

Used by 5 apps in this directory

TypeScript
80%
AGPL 3.0

massCode

Code Editors · Developer Tools · Productivity

7,003

A free, local-first developer workspace unifying snippets, notes, HTTP requests, calculations, drawings, and dev tools in one desktop app.

View details
87
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 80%
Vue 19%
Updated 6 days ago
TypeScript
65%
Other

NocoDB

Databases · Low Code Platforms · No Code Platforms

65,098

Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.

View details
90
Repo Health
77
Technical
62
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 1 weeks ago
TypeScript
96%
MIT

Payload CMS

Blogging · CMS · Developer Tools

44,995

The open-source, Next.js-native headless CMS that lives inside your /app folder and gives you a full TypeScript backend instantly.

View details
91
Repo Health
88
Technical
65
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
JavaScript
100%
AGPL 3.0

Social Analyzer

Security

24,134

Find and analyze a person's digital footprint across 1000+ social media platforms using multi-layer detection, OCR, and metadata extraction.

View details
42
Repo Health
52
Technical
68
Dependency
Built with
JavaScript 100%
Updated 8 months ago
TypeScript
82%
Other

twenty

CRM

57,585

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 82%
MDX 15%
Updated 5 days ago

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