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

fs-jetpack

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-jetpack - npm Package Compare versions

Comparing version 4.2.0 to 4.3.0

66

lib/find.js

@@ -14,2 +14,3 @@ "use strict";

matching: ["string", "array of string"],
filter: ["function"],
files: ["boolean"],

@@ -82,10 +83,18 @@ directories: ["boolean"],

path,
{ maxLevelsDeep, symlinks: "follow" },
{ maxLevelsDeep, symlinks: "follow", inspectOptions: { times: true } },
(itemPath, item) => {
if (item && itemPath !== path && matchesAnyOfGlobs(itemPath)) {
if (
const weHaveMatch =
(item.type === "file" && options.files === true) ||
(item.type === "dir" && options.directories === true)
) {
foundAbsolutePaths.push(itemPath);
(item.type === "dir" && options.directories === true);
if (weHaveMatch) {
if (options.filter) {
const passedThroughFilter = options.filter(item);
if (passedThroughFilter) {
foundAbsolutePaths.push(itemPath);
}
} else {
foundAbsolutePaths.push(itemPath);
}
}

@@ -96,2 +105,4 @@ }

foundAbsolutePaths.sort();
return processFoundPaths(foundAbsolutePaths, options.cwd);

@@ -129,12 +140,44 @@ };

let waitingForFiltersToFinish = 0;
let treeWalkerDone = false;
const maybeDone = () => {
if (treeWalkerDone && waitingForFiltersToFinish === 0) {
foundAbsolutePaths.sort();
resolve(processFoundPaths(foundAbsolutePaths, options.cwd));
}
};
treeWalker.async(
path,
{ maxLevelsDeep, symlinks: "follow" },
{ maxLevelsDeep, symlinks: "follow", inspectOptions: { times: true } },
(itemPath, item) => {
if (item && itemPath !== path && matchesAnyOfGlobs(itemPath)) {
if (
const weHaveMatch =
(item.type === "file" && options.files === true) ||
(item.type === "dir" && options.directories === true)
) {
foundAbsolutePaths.push(itemPath);
(item.type === "dir" && options.directories === true);
if (weHaveMatch) {
if (options.filter) {
const passedThroughFilter = options.filter(item);
const isPromise = typeof passedThroughFilter.then === "function";
if (isPromise) {
waitingForFiltersToFinish += 1;
passedThroughFilter
.then(passedThroughFilterResult => {
if (passedThroughFilterResult) {
foundAbsolutePaths.push(itemPath);
}
waitingForFiltersToFinish -= 1;
maybeDone();
})
.catch(err => {
reject(err);
});
} else if (passedThroughFilter) {
foundAbsolutePaths.push(itemPath);
}
} else {
foundAbsolutePaths.push(itemPath);
}
}

@@ -147,3 +190,4 @@ }

} else {
resolve(processFoundPaths(foundAbsolutePaths, options.cwd));
treeWalkerDone = true;
maybeDone();
}

@@ -150,0 +194,0 @@ }

2

package.json
{
"name": "fs-jetpack",
"description": "Better file system API",
"version": "4.2.0",
"version": "4.3.0",
"author": "Jakub Szwacz <jakub@szwacz.com>",

@@ -6,0 +6,0 @@ "dependencies": {

# fs-jetpack [![Build Status](https://travis-ci.com/szwacz/fs-jetpack.svg?branch=master)](https://travis-ci.com/szwacz/fs-jetpack) [![Build status](https://ci.appveyor.com/api/projects/status/er206e91fpuuqf58?svg=true)](https://ci.appveyor.com/project/szwacz/fs-jetpack) [![codecov](https://codecov.io/gh/szwacz/fs-jetpack/branch/master/graph/badge.svg)](https://codecov.io/gh/szwacz/fs-jetpack)
_Fs-jetpack_ was brought to life out of frustration: "Why [node.js standard 'fs' library](http://nodejs.org/api/fs.html) has to be so tedious in use?. There are efforts to make mentioned API more pleasant ([fs-extra](https://github.com/jprichardson/node-fs-extra), [mkdirp](https://github.com/isaacs/node-mkdirp), [rimraf](https://github.com/isaacs/rimraf), etc.) but all of them just sprinkle something extra on top, not addressing the problem from the ground up. That's what _fs-jetpack_ did. Just started from scratch, and now has to offer completely redesigned, much more convenient API to work with file system.
This project was started out of frustration "Why using [standard 'fs' library](http://nodejs.org/api/fs.html) has to be so tedious?". There are efforts to make the experience more pleasant ([fs-extra](https://github.com/jprichardson/node-fs-extra), [mkdirp](https://github.com/isaacs/node-mkdirp), [rimraf](https://github.com/isaacs/rimraf), etc.) but all of them just sprinkle something extra on top, not addressing the root problem. That is where _fs-jetpack_ aims: completely rethought, much more convenient API to work with file system. You will especially appreciate it as a scripting/tooling library and for your build pipelines.

@@ -84,16 +84,12 @@ # Table of Contents

Let's say you want to create folder structure...
Let's say you want to create folder structure as demonstrated in comment below. Peace of cake!
```
.
|- greets
|- greet.txt
|- greet.json
|- greets-i18n
|- polish.txt
```
```js
// .
// |- greets
// |- greet.txt
// |- greet.json
// |- greets-i18n
// |- polish.txt
Peace of cake with jetpack!
```js
jetpack

@@ -108,2 +104,31 @@ .dir("greets")

Need to copy whole directory of files, but first perform some transformations on each file?
```js
const src = jetpack.cwd("path/to/source/folder");
const dst = jetpack.cwd("path/to/destination");
src.find({ matching: "*" }).forEach((path) => {
const content = src.read(path);
const transformedContent = transformTheFileHoweverYouWant(content);
dst.write(path, transformedContent);
});
```
Need to delete all temporary and log files inside `my_folder` tree?
```js
jetpack.find("my_folder", { matching: ["*.tmp", "*.log"] }).forEach(jetpack.remove);
```
Need to perform temporary data transformations?
```js
const dir = jetpack.tmpDir();
dir.write("data.txt", myData);
// Perform some operations on the data and when you're done
// and don't need the folder any longer just call...
dir.remove();
```
# Getting Started

@@ -350,2 +375,3 @@

- `matching` (default `"*"`) glob patterns of files you want to find ([all possible globs are described further in this readme](#matching-patterns)).
- `filter` (default `undefined`) function that is called on each matched path with [inspect object](#inspectpath-options) of that path as an argument. Return `true` or `false` to indicate whether given path should stay on list or should be filtered out (see example below).
- `files` (default `true`) whether or not should search for files.

@@ -373,2 +399,11 @@ - `directories` (default `false`) whether or not should search for directories.

// Finds all '.txt' files that were modified after 2019-01-01
const borderDate = new Date("2019-01-01")
jetpack.find("foo", {
matching: "*.txt",
filter: (inspectObj) => {
return inspectObj.modifyTime > borderDate
}
});
// Finds all '.js' files inside 'my-project' but excluding those in 'vendor' subtree.

@@ -375,0 +410,0 @@ jetpack.find("my-project", { matching: ["*.js", "!vendor/**/*"] });

@@ -39,2 +39,3 @@ /// <reference types="node" />

matching?: string | string[];
filter?: (fileInspect: InspectResult) => boolean | Promise<boolean>;
files?: boolean;

@@ -41,0 +42,0 @@ directories?: boolean;

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