(
message: string,
opts: ParserOptions = {}
)
| 37 | } |
| 38 | |
| 39 | export function parse( |
| 40 | message: string, |
| 41 | opts: ParserOptions = {} |
| 42 | ): MessageFormatElement[] { |
| 43 | opts = { |
| 44 | shouldParseSkeletons: true, |
| 45 | requiresOtherClause: true, |
| 46 | ...opts, |
| 47 | } |
| 48 | const result = new Parser(message, opts).parse() |
| 49 | if (result.err) { |
| 50 | const error = SyntaxError(ErrorKind[result.err.kind]) |
| 51 | // @ts-expect-error Assign to error object |
| 52 | error.location = result.err.location |
| 53 | // @ts-expect-error Assign to error object |
| 54 | error.originalMessage = result.err.message |
| 55 | throw error |
| 56 | } |
| 57 | |
| 58 | if (!opts?.captureLocation) { |
| 59 | pruneLocation(result.val) |
| 60 | } |
| 61 | return result.val |
| 62 | } |
| 63 | export * from '#packages/icu-messageformat-parser/types.js' |
| 64 | export type {ParserOptions} |
| 65 | // only for testing |
no test coverage detected