Skip to content

Commit d7d0bd8

Browse files
committed
typescript
1 parent 65a8092 commit d7d0bd8

16 files changed

+736
-619
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules
2-
tmp
2+
tmp
3+
*.js
4+
*.d.ts
5+
!types/

lib/entry.js

-43
This file was deleted.

lib/entry.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const DIRECTORY_MODE = 16877;
2+
3+
import fs = require('fs');
4+
export interface BaseEntry {
5+
relativePath: string;
6+
isDirectory() : boolean;
7+
}
8+
9+
export interface DefaultEntry extends BaseEntry {
10+
relativePath: string;
11+
mode?: number;
12+
size?: number;
13+
mtime?: number | Date; // All algorithms coerce to number
14+
isDirectory() : boolean;
15+
}
16+
17+
export default class Entry implements DefaultEntry {
18+
relativePath: string;
19+
mode?: number;
20+
size?: number;
21+
mtime?: number | Date; // All algorithms coerce to number
22+
23+
constructor(relativePath:string, size?:number, mtime?: number | Date, mode?: number) {
24+
if (mode === undefined) {
25+
const isDirectory = relativePath.charAt(relativePath.length - 1) === '/';
26+
this.mode = isDirectory ? DIRECTORY_MODE : 0;
27+
} else {
28+
const modeType = typeof mode;
29+
if (modeType !== 'number') {
30+
throw new TypeError(`Expected 'mode' to be of type 'number' but was of type '${modeType}' instead.`);
31+
}
32+
this.mode = mode;
33+
}
34+
35+
if (mtime !== undefined) {
36+
this.mtime = mtime;
37+
}
38+
39+
this.relativePath = relativePath;
40+
this.size = size;
41+
}
42+
43+
static isDirectory(entry: Entry) {
44+
if (entry.mode === undefined) {
45+
return false
46+
} else {
47+
return (entry.mode & 61440) === 16384
48+
}
49+
}
50+
51+
static isFile(entry: Entry) {
52+
return !this.isDirectory(entry);
53+
}
54+
55+
static fromStat(relativePath: string, stat: fs.Stats) {
56+
return new this(relativePath, stat.size, stat.mtime, stat.mode);
57+
}
58+
59+
isDirectory() {
60+
return (this.constructor as typeof Entry).isDirectory(this);
61+
}
62+
};
63+
64+

lib/index.d.ts

-51
This file was deleted.

0 commit comments

Comments
 (0)