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

zeptomatch-explode

v1.0.0

Published

A little utility for exploding a zeptomatch-flavored glob into its dynamic and static parts.

Downloads

65,508

Readme

Zeptomatch Explode

A little utility for exploding a zeptomatch-flavored glob into its dynamic and static parts.

The idea is to extract the static parts of a glob, potentially from both ends, for optimization purposes. Which static parts can be detected as such, and which dynamic parts can be resolved into static parts, is an implementation detail.

Install

npm install --save zeptomatch-explode

Usage

explodeStart

This function extracts the static parts of a glob from its start, stopping at the first dynamic part found.

It returns an array of static parts, and the rest of the glob, the dynamic part. The dynamic part is never empty, unless the entire glob is an empty string, so the last part of a glob is never considered static by this function.

The static parts are returned as an array because some simple dynamic starts are resolved into all the static strings that would match them.

The idea is that for example for simple globs that may look like this: foo/**/*, instead of searching from the root and then matching against the whole glob, if you extract the static part out of it you can just search for everything inside the foo folder, which is potentially faster, as other folders are not searched into and no files need to actually be matched against the glob, in this particular example.

import {explodeStart} from 'zeptomatch-explode';

const result1 = explodeStart ( 'foo/**/*' );

result1.statics; // => ['foo']
result1.dynamic; // => '**/*'

const result2 = explodeStart ( 'foo{bar,baz}/**/*' );

result2.statics; // => ['foobar', 'foobaz']
result2.dynamic; // => '**/*'

const result3 = explodeStart ( 'foo' );

result3.statics; // => []
result3.dynamic; // => 'foo'

explodeEnd

This function extracts the static part of a glob from its end, stopping at the first slash found.

It returns an array of static parts, and the rest of the glob, the dynamic part. The rest of the glob is never empty, it gets generalized automatically to match against any file.

The static parts are returned as an array because some simple dynamic ends are resolved into all the static strings that would match them.

The idea is that by extracting this information from the end of a glob you can generate optimized matching functions that just check the end of a path, instead of matching the whole path against the glob, very quickly.

import {explodeEnd} from 'zeptomatch-explode';

const result1 = explodeEnd ( '**/*.js' );

result1.flexibleStart; // => true
result1.flexibleEnd; // => false
result1.statics; // => ['.js']
result1.dynamic; // => '**/*'

const result2 = explodeEnd ( '**/index.{js,ts}' );

result2.flexibleStart; // => false
result2.flexibleEnd; // => false
result2.statics; // => ['index.js', 'index.ts']
result2.dynamic; // => '**/*'

const result3 = explodeEnd ( '**/*.test.*' );

result3.flexibleStart; // => true
result3.flexibleEnd; // => true
result3.statics; // => ['.test.']
result3.dynamic; // => '**/*'

License

MIT © Fabio Spampinato