dir-analysis-tool 1.0.0 → 1.0.2
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/README.md +39 -39
- package/bin/advanced-analysis.d.ts +43 -0
- package/bin/advanced-analysis.d.ts.map +1 -0
- package/bin/advanced-analysis.js +187 -0
- package/bin/advanced-analysis.js.map +1 -0
- package/bin/analyzer.d.ts +40 -0
- package/bin/analyzer.d.ts.map +1 -0
- package/bin/analyzer.js +215 -0
- package/bin/analyzer.js.map +1 -0
- package/bin/classifier.d.ts +27 -0
- package/bin/classifier.d.ts.map +1 -0
- package/{src/classifier.ts → bin/classifier.js} +63 -83
- package/bin/classifier.js.map +1 -0
- package/bin/cli.d.ts +2 -0
- package/bin/cli.d.ts.map +1 -0
- package/bin/cli.js +423 -0
- package/bin/cli.js.map +1 -0
- package/bin/config.d.ts +10 -0
- package/bin/config.d.ts.map +1 -0
- package/bin/config.js +94 -0
- package/bin/config.js.map +1 -0
- package/bin/export.d.ts +20 -0
- package/bin/export.d.ts.map +1 -0
- package/{src/export.ts → bin/export.js} +56 -80
- package/bin/export.js.map +1 -0
- package/bin/html-report.d.ts +12 -0
- package/bin/html-report.d.ts.map +1 -0
- package/{src/html-report.ts → bin/html-report.js} +83 -92
- package/bin/html-report.js.map +1 -0
- package/bin/index.d.ts +3 -0
- package/bin/index.d.ts.map +1 -0
- package/bin/index.js +1 -1
- package/bin/index.js.map +1 -0
- package/bin/interactive.d.ts +27 -0
- package/bin/interactive.d.ts.map +1 -0
- package/{src/interactive.ts → bin/interactive.js} +637 -656
- package/bin/interactive.js.map +1 -0
- package/bin/progress.d.ts +9 -0
- package/bin/progress.d.ts.map +1 -0
- package/{src/progress.ts → bin/progress.js} +42 -47
- package/bin/progress.js.map +1 -0
- package/bin/tree-view.d.ts +21 -0
- package/bin/tree-view.d.ts.map +1 -0
- package/{src/tree-view.ts → bin/tree-view.js} +140 -129
- package/bin/tree-view.js.map +1 -0
- package/{src/types.ts → bin/types.d.ts} +43 -47
- package/bin/types.d.ts.map +1 -0
- package/bin/types.js +3 -0
- package/bin/types.js.map +1 -0
- package/bin/utils.d.ts +24 -0
- package/bin/utils.d.ts.map +1 -0
- package/{src/utils.ts → bin/utils.js} +59 -54
- package/bin/utils.js.map +1 -0
- package/package.json +6 -1
- package/.dir-analyzer.json +0 -11
- package/example-config.json +0 -13
- package/src/advanced-analysis.ts +0 -185
- package/src/analyzer.ts +0 -278
- package/src/cli.ts +0 -431
- package/src/config.ts +0 -66
- package/src/index.ts +0 -2
- package/tsconfig.json +0 -31
package/bin/analyzer.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DirectoryAnalyzer = void 0;
|
|
37
|
+
const fs_1 = require("fs");
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const classifier_1 = require("./classifier");
|
|
40
|
+
const utils_1 = require("./utils");
|
|
41
|
+
const advanced_analysis_1 = require("./advanced-analysis");
|
|
42
|
+
const tree_view_1 = require("./tree-view");
|
|
43
|
+
class DirectoryAnalyzer {
|
|
44
|
+
classifier;
|
|
45
|
+
totalSize = 0;
|
|
46
|
+
folderCount = 0;
|
|
47
|
+
fileCount = 0;
|
|
48
|
+
allFiles = [];
|
|
49
|
+
processedFiles = 0;
|
|
50
|
+
currentDepth = 0;
|
|
51
|
+
constructor() {
|
|
52
|
+
this.classifier = new classifier_1.FileClassifier();
|
|
53
|
+
}
|
|
54
|
+
async analyze(options) {
|
|
55
|
+
// Reset counters
|
|
56
|
+
this.totalSize = 0;
|
|
57
|
+
this.folderCount = 0;
|
|
58
|
+
this.fileCount = 0;
|
|
59
|
+
this.allFiles = [];
|
|
60
|
+
this.processedFiles = 0;
|
|
61
|
+
this.currentDepth = 0;
|
|
62
|
+
this.classifier.reset();
|
|
63
|
+
// Validate path exists
|
|
64
|
+
try {
|
|
65
|
+
const stats = await fs_1.promises.stat(options.path);
|
|
66
|
+
if (!stats.isDirectory()) {
|
|
67
|
+
throw new Error(`Path '${options.path}' is not a directory`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new Error(`Unable to access path '${options.path}': ${error}`);
|
|
72
|
+
}
|
|
73
|
+
if (options.progressCallback) {
|
|
74
|
+
options.progressCallback(0, 1, 'Scanning directories...');
|
|
75
|
+
}
|
|
76
|
+
// First pass: count total files for progress tracking
|
|
77
|
+
const totalFiles = await this.countFiles(options.path, options.recursive, options.excludePatterns, options.maxDepth || -1);
|
|
78
|
+
// Second pass: analyze directory
|
|
79
|
+
await this.analyzeDirectory(options.path, options.recursive, options.excludePatterns, options.progressCallback, totalFiles, options.maxDepth || -1, 0);
|
|
80
|
+
const basicResult = {
|
|
81
|
+
path: options.path,
|
|
82
|
+
totalSizeBytes: this.totalSize,
|
|
83
|
+
totalSizeMB: (0, utils_1.formatSizeInMB)(this.totalSize),
|
|
84
|
+
folders: this.folderCount,
|
|
85
|
+
files: this.fileCount,
|
|
86
|
+
types: this.classifier.getClassification()
|
|
87
|
+
};
|
|
88
|
+
const extendedResult = { ...basicResult };
|
|
89
|
+
// Large file detection
|
|
90
|
+
if (options.largeSizeThreshold) {
|
|
91
|
+
extendedResult.largeFiles = advanced_analysis_1.LargeFileDetector.detectLargeFiles(this.allFiles, options.largeSizeThreshold);
|
|
92
|
+
}
|
|
93
|
+
// Duplicate detection
|
|
94
|
+
if (options.enableDuplicateDetection) {
|
|
95
|
+
const duplicateDetector = new advanced_analysis_1.DuplicateDetector();
|
|
96
|
+
const filePaths = this.allFiles.map(f => f.path);
|
|
97
|
+
if (options.progressCallback) {
|
|
98
|
+
options.progressCallback(0, filePaths.length, 'Detecting duplicates...');
|
|
99
|
+
}
|
|
100
|
+
extendedResult.duplicateGroups = await duplicateDetector.detectDuplicates(filePaths, options.progressCallback);
|
|
101
|
+
if (extendedResult.duplicateGroups.length > 0) {
|
|
102
|
+
const totalWastedSpace = extendedResult.duplicateGroups.reduce((sum, group) => sum + group.totalWastedSpace, 0);
|
|
103
|
+
extendedResult.duplicateStats = {
|
|
104
|
+
totalGroups: extendedResult.duplicateGroups.length,
|
|
105
|
+
totalWastedSpace,
|
|
106
|
+
totalWastedSpaceFormatted: require('./utils').formatSize(totalWastedSpace)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Phase 1 new features
|
|
111
|
+
// Apply file filters
|
|
112
|
+
let filteredFiles = this.allFiles;
|
|
113
|
+
// Apply size filters
|
|
114
|
+
if (options.minSize !== undefined || options.maxSize !== undefined) {
|
|
115
|
+
filteredFiles = advanced_analysis_1.FileFilter.filterBySize(filteredFiles, options.minSize, options.maxSize);
|
|
116
|
+
}
|
|
117
|
+
// Apply date filters
|
|
118
|
+
if (options.dateFrom || options.dateTo) {
|
|
119
|
+
filteredFiles = await advanced_analysis_1.FileFilter.filterByDate(filteredFiles, options.dateFrom, options.dateTo);
|
|
120
|
+
}
|
|
121
|
+
// Top N largest files
|
|
122
|
+
if (options.topN) {
|
|
123
|
+
extendedResult.topLargestFiles = advanced_analysis_1.LargeFileDetector.getTopLargestFiles(filteredFiles, options.topN);
|
|
124
|
+
}
|
|
125
|
+
// Empty file detection
|
|
126
|
+
if (options.showEmptyFiles) {
|
|
127
|
+
extendedResult.emptyFiles = await advanced_analysis_1.EmptyFileDetector.detectEmptyFiles(this.allFiles);
|
|
128
|
+
}
|
|
129
|
+
// Tree view generation (only for smaller datasets to avoid performance issues)
|
|
130
|
+
if (filteredFiles.length <= 1000) {
|
|
131
|
+
extendedResult.treeView = tree_view_1.TreeViewGenerator.generateCompactTreeView(filteredFiles, options.path, 50);
|
|
132
|
+
}
|
|
133
|
+
return extendedResult;
|
|
134
|
+
}
|
|
135
|
+
async countFiles(dirPath, recursive, excludePatterns, maxDepth, currentDepth = 0) {
|
|
136
|
+
if (maxDepth >= 0 && currentDepth > maxDepth) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const entries = await fs_1.promises.readdir(dirPath, { withFileTypes: true });
|
|
141
|
+
let count = 0;
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
if (entry.isDirectory()) {
|
|
144
|
+
if ((0, utils_1.shouldExcludeDirectory)(entry.name, excludePatterns)) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (recursive) {
|
|
148
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
149
|
+
count += await this.countFiles(fullPath, recursive, excludePatterns, maxDepth, currentDepth + 1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else if (entry.isFile()) {
|
|
153
|
+
if (!(0, utils_1.shouldExcludeFile)(entry.name, excludePatterns)) {
|
|
154
|
+
count++;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return count;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async analyzeDirectory(dirPath, recursive, excludePatterns, progressCallback, totalFiles, maxDepth = -1, currentDepth = 0) {
|
|
165
|
+
if (maxDepth >= 0 && currentDepth > maxDepth) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
const entries = await fs_1.promises.readdir(dirPath, { withFileTypes: true });
|
|
170
|
+
for (const entry of entries) {
|
|
171
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
172
|
+
if (entry.isDirectory()) {
|
|
173
|
+
// Check if directory should be excluded
|
|
174
|
+
if ((0, utils_1.shouldExcludeDirectory)(entry.name, excludePatterns)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
this.folderCount++;
|
|
178
|
+
if (recursive) {
|
|
179
|
+
await this.analyzeDirectory(fullPath, recursive, excludePatterns, progressCallback, totalFiles, maxDepth, currentDepth + 1);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else if (entry.isFile()) {
|
|
183
|
+
// Check if file should be excluded
|
|
184
|
+
if ((0, utils_1.shouldExcludeFile)(entry.name, excludePatterns)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const stats = await fs_1.promises.stat(fullPath);
|
|
189
|
+
this.totalSize += stats.size;
|
|
190
|
+
this.fileCount++;
|
|
191
|
+
this.classifier.classifyFile(entry.name);
|
|
192
|
+
// Store file info for advanced analysis
|
|
193
|
+
this.allFiles.push({
|
|
194
|
+
path: fullPath,
|
|
195
|
+
size: stats.size
|
|
196
|
+
});
|
|
197
|
+
this.processedFiles++;
|
|
198
|
+
if (progressCallback && totalFiles) {
|
|
199
|
+
progressCallback(this.processedFiles, totalFiles, fullPath);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
// Skip files that can't be accessed
|
|
204
|
+
console.warn(`Warning: Unable to access file '${fullPath}': ${error}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
console.warn(`Warning: Unable to read directory '${dirPath}': ${error}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.DirectoryAnalyzer = DirectoryAnalyzer;
|
|
215
|
+
//# sourceMappingURL=analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAAoC;AACpC,2CAA6B;AAC7B,6CAAsE;AACtE,mCAAoF;AACpF,2DAA0G;AAE1G,2CAAgD;AA4BhD,MAAa,iBAAiB;IAClB,UAAU,CAAiB;IAC3B,SAAS,GAAW,CAAC,CAAC;IACtB,WAAW,GAAW,CAAC,CAAC;IACxB,SAAS,GAAW,CAAC,CAAC;IACtB,QAAQ,GAA0C,EAAE,CAAC;IACrD,cAAc,GAAW,CAAC,CAAC;IAC3B,YAAY,GAAW,CAAC,CAAC;IAEjC;QACI,IAAI,CAAC,UAAU,GAAG,IAAI,2BAAc,EAAE,CAAC;IAC3C,CAAC;IAED,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ACtC,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,IAAI,CAAC;wBAC7B,IAAI,CAAC,SAAS,EAAE,CAAC;wBACjB,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;wBAEzC,wCAAwC;wBACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;4BACf,IAAI,EAAE,QAAQ;4BACd,IAAI,EAAE,KAAK,CAAC,IAAI;yBACnB,CAAC,CAAC;wBAEH,IAAI,CAAC,cAAc,EAAE,CAAC;wBAEtB,IAAI,gBAAgB,IAAI,UAAU,EAAE,CAAC;4BACjC,gBAAgB,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;wBAChE,CAAC;oBACL,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACb,oCAAoC;wBACpC,OAAO,CAAC,IAAI,CAAC,mCAAmC,QAAQ,MAAM,KAAK,EAAE,CAAC,CAAC;oBAC3E,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,sCAAsC,OAAO,MAAM,KAAK,EAAE,CAAC,CAAC;QAC7E,CAAC;IACL,CAAC;CACJ;AAnPD,8CAmPC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface FileTypeClassification {
|
|
2
|
+
images: number;
|
|
3
|
+
videos: number;
|
|
4
|
+
documents: number;
|
|
5
|
+
audio: number;
|
|
6
|
+
code: number;
|
|
7
|
+
archives: number;
|
|
8
|
+
other: number;
|
|
9
|
+
}
|
|
10
|
+
export interface FileTypeExtensions {
|
|
11
|
+
images: string[];
|
|
12
|
+
videos: string[];
|
|
13
|
+
documents: string[];
|
|
14
|
+
audio: string[];
|
|
15
|
+
code: string[];
|
|
16
|
+
archives: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare const FILE_TYPE_EXTENSIONS: FileTypeExtensions;
|
|
19
|
+
export declare class FileClassifier {
|
|
20
|
+
private classification;
|
|
21
|
+
classifyFile(filename: string): void;
|
|
22
|
+
private getFileExtension;
|
|
23
|
+
private getFileType;
|
|
24
|
+
getClassification(): FileTypeClassification;
|
|
25
|
+
reset(): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../src/classifier.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,eAAO,MAAM,oBAAoB,EAAE,kBAYlC,CAAC;AAEF,qBAAa,cAAc;IACvB,OAAO,CAAC,cAAc,CAQpB;IAEF,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMpC,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,WAAW;IASnB,iBAAiB,IAAI,sBAAsB;IAI3C,KAAK,IAAI,IAAI;CAWhB"}
|
|
@@ -1,83 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.classification
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return 'other';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getClassification(): FileTypeClassification {
|
|
69
|
-
return { ...this.classification };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
reset(): void {
|
|
73
|
-
this.classification = {
|
|
74
|
-
images: 0,
|
|
75
|
-
videos: 0,
|
|
76
|
-
documents: 0,
|
|
77
|
-
audio: 0,
|
|
78
|
-
code: 0,
|
|
79
|
-
archives: 0,
|
|
80
|
-
other: 0
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileClassifier = exports.FILE_TYPE_EXTENSIONS = void 0;
|
|
4
|
+
exports.FILE_TYPE_EXTENSIONS = {
|
|
5
|
+
images: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.bmp', '.tiff', '.ico'],
|
|
6
|
+
videos: ['.mp4', '.mkv', '.avi', '.mov', '.webm', '.flv', '.wmv', '.m4v'],
|
|
7
|
+
documents: ['.pdf', '.docx', '.xlsx', '.pptx', '.txt', '.doc', '.xls', '.ppt', '.rtf', '.odt', '.ods', '.odp'],
|
|
8
|
+
audio: ['.mp3', '.wav', '.flac', '.aac', '.ogg', '.wma', '.m4a'],
|
|
9
|
+
code: [
|
|
10
|
+
'.js', '.ts', '.jsx', '.tsx', '.py', '.java', '.cpp', '.c', '.h', '.hpp',
|
|
11
|
+
'.cs', '.php', '.rb', '.go', '.rs', '.swift', '.kt', '.scala', '.clj',
|
|
12
|
+
'.sh', '.bat', '.ps1', '.sql', '.html', '.css', '.scss', '.sass', '.less',
|
|
13
|
+
'.json', '.xml', '.yaml', '.yml', '.toml', '.ini', '.cfg', '.conf'
|
|
14
|
+
],
|
|
15
|
+
archives: ['.zip', '.rar', '.7z', '.tar', '.gz', '.bz2', '.xz', '.tar.gz', '.tar.bz2']
|
|
16
|
+
};
|
|
17
|
+
class FileClassifier {
|
|
18
|
+
classification = {
|
|
19
|
+
images: 0,
|
|
20
|
+
videos: 0,
|
|
21
|
+
documents: 0,
|
|
22
|
+
audio: 0,
|
|
23
|
+
code: 0,
|
|
24
|
+
archives: 0,
|
|
25
|
+
other: 0
|
|
26
|
+
};
|
|
27
|
+
classifyFile(filename) {
|
|
28
|
+
const extension = this.getFileExtension(filename);
|
|
29
|
+
const fileType = this.getFileType(extension);
|
|
30
|
+
this.classification[fileType]++;
|
|
31
|
+
}
|
|
32
|
+
getFileExtension(filename) {
|
|
33
|
+
const lastDotIndex = filename.lastIndexOf('.');
|
|
34
|
+
if (lastDotIndex === -1 || lastDotIndex === filename.length - 1) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
return filename.substring(lastDotIndex).toLowerCase();
|
|
38
|
+
}
|
|
39
|
+
getFileType(extension) {
|
|
40
|
+
for (const [type, extensions] of Object.entries(exports.FILE_TYPE_EXTENSIONS)) {
|
|
41
|
+
if (extensions.includes(extension)) {
|
|
42
|
+
return type;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return 'other';
|
|
46
|
+
}
|
|
47
|
+
getClassification() {
|
|
48
|
+
return { ...this.classification };
|
|
49
|
+
}
|
|
50
|
+
reset() {
|
|
51
|
+
this.classification = {
|
|
52
|
+
images: 0,
|
|
53
|
+
videos: 0,
|
|
54
|
+
documents: 0,
|
|
55
|
+
audio: 0,
|
|
56
|
+
code: 0,
|
|
57
|
+
archives: 0,
|
|
58
|
+
other: 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.FileClassifier = FileClassifier;
|
|
63
|
+
//# sourceMappingURL=classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifier.js","sourceRoot":"","sources":["../src/classifier.ts"],"names":[],"mappings":";;;AAmBa,QAAA,oBAAoB,GAAuB;IACpD,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;IACnF,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IACzE,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAC9G,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAChE,IAAI,EAAE;QACF,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAA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