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

brace-expander-js

v1.0.1

Published

Shell-style Brace Expansions performed by JavaScript.

Downloads

2

Readme

BraceExpander.js

About

A JavaScript-based implementation of Shell Brace Expansions because I couldn't find anything extant.

This takes something like /path/to/{foo,bar{a,b}} and turns it into:

  • /path/to/foo
  • /path/to/bar/a
  • /path/to/bar/b

Usage

// "one-liner" version
var expansions = new BraceExpander('input_to_expand').getExpansions();

// "clean code" version
var Expanded = new BraceExpander('input_to_expand');
var expansions = Expanded.getExpansions();
var expansionsQuantity = Expanded.getExpansionsCount();

Quick Start

If you would just like to run this "real quick" to see how a particular expansion spring is going to be handled and/or just want to use this project with minimal setup, here is how to do accomplish that with minimal effort.

Short version (if you already know what you're doing):

  1. Simply "import" the src/BraceExpander.js file into your browser's DevTools Console and run new BraceExpander('input_to_expand');

Long version (if that didn't make 100% sense):

  1. Open the "Console" portion of your browser's Developer Tools.
  2. Open src/BraceExpander.js from this repository and "run" that code in your Console (i.e. "copy & paste" and "hit enter").
    • Note: "running" this code won't give you any ineresting output since literally the only thing it does it create a prototype.
  3. Run new BraceExpander('/path/to/{foo,bar}').getExpansions();.
    • Note: You could also just follow the Usage instructions from this README and console.log(expansions); at the end, but honestly if you're reading a Quick Start then you probably want a one-liner.

Examples

Simple

No expansion

Input

/path/to/file

Output
  • /path/to/file

Improper expansion (most shells will error)

Input

/path/to/{file1}

Output
  • /path/to/file1

Simple expansion

Input

/path/to/{file1,file2}

Output
  • /path/to/file1
  • /path/to/file2

Simple expansion with subfolders

Input

/path/to/{dir1/file1,dir2/dir3/file2}

Output
  • /path/to/dir1/file1
  • /path/to/dir2/dir3/file2

Simple expansion with suffix

Input

/path/to/{dir1,dir2}/file1

Output
  • /path/to/dir1/file1
  • /path/to/dir2/file1

Simple expansion with blank and suffix

Input

/path/to/{dir1,}/file1

Output
  • /path/to/dir1/file1
  • /path/to/file1

Triple expansion

Input

/path/to/{file1,file2,dir1/file3}

Output
  • /path/to/file1
  • /path/to/file2
  • /path/to/dir1/file3

Triple expansion * quadruple expansion (with content between)

Input

/path/to/{file1,file2,file3}.{ext1,ext2,ext3,ext4}

Output
  • /path/to/file1.ext1
  • /path/to/file1.ext2
  • /path/to/file1.ext3
  • /path/to/file1.ext4
  • /path/to/file2.ext1
  • /path/to/file2.ext2
  • /path/to/file2.ext3
  • /path/to/file2.ext4
  • /path/to/file3.ext1
  • /path/to/file3.ext2
  • /path/to/file3.ext3
  • /path/to/file3.ext4

Simple expansion with nested triple expansion

Input

/path/to/{dir1,dir2/{file1,file2,file3}.txt}

Output
  • /path/to/dir1
  • /path/to/dir2/file1.txt
  • /path/to/dir2/file2.txt
  • /path/to/dir2/file3.txt

Advanced

Some fun

Input

/path/to/{dir1/{dir2,dir3/file1.{ext1,ext2},file2,file3,file4},{dir4,dir5,dir6/{,dir7}}/file5}

Human-readable Input
/path/to/{
	dir1/{
		dir2,
		dir3/file1.{
			ext1,
			ext2
		},
		file2,
		file3,
		file4
	},
	{
		dir4,
		dir5,
		dir6/{
			dir7,
		}
	}/file5
}
Output
  • /path/to/dir1/dir2
  • /path/to/dir1/dir3/file1.ext1
  • /path/to/dir1/dir3/file1.ext2
  • /path/to/dir1/file2
  • /path/to/dir1/file3
  • /path/to/dir1/file4
  • /path/to/dir4/file5
  • /path/to/dir5/file5
  • /path/to/dir6/file5
  • /path/to/dir6/dir7/file5

Excerpt from the script for which this was created

Filesystem
/var/www/project
|-- app
|   |-- code/local
|       |-- MyNamespace
|           |-- Module123
|       |-- DifferentNamespace
|           |-- Module123
|-- design/frontend/mytheme/default
|   |-- template/feature
|   |-- layout/feature.xml
|-- skin/frontend/mytheme
    |-- feature.css
    |-- js/feature.js
Input

/var/www/magento/{app/{code/local/{MyNamespace,DifferentNamespace}/Module123,design/frontend/mytheme/default/{template/feature,layout/feature.xml}},skin/frontend/mytheme/{feature.css,js/feature.js}}

Human-Readable
/var/www/magento/{
	app/{
		code/local/{
			MyNamespace,
			DifferentNamespace
		}/Module123,
		design/frontend/mytheme/default/{
			template/feature,
			layout/feature.xml
		}
	},
	skin/frontend/mytheme/{
		feature.css,
		js/feature.js
	}
}
Output
  • /var/www/magento/app/code/local/MyNamespace/Module123
  • /var/www/magento/app/code/local/DifferentNamespace/Module123
  • /var/www/magento/app/design/frontend/mytheme/default/template/feature
  • /var/www/magento/app/design/frontend/mytheme/default/layout/feature.xml
  • /var/www/magento/skin/frontend/mytheme/feature.css
  • /var/www/magento/skin/frontend/mytheme/js/feature.js