Skip to content

to typescript #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
tmp
tmp
*.js
*.d.ts
!types/
43 changes: 0 additions & 43 deletions lib/entry.js

This file was deleted.

64 changes: 64 additions & 0 deletions lib/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const DIRECTORY_MODE = 16877;

import fs = require('fs');
export interface BaseEntry {
relativePath: string;
isDirectory() : boolean;
}

export interface DefaultEntry extends BaseEntry {
relativePath: string;
mode?: number;
size?: number;
mtime?: number | Date; // All algorithms coerce to number
isDirectory() : boolean;
}

export default class Entry implements DefaultEntry {
relativePath: string;
mode?: number;
size?: number;
mtime?: number | Date; // All algorithms coerce to number

constructor(relativePath:string, size?:number, mtime?: number | Date, mode?: number) {
if (mode === undefined) {
const isDirectory = relativePath.charAt(relativePath.length - 1) === '/';
this.mode = isDirectory ? DIRECTORY_MODE : 0;
} else {
const modeType = typeof mode;
if (modeType !== 'number') {
throw new TypeError(`Expected 'mode' to be of type 'number' but was of type '${modeType}' instead.`);
}
this.mode = mode;
}

if (mtime !== undefined) {
this.mtime = mtime;
}

this.relativePath = relativePath;
this.size = size;
}

static isDirectory(entry: Entry) {
if (entry.mode === undefined) {
return false
} else {
return (entry.mode & 61440) === 16384
}
}

static isFile(entry: Entry) {
return !this.isDirectory(entry);
}

static fromStat(relativePath: string, stat: fs.Stats) {
return new this(relativePath, stat.size, stat.mtime, stat.mode);
}

isDirectory() {
return (this.constructor as typeof Entry).isDirectory(this);
}
};


51 changes: 0 additions & 51 deletions lib/index.d.ts

This file was deleted.

Loading