Ano ang isang TOML file?
Ang TOML (Tom’s Obvious Minimal Language) ay isang minimal na configuration file format na gumagamit ng .toml extension. Nilalayon ng TOML na maging madaling basahin, mag-map nang hindi malabo sa mga diksyunaryo, at maging madaling i-parse sa iba’t ibang istruktura ng data. Ang TOML ay may open-source na detalye na nakatanggap ng mga kontribusyon sa komunidad. Ang TOML ay sinusuportahan ng maraming programming language tulad ng C, C#, Dart, Elixir, Erlang, Go, Java, PHP, Python, Ruby, Swift, atbp. Ang uri ng MIME para sa TOML file ay application/toml.
TOML File Format
Ang mga TOML file ay pangunahing binubuo ng mga Key/value Pairs, mga seksyon/talahanayan, mga komento at dapat ay isang valid na UTF-8 na naka-encode na Unicode na dokumento. Sinusuportahan ng TOML ang mga uri ng data ng String, Integer, Float, Boolean, Datetime, Array, at Table(hash table/diksyonaryo). Ang TOML ay isang case-sensitive na wika.
Syntax
Key-Value Pairs: Key-value pairs are separated by equals sign (=). Each pair must be on a new line.
first = "Tom" last = "Preston-Werner"
Comments: Comments begin with the hash (#) symbol.
# This is a TOML document.
Strings: Strings are surrounded by quotation (") marks.
string = "Example String"
Multi-line Strings: Multi-line Strings are surrounded by three quotation (""") marks.
[home address] street = """123 Tornado Alley Suite 16""" city = "East Centerville" state = "KS"
Integers/Floats
integer = 20 float = 20.5
Booleans: Booleans are always lowercase.
bool1 = true bool2 = false
Date-Time: For DateTime, you may use an RFC 3339 formatted date-time as shown in the example below.
offset_date_time = 1979-05-27 07:32:00Z local_date_time = 1979-05-27T07:32:00 local_date = 1979-05-27 local_time = 07:32:00
Arrays: Arrays are surrounded by square brackets with elements separated by commas (,).
colors = [ "red", "yellow", "green" ]
Tables: Tables are collections of key/value pairs that are defined by headers on a new line surrounded by square brackets ([]). The table ends when a new header is provided or when the file ends.
[home address] street = """123 Tornado Alley Suite 16""" city = "East Centerville" state = "KS" [office address] street = """123 Tornado Alley Suite 16""" city = "East Centerville" state = "KS"
Inline tables are surrounded by curly braces ({}) with each key/value pair separated by comma (,).
name = { first = "Tom", last = "Pitt" }