TOML 备忘清单
这是 TOML 格式配置文件语法的快速参考备忘清单。
入门
介绍
TOML 是一种最小的配置文件格式,由于明显的语义而易于阅读。
- Document (toml.io)
- Learn X in Y minutes (learnxinyminutes.com)
- Better TOML VSCode 插件 (visualstudio.com)
示例
bool = truedate = 2006-05-27T07:32:00Zstring = "hello"number = 42float = 3.14scientificNotation = 1e+12
注释
# A single line comment example# block level comment example# 注释行 1# 注释行 2# 注释行 3
整数
int1 = +42int2 = 0int3 = -21integerRange = 64
浮点数
float2 = 3.1415float4 = 5e+22float7 = 6.626e-34
布尔值
bool1 = truebool2 = falseboolMustBeLowercase = true
时间日期
date1 = 1989-05-27T07:32:00Zdate2 = 1989-05-26T15:32:00-07:00date3 = 1989-05-27T07:32:00date4 = 1989-05-27time1 = 07:32:00time2 = 00:32:00.999999
字符串
str1 = "I'm a string."str2 = "You can \"quote\" me."str3 = "Name\tJos\u00E9\nLoc\tSF."
See: Strings
Table
[owner]name = "Tom Preston-Werner"dob = 1979-05-27T07:32:00-08:00
See: Tables
数组
array1 = [1, 2, 3]array2 = ["Commas", "are", "delimiter"]array3 = [8001, 8001, 8002]
友好数组
array1 = [ "Don't mix", "different", "types" ]array2 = [ [ 1.2, 2.4 ], ["all", 'strings', """are the same""", '''type'''] ]array3 = ["Whitespace", "is","ignored"]
TOML 字符串
多行字符串
multiLineString = """Multi-line basic strings are surroundedby three quotation marks on each sideand allow newlines."""
文字字符串
path = 'C:\Users\nodejs\templates'path2 = '\\User\admin$\system32'quoted = 'Tom "Dubs" Preston-Werner'regex = '<\i\c*\s*>'
用单引号括起来。不允许转义。
多行文字字符串
re = '''\d{2} apps is t[wo]o many'''lines = '''The first newline istrimmed in raw strings.All other whitespaceis preserved.'''
TOML Tables
基本的
[name]foo = 1bar = 2
foo 和 bar 是名为name 的表中的键
嵌套
[table1]foo = "bar"[table1.nested_table]baz = "bat"
类数组
[[comments]]author = "Nate"text = "Great Article!"[[comments]]author = "Anonymous"text = "Love it!"
↓ 等效的 JSON
{"comments" : [{"author" : "Nate","text" : "Great Article!"},{"author" : "Anonymous","text" : "Love It!"}]}
点分隔
[dog."tater.man"]type = "pug"
↓ 等效的 JSON
{"dog": {"tater.man": {"type": "pug"}}}
多嵌套
[foo.bar.baz]bat = "hi"
↓ 等效的 JSON
{"foo" : {"bar" : {"baz" : {"bat" : "hi"}}}}
忽略空格
[a.b.c] # this is best practice[ d.e.f ] # same as [d.e.f][ g . h .i ] # same as [g.h.i][ j . "ʞ" .'l' ] # same as [j."ʞ".'l']
Inline Table
name = { first = "Tom", last = "Preston-Werner" }point = { x = 1, y = 2 }animal = { type.name = "pug" }
另见
- Document (toml.io)
- Learn X in Y minutes (learnxinyminutes.com)
- Better TOML VSCode 插件 (visualstudio.com)
- INI 格式配置文件备忘清单 (jaywcjlove.github.io)
- YAML 格式配置文件备忘清单 (jaywcjlove.github.io)
