UNPKG

@xwordly/xword-parser

Version:

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

124 lines (121 loc) 5.08 kB
'use strict'; // src/types.ts var asClueNumber = (n) => n; var asGridCoordinate = (n) => n; var asRebusId = (n) => n; var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => { ErrorCode2["FORMAT_DETECTION_FAILED"] = "FORMAT_DETECTION_FAILED"; ErrorCode2["INVALID_FILE"] = "INVALID_FILE"; ErrorCode2["UNSUPPORTED_PUZZLE_TYPE"] = "UNSUPPORTED_PUZZLE_TYPE"; ErrorCode2["BINARY_PARSE_ERROR"] = "BINARY_PARSE_ERROR"; ErrorCode2["IPUZ_PARSE_ERROR"] = "IPUZ_PARSE_ERROR"; ErrorCode2["IPUZ_INVALID_JSON"] = "IPUZ_INVALID_JSON"; ErrorCode2["IPUZ_MISSING_VERSION"] = "IPUZ_MISSING_VERSION"; ErrorCode2["IPUZ_MISSING_KIND"] = "IPUZ_MISSING_KIND"; ErrorCode2["IPUZ_MISSING_REQUIRED_FIELD"] = "IPUZ_MISSING_REQUIRED_FIELD"; ErrorCode2["IPUZ_INVALID_DATA_TYPE"] = "IPUZ_INVALID_DATA_TYPE"; ErrorCode2["IPUZ_INVALID_GRID_SIZE"] = "IPUZ_INVALID_GRID_SIZE"; ErrorCode2["PUZ_PARSE_ERROR"] = "PUZ_PARSE_ERROR"; ErrorCode2["PUZ_INVALID_HEADER"] = "PUZ_INVALID_HEADER"; ErrorCode2["PUZ_INVALID_GRID"] = "PUZ_INVALID_GRID"; ErrorCode2["PUZ_CHECKSUM_MISMATCH"] = "PUZ_CHECKSUM_MISMATCH"; ErrorCode2["JPZ_PARSE_ERROR"] = "JPZ_PARSE_ERROR"; ErrorCode2["JPZ_INVALID_XML"] = "JPZ_INVALID_XML"; ErrorCode2["JPZ_MISSING_GRID"] = "JPZ_MISSING_GRID"; ErrorCode2["JPZ_INVALID_GRID"] = "JPZ_INVALID_GRID"; ErrorCode2["XD_PARSE_ERROR"] = "XD_PARSE_ERROR"; ErrorCode2["XD_FORMAT_ERROR"] = "XD_FORMAT_ERROR"; ErrorCode2["XD_INVALID_GRID"] = "XD_INVALID_GRID"; ErrorCode2["XD_MISSING_CLUES"] = "XD_MISSING_CLUES"; return ErrorCode2; })(ErrorCode || {}); // src/errors.ts var ParseError = class extends Error { code; context; constructor(message, code = "FORMAT_DETECTION_FAILED" /* FORMAT_DETECTION_FAILED */, context, cause) { super(message, { cause }); this.code = code; this.context = context; } /** * Determines if this error indicates a format mismatch (file is valid but wrong format) * vs a real parsing error (file is corrupted or has other issues) */ isFormatMismatch() { return this.code === "UNSUPPORTED_PUZZLE_TYPE" /* UNSUPPORTED_PUZZLE_TYPE */ || this.code === "FORMAT_DETECTION_FAILED" /* FORMAT_DETECTION_FAILED */; } }; var FormatDetectionError = class extends ParseError { constructor(message = "Unable to detect puzzle format", context, cause) { super(message, "FORMAT_DETECTION_FAILED" /* FORMAT_DETECTION_FAILED */, context, cause); } }; var InvalidFileError = class extends ParseError { constructor(format, message, context, cause) { super(`Invalid ${format} file: ${message}`, "INVALID_FILE" /* INVALID_FILE */, context, cause); } }; var UnsupportedPuzzleTypeError = class extends ParseError { constructor(puzzleType, context, cause) { super( `${puzzleType} puzzles are not supported`, "UNSUPPORTED_PUZZLE_TYPE" /* UNSUPPORTED_PUZZLE_TYPE */, context, cause ); } }; var IpuzParseError = class extends ParseError { constructor(message, code = "IPUZ_PARSE_ERROR" /* IPUZ_PARSE_ERROR */, context, cause) { super(message, code, context, cause); } isFormatMismatch() { return super.isFormatMismatch() || this.code === "IPUZ_INVALID_JSON" /* IPUZ_INVALID_JSON */ || this.code === "IPUZ_MISSING_VERSION" /* IPUZ_MISSING_VERSION */ || this.code === "IPUZ_MISSING_KIND" /* IPUZ_MISSING_KIND */; } }; var PuzParseError = class extends ParseError { constructor(message, code = "PUZ_PARSE_ERROR" /* PUZ_PARSE_ERROR */, context, cause) { super(message, code, context, cause); } isFormatMismatch() { return super.isFormatMismatch() || this.code === "PUZ_INVALID_HEADER" /* PUZ_INVALID_HEADER */; } }; var JpzParseError = class extends ParseError { constructor(message, code = "JPZ_PARSE_ERROR" /* JPZ_PARSE_ERROR */, context, cause) { super(message, code, context, cause); } isFormatMismatch() { return super.isFormatMismatch() || this.code === "JPZ_INVALID_XML" /* JPZ_INVALID_XML */; } }; var XdParseError = class extends ParseError { constructor(message, code = "XD_PARSE_ERROR" /* XD_PARSE_ERROR */, context, cause) { super(message, code, context, cause); } isFormatMismatch() { return super.isFormatMismatch() || this.code === "XD_FORMAT_ERROR" /* XD_FORMAT_ERROR */; } }; var BinaryParseError = class extends ParseError { constructor(message, context) { super(message, "BINARY_PARSE_ERROR" /* BINARY_PARSE_ERROR */, context); this.name = "BinaryParseError"; } }; exports.BinaryParseError = BinaryParseError; exports.ErrorCode = ErrorCode; exports.FormatDetectionError = FormatDetectionError; exports.InvalidFileError = InvalidFileError; exports.IpuzParseError = IpuzParseError; exports.JpzParseError = JpzParseError; exports.ParseError = ParseError; exports.PuzParseError = PuzParseError; exports.UnsupportedPuzzleTypeError = UnsupportedPuzzleTypeError; exports.XdParseError = XdParseError; exports.asClueNumber = asClueNumber; exports.asGridCoordinate = asGridCoordinate; exports.asRebusId = asRebusId; //# sourceMappingURL=chunk-KVCCVFYY.js.map //# sourceMappingURL=chunk-KVCCVFYY.js.map