python2igcse
Version:
Convert Python code to IGCSE Pseudocode format
100 lines • 3.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Python2IGCSEBrowser = void 0;
exports.convertPythonToIGCSE = convertPythonToIGCSE;
// Browser entry point for Python to IGCSE Pseudocode Converter
const converter_1 = require("./converter");
/**
* Browser-compatible version of Python2IGCSE converter
* This class excludes Node.js-specific features like file system operations
*/
class Python2IGCSEBrowser {
constructor(options = {}) {
const defaultOptions = {
outputFormat: 'plain',
indentSize: 3,
indentType: 'spaces',
lineEnding: '\n',
maxLineLength: 80,
beautify: true,
strictMode: false,
includeComments: true,
includeLineNumbers: false,
preserveWhitespace: false,
uppercaseKeywords: true,
spaceAroundOperators: true,
spaceAfterCommas: true,
maxErrors: 10,
timeout: 30000,
};
this.options = { ...defaultOptions, ...options };
}
/**
* Convert Python code string to IGCSE pseudocode
* @param pythonCode - Python source code as string
* @returns ConversionResult - IGCSE pseudocode result
*/
convertCode(pythonCode) {
try {
const converter = new converter_1.Converter(this.options);
return converter.convert(pythonCode);
}
catch (error) {
throw new Error(`Conversion failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}
/**
* Validate Python syntax without conversion
* @param pythonCode - Python source code as string
* @returns ValidationResult - validation result with errors and warnings
*/
validateSyntax(pythonCode) {
try {
const result = this.convertCode(pythonCode);
return {
isValid: result.parseResult.errors.length === 0,
errors: result.parseResult.errors.map((e) => e.message),
warnings: (result.parseResult.warnings || []).map((w) => w.message),
};
}
catch (error) {
return {
isValid: false,
errors: [error instanceof Error ? error.message : 'Unknown validation error'],
warnings: [],
};
}
}
/**
* Get conversion options
* @returns ConversionOptions - current options
*/
getOptions() {
return { ...this.options };
}
/**
* Update conversion options
* @param options - partial options to update
*/
updateOptions(options) {
this.options = { ...this.options, ...options };
}
/**
* Get available output formats
*/
static getAvailableFormats() {
return ['plain', 'markdown'];
}
}
exports.Python2IGCSEBrowser = Python2IGCSEBrowser;
// Export for global usage
if (typeof globalThis !== 'undefined' && typeof globalThis.window !== 'undefined') {
globalThis.window.Python2IGCSE = Python2IGCSEBrowser;
}
// Browser-compatible conversion function
function convertPythonToIGCSE(pythonCode, options = {}) {
const converter = new converter_1.Converter(options);
return converter.convert(pythonCode);
}
exports.default = Python2IGCSEBrowser;
//# sourceMappingURL=browser.js.map