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

barreler

v0.0.8

Published

Generator for barrel files (export from index files) for JavaScript and TypeScript.

Downloads

79

Readme

Barreler

Generator for barrel files (export from index files) for JavaScript and TypeScript.

Features

  • Creates index files with all named exports from a file.
  • Recursively creates index files for folder contents.

Getting started

Install globally for command line usage:

npm install -g barreler

or locally:

npm install --save-dev barreler

Usage

Use from Command line

Run barreler with one or more files or directoreies:

barreler ./file.js ./file.js ./folder

Options:

--mode, -m      Select mode values = ['all-level-index', 'multifile-index']
--include, -i   Sets pattern for file inclusion. Comma separated list. default: *.[jt]s(x)?
--exclude, -e   Sets pattern for file exclusion. Comma separated list. default: *(spec|test).[jt]s(x)?,*__tests__/*.[jt]s(x)?

Use as npm dependency

Import barrel method and provide array of files or directories to barrel.

import { barrel } from "barreler";

await barrel(files, options?);

Options:

BarrelerOptions {
  mode: BarrelerMode; // default: BarrelerMode.MultiFileIndex
  include: string[];  // default: ["*.[jt]s(x)?"],
  exclude: string[];  // default: ["*(spec|test).[jt]s(x)?", "*__tests__/*.[jt]s(x)?"]
}

Modes

AllLevelIndex / all-level-index

Generates index file on file level and exports file exports into this index.

Example:


|-- index.ts <-- generated (export from: company.ts, /farm and /store)
|-- company.ts
|-- /services
|   |-- farm.service.ts
|   |-- index.ts <-- generated
|-- /store
|   |-- chicken.store.ts
|   |-- pig.store.ts
|   |-- index.ts <-- generated

MultiFileIndex / multifile-index (default)

Generates index file on lever where there is more than 1 file to export from.

This is default mode.

Example:

|-- index.ts <-- generated (export from: company.ts, farm.service.ts and /store)
|-- company.ts
|-- /services
|   |-- farm.service.ts
|-- /store
|   |-- chicken.store.ts
|   |-- pig.store.ts
|   |-- index.ts <-- generated

Use cases

Generate index from single file

Structure:

|-- /services
|   |-- farm.service.ts
// farm.service.ts
export function feedAnimals() {}
export function cleanFarm() {}

Running barreler ./services/farm.service.ts would generate:

|-- /services
|   |-- farm.service.ts
|   |-- index.ts
// index.ts
export { feedAnimals, cleanFarm } from "./farm.service";

This would enable us to import any farm.service function directly from /services.

Generate index from folder

Structure:

|-- /services
|   |-- farm.service.ts
// farm.service.ts
export function feedAnimals() {}
export function cleanFarm() {}

Running barreler ./services would generate:

|-- /services
|   |-- farm.service.ts
|   |-- index.ts
|-- index.ts
// ./services/index.ts
export { feedAnimals, cleanFarm } from "./farm.service";
// ./index.ts
export * from "./services";

Limitations

Does not work on multiline or barrel exports.

const a;
const b;
const c;

export { a, b };
export c;

Would only export c.