UNPKG

sortier

Version:
23 lines (22 loc) 940 B
import { JavascriptReprinter } from "../../language-js/index.js"; import { StringUtils } from "../../utilities/string-utils.js"; export class Reprinter { static EXTENSIONS = [".json", ".json.txt"]; getRewrittenContents(filename, fileContents, // Left in for consistency with other sort functions // eslint-disable-next-line @typescript-eslint/no-unused-vars options) { const prefix = "export default ("; const suffix = ");"; const temporaryFileContents = prefix + fileContents + suffix; const rewritten = new JavascriptReprinter().getRewrittenContents(filename + ".ts", temporaryFileContents, { js: { parser: "typescript", }, }); return rewritten.substring(prefix.length, rewritten.length - suffix.length); } isFileSupported(filename) { return StringUtils.stringEndsWithAny(filename, Reprinter.EXTENSIONS); } }