304NotModified / messagetemplates-fsharp

Message templates - the ability to format named string values, and capture the properties

Home Page:http://messagetemplates.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FsMessageTemplates

An implementation of {named} string replacements, which allows formatting, parsing, and capturing properties.

FsMessageTemplates is compatible with the Message Templates Standard.

The F# implementation was designed to be paket-github referenced, or installed as a nuget package.

Build status

Samples

Format an F# Record

type User = { Id:int; Name:string }
format (parse "Hello, {@user}") [| {Id=1; Name="Adam"} |]
// > val it : string = "Hello, User { Id: 1, Name: "Adam" }"

Message Template Syntax

Message Templates are a superset of standard .NET format strings, so any format string acceptable to string.Format() will also be correctly processed by FsMessageTemplates.

  • Property names are written between { and } brackets
  • Brackets can be escaped by doubling them, e.g. {{ will be rendered as {
  • Formats that use numeric property names, like {0} and {1} exclusively, will be matched with the Format method's parameters by treating the property names as indexes; this is identical to string.Format()'s behaviour
  • If any of the property names are non-numeric, then all property names will be matched from left-to-right with the Format method's parameters
  • Property names may be prefixed with an optional operator, @ or $, to control how the property is serialised
  • Property names may be suffixed with an optional format, e.g. :000, to control how the property is rendered; these format strings behave exactly as their counterparts within the string.Format() syntax

About

Message templates - the ability to format named string values, and capture the properties

http://messagetemplates.org/

License:Apache License 2.0


Languages

Language:F# 98.7%Language:PowerShell 0.9%Language:Shell 0.4%Language:Batchfile 0.0%