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

mergefs

v1.0.2

Published

Like Object.assign but recursive and for files.

Downloads

7

Readme

mergefs

Like Object.assign but recursive and for files.

The Idea

Specify an output folder, and any number of input folders. They will be merged in order to the output, overwriting files duplicated by name.

In addition, you can also list specific filepaths, in which case only those files will be merged from the input folders and written to the output folders.

The Library

You can import or require or whatnot the usual ways:

const mergefs = require('mergefs')
// or
import { mergefs } from 'mergefs'

Then you call that function, specifying a single output path and an ordered array of input paths, with an optional list of file paths:

await mergefs({
	// required
	output: './out',
	// required
	input: [
		'./foo',
		'./bar',
		'./bizz'
	],
	// optional
	files: [
		'fizz/buzz.txt'
	]
});

There is no output from calling this function. If there is an error it will be thrown.

The API

output: String required

The path to the output folder.

If the folder doesn't exist, it will be made.

input: Array<String> required

An ordered list of paths to input folders.

The order matters: the last input will override the first, if there are files with the same name.

files: Array<String>

An unordered list of specific file paths to merge.

The Examples

Suppose you have a folder structure like this:

input
  |- 001
  |  |- aaa
  |  |  \- file.txt // "text-1"
  |  \- bbb
  |  |  \- file.txt // "text-2"
  |- 002
  |  |- aaa
  |  |  \- file.txt // "text-3"
  |  \- ccc
  |     \- file.txt // "text-4"
  \- 003
     |- bbb
     |  \- file.txt // "text-5"
     \- ccc
        \- file.txt // "text-6"

The Example 1: Merge Everything

If you wanted to merge all input folders, you would do:

await mergefs({
	output: '/output',
	input: [
		'/input/001',
		'/input/002',
		'/input/003'
	]
});

Then the structure of the output folder would be:

output
  |- aaa
  |  \- file.txt // "text-3"
  |- bbb
  | \- file.txt // "text-5"
  \- ccc
     \- file.txt // "text-6"

The Example 2: Change Merge Order

If we take the same example but change the order of the input folders:

await mergefs({
	output: '/output',
	input: [
		'/input/003',
		'/input/002',
		'/input/001'
	]
});

Then the structure of the output folder would be:

output
  |- aaa
  |  \- file.txt // "text-1"
  |- bbb
  | \- file.txt // "text-2"
  \- ccc
     \- file.txt // "text-4"

The Example 3: Merge Specific Files

If we take the same input folder structure but list specific files:

await mergefs({
	output: '/output',
	input: [
		'/input/001',
		'/input/002',
		'/input/003'
	],
	files: [
		'ccc/file.txt'
	]
});

Then the structure of the output folder would be:

output
  \- ccc
     \- file.txt // "text-6"

The Path Details

Both the input and output paths will be resolved using the builtin NodeJS path.resolve.

You can use relative or absolute paths, and they will be interpreted using that module.

The files properties will be resolved with the input paths using path.join and then path.resolve on the resulting filepath.

The License

Published and released under the Very Open License.