UNPKG

@specs-feup/lara

Version:

A js port of the popular framework for building source-to-source compilers

31 lines 939 B
import Io from "../Io.js"; import JavaTypes from "./JavaTypes.js"; /** * Replaces strings inside a larger string. */ export default class Replacer { _contents; constructor(contentsOrFile) { // If a file, read the contents if (typeof contentsOrFile === "string") { this._contents = contentsOrFile; } else if (JavaTypes.instanceOf(contentsOrFile, "java.io.File")) { this._contents = Io.readFile(contentsOrFile); } else { throw new Error("Replacer constructor expects a string or a java.io.File instance."); } } static fromFilename(filename) { return new Replacer(Io.getPath(filename)); } replaceAll(target, replacement) { this._contents = this._contents.replaceAll(target, replacement); return this; } getString() { return this._contents; } } //# sourceMappingURL=Replacer.js.map