UNPKG

react-native-legal

Version:
38 lines (37 loc) 1.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.modifyXMLFileContent = exports.modifyFileContent = void 0; const fs_1 = __importDefault(require("fs")); const xml2js_1 = __importDefault(require("xml2js")); /** * Used to modify a file at a specified file path * * It provides the file content as a utf-8 string inside a callback parameter. * The modified result should be returned from a callback parameter as a utf-8 string */ function modifyFileContent(filepath, transformFile) { const content = fs_1.default.readFileSync(filepath, { encoding: 'utf-8' }); const modifiedContent = transformFile(content); fs_1.default.writeFileSync(filepath, modifiedContent); } exports.modifyFileContent = modifyFileContent; /** * Used to modify a XML file at a specified file path * * It provides XML content parsed to a JS object inside a callback parameter * The modified result should be a JS object returned from a callback parameter */ // eslint-disable-next-line @typescript-eslint/no-explicit-any async function modifyXMLFileContent(filepath, transformXMLFile) { const content = fs_1.default.readFileSync(filepath, { encoding: 'utf-8' }); const parser = new xml2js_1.default.Parser(); const obj = await parser.parseStringPromise(content); const modifiedObj = transformXMLFile(obj); const builder = new xml2js_1.default.Builder({ headless: true }); const modifiedContent = builder.buildObject(modifiedObj); fs_1.default.writeFileSync(filepath, modifiedContent); } exports.modifyXMLFileContent = modifyXMLFileContent;