@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
67 lines (65 loc) • 2.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubjectNextUpdaterUtil = void 0;
const common_1 = require("../../../common");
const logger_1 = require("../../utils/logger");
class SubjectNextUpdaterUtil {
/**
* 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 result;
}
/**
* the regexFixer function.
* @param inputString the input file data string.
* @returns the updated file data string.
*/
regexFixer(inputString) {
// Define the regular expression pattern
const regexPattern = /this\.(\w+)\.next\(\);/;
const match = inputString.match(regexPattern);
if (match) {
var extractedString = match[1];
console.log(extractedString);
/**
* public myString: Subject();
* protected myString: Subject();
* private myString: Subject();
* To:
* public myString: Subject<void>();
* protected myString: Subject<void>();
* private myString: Subject<void>();
*/
const regex = new RegExp(`(${extractedString}:\\s+Subject\\(\\);)`, 'g');
inputString = inputString.replace(regex, `${extractedString}: Subject<void>();`);
/**
* public myString = new Subject();
* protected myString = new Subject();
* private myString = new Subject();
* TO:
* public myString = new Subject<void>();
* protected myString = new Subject<void>();
* private myString = new Subject<void>();
*
* 'private myString = new Subject();'.replace(new RegExp(`(public|protected|private)\\s+(\\w+)\\s*=\\s*new\\s+Subject\\(\\);`, 'g'), '$1 $2 = new Subject<void>();')
*/
const regex2 = new RegExp(`(public|protected|private)\\s+(\\w+)\\s*=\\s*new\\s+Subject\\(\\);`, 'g');
inputString = inputString.replace(regex2, `$1 $2 = new Subject<void>();`);
}
else {
console.log("No match found");
}
return inputString;
}
}
exports.SubjectNextUpdaterUtil = SubjectNextUpdaterUtil;
//# sourceMappingURL=subjuct-next-updater-util.js.map