UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

51 lines (49 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringReplaceUpdater = void 0; const common_1 = require("../../../common"); const logger_1 = require("../../utils/logger"); /** * the StringReplaceUpdater error handler/updater. */ class StringReplaceUpdater { /** * the update function. * @param fileData the file data. * @param error the error object. * @returns the updated file data. */ update(fileData, error) { if (!fileData) { logger_1.Logger.error(`Cannot find file data`); } const result = this.regexFixer(fileData); error.resolved = common_1.ResolveState.Resolved; return new Promise(resolve => resolve(result)); } /** * the update function. * @param inputString the input file data string. * @returns the updated file data string. */ regexFixer(inputString) { const regexPattern = /ajaxRequest\.headers/; const target = '(<any>ajaxRequest).headers'; if (regexPattern.test(inputString)) { const data = inputString.split('\n'); for (let i = 0; i < data.length; i++) { if (!data[i].includes(target)) { data[i] = data[i].replace('ajaxRequest.headers', target); logger_1.Logger.log(data[i]); } } return data.join('\n'); } else { logger_1.Logger.log('no-op'); } return inputString; } } exports.StringReplaceUpdater = StringReplaceUpdater; //# sourceMappingURL=string-replace-updater.js.map