1
Fork 0

add File#paths, an array of historical paths

This commit is contained in:
Conduitry 2018-02-19 02:38:14 -05:00
parent 8c49863f40
commit e31dc43666
2 changed files with 17 additions and 1 deletions

4
API.md
View file

@ -18,6 +18,10 @@ A new `File` instance to serve as the representation of a physical file, a gener
The file's path can be retrieved or updated by getting and setting `path`.
### `paths`
An array of all `path`s this file has had, in chronological order. Setting `path` automatically updates this.
### `ext`
The file's extension (including the preceding `.`) can be retrieved or updated by getting and setting `path`. The `ext` and `path` properties are kept in sync.

View file

@ -1,11 +1,23 @@
export default class File {
constructor(path) {
this.path = path
this._path = path
this.paths = path ? [path] : []
this.stat = null
this._bytes = null
this._text = null
}
get path() {
return this._path
}
set path(path) {
if (this._path !== path) {
this._path = path
this.paths.push(path)
}
}
get ext() {
if (this.path && this.path.match) {
let match = this.path.match(/\.[^./\\]+$/)