npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

filepath-validator-kit

v0.1.0

Published

Validate file paths with portable, POSIX, or Windows diagnostics.

Readme

filepath-validator-kit

npm version License: MPL-2.0 CI

Validate file path strings with explicit portable, POSIX or Windows policies and structured diagnostics.

filepath-validator-kit is a small clean-room toolkit for forms, config editors, archive builders and CLIs that need to explain why a user-provided path is unsafe or unsupported. It validates strings only: no filesystem access, no path resolution, no symlink checks and no mutation of user input.

Links: npm · GitHub

Package quality

  • TypeScript types are generated from the source.
  • ESM-only package with no runtime dependencies.
  • Marked as side-effect free for bundlers.
  • Browser-friendly implementation with no Node-only APIs.
  • CI runs npm ci, typecheck, build, and test.
  • Tested on Node.js 20 and 22 with GitHub Actions.

Install

npm install filepath-validator-kit

Quick Start

import {
  assertValidPath,
  createFilePathValidator,
  isValidPath,
  validateFilePath
} from "filepath-validator-kit";

isValidPath("notes/2026-05-12.txt");
// true

const result = validateFilePath("reports/con.txt", { platform: "portable" });

if (!result.valid) {
  result.issues[0]?.code;
  // "windows-reserved-name"

  result.issues[0]?.segment;
  // "con.txt"
}

assertValidPath("exports/report.csv");
// "exports/report.csv"

const uploadPath = createFilePathValidator({
  platform: "portable",
  allowAbsolute: false
});

uploadPath.isValid("exports/report.csv");
// true

Why this package

Some path validators only answer true or false. That is hard to use in product UI, imports, config files and command-line tools because the caller still has to explain what went wrong.

filepath-validator-kit returns stable issue codes, source offsets and the failing path segment:

const result = validateFilePath("safe//con.txt", { platform: "portable" });

result.issues;
// [
//   {
//     code: "empty-segment",
//     message: "Path contains an empty segment.",
//     segmentIndex: 1,
//     segment: "",
//     start: 5,
//     end: 5
//   },
//   {
//     code: "windows-reserved-name",
//     message: "Path segment is a Windows-reserved device name.",
//     segmentIndex: 2,
//     segment: "con.txt",
//     start: 6,
//     end: 13
//   }
// ]

API

validateFilePath(input, options?)

Returns a FilePathValidationResult with the original input, normalized separators, absolute-path metadata, parsed segments and structured issues.

type FilePathValidationResult = {
  valid: boolean;
  input: unknown;
  normalizedSeparators: string;
  absolute: boolean;
  segments: FilePathSegment[];
  issues: FilePathValidationIssue[];
};

Example:

const result = validateFilePath("assets/logo?.svg", {
  platform: "windows",
  allowAbsolute: false,
  allowTraversal: false
});

vetPath(input, options?)

Short alias for validateFilePath(input, options). It is useful when you prefer compact names, but validateFilePath is the clearest default in application code.

isValidPath(input, options?)

Boolean shortcut for validateFilePath(input, options).valid.

isValidPath("assets/logo.svg", { platform: "portable" });
// true

assertValidPath(input, options?)

Returns the input string when it is valid or throws PathVetError with the full validation result attached.

try {
  assertValidPath("reports/con.txt", { platform: "portable" });
} catch (error) {
  if (error instanceof PathVetError) {
    console.log(error.result.issues);
  }
}

createFilePathValidator(defaultOptions?)

Creates a small validator object that reuses the same defaults across a form, CLI or import pipeline. Per-call options override the defaults.

const uploadPath = createFilePathValidator({
  platform: "portable",
  allowAbsolute: false,
  allowTraversal: false
});

uploadPath.validate("exports/report.csv");
uploadPath.isValid("exports/report.csv");
uploadPath.assertValid("exports/report.csv");

uploadPath.isValid("/tmp/report.csv", { allowAbsolute: true });
// true

Types

The package exports the descriptive FilePath* type names used by the main API:

  • FilePathValidationOptions
  • FilePathValidationResult
  • FilePathValidationIssue
  • FilePathSegment
  • FilePathValidator

The shorter PathVet* type names are also exported for users who prefer the compact alias.

Options

| Option | Default | Description | | --- | --- | --- | | platform | "portable" | Validation policy: "portable", "posix" or "windows". | | allowAbsolute | true | Reject absolute paths when set to false. | | allowRelative | true | Reject relative paths when set to false. | | allowTraversal | false | Allow . and .. segments. | | allowEmptySegments | false | Allow repeated separators such as safe//file.txt. | | maxLength | none | Optional full path length limit. | | maxSegmentLength | none | Optional per-segment length limit. |

Policies

  • portable: rejects Windows-reserved characters, Windows device names and Windows trailing dots/spaces.
  • windows: applies Windows segment restrictions.
  • posix: accepts characters such as ? and : because they are not path separators under POSIX.

Root-only absolute paths such as / and C:\\ are accepted when absolute paths are allowed.

Diagnostics

Issue codes are stable and intended for UI messages, logs or localization:

  • empty-input
  • not-a-string
  • invalid-option
  • absolute-not-allowed
  • relative-not-allowed
  • traversal-not-allowed
  • empty-segment
  • segment-too-long
  • path-too-long
  • nul-byte
  • windows-reserved-character
  • windows-reserved-name
  • windows-trailing-dot-or-space

Limits

This package validates path strings only. It does not:

  • check whether a file exists;
  • normalize or resolve paths;
  • inspect permissions;
  • resolve symlinks;
  • sanitize filenames;
  • guarantee that every filesystem, archive format or host application will accept the path.

Use it as an explainable first-pass validation layer before application-specific checks.

License

MPL-2.0