这是 TOML 格式配置文件语法的快速参考备忘清单。
TOML 是一种最小的配置文件格式,由于明显的语义而易于阅读。
bool = true
date = 2006-05-27T07:32:00Z
string = "hello"
number = 42
float = 3.14
scientificNotation = 1e+12
# A single line comment example
# block level comment example
# 注释行 1
# 注释行 2
# 注释行 3
int1 = +42
int2 = 0
int3 = -21
integerRange = 64
float2 = 3.1415
float4 = 5e+22
float7 = 6.626e-34
bool1 = true
bool2 = false
boolMustBeLowercase = true
date1 = 1989-05-27T07:32:00Z
date2 = 1989-05-26T15:32:00-07:00
date3 = 1989-05-27T07:32:00
date4 = 1989-05-27
time1 = 07:32:00
time2 = 00:32:00.999999
str1 = "I'm a string."
str2 = "You can \"quote\" me."
str3 = "Name\tJos\u00E9\nLoc\tSF."
See: Strings
[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"
]
str1 = "I'm a string."
str2 = "You can \"quote\" me."
str3 = "Name\tJos\u00E9\nLoc\tSF."
str1 = """
Roses are red
Violets are blue"""
str2 = """\
The quick brown \
fox jumps over \
the lazy dog.\
"""
用行末反斜杠自动剔除非空白字符前的任何空白字符
re = '''\d{2} apps is t[wo]o many'''
lines = '''
The first newline is
trimmed in raw strings.
All other whitespace
is preserved.
'''
由于没有转义,无法在由单引号包裹的字面量字符串中写入单引号
path = 'C:\Users\nodejs\templates'
path2 = '\\User\admin$\system32'
quoted = 'Tom "Dubs" Preston-Werner'
regex = '<\i\c*\s*>'
用单引号括起来。不允许转义。
整数、浮点数、无穷甚至非数都是支持的。你可以用科学计数法甚至千分符
int1 = +99
int2 = 42
int3 = 0
int4 = -17
0x
hex1 = 0xDEADBEEF
hex2 = 0xdeadbeef
hex3 = 0xdead_beef
0o
oct1 = 0o01234567
oct2 = 0o755
0b
bin1 = 0b11010110
float7 = 6.626e-34
float8 = 224_617.445_991_228
float1 = +1.0
float2 = 3.1415
float3 = -0.01
float4 = 5e+22
float5 = 1e06
float6 = -2E-2
infinite1 = inf # 正无穷
infinite2 = +inf # 正无穷
infinite3 = -inf # 负无穷
not1 = nan
not2 = +nan
not3 = -nan
TOML 支持日期、时刻、日期时刻,带或者不带时区偏移
odt1 = 1979-05-27T07:32:00Z
odt2 = 1979-05-27T00:32:00-07:00
odt3 = 1979-05-27T00:32:00.999999-07:00
ldt1 = 1979-05-27T07:32:00
ldt2 = 1979-05-27T00:32:00.999999
ld1 = 1979-05-27
lt1 = 07:32:00
lt2 = 00:32:00.999999
[name]
foo = 1
bar = 2
foo
和 bar
是名为name
的表中的键
[table1]
foo = "bar"
[table1.nested_table]
baz = "bat"
[[comments]]
author = "Nate"
text = "Great Article!"
[[comments]]
author = "Anonymous"
text = "Love it!"
{
"comments" : [
{
"author" : "Nate",
"text" : "Great Article!"
},
{
"author" : "Anonymous",
"text" : "Love It!"
}
]
}
[dog."tater.man"]
type = "pug"
{
"dog": {
"tater.man": {
"type": "pug"
}
}
}
[foo.bar.baz]
bat = "hi"
{
"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']
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)