UNPKG

1.02 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const AbstractScriptedFlushable_1 = require("../../internal/common/AbstractScriptedFlushable");
4/**
5 * Convenient support for all File implementations
6 */
7class AbstractFile extends AbstractScriptedFlushable_1.AbstractScriptedFlushable {
8 get name() {
9 return this.path.split("/").pop();
10 }
11 get extension() {
12 return this.name.includes(".") ?
13 this.name.split(".").pop() :
14 "";
15 }
16 rename(name) {
17 return this.setPath(this.path.replace(new RegExp(`${this.name}$`), name));
18 }
19 replace(re, replacement) {
20 return this.getContent()
21 .then(content => this.setContent(content.replace(re, replacement)));
22 }
23 replaceAll(oldLiteral, newLiteral) {
24 return this.getContent()
25 .then(content => this.setContent(content.split(oldLiteral).join(newLiteral)));
26 }
27}
28exports.AbstractFile = AbstractFile;
29//# sourceMappingURL=AbstractFile.js.map
\No newline at end of file