|
| 1 | +################################################################################ |
| 2 | +## Comment |
| 3 | + |
| 4 | +# Speak your mind with the hash symbol. They go from the symbol to the end of |
| 5 | +# the line. |
| 6 | + |
| 7 | + |
| 8 | +################################################################################ |
| 9 | +## Table |
| 10 | + |
| 11 | +# Tables (also known as hash tables or dictionaries) are collections of |
| 12 | +# key/value pairs. They appear in square brackets on a line by themselves. |
| 13 | + |
| 14 | +[table] |
| 15 | + |
| 16 | +key = "value" # Yeah, you can do this. |
| 17 | + |
| 18 | +# Nested tables are denoted by table names with dots in them. Name your tables |
| 19 | +# whatever crap you please, just don't use #, ., [ or ]. |
| 20 | + |
| 21 | +[table.subtable] |
| 22 | + |
| 23 | +key = "another value" |
| 24 | + |
| 25 | +# You don't need to specify all the super-tables if you don't want to. TOML |
| 26 | +# knows how to do it for you. |
| 27 | + |
| 28 | +# [x] you |
| 29 | +# [x.y] don't |
| 30 | +# [x.y.z] need these |
| 31 | +[x.y.z.w] # for this to work |
| 32 | + |
| 33 | + |
| 34 | +################################################################################ |
| 35 | +## Inline Table |
| 36 | + |
| 37 | +# Inline tables provide a more compact syntax for expressing tables. They are |
| 38 | +# especially useful for grouped data that can otherwise quickly become verbose. |
| 39 | +# Inline tables are enclosed in curly braces `{` and `}`. No newlines are |
| 40 | +# allowed between the curly braces unless they are valid within a value. |
| 41 | + |
| 42 | +[table.inline] |
| 43 | + |
| 44 | +name = { first = "Tom", last = "Preston-Werner" } |
| 45 | +point = { x = 1, y = 2 } |
| 46 | + |
| 47 | + |
| 48 | +################################################################################ |
| 49 | +## String |
| 50 | + |
| 51 | +# There are four ways to express strings: basic, multi-line basic, literal, and |
| 52 | +# multi-line literal. All strings must contain only valid UTF-8 characters. |
| 53 | + |
| 54 | +[string.basic] |
| 55 | + |
| 56 | +basic = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF." |
| 57 | + |
| 58 | +[string.multiline] |
| 59 | + |
| 60 | +# The following strings are byte-for-byte equivalent: |
| 61 | +key1 = "One\nTwo" |
| 62 | +key2 = """One\nTwo""" |
| 63 | +key3 = """ |
| 64 | +One |
| 65 | +Two""" |
| 66 | + |
| 67 | +[string.multiline.continued] |
| 68 | + |
| 69 | +# The following strings are byte-for-byte equivalent: |
| 70 | +key1 = "The quick brown fox jumps over the lazy dog." |
| 71 | + |
| 72 | +key2 = """ |
| 73 | +The quick brown \ |
| 74 | +
|
| 75 | +
|
| 76 | + fox jumps over \ |
| 77 | + the lazy dog.""" |
| 78 | + |
| 79 | +key3 = """\ |
| 80 | + The quick brown \ |
| 81 | + fox jumps over \ |
| 82 | + the lazy dog.\ |
| 83 | + """ |
| 84 | + |
| 85 | +[string.literal] |
| 86 | + |
| 87 | +# What you see is what you get. |
| 88 | +winpath = 'C:\Users\nodejs\templates' |
| 89 | +winpath2 = '\\ServerX\admin$\system32\' |
| 90 | +quoted = 'Tom "Dubs" Preston-Werner' |
| 91 | +regex = '<\i\c*\s*>' |
| 92 | + |
| 93 | + |
| 94 | +[string.literal.multiline] |
| 95 | + |
| 96 | +regex2 = '''I [dw]on't need \d{2} apples''' |
| 97 | +lines = ''' |
| 98 | +The first newline is |
| 99 | +trimmed in raw strings. |
| 100 | + All other whitespace |
| 101 | + is preserved. |
| 102 | +''' |
| 103 | + |
| 104 | + |
| 105 | +################################################################################ |
| 106 | +## Integer |
| 107 | + |
| 108 | +# Integers are whole numbers. Positive numbers may be prefixed with a plus sign. |
| 109 | +# Negative numbers are prefixed with a minus sign. |
| 110 | + |
| 111 | +[integer] |
| 112 | + |
| 113 | +key1 = +99 |
| 114 | +key2 = 42 |
| 115 | +key3 = 0 |
| 116 | +key4 = -17 |
| 117 | + |
| 118 | +[integer.underscores] |
| 119 | + |
| 120 | +# For large numbers, you may use underscores to enhance readability. Each |
| 121 | +# underscore must be surrounded by at least one digit. |
| 122 | +key1 = 1_000 |
| 123 | +key2 = 5_349_221 |
| 124 | +key3 = 1_2_3_4_5 # valid but inadvisable |
| 125 | + |
| 126 | + |
| 127 | +################################################################################ |
| 128 | +## Float |
| 129 | + |
| 130 | +# A float consists of an integer part (which may be prefixed with a plus or |
| 131 | +# minus sign) followed by a fractional part and/or an exponent part. |
| 132 | + |
| 133 | +[float.fractional] |
| 134 | + |
| 135 | +key1 = +1.0 |
| 136 | +key2 = 3.1415 |
| 137 | +key3 = -0.01 |
| 138 | + |
| 139 | +[float.exponent] |
| 140 | + |
| 141 | +key1 = 5e+22 |
| 142 | +key2 = 1e6 |
| 143 | +key3 = -2E-2 |
| 144 | + |
| 145 | +[float.both] |
| 146 | + |
| 147 | +key = 6.626e-34 |
| 148 | + |
| 149 | +[float.underscores] |
| 150 | + |
| 151 | +key1 = 9_224_617.445_991_228_313 |
| 152 | +key2 = 1e1_000 |
| 153 | + |
| 154 | + |
| 155 | +################################################################################ |
| 156 | +## Boolean |
| 157 | + |
| 158 | +# Booleans are just the tokens you're used to. Always lowercase. |
| 159 | + |
| 160 | +[boolean] |
| 161 | + |
| 162 | +True = true |
| 163 | +False = false |
| 164 | + |
| 165 | + |
| 166 | +################################################################################ |
| 167 | +## Datetime |
| 168 | + |
| 169 | +# Datetimes are RFC 3339 dates. |
| 170 | + |
| 171 | +[datetime] |
| 172 | + |
| 173 | +key1 = 1979-05-27T07:32:00Z |
| 174 | +key2 = 1979-05-27T00:32:00-07:00 |
| 175 | +key3 = 1979-05-27T00:32:00.999999-07:00 |
| 176 | + |
| 177 | + |
| 178 | +################################################################################ |
| 179 | +## Array |
| 180 | + |
| 181 | +# Arrays are square brackets with other primitives inside. Whitespace is |
| 182 | +# ignored. Elements are separated by commas. Data types may not be mixed. |
| 183 | + |
| 184 | +[array] |
| 185 | + |
| 186 | +key1 = [ 1, 2, 3 ] |
| 187 | +key2 = [ "red", "yellow", "green" ] |
| 188 | +key3 = [ [ 1, 2 ], [3, 4, 5] ] |
| 189 | +key4 = [ [ 1, 2 ], ["a", "b", "c"] ] # this is ok |
| 190 | + |
| 191 | +# Arrays can also be multiline. So in addition to ignoring whitespace, arrays |
| 192 | +# also ignore newlines between the brackets. Terminating commas are ok before |
| 193 | +# the closing bracket. |
| 194 | + |
| 195 | +key5 = [ |
| 196 | + 1, 2, 3 |
| 197 | +] |
| 198 | +key6 = [ |
| 199 | + 1, |
| 200 | + 2, # this is ok |
| 201 | +] |
| 202 | + |
| 203 | + |
| 204 | +################################################################################ |
| 205 | +## Array of Tables |
| 206 | + |
| 207 | +# These can be expressed by using a table name in double brackets. Each table |
| 208 | +# with the same double bracketed name will be an element in the array. The |
| 209 | +# tables are inserted in the order encountered. |
| 210 | + |
| 211 | +[[products]] |
| 212 | + |
| 213 | +name = "Hammer" |
| 214 | +sku = 738594937 |
| 215 | + |
| 216 | +[[products]] |
| 217 | + |
| 218 | +[[products]] |
| 219 | + |
| 220 | +name = "Nail" |
| 221 | +sku = 284758393 |
| 222 | +color = "gray" |
| 223 | + |
| 224 | + |
| 225 | +# You can create nested arrays of tables as well. |
| 226 | + |
| 227 | +[[fruit]] |
| 228 | + name = "apple" |
| 229 | + |
| 230 | + [fruit.physical] |
| 231 | + color = "red" |
| 232 | + shape = "round" |
| 233 | + |
| 234 | + [[fruit.variety]] |
| 235 | + name = "red delicious" |
| 236 | + |
| 237 | + [[fruit.variety]] |
| 238 | + name = "granny smith" |
| 239 | + |
| 240 | +[[fruit]] |
| 241 | + name = "banana" |
| 242 | + |
| 243 | + [[fruit.variety]] |
| 244 | + name = "plantain" |
0 commit comments