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 🙏

© 2024 – Pkg Stats / Ryan Hefner

glomp

v3.1.1

Published

Lightweight, clearly-defined alternative to file glob strings

Downloads

73

Readme

glomp

Lightweight, clearly-defined alternative to file glob strings

The Problem

File globs like ./src/**/*.js are great... until you get to know them.

  • Globbing libraries are big and complicated
  • The behavior of ** and * differs depending on the library or context (for instance, bash treats **/* differently depending on if the globstar option is set, but the globstar option isn't available in older versions of bash)
  • Debugging globs is hard
  • It's not always obvious how libraries will interpret non-absolute glob paths
    • For instance, ./package.json could refer to lots of different files depending on what the current working directory is when the library parses files
  • Some libraries include files starting with a . in their results by default, but others don't
  • Some libraries automatically expand folder globs to end with **/*, and others don't.
    • For instance, in tsconfig, src means src/**/*, but in bash, src only means src.
  • It's not obvious how they compose together; does a file need to match all of the globs in the list, or just one?

If you work with glob strings a lot, this kind of stuff starts to bite you over and over, and it gets old. Despite their prevalence, glob strings are far from standardized.

This is particularly annoying when you consider that for 90% of projects, they only care about a particular subset of glob syntax, but we're using these huge globbing libraries despite that.

This Library's Solution

So, this library provides a way to find files on disk that match a particular pattern, but it doesn't use glob strings. This makes it:

  • Easier to debug (just drop a console.log in the relevant match rule function)
  • Easier to understand (the library is very small, and its semantics are clearly-defined)
  • Composable (combine multiple patterns together using .and, .andNot, .or, and .inverse)

Here's a taste of what it looks like:

// Instead of this:
import fastGlob from "fast-glob";

const filePaths = await fastGlob([
  "**/*.ts",
  "!**/*.d.ts",
  "!node_modules/**/*",
]);

// You do this:
import glomp from "glomp";

const filePaths = await glomp
  .withExtension(".ts")
  .excludeExtension(".d.ts")
  .excludeDir("node_modules")
  .findMatches(process.cwd());

API Documentation

Please see api/index.d.ts for API documentation. There are lots of comments.

License

MIT