Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

files-pipe

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

files-pipe

## Installation

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
decreased by-10.25%
Maintainers
1
Weekly downloads
 
Created
Source

files-pipe 🧪

Installation

First, install the files-pipe component like so:

npm install -D -E files-pipe

Then, create a new pipe from this component:

Index.ts

import { Files } from "files-pipe";

await new Files().In("./input");

Getting started

The files-pipe will now provide you with a pipe method which you can use to execute the callback on each file from the pipe.

Index.ts

import { Files } from "files-pipe";

await (
	await (await new Files().In("./Input")).By("**/*.md")
).Pipe({
	// Append some content to all of the text files
	Wrote: (On) => (On.Buffer += "LICENSE [MIT]"),
});

These are the defaults for each callback.

import { Files } from "files-pipe";

await new Files().Pipe({
	// Writes the buffer into a file
	Wrote: async (On) => On.Buffer,
	// Reads the file into a buffer
	Read: async (On) => await fs.promises.readFile(On.Input, "utf-8"),
	// Checks if the file has passed any checks
	Passed: async (On) => On && true,
	// When the file cannot be processed
	Failed: async (Input) => `Error: Cannot process file ${Input}!`,
	// When the file is processed
	Accomplished: async (On) => `Processed ${On.Input} in ${On.Output}.`,
	// When the whole plan is fulfilled
	Fulfilled: async (Plan) =>
		`Successfully processed a total of ${Plan.Files} ${
			Plan.Files === 1 ? "file" : "files"
		}.`,
	// When the plan has changed
	Changed: async (Plan) => Plan,
});

You can add multiple paths to your pipe by specifying an array as the path variable.

Index.ts

import { Files } from "files-pipe";

await new Files().In(["./Input", "./Input2"]);

You can also provide a map of paths for different input output directories.

Index.ts

import { Files } from "files-pipe";

await new Files().In(new Map([["./Input", "./Output"]]));

You can provide a filter to exclude files from your pipe. A filter can be an array of regexes or a single match. You can use functions, as well to match on file names.

Index.ts

import { Files } from "files-pipe";

await new Files().Not([
	"File.txt",
	(File: string) => File === "./Input/File.txt",
]);

Set logger to 0 if you do not want to see debug messages. Default is 2.

Index.ts

import { Files } from "files-pipe";

new Files(0);

Changelog

See CHANGELOG.md for a history of changes to this component.

FAQs

Package last updated on 08 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc