packages/icu-messageformat-parser-wasm/README.md
⚠️ Note: This package is not published to npm. Benchmarks show the WASM parser is currently 14-19x slower than the JavaScript parser due to async initialization overhead, JSON serialization costs, and the small size of typical parsing operations. See BENCHMARK.md for detailed performance analysis.
WebAssembly-powered ICU MessageFormat parser for JavaScript/TypeScript applications.
This package provides a Rust-compiled WebAssembly parser as an experimental alternative to the pure JavaScript parser. While it achieves 100% functional compatibility with all 117 integration tests passing, the current implementation is not performance-competitive for typical use cases.
Experimental / Not Published
This package demonstrates the feasibility of using Rust + WASM for ICU MessageFormat parsing but is not recommended for production use. The JavaScript parser (@formatjs/icu-messageformat-parser) is significantly faster for typical use cases.
This package is not published to npm. To use it, build from source:
bazel build //packages/icu-messageformat-parser-wasm:pkg
import {parse} from '@formatjs/icu-messageformat-parser-wasm'
// Parse an ICU MessageFormat string
const ast = await parse('Hello {name}!')
console.log(ast)
// [
// { type: 0, value: 'Hello ' },
// { type: 1, value: 'name' },
// { type: 0, value: '!' }
// ]
// Parse with options
const ast2 = await parse(
'You have {count, plural, one {# item} other {# items}}',
{
captureLocation: false,
shouldParseSkeletons: true,
}
)
parse(input: string, options?: ParserOptions): Promise<MessageFormatElement[]>Parses an ICU MessageFormat string and returns an AST (Abstract Syntax Tree) representing the message structure.
Parameters:
input: The ICU MessageFormat string to parseoptions: Optional parser configuration
ignoreTag?: boolean - Treat HTML/XML tags as literal text (default: false)requiresOtherClause?: boolean - Require 'other' clause in plural/select (default: true)shouldParseSkeletons?: boolean - Parse number/date skeletons (default: true)captureLocation?: boolean - Capture source location info (default: true)locale?: string - Locale for parsing (e.g., 'en-US')Returns:
Promise<MessageFormatElement[]>: An array of message format elementsExample:
const ast = await parse(
'You have {count, plural, one {# item} other {# items}}',
{
captureLocation: false,
}
)
This package exports TypeScript type definitions that match the @formatjs/icu-messageformat-parser package:
MessageFormatElement: Union of all element typesLiteralElement, ArgumentElement, NumberElement, DateElement, TimeElement, SelectElement, PluralElement, PoundElement, TagElement: Specific element typesTYPE: Enum of element typesSKELETON_TYPE: Enum of skeleton typesSee the type definitions for complete details.
⚠️ The WASM parser is currently 14-19x slower than the JavaScript parser for typical use cases.
See BENCHMARK.md for detailed performance analysis. Key findings:
Why is it slower?
When might WASM be useful?
This package serves as:
For production use, we recommend @formatjs/icu-messageformat-parser (the JavaScript version).
fs for loading WASM)MIT