mf2

package module
v0.0.0-...-8700042 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: MIT Imports: 6 Imported by: 0

README

Message Format 2 Parser

CI

This parser parses the localized message strings based on the Message Format 2 Draft by the Message Format Working Group (MFWG).

Requirements

  • Golang 1.22+
  • IANA Time Zone database - one of:
    • the directory or uncompressed zip file named by the ZONEINFO environment variable
    • on a Unix system, the system standard installation location
    • $GOROOT/lib/time/zoneinfo.zip
    • the time/tzdata package

Features

Function registry

List of the default functions registered in the function registry. The functions support localized formatting.

Function Signature Option Status
date format style
datetime format dateStyle
datetime format timeStyle
datetime format calendar
datetime format numberingSystem
datetime format timeZone
datetime format hourCycle
datetime format dayPeriod
datetime format weekday
datetime format era
datetime format year
datetime format month
datetime format day
datetime format hour
datetime format minute
datetime format second
datetime format fractionalSecondDigits
datetime format timeZoneName
number format compactDisplay
number format currency
number format currencyDisplay
number format currencySign
number format notation
number format numberingSystem
number format signDisplay (auto, always, exceptZero, never) ✅︎
number format style (decimal, percent) ✅︎
number format style (currency, unit)
number format unit
number format unitDisplay
number format minimumIntegerDigits ✅︎
number format minimumFractionDigits ✅︎
number format maximumFractionDigits ✅︎
number format minimumSignificantDigits
number format maximumSignificantDigits ✅︎
number match select
number match minimumIntegerDigits
number match minimumFractionDigits
number match maximumFractionDigits
number match minimumSignificantDigits
number match maximumSignificantDigits
number match minimumFractionDigits
number match minimumFractionDigits
integer (number alias)
ordinal (number alias)
plural (number alias)
string
time

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyAttribute

func EmptyAttribute(name string) attribute

func LiteralAttribute

func LiteralAttribute(name string, value any) attribute

func VarAttribute

func VarAttribute(name, varName string) attribute

Types

type AnnotationStart

type AnnotationStart int
const (
	Caret     AnnotationStart = iota // ^
	Ampersand                        // &
)

Private Use start character.

const (
	Exclamation AnnotationStart = iota + 2 // !
	Percent                                // %
	Asterisk                               // *
	Plus                                   // +
	LessThan                               // <
	GreaterThan                            // >
	Question                               // ?
	Tilde                                  // ~
)

Reserved start character.

func (AnnotationStart) String

func (a AnnotationStart) String() string

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Build

func (b *Builder) Build() (string, error)

func (*Builder) CloseMarkup

func (b *Builder) CloseMarkup(name string, attributes ...attribute) *Builder

func (*Builder) Expr

func (b *Builder) Expr(expr *Expression) *Builder

func (*Builder) Input

func (b *Builder) Input(expr *Expression) *Builder

Input adds input declaration to the builder.

func (*Builder) Keys

func (b *Builder) Keys(key any, keys ...any) *Builder

func (*Builder) Local

func (b *Builder) Local(v string, expr *Expression) *Builder

Local adds local declaration to the builder.

func (*Builder) Match

func (b *Builder) Match(selector *Expression, selectors ...*Expression) *Builder

func (*Builder) MustBuild

func (b *Builder) MustBuild() string

func (*Builder) Newline

func (b *Builder) Newline(s string) *Builder

func (*Builder) OpenMarkup

func (b *Builder) OpenMarkup(name string, optionsAndAttributes ...OptsAndAttr) *Builder

func (*Builder) Reserved

func (b *Builder) Reserved(
	keyword string,
	expression *Expression,
	reservedOrExpression ...ReservedOrExpression,
) *Builder

Reserved adds reserved statement to the builder.

func (*Builder) SelfCloseMarkup

func (b *Builder) SelfCloseMarkup(name string, optionsAndAttributes ...OptsAndAttr) *Builder

func (*Builder) Spacing

func (b *Builder) Spacing(s string) *Builder

TODO: add to all expressions.

func (*Builder) Text

func (b *Builder) Text(s string) *Builder

type Expression

type Expression struct {
	// contains filtered or unexported fields
}

func Annotation

func Annotation(start AnnotationStart, reservedBody ...ReservedBody) *Expression

Annotation adds Private Use or Reserved annotation to the expression.

func Expr

func Expr() *Expression

func Literal

func Literal(v any) *Expression

func Var

func Var(name string) *Expression

func (*Expression) Annotation

func (e *Expression) Annotation(start AnnotationStart, reservedBody ...ReservedBody) *Expression

Annotation adds Private Use or Reserved annotation to the expression.

func (*Expression) Attr

func (e *Expression) Attr(attributes ...attribute) *Expression

Attr adds attributes to the expression.

func (*Expression) Func

func (e *Expression) Func(name string, option ...FuncOption) *Expression

func (*Expression) Literal

func (e *Expression) Literal(v any) *Expression

func (*Expression) Var

func (e *Expression) Var(name string) *Expression

type FuncOption

type FuncOption struct {
	// contains filtered or unexported fields
}

func LiteralOption

func LiteralOption(name string, value any) FuncOption

func VarOption

func VarOption(name, varName string) FuncOption

type OptsAndAttr

type OptsAndAttr interface {
	// contains filtered or unexported methods
}

Hack: limit to only options and attributes, instead of any.

type Quoted

type Quoted string

type ReservedBody

type ReservedBody interface {
	// contains filtered or unexported methods
}

type ReservedOrExpression

type ReservedOrExpression interface {
	// contains filtered or unexported methods
}

type ReservedText

type ReservedText string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL