@hypernym/utils 1.1.0 → 1.1.1
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/dist/{node.cjs → node/index.cjs} +7 -9
- package/dist/{node.d.ts → node/index.d.ts} +3 -3
- package/dist/{node.mjs → node/index.mjs} +8 -10
- package/package.json +11 -11
- /package/dist/{utils.cjs → index.cjs} +0 -0
- /package/dist/{utils.d.ts → index.d.ts} +0 -0
- /package/dist/{utils.mjs → index.mjs} +0 -0
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var promises = require('node:fs/promises');
|
|
4
4
|
var node_path = require('node:path');
|
|
5
|
-
var formatBytes = require('../mix/format-bytes');
|
|
6
5
|
|
|
7
6
|
async function exists(path) {
|
|
8
7
|
return await promises.access(path, promises.constants.F_OK).then(() => true).catch(() => false);
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
async function getDirStats(
|
|
10
|
+
async function getDirStats(path, options) {
|
|
11
|
+
const dirPath = node_path.resolve(path);
|
|
12
12
|
const dirFiles = await promises.readdir(dirPath);
|
|
13
13
|
const dirBase = node_path.basename(dirPath);
|
|
14
14
|
let dirStats = [];
|
|
@@ -19,7 +19,7 @@ async function getDirStats(dirPath, options) {
|
|
|
19
19
|
let fileIndex = -1;
|
|
20
20
|
let subdirIndex = -1;
|
|
21
21
|
for (const file of dirFiles) {
|
|
22
|
-
const filePath = node_path.resolve(
|
|
22
|
+
const filePath = node_path.resolve(path, file);
|
|
23
23
|
const fileStat = await promises.stat(filePath);
|
|
24
24
|
if (fileStat.isDirectory()) {
|
|
25
25
|
subdirIndex++;
|
|
@@ -29,20 +29,18 @@ async function getDirStats(dirPath, options) {
|
|
|
29
29
|
base: file
|
|
30
30
|
});
|
|
31
31
|
if (options?.recursive) {
|
|
32
|
-
dirBase === dirPath ? dirBase : node_path.basename(filePath);
|
|
33
32
|
const stats = await getDirStats(filePath);
|
|
34
33
|
const updateDirStats = { ...stats[0], ...{ index: dirIndex++ } };
|
|
35
34
|
dirStats = [...dirStats, updateDirStats];
|
|
36
35
|
}
|
|
37
36
|
} else {
|
|
38
37
|
const { base, name, ext } = node_path.parse(file);
|
|
39
|
-
const
|
|
40
|
-
const size = formatBytes.formatBytes(fileStat.size);
|
|
38
|
+
const { size } = fileStat;
|
|
41
39
|
fileIndex++;
|
|
42
|
-
dirSize +=
|
|
40
|
+
dirSize += size;
|
|
43
41
|
fileList.push({
|
|
44
42
|
index: fileIndex,
|
|
45
|
-
path,
|
|
43
|
+
path: filePath,
|
|
46
44
|
base,
|
|
47
45
|
name,
|
|
48
46
|
ext,
|
|
@@ -54,7 +52,7 @@ async function getDirStats(dirPath, options) {
|
|
|
54
52
|
index: dirIndex,
|
|
55
53
|
path: dirPath,
|
|
56
54
|
base: dirBase,
|
|
57
|
-
size:
|
|
55
|
+
size: dirSize,
|
|
58
56
|
subdirs: subdirList,
|
|
59
57
|
files: fileList
|
|
60
58
|
});
|
|
@@ -8,7 +8,7 @@ declare function exists(path: string): Promise<boolean>;
|
|
|
8
8
|
*
|
|
9
9
|
* By default, recursive mode is disabled so only one level is scanned.
|
|
10
10
|
*/
|
|
11
|
-
declare function getDirStats(
|
|
11
|
+
declare function getDirStats(path: string, options?: DirStatsOptions): Promise<DirStats[]>;
|
|
12
12
|
|
|
13
13
|
interface SubdirDetails {
|
|
14
14
|
index: number;
|
|
@@ -21,13 +21,13 @@ interface FileDetails {
|
|
|
21
21
|
base: string;
|
|
22
22
|
name: string;
|
|
23
23
|
ext: string;
|
|
24
|
-
size:
|
|
24
|
+
size: number;
|
|
25
25
|
}
|
|
26
26
|
interface DirStats {
|
|
27
27
|
index: number;
|
|
28
28
|
path: string;
|
|
29
29
|
base: string;
|
|
30
|
-
size:
|
|
30
|
+
size: number;
|
|
31
31
|
subdirs: SubdirDetails[];
|
|
32
32
|
files: FileDetails[];
|
|
33
33
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { access, constants, readdir, stat } from 'node:fs/promises';
|
|
2
|
-
import {
|
|
3
|
-
import { formatBytes } from '../mix/format-bytes';
|
|
2
|
+
import { resolve, basename, parse } from 'node:path';
|
|
4
3
|
|
|
5
4
|
async function exists(path) {
|
|
6
5
|
return await access(path, constants.F_OK).then(() => true).catch(() => false);
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
async function getDirStats(
|
|
8
|
+
async function getDirStats(path, options) {
|
|
9
|
+
const dirPath = resolve(path);
|
|
10
10
|
const dirFiles = await readdir(dirPath);
|
|
11
11
|
const dirBase = basename(dirPath);
|
|
12
12
|
let dirStats = [];
|
|
@@ -17,7 +17,7 @@ async function getDirStats(dirPath, options) {
|
|
|
17
17
|
let fileIndex = -1;
|
|
18
18
|
let subdirIndex = -1;
|
|
19
19
|
for (const file of dirFiles) {
|
|
20
|
-
const filePath = resolve(
|
|
20
|
+
const filePath = resolve(path, file);
|
|
21
21
|
const fileStat = await stat(filePath);
|
|
22
22
|
if (fileStat.isDirectory()) {
|
|
23
23
|
subdirIndex++;
|
|
@@ -27,20 +27,18 @@ async function getDirStats(dirPath, options) {
|
|
|
27
27
|
base: file
|
|
28
28
|
});
|
|
29
29
|
if (options?.recursive) {
|
|
30
|
-
dirBase === dirPath ? dirBase : basename(filePath);
|
|
31
30
|
const stats = await getDirStats(filePath);
|
|
32
31
|
const updateDirStats = { ...stats[0], ...{ index: dirIndex++ } };
|
|
33
32
|
dirStats = [...dirStats, updateDirStats];
|
|
34
33
|
}
|
|
35
34
|
} else {
|
|
36
35
|
const { base, name, ext } = parse(file);
|
|
37
|
-
const
|
|
38
|
-
const size = formatBytes(fileStat.size);
|
|
36
|
+
const { size } = fileStat;
|
|
39
37
|
fileIndex++;
|
|
40
|
-
dirSize +=
|
|
38
|
+
dirSize += size;
|
|
41
39
|
fileList.push({
|
|
42
40
|
index: fileIndex,
|
|
43
|
-
path,
|
|
41
|
+
path: filePath,
|
|
44
42
|
base,
|
|
45
43
|
name,
|
|
46
44
|
ext,
|
|
@@ -52,7 +50,7 @@ async function getDirStats(dirPath, options) {
|
|
|
52
50
|
index: dirIndex,
|
|
53
51
|
path: dirPath,
|
|
54
52
|
base: dirBase,
|
|
55
|
-
size:
|
|
53
|
+
size: dirSize,
|
|
56
54
|
subdirs: subdirList,
|
|
57
55
|
files: fileList
|
|
58
56
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypernym/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"author": "Hypernym Studio",
|
|
5
5
|
"maintainers": [
|
|
6
6
|
"Ivo Dolenc (https://github.com/ivodolenc)"
|
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
"repository": "hypernym-studio/utils",
|
|
12
12
|
"homepage": "https://github.com/hypernym-studio/utils",
|
|
13
13
|
"type": "module",
|
|
14
|
-
"main": "./dist/
|
|
15
|
-
"module": "./dist/
|
|
16
|
-
"types": "./dist/
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"types": "./dist/
|
|
20
|
-
"import": "./dist/
|
|
21
|
-
"require": "./dist/
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
22
|
},
|
|
23
23
|
"./node": {
|
|
24
|
-
"types": "./dist/node.d.ts",
|
|
25
|
-
"import": "./dist/node.mjs",
|
|
26
|
-
"require": "./dist/node.cjs"
|
|
24
|
+
"types": "./dist/node/index.d.ts",
|
|
25
|
+
"import": "./dist/node/index.mjs",
|
|
26
|
+
"require": "./dist/node/index.cjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"rollup-plugin-dts": "^5.3.0",
|
|
60
60
|
"rollup-plugin-esbuild": "^5.0.0",
|
|
61
61
|
"typescript": "^5.0.4",
|
|
62
|
-
"vite": "^4.4.
|
|
62
|
+
"vite": "^4.4.3",
|
|
63
63
|
"vite-node": "^0.33.0",
|
|
64
64
|
"vitest": "^0.33.0"
|
|
65
65
|
},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|