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

classify-filename

v0.1.2

Published

Sort filenames into named buckets by rules — strings, regex, or predicates. Zero dependencies.

Readme

classify-filename

npm version npm downloads minzipped size types included license

Sort filenames into named buckets by rules. Zero dependencies, tiny footprint.

npm install classify-filename

Quick start

import { classify } from 'classify-filename';

const files = [
  'NOC_2024.pdf',
  'noc_letter.pdf',
  'agreement_v1.docx',
  'invoice_2.pdf',
  'invoice_10.pdf',
  'random.txt',
];

const result = classify(files, [
  { name: 'noc',        match: /^noc/i },
  { name: 'agreements', match: 'agreement' },
  { name: 'invoices',   match: /^invoice/i },
]);

// result.sections:
// {
//   noc:           ['noc_letter.pdf', 'NOC_2024.pdf'],
//   agreements:    ['agreement_v1.docx'],
//   invoices:      ['invoice_2.pdf', 'invoice_10.pdf'],  // natural sort: 2 before 10
//   uncategorized: ['random.txt'],
// }

API

classify(filenames, sections, options?)

Parameters

  • filenames: string[] — the filenames to sort.
  • sections: Section[] — buckets with matching rules. Order matters — earlier sections win on conflict.
  • options: ClassifyOptions — see below.

Returns ClassifyResult{ sections: Record<string, string[]> }, plus matches when explain: true.

Matchers

A section's match can be:

  • a string — substring match (case-insensitive by default)
  • a RegExp.test()-ed against the filename; respects its own flags
  • a function(filename) => boolean for arbitrary logic
  • an array of the above — OR-combined
{ name: 'legal', match: ['agreement', 'contract', /nda/i] }

Options

| Option | Default | Behavior | | --- | --- | --- | | caseSensitive | false | Applies only to string matchers. RegExp matchers respect their own flags. | | fallback | 'uncategorized' | Bucket for unmatched files. Pass false to drop them. | | multiMatch | false | If true, a file lands in every matching section, not just the first. | | sort | 'asc' | Natural-sort ascending. 'desc', a comparator, or false to disable. | | explain | false | When true, result includes a matches map from filename → section name. |

Priority is section order

The first section whose predicate returns true wins:

// noc_agreement.pdf lands in 'noc', not 'agreements'.
classify(['noc_agreement.pdf'], [
  { name: 'noc',        match: 'noc' },        // checked first
  { name: 'agreements', match: 'agreement' },
]);

Put narrow rules first, broad rules last.

Debugging with explain

const result = classify(files, sections, { explain: true });
console.log(result.matches);
// { 'noc_agreement.pdf': 'noc', 'random.txt': 'uncategorized', ... }

Why not just .filter()?

.filter() gives you one bucket. Real file sorting needs multiple named buckets, priority rules, natural sort, and a fallback for unmatched files — that's boilerplate you'd rewrite every time. classify-filename wraps it in a single call.

Not in v1

  • No glob support — use a RegExp for now.
  • No file-object input (size, date) — filename-only. Coming in v1.1.
  • No CLI — this is a library. A bin wrapper may follow.

See ROADMAP.md for what's planned.

License

MIT