Skip to content

Commit fbc145f

Browse files
committed
typescript
1 parent 65a8092 commit fbc145f

16 files changed

+700
-619
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
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

Lines changed: 0 additions & 43 deletions
This file was deleted.

lib/entry.ts

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

lib/index.d.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)