import fs from "fs" ; import path from "path" ; import Immutable from "immutable" ; import parsers from "../parsers" ; import Parser from "./parser" ; class File extends Immutable . Record ( { path : String ( ) , mtime : Date ( ) , } ) { getPath ( ) { return this . get ( "path" ) ; } getMTime ( ) { return this . get ( "mtime" ) ; } return { boolean } exists ( ) { return Boolean ( this . getPath ( ) ) ; } return { string } getType ( ) { const parser = this . getParser ( ) ; if ( parser ) { return parser . getName ( ) ; } else { return undefined ; } } return { string } getExtension ( ) { return path . extname ( this . getPath ( ) ) . toLowerCase ( ) ; } return { Parser } getParser ( ) { return parsers . getByExt ( this . getExtension ( ) ) ; } param { string } filepath param { Object | fs . Stats } stat return { File } static createFromStat ( filepath , stat ) { return new File ( { path : filepath , mtime : stat . mtime , } ) ; } param { string } filepath return { File } static createWithFilepath ( filepath ) { return new File ( { path : filepath , } ) ; } } export default File ;