UNPKG

@xwordly/xword-parser

Version:

Fast, type-safe TypeScript library for parsing crossword puzzles (PUZ, iPUZ, JPZ, XD)

159 lines (156 loc) 5.59 kB
'use strict'; var chunkTFE3E6Z3_js = require('./chunk-TFE3E6Z3.js'); var chunkM5HOH25J_js = require('./chunk-M5HOH25J.js'); var chunkRB5LJQIT_js = require('./chunk-RB5LJQIT.js'); var chunk5YBHNJTI_js = require('./chunk-5YBHNJTI.js'); var chunkPFLLYQT4_js = require('./chunk-PFLLYQT4.js'); require('./chunk-3QROV6K6.js'); var chunkKVCCVFYY_js = require('./chunk-KVCCVFYY.js'); // src/index.ts function parse(data, options) { let content; if (data instanceof ArrayBuffer) { content = Buffer.from(data); } else { content = data; } const formatsToTry = chunkTFE3E6Z3_js.getOrderedFormatsToTry(content, options?.filename); let lastError; for (const format of formatsToTry) { try { switch (format) { case "ipuz": { const textContent = typeof content === "string" ? content : content.toString(options?.encoding || "utf-8"); const puzzle = chunkM5HOH25J_js.parseIpuz(textContent, options); return chunkM5HOH25J_js.convertIpuzToUnified(puzzle); } case "puz": { if (typeof content !== "string") { const puzzle = chunk5YBHNJTI_js.parsePuz(content, options); return chunk5YBHNJTI_js.convertPuzToUnified(puzzle); } break; } case "jpz": { const textContent = typeof content === "string" ? content : content.toString(options?.encoding || "utf-8"); const puzzle = chunkPFLLYQT4_js.parseJpz(textContent, options); return chunkPFLLYQT4_js.convertJpzToUnified(puzzle); } case "xd": { const textContent = typeof content === "string" ? content : content.toString(options?.encoding || "utf-8"); const puzzle = chunkRB5LJQIT_js.parseXd(textContent, options); return chunkRB5LJQIT_js.convertXdToUnified(puzzle); } } } catch (e) { lastError = e; if (e instanceof chunkKVCCVFYY_js.ParseError && !e.isFormatMismatch()) { throw e; } } } if (lastError && !(lastError instanceof chunkKVCCVFYY_js.ParseError && lastError.isFormatMismatch())) { if (lastError instanceof Error) { throw lastError; } throw new chunkKVCCVFYY_js.FormatDetectionError( "Unable to detect puzzle format. Supported formats: iPUZ, PUZ, JPZ, XD", void 0, lastError ); } throw new chunkKVCCVFYY_js.FormatDetectionError( "Unable to detect puzzle format. Supported formats: iPUZ, PUZ, JPZ, XD" ); } Object.defineProperty(exports, "CellType", { enumerable: true, get: function () { return chunkM5HOH25J_js.CellType; } }); Object.defineProperty(exports, "convertIpuzToUnified", { enumerable: true, get: function () { return chunkM5HOH25J_js.convertIpuzToUnified; } }); Object.defineProperty(exports, "parseIpuz", { enumerable: true, get: function () { return chunkM5HOH25J_js.parseIpuz; } }); Object.defineProperty(exports, "convertXdToUnified", { enumerable: true, get: function () { return chunkRB5LJQIT_js.convertXdToUnified; } }); Object.defineProperty(exports, "parseXd", { enumerable: true, get: function () { return chunkRB5LJQIT_js.parseXd; } }); Object.defineProperty(exports, "convertPuzToUnified", { enumerable: true, get: function () { return chunk5YBHNJTI_js.convertPuzToUnified; } }); Object.defineProperty(exports, "parsePuz", { enumerable: true, get: function () { return chunk5YBHNJTI_js.parsePuz; } }); Object.defineProperty(exports, "convertJpzToUnified", { enumerable: true, get: function () { return chunkPFLLYQT4_js.convertJpzToUnified; } }); Object.defineProperty(exports, "parseJpz", { enumerable: true, get: function () { return chunkPFLLYQT4_js.parseJpz; } }); Object.defineProperty(exports, "BinaryParseError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.BinaryParseError; } }); Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return chunkKVCCVFYY_js.ErrorCode; } }); Object.defineProperty(exports, "FormatDetectionError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.FormatDetectionError; } }); Object.defineProperty(exports, "InvalidFileError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.InvalidFileError; } }); Object.defineProperty(exports, "IpuzParseError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.IpuzParseError; } }); Object.defineProperty(exports, "JpzParseError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.JpzParseError; } }); Object.defineProperty(exports, "ParseError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.ParseError; } }); Object.defineProperty(exports, "PuzParseError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.PuzParseError; } }); Object.defineProperty(exports, "UnsupportedPuzzleTypeError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.UnsupportedPuzzleTypeError; } }); Object.defineProperty(exports, "XdParseError", { enumerable: true, get: function () { return chunkKVCCVFYY_js.XdParseError; } }); Object.defineProperty(exports, "asClueNumber", { enumerable: true, get: function () { return chunkKVCCVFYY_js.asClueNumber; } }); Object.defineProperty(exports, "asGridCoordinate", { enumerable: true, get: function () { return chunkKVCCVFYY_js.asGridCoordinate; } }); Object.defineProperty(exports, "asRebusId", { enumerable: true, get: function () { return chunkKVCCVFYY_js.asRebusId; } }); exports.parse = parse; //# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map