add File#paths, an array of historical paths
This commit is contained in:
parent
8c49863f40
commit
e31dc43666
2 changed files with 17 additions and 1 deletions
4
API.md
4
API.md
|
@ -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.
|
||||
|
|
14
src/File.js
14
src/File.js
|
@ -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(/\.[^./\\]+$/)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue