@bemoje/fs 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/deleteOlderThan.cjs +23 -0
- package/lib/deleteOlderThan.d.cts +8 -0
- package/lib/deleteOlderThan.d.ts +8 -0
- package/lib/deleteOlderThan.js +16 -0
- package/lib/getFileAge.cjs +18 -0
- package/lib/getFileAge.d.cts +7 -0
- package/lib/getFileAge.d.ts +7 -0
- package/lib/getFileAge.js +11 -0
- package/lib/getFirstFileInDir.cjs +26 -0
- package/lib/getFirstFileInDir.d.cts +6 -0
- package/lib/getFirstFileInDir.d.ts +6 -0
- package/lib/getFirstFileInDir.js +19 -0
- package/lib/index.cjs +89 -0
- package/lib/index.d.cts +13 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +12 -0
- package/lib/readFileFirstLine.cjs +26 -0
- package/lib/readFileFirstLine.d.cts +6 -0
- package/lib/readFileFirstLine.d.ts +6 -0
- package/lib/readFileFirstLine.js +18 -0
- package/lib/removeDataUrlSchemePrefix.cjs +10 -0
- package/lib/removeDataUrlSchemePrefix.d.cts +8 -0
- package/lib/removeDataUrlSchemePrefix.d.ts +8 -0
- package/lib/removeDataUrlSchemePrefix.js +8 -0
- package/lib/updateFile.cjs +19 -0
- package/lib/updateFile.d.cts +7 -0
- package/lib/updateFile.d.ts +7 -0
- package/lib/updateFile.js +12 -0
- package/lib/updateFileLines.cjs +21 -0
- package/lib/updateFileLines.d.cts +8 -0
- package/lib/updateFileLines.d.ts +8 -0
- package/lib/updateFileLines.js +14 -0
- package/lib/updateFileLinesSync.cjs +21 -0
- package/lib/updateFileLinesSync.d.cts +6 -0
- package/lib/updateFileLinesSync.d.ts +6 -0
- package/lib/updateFileLinesSync.js +14 -0
- package/lib/updateFileSync.cjs +19 -0
- package/lib/updateFileSync.d.cts +6 -0
- package/lib/updateFileSync.d.ts +6 -0
- package/lib/updateFileSync.js +12 -0
- package/lib/updateJsonFile.cjs +23 -0
- package/lib/updateJsonFile.d.cts +8 -0
- package/lib/updateJsonFile.d.ts +8 -0
- package/lib/updateJsonFile.js +16 -0
- package/lib/updateJsonFileSync.cjs +23 -0
- package/lib/updateJsonFileSync.d.cts +6 -0
- package/lib/updateJsonFileSync.d.ts +6 -0
- package/lib/updateJsonFileSync.js +16 -0
- package/lib/walkDirectory.cjs +71 -0
- package/lib/walkDirectory.d.cts +48 -0
- package/lib/walkDirectory.d.ts +48 -0
- package/lib/walkDirectory.js +62 -0
- package/package.json +209 -19
- package/index.d.ts +0 -113
- package/index.mjs +0 -168
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates a JSON file by applying a transformation function to the parsed content.
|
|
3
|
+
* If the file doesn't exist or can't be parsed, uses the default value.
|
|
4
|
+
* Creates the file and directories if they don't exist.
|
|
5
|
+
*/
|
|
6
|
+
declare function updateJsonFile<T extends object, R extends object>(filepath: string, update: (parsedFileContent: T) => R | Promise<R>, defaultValue?: T): Promise<R>;
|
|
7
|
+
|
|
8
|
+
export { updateJsonFile };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates a JSON file by applying a transformation function to the parsed content.
|
|
3
|
+
* If the file doesn't exist or can't be parsed, uses the default value.
|
|
4
|
+
* Creates the file and directories if they don't exist.
|
|
5
|
+
*/
|
|
6
|
+
declare function updateJsonFile<T extends object, R extends object>(filepath: string, update: (parsedFileContent: T) => R | Promise<R>, defaultValue?: T): Promise<R>;
|
|
7
|
+
|
|
8
|
+
export { updateJsonFile };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
|
|
4
|
+
async function updateJsonFile(filepath, update, defaultValue = {}) {
|
|
5
|
+
let content = defaultValue;
|
|
6
|
+
try {
|
|
7
|
+
content = await fs.readJson(filepath);
|
|
8
|
+
} catch (_) {
|
|
9
|
+
}
|
|
10
|
+
const updated = await update(content);
|
|
11
|
+
await fs.outputJson(filepath, updated);
|
|
12
|
+
return updated;
|
|
13
|
+
}
|
|
14
|
+
__name(updateJsonFile, "updateJsonFile");
|
|
15
|
+
|
|
16
|
+
export { updateJsonFile };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs-extra');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
function updateJsonFileSync(filepath, update, defaultValue = {}) {
|
|
12
|
+
let content = defaultValue;
|
|
13
|
+
try {
|
|
14
|
+
content = fs__default.default.readJsonSync(filepath);
|
|
15
|
+
} catch (_) {
|
|
16
|
+
}
|
|
17
|
+
const updated = update(content);
|
|
18
|
+
fs__default.default.outputJsonSync(filepath, updated);
|
|
19
|
+
return updated;
|
|
20
|
+
}
|
|
21
|
+
__name(updateJsonFileSync, "updateJsonFileSync");
|
|
22
|
+
|
|
23
|
+
exports.updateJsonFileSync = updateJsonFileSync;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
|
|
4
|
+
function updateJsonFileSync(filepath, update, defaultValue = {}) {
|
|
5
|
+
let content = defaultValue;
|
|
6
|
+
try {
|
|
7
|
+
content = fs.readJsonSync(filepath);
|
|
8
|
+
} catch (_) {
|
|
9
|
+
}
|
|
10
|
+
const updated = update(content);
|
|
11
|
+
fs.outputJsonSync(filepath, updated);
|
|
12
|
+
return updated;
|
|
13
|
+
}
|
|
14
|
+
__name(updateJsonFileSync, "updateJsonFileSync");
|
|
15
|
+
|
|
16
|
+
export { updateJsonFileSync };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs-extra');
|
|
4
|
+
var upath = require('upath');
|
|
5
|
+
var walkdir = require('walkdir');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
10
|
+
var upath__default = /*#__PURE__*/_interopDefault(upath);
|
|
11
|
+
var walkdir__default = /*#__PURE__*/_interopDefault(walkdir);
|
|
12
|
+
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
function walkDirectory(dirpath, options) {
|
|
16
|
+
dirpath = upath__default.default.normalizeSafe(dirpath);
|
|
17
|
+
if (!options.stats && !options.only) {
|
|
18
|
+
return walkdir__default.default.sync(dirpath, {
|
|
19
|
+
...convertToWalkdirOptions(options),
|
|
20
|
+
return_object: false
|
|
21
|
+
}).map((fspath) => {
|
|
22
|
+
return upath__default.default.normalizeSafe(fspath);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
let entries = Object.entries(walkdir__default.default.sync(dirpath, convertToWalkdirOptions(options)));
|
|
26
|
+
if (options.only === "files") {
|
|
27
|
+
entries = entries.filter(([_, stats]) => {
|
|
28
|
+
return stats.isFile();
|
|
29
|
+
});
|
|
30
|
+
} else if (options.only === "directories") {
|
|
31
|
+
entries = entries.filter(([_, stats]) => {
|
|
32
|
+
return stats.isDirectory();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
entries = entries.map(([fspath, stats]) => {
|
|
36
|
+
return [
|
|
37
|
+
upath__default.default.normalizeSafe(fspath),
|
|
38
|
+
stats
|
|
39
|
+
];
|
|
40
|
+
});
|
|
41
|
+
return options.stats ? entries : entries.map(([fspath]) => {
|
|
42
|
+
return fspath;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
__name(walkDirectory, "walkDirectory");
|
|
46
|
+
function convertToWalkdirOptions(options) {
|
|
47
|
+
const result = {
|
|
48
|
+
fs: fs__default.default,
|
|
49
|
+
sync: true,
|
|
50
|
+
return_object: true
|
|
51
|
+
};
|
|
52
|
+
if (options.maxDepth !== void 0) {
|
|
53
|
+
result.max_depth = options.maxDepth;
|
|
54
|
+
}
|
|
55
|
+
if (options.followSymlinks !== void 0) {
|
|
56
|
+
result.follow_symlinks = options.followSymlinks;
|
|
57
|
+
}
|
|
58
|
+
if (options.ignoreInodes !== void 0) {
|
|
59
|
+
result.track_inodes = !options.ignoreInodes;
|
|
60
|
+
}
|
|
61
|
+
if (options.filter) {
|
|
62
|
+
const filter = options.filter;
|
|
63
|
+
result.filter = (dirpath, files) => {
|
|
64
|
+
return filter(upath__default.default.normalizeSafe(dirpath), upath__default.default.basename(dirpath)) ? files : [];
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
__name(convertToWalkdirOptions, "convertToWalkdirOptions");
|
|
70
|
+
|
|
71
|
+
exports.walkDirectory = walkDirectory;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Stats } from 'fs-extra';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Walk a directory recursively and return an array of paths.
|
|
5
|
+
*/
|
|
6
|
+
declare function walkDirectory(dirpath: string, options: WalkDirectoryOptionsWithoutStats): string[];
|
|
7
|
+
/**
|
|
8
|
+
* Walk a directory recursively and return an array of [path: string, stats: Stats] tuples.
|
|
9
|
+
*/
|
|
10
|
+
declare function walkDirectory(dirpath: string, options: WalkDirectoryOptionsWithStats): [path: string, stats: Stats][];
|
|
11
|
+
/**
|
|
12
|
+
* Options for @see walkDirectory
|
|
13
|
+
*/
|
|
14
|
+
interface WalkDirectoryOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Return stats for each path.
|
|
17
|
+
*/
|
|
18
|
+
stats?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Only return either files or directories.
|
|
21
|
+
*/
|
|
22
|
+
only?: 'files' | 'directories';
|
|
23
|
+
/**
|
|
24
|
+
* Recursion depth limit.
|
|
25
|
+
*/
|
|
26
|
+
maxDepth?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Determine whether to walk a given directory.
|
|
29
|
+
*/
|
|
30
|
+
filter?: (dirpath: string, basename: string) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Follow symbolic links.
|
|
33
|
+
*/
|
|
34
|
+
followSymlinks?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* On filesystems where inodes are not unique (eg. windows), some files may not be walked due to inode collision.
|
|
37
|
+
* Turning off this behavior may be required but at the same time may lead to hitting max_depth via link loop.
|
|
38
|
+
*/
|
|
39
|
+
ignoreInodes?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface WalkDirectoryOptionsWithoutStats extends WalkDirectoryOptions {
|
|
42
|
+
stats?: false;
|
|
43
|
+
}
|
|
44
|
+
interface WalkDirectoryOptionsWithStats extends WalkDirectoryOptions {
|
|
45
|
+
stats: true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { type WalkDirectoryOptions, type WalkDirectoryOptionsWithStats, type WalkDirectoryOptionsWithoutStats, walkDirectory };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Stats } from 'fs-extra';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Walk a directory recursively and return an array of paths.
|
|
5
|
+
*/
|
|
6
|
+
declare function walkDirectory(dirpath: string, options: WalkDirectoryOptionsWithoutStats): string[];
|
|
7
|
+
/**
|
|
8
|
+
* Walk a directory recursively and return an array of [path: string, stats: Stats] tuples.
|
|
9
|
+
*/
|
|
10
|
+
declare function walkDirectory(dirpath: string, options: WalkDirectoryOptionsWithStats): [path: string, stats: Stats][];
|
|
11
|
+
/**
|
|
12
|
+
* Options for @see walkDirectory
|
|
13
|
+
*/
|
|
14
|
+
interface WalkDirectoryOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Return stats for each path.
|
|
17
|
+
*/
|
|
18
|
+
stats?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Only return either files or directories.
|
|
21
|
+
*/
|
|
22
|
+
only?: 'files' | 'directories';
|
|
23
|
+
/**
|
|
24
|
+
* Recursion depth limit.
|
|
25
|
+
*/
|
|
26
|
+
maxDepth?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Determine whether to walk a given directory.
|
|
29
|
+
*/
|
|
30
|
+
filter?: (dirpath: string, basename: string) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Follow symbolic links.
|
|
33
|
+
*/
|
|
34
|
+
followSymlinks?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* On filesystems where inodes are not unique (eg. windows), some files may not be walked due to inode collision.
|
|
37
|
+
* Turning off this behavior may be required but at the same time may lead to hitting max_depth via link loop.
|
|
38
|
+
*/
|
|
39
|
+
ignoreInodes?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface WalkDirectoryOptionsWithoutStats extends WalkDirectoryOptions {
|
|
42
|
+
stats?: false;
|
|
43
|
+
}
|
|
44
|
+
interface WalkDirectoryOptionsWithStats extends WalkDirectoryOptions {
|
|
45
|
+
stats: true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { type WalkDirectoryOptions, type WalkDirectoryOptionsWithStats, type WalkDirectoryOptionsWithoutStats, walkDirectory };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import upath from 'upath';
|
|
4
|
+
import walkdir from 'walkdir';
|
|
5
|
+
|
|
6
|
+
function walkDirectory(dirpath, options) {
|
|
7
|
+
dirpath = upath.normalizeSafe(dirpath);
|
|
8
|
+
if (!options.stats && !options.only) {
|
|
9
|
+
return walkdir.sync(dirpath, {
|
|
10
|
+
...convertToWalkdirOptions(options),
|
|
11
|
+
return_object: false
|
|
12
|
+
}).map((fspath) => {
|
|
13
|
+
return upath.normalizeSafe(fspath);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
let entries = Object.entries(walkdir.sync(dirpath, convertToWalkdirOptions(options)));
|
|
17
|
+
if (options.only === "files") {
|
|
18
|
+
entries = entries.filter(([_, stats]) => {
|
|
19
|
+
return stats.isFile();
|
|
20
|
+
});
|
|
21
|
+
} else if (options.only === "directories") {
|
|
22
|
+
entries = entries.filter(([_, stats]) => {
|
|
23
|
+
return stats.isDirectory();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
entries = entries.map(([fspath, stats]) => {
|
|
27
|
+
return [
|
|
28
|
+
upath.normalizeSafe(fspath),
|
|
29
|
+
stats
|
|
30
|
+
];
|
|
31
|
+
});
|
|
32
|
+
return options.stats ? entries : entries.map(([fspath]) => {
|
|
33
|
+
return fspath;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
__name(walkDirectory, "walkDirectory");
|
|
37
|
+
function convertToWalkdirOptions(options) {
|
|
38
|
+
const result = {
|
|
39
|
+
fs,
|
|
40
|
+
sync: true,
|
|
41
|
+
return_object: true
|
|
42
|
+
};
|
|
43
|
+
if (options.maxDepth !== void 0) {
|
|
44
|
+
result.max_depth = options.maxDepth;
|
|
45
|
+
}
|
|
46
|
+
if (options.followSymlinks !== void 0) {
|
|
47
|
+
result.follow_symlinks = options.followSymlinks;
|
|
48
|
+
}
|
|
49
|
+
if (options.ignoreInodes !== void 0) {
|
|
50
|
+
result.track_inodes = !options.ignoreInodes;
|
|
51
|
+
}
|
|
52
|
+
if (options.filter) {
|
|
53
|
+
const filter = options.filter;
|
|
54
|
+
result.filter = (dirpath, files) => {
|
|
55
|
+
return filter(upath.normalizeSafe(dirpath), upath.basename(dirpath)) ? files : [];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
__name(convertToWalkdirOptions, "convertToWalkdirOptions");
|
|
61
|
+
|
|
62
|
+
export { walkDirectory };
|
package/package.json
CHANGED
|
@@ -1,37 +1,227 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemoje/fs",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "
|
|
5
|
-
"type": "module",
|
|
6
|
-
"sideEffects": false,
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "File system utilities for reading, updating, and managing files and directories.",
|
|
7
5
|
"keywords": [
|
|
8
|
-
"fs"
|
|
6
|
+
"fs",
|
|
7
|
+
"file-system",
|
|
8
|
+
"files",
|
|
9
|
+
"directories",
|
|
10
|
+
"reading",
|
|
11
|
+
"writing",
|
|
12
|
+
"node",
|
|
13
|
+
"utilities",
|
|
14
|
+
"typescript"
|
|
9
15
|
],
|
|
10
|
-
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"types": "./index.d.ts",
|
|
13
|
-
"import": "./index.mjs",
|
|
14
|
-
"default": "./index.mjs"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
16
|
"dependencies": {
|
|
18
|
-
"fs-extra": "^11.3.
|
|
17
|
+
"fs-extra": "^11.3.4",
|
|
19
18
|
"upath": "^2.0.1",
|
|
20
19
|
"walkdir": "^0.4.1",
|
|
21
20
|
"@types/fs-extra": "^11.0.4"
|
|
22
21
|
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
23
24
|
"publishConfig": {
|
|
24
25
|
"access": "public"
|
|
25
26
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
27
|
+
"main": "./lib/index.cjs",
|
|
28
|
+
"module": "./lib/index.js",
|
|
29
|
+
"types": "./lib/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./lib/index.d.ts",
|
|
34
|
+
"default": "./lib/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./lib/index.d.cts",
|
|
38
|
+
"default": "./lib/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./deleteOlderThan": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./lib/deleteOlderThan.d.ts",
|
|
44
|
+
"default": "./lib/deleteOlderThan.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./lib/deleteOlderThan.d.cts",
|
|
48
|
+
"default": "./lib/deleteOlderThan.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./getFileAge": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./lib/getFileAge.d.ts",
|
|
54
|
+
"default": "./lib/getFileAge.js"
|
|
55
|
+
},
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./lib/getFileAge.d.cts",
|
|
58
|
+
"default": "./lib/getFileAge.cjs"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"./getFirstFileInDir": {
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./lib/getFirstFileInDir.d.ts",
|
|
64
|
+
"default": "./lib/getFirstFileInDir.js"
|
|
65
|
+
},
|
|
66
|
+
"require": {
|
|
67
|
+
"types": "./lib/getFirstFileInDir.d.cts",
|
|
68
|
+
"default": "./lib/getFirstFileInDir.cjs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"./readFileFirstLine": {
|
|
72
|
+
"import": {
|
|
73
|
+
"types": "./lib/readFileFirstLine.d.ts",
|
|
74
|
+
"default": "./lib/readFileFirstLine.js"
|
|
75
|
+
},
|
|
76
|
+
"require": {
|
|
77
|
+
"types": "./lib/readFileFirstLine.d.cts",
|
|
78
|
+
"default": "./lib/readFileFirstLine.cjs"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"./removeDataUrlSchemePrefix": {
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./lib/removeDataUrlSchemePrefix.d.ts",
|
|
84
|
+
"default": "./lib/removeDataUrlSchemePrefix.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./lib/removeDataUrlSchemePrefix.d.cts",
|
|
88
|
+
"default": "./lib/removeDataUrlSchemePrefix.cjs"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"./updateFile": {
|
|
92
|
+
"import": {
|
|
93
|
+
"types": "./lib/updateFile.d.ts",
|
|
94
|
+
"default": "./lib/updateFile.js"
|
|
95
|
+
},
|
|
96
|
+
"require": {
|
|
97
|
+
"types": "./lib/updateFile.d.cts",
|
|
98
|
+
"default": "./lib/updateFile.cjs"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"./updateFileLines": {
|
|
102
|
+
"import": {
|
|
103
|
+
"types": "./lib/updateFileLines.d.ts",
|
|
104
|
+
"default": "./lib/updateFileLines.js"
|
|
105
|
+
},
|
|
106
|
+
"require": {
|
|
107
|
+
"types": "./lib/updateFileLines.d.cts",
|
|
108
|
+
"default": "./lib/updateFileLines.cjs"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"./updateFileLinesSync": {
|
|
112
|
+
"import": {
|
|
113
|
+
"types": "./lib/updateFileLinesSync.d.ts",
|
|
114
|
+
"default": "./lib/updateFileLinesSync.js"
|
|
115
|
+
},
|
|
116
|
+
"require": {
|
|
117
|
+
"types": "./lib/updateFileLinesSync.d.cts",
|
|
118
|
+
"default": "./lib/updateFileLinesSync.cjs"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"./updateFileSync": {
|
|
122
|
+
"import": {
|
|
123
|
+
"types": "./lib/updateFileSync.d.ts",
|
|
124
|
+
"default": "./lib/updateFileSync.js"
|
|
125
|
+
},
|
|
126
|
+
"require": {
|
|
127
|
+
"types": "./lib/updateFileSync.d.cts",
|
|
128
|
+
"default": "./lib/updateFileSync.cjs"
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"./updateJsonFile": {
|
|
132
|
+
"import": {
|
|
133
|
+
"types": "./lib/updateJsonFile.d.ts",
|
|
134
|
+
"default": "./lib/updateJsonFile.js"
|
|
135
|
+
},
|
|
136
|
+
"require": {
|
|
137
|
+
"types": "./lib/updateJsonFile.d.cts",
|
|
138
|
+
"default": "./lib/updateJsonFile.cjs"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"./updateJsonFileSync": {
|
|
142
|
+
"import": {
|
|
143
|
+
"types": "./lib/updateJsonFileSync.d.ts",
|
|
144
|
+
"default": "./lib/updateJsonFileSync.js"
|
|
145
|
+
},
|
|
146
|
+
"require": {
|
|
147
|
+
"types": "./lib/updateJsonFileSync.d.cts",
|
|
148
|
+
"default": "./lib/updateJsonFileSync.cjs"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"./walkDirectory": {
|
|
152
|
+
"import": {
|
|
153
|
+
"types": "./lib/walkDirectory.d.ts",
|
|
154
|
+
"default": "./lib/walkDirectory.js"
|
|
155
|
+
},
|
|
156
|
+
"require": {
|
|
157
|
+
"types": "./lib/walkDirectory.d.cts",
|
|
158
|
+
"default": "./lib/walkDirectory.cjs"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
31
161
|
},
|
|
162
|
+
"files": [
|
|
163
|
+
"./lib/index.js",
|
|
164
|
+
"./lib/index.d.ts",
|
|
165
|
+
"./lib/index.cjs",
|
|
166
|
+
"./lib/index.d.cts",
|
|
167
|
+
"./lib/deleteOlderThan.js",
|
|
168
|
+
"./lib/deleteOlderThan.d.ts",
|
|
169
|
+
"./lib/deleteOlderThan.cjs",
|
|
170
|
+
"./lib/deleteOlderThan.d.cts",
|
|
171
|
+
"./lib/getFileAge.js",
|
|
172
|
+
"./lib/getFileAge.d.ts",
|
|
173
|
+
"./lib/getFileAge.cjs",
|
|
174
|
+
"./lib/getFileAge.d.cts",
|
|
175
|
+
"./lib/getFirstFileInDir.js",
|
|
176
|
+
"./lib/getFirstFileInDir.d.ts",
|
|
177
|
+
"./lib/getFirstFileInDir.cjs",
|
|
178
|
+
"./lib/getFirstFileInDir.d.cts",
|
|
179
|
+
"./lib/readFileFirstLine.js",
|
|
180
|
+
"./lib/readFileFirstLine.d.ts",
|
|
181
|
+
"./lib/readFileFirstLine.cjs",
|
|
182
|
+
"./lib/readFileFirstLine.d.cts",
|
|
183
|
+
"./lib/removeDataUrlSchemePrefix.js",
|
|
184
|
+
"./lib/removeDataUrlSchemePrefix.d.ts",
|
|
185
|
+
"./lib/removeDataUrlSchemePrefix.cjs",
|
|
186
|
+
"./lib/removeDataUrlSchemePrefix.d.cts",
|
|
187
|
+
"./lib/updateFile.js",
|
|
188
|
+
"./lib/updateFile.d.ts",
|
|
189
|
+
"./lib/updateFile.cjs",
|
|
190
|
+
"./lib/updateFile.d.cts",
|
|
191
|
+
"./lib/updateFileLines.js",
|
|
192
|
+
"./lib/updateFileLines.d.ts",
|
|
193
|
+
"./lib/updateFileLines.cjs",
|
|
194
|
+
"./lib/updateFileLines.d.cts",
|
|
195
|
+
"./lib/updateFileLinesSync.js",
|
|
196
|
+
"./lib/updateFileLinesSync.d.ts",
|
|
197
|
+
"./lib/updateFileLinesSync.cjs",
|
|
198
|
+
"./lib/updateFileLinesSync.d.cts",
|
|
199
|
+
"./lib/updateFileSync.js",
|
|
200
|
+
"./lib/updateFileSync.d.ts",
|
|
201
|
+
"./lib/updateFileSync.cjs",
|
|
202
|
+
"./lib/updateFileSync.d.cts",
|
|
203
|
+
"./lib/updateJsonFile.js",
|
|
204
|
+
"./lib/updateJsonFile.d.ts",
|
|
205
|
+
"./lib/updateJsonFile.cjs",
|
|
206
|
+
"./lib/updateJsonFile.d.cts",
|
|
207
|
+
"./lib/updateJsonFileSync.js",
|
|
208
|
+
"./lib/updateJsonFileSync.d.ts",
|
|
209
|
+
"./lib/updateJsonFileSync.cjs",
|
|
210
|
+
"./lib/updateJsonFileSync.d.cts",
|
|
211
|
+
"./lib/walkDirectory.js",
|
|
212
|
+
"./lib/walkDirectory.d.ts",
|
|
213
|
+
"./lib/walkDirectory.cjs",
|
|
214
|
+
"./lib/walkDirectory.d.cts"
|
|
215
|
+
],
|
|
32
216
|
"repository": {
|
|
33
217
|
"type": "git",
|
|
34
218
|
"url": "git+https://github.com/bemoje/mono.git",
|
|
35
219
|
"directory": "libs/fs"
|
|
36
|
-
}
|
|
220
|
+
},
|
|
221
|
+
"author": {
|
|
222
|
+
"name": "Benjamin Møller Jensen",
|
|
223
|
+
"email": "bemoje@bemoje.net",
|
|
224
|
+
"url": "https://github.com/bemoje/"
|
|
225
|
+
},
|
|
226
|
+
"license": "MIT"
|
|
37
227
|
}
|
package/index.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Stats } from 'fs-extra';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Delete files older than a given timestamp
|
|
5
|
-
* @param dp The dirpath to a folder in which to delete files from
|
|
6
|
-
* @param ageThreshold The age in milliseconds to compare against
|
|
7
|
-
*/
|
|
8
|
-
declare function deleteOlderThan(dp: string, ageThreshold: number): Promise<void>;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Retrieves the age of a file in milliseconds.
|
|
12
|
-
* @param filepath - The path to the file.
|
|
13
|
-
*/
|
|
14
|
-
declare function getFileAge(filepath: string): Promise<number>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Get the name of the first file (not directory) found in a directory.
|
|
18
|
-
*/
|
|
19
|
-
declare function getFirstFileInDir(dirpath: string): Promise<string>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Reads the first line of a file asynchronously.
|
|
23
|
-
*/
|
|
24
|
-
declare function readFileFirstLine(filepath: string): Promise<string>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Removes the data URL scheme prefix from a given string.
|
|
28
|
-
* @param dataUrl - The string to remove the prefix from.
|
|
29
|
-
* @returns The string with the prefix removed.
|
|
30
|
-
*/
|
|
31
|
-
declare function removeDataUrlSchemePrefix(dataUrl: string): string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Updates a file by reading its content, applying a transformation function, and writing back the result.
|
|
35
|
-
* Creates the file and directories if they don't exist.
|
|
36
|
-
*/
|
|
37
|
-
declare function updateFile(filepath: string, update: (fileContent: string) => string | Promise<string>): Promise<void>;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Updates a file by applying a transformation function to an array of lines.
|
|
41
|
-
* The transformation can return either a string (the entire new content) or an array of lines.
|
|
42
|
-
* Creates the file and directories if they don't exist.
|
|
43
|
-
*/
|
|
44
|
-
declare function updateFileLines(filepath: string, update: (fileContentLines: string[]) => string | string[] | Promise<string | string[]>): Promise<void>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Synchronous version of `updateFileLines`.
|
|
48
|
-
*/
|
|
49
|
-
declare function updateFileLinesSync(filepath: string, update: (fileContentLines: string[]) => string | string[]): void;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Synchronous version of `updateFile`.
|
|
53
|
-
*/
|
|
54
|
-
declare function updateFileSync(filepath: string, update: (fileContent: string) => string): void;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Updates a JSON file by applying a transformation function to the parsed content.
|
|
58
|
-
* If the file doesn't exist or can't be parsed, uses the default value.
|
|
59
|
-
* Creates the file and directories if they don't exist.
|
|
60
|
-
*/
|
|
61
|
-
declare function updateJsonFile<T extends object, R extends object>(filepath: string, update: (parsedFileContent: T) => R | Promise<R>, defaultValue?: T): Promise<R>;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Synchronous version of `updateJsonFile`.
|
|
65
|
-
*/
|
|
66
|
-
declare function updateJsonFileSync<T extends object, R extends object>(filepath: string, update: (parsedFileContent: T) => R, defaultValue?: T): R;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Walk a directory recursively and return an array of paths.
|
|
70
|
-
*/
|
|
71
|
-
declare function walkDirectory(dirpath: string, options: WalkDirectoryOptionsWithoutStats): string[];
|
|
72
|
-
/**
|
|
73
|
-
* Walk a directory recursively and return an array of [path: string, stats: Stats] tuples.
|
|
74
|
-
*/
|
|
75
|
-
declare function walkDirectory(dirpath: string, options: WalkDirectoryOptionsWithStats): [path: string, stats: Stats][];
|
|
76
|
-
/**
|
|
77
|
-
* Options for @see walkDirectory
|
|
78
|
-
*/
|
|
79
|
-
interface WalkDirectoryOptions {
|
|
80
|
-
/**
|
|
81
|
-
* Return stats for each path.
|
|
82
|
-
*/
|
|
83
|
-
stats?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Only return either files or directories.
|
|
86
|
-
*/
|
|
87
|
-
only?: 'files' | 'directories';
|
|
88
|
-
/**
|
|
89
|
-
* Recursion depth limit.
|
|
90
|
-
*/
|
|
91
|
-
maxDepth?: number;
|
|
92
|
-
/**
|
|
93
|
-
* Determine whether to walk a given directory.
|
|
94
|
-
*/
|
|
95
|
-
filter?: (dirpath: string, basename: string) => boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Follow symbolic links.
|
|
98
|
-
*/
|
|
99
|
-
followSymlinks?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* On filesystems where inodes are not unique (eg. windows), some files may not be walked due to inode collision.
|
|
102
|
-
* Turning off this behavior may be required but at the same time may lead to hitting max_depth via link loop.
|
|
103
|
-
*/
|
|
104
|
-
ignoreInodes?: boolean;
|
|
105
|
-
}
|
|
106
|
-
interface WalkDirectoryOptionsWithoutStats extends WalkDirectoryOptions {
|
|
107
|
-
stats?: false;
|
|
108
|
-
}
|
|
109
|
-
interface WalkDirectoryOptionsWithStats extends WalkDirectoryOptions {
|
|
110
|
-
stats: true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export { type WalkDirectoryOptions, type WalkDirectoryOptionsWithStats, type WalkDirectoryOptionsWithoutStats, deleteOlderThan, getFileAge, getFirstFileInDir, readFileFirstLine, removeDataUrlSchemePrefix, updateFile, updateFileLines, updateFileLinesSync, updateFileSync, updateJsonFile, updateJsonFileSync, walkDirectory };
|