43 lines
931 B
TypeScript
43 lines
931 B
TypeScript
import { Directory } from "./Directory"
|
|
|
|
export class File {
|
|
readonly location: Directory
|
|
readonly name: string
|
|
readonly path: string
|
|
private data: any
|
|
|
|
constructor(path: string) {
|
|
this.path = path
|
|
const match = path.match(/^(\/[^\/]*)+\/?$/gm)
|
|
|
|
if (!match)
|
|
throw new SyntaxError("Bad filepath")
|
|
|
|
this.location = new Directory(match[0])
|
|
this.name = match[1]
|
|
|
|
new Directory(path)
|
|
|
|
console.log(this.location)
|
|
console.log(this.name)
|
|
}
|
|
|
|
Exists(): boolean {
|
|
return window.localStorage.getItem(this.path) !== null && window.localStorage.getItem(this.path) !== undefined
|
|
}
|
|
|
|
Remove() {
|
|
window.localStorage.removeItem(this.path)
|
|
}
|
|
|
|
Write(data: any) {
|
|
this.data = data
|
|
|
|
window.localStorage.setItem(this.path, JSON.stringify(this))
|
|
}
|
|
|
|
Read(): any {
|
|
return this.data
|
|
}
|
|
}
|