sortier
Version:
An opinionated code sorter
27 lines (26 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Reprinter = void 0;
const index_js_1 = require("../../language-js/index.js");
const string_utils_js_1 = require("../../utilities/string-utils.js");
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 index_js_1.JavascriptReprinter().getRewrittenContents(filename + ".ts", temporaryFileContents, {
js: {
parser: "typescript",
},
});
return rewritten.substring(prefix.length, rewritten.length - suffix.length);
}
isFileSupported(filename) {
return string_utils_js_1.StringUtils.stringEndsWithAny(filename, Reprinter.EXTENSIONS);
}
}
exports.Reprinter = Reprinter;