4.6.5 • Published 4 months ago
@jsenv/filesystem v4.6.5
Jsenv filesystem
Collection of functions to interact with filesystem in Node.js
List files using pattern matching
import { listFilesMatching } from "@jsenv/filesystem";
const jsFiles = await listFilesMatching({
directoryUrl: new URL("./", import.meta.url),
patterns: {
"./**/*.js": true,
"./**/*.test.js": false,
},
});
[
'file:///Users/dmail/docs/demo/a.js',
'file:///Users/dmail/docs/demo/b.js'
]
Watch a specific file changes
import { readFileSync } from "node:fs";
import { registerFileLifecycle } from "@jsenv/filesystem";
const packageJSONFileUrl = new URL("./package.json", import.meta.url);
let packageJSON = null;
const unregister = registerFileLifecycle(packageJSONFileUrl, {
added: () => {
packageJSON = JSON.parse(String(readFileSync(packageJSONFileUrl)));
},
updated: () => {
packageJSON = JSON.parse(String(readFileSync(packageJSONFileUrl)));
},
removed: () => {
packageJSON = null;
},
notifyExistent: true,
});
unregister(); // stop watching the file changes
Watch many files changes
import { registerDirectoryLifecycle } from "@jsenv/filesystem";
const directoryContentDescription = {};
const unregister = registerDirectoryLifecycle("file:///directory/", {
watchPatterns: {
"./**/*": true,
"./node_modules/": false,
},
added: ({ relativeUrl, type }) => {
directoryContentDescription[relativeUrl] = type;
},
removed: ({ relativeUrl }) => {
delete directoryContentDescription[relativeUrl];
},
});
unregister(); // stop watching the directory changes
API
Installation
npm install @jsenv/filesystem
4.6.5
4 months ago
4.6.4
4 months ago
4.6.3
4 months ago
4.4.0
6 months ago
4.6.1
6 months ago
4.2.5
10 months ago
4.6.0
6 months ago
4.2.4
11 months ago
4.2.6
10 months ago
4.5.0
6 months ago
4.3.2
8 months ago
4.3.1
8 months ago
4.5.1
6 months ago
4.3.0
8 months ago
4.2.3
1 year ago
4.2.2
1 year ago
4.2.1
1 year ago
4.2.0
1 year ago
4.1.8
1 year ago
4.1.7
1 year ago
4.1.9
1 year ago
4.1.6
2 years ago
4.1.4
2 years ago
4.1.5
2 years ago
4.0.9
2 years ago
4.0.8
2 years ago
4.0.5
2 years ago
4.1.3
2 years ago
4.0.4
2 years ago
4.0.10
2 years ago
4.0.7
2 years ago
4.0.6
2 years ago
4.1.0
2 years ago
4.0.1
2 years ago
4.0.0
2 years ago
4.1.2
2 years ago
4.0.3
2 years ago
4.1.1
2 years ago
4.0.2
2 years ago
3.2.2
2 years ago
3.2.1
2 years ago
3.2.0
2 years ago
3.1.0
2 years ago
3.0.0
2 years ago
2.7.2
2 years ago
2.7.0
2 years ago
2.6.1
2 years ago
2.7.1
2 years ago
2.6.0
2 years ago
2.5.0
3 years ago
2.4.0
3 years ago
2.5.1
3 years ago
2.3.0
3 years ago
2.3.1
3 years ago
2.2.0
3 years ago
2.1.1
3 years ago
2.1.0
3 years ago
2.0.0
3 years ago
1.0.0
3 years ago