You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* * Added `toml.decodeFromFile`, `toml.encodeToFile`.
* Renamed `toml.tomlToJSON` and `toml.tomlToYAML` to `toml.toJSON` and `toml.toYAML`
* Add tests for the property accessors of `toml.Date`, `toml.Time`, `toml.DateTime`, and `toml.TimeOffset`, and for `toml.toJSON` and `toml.toYAML`
- Encodes `data` to the file specified in `fileOrOptions`. the file will be created if it doesn't exist.
16
+
- When `fileOrOptions` is a string, it simply is the file path.
17
+
- When `fileOrOptions` is a table, it should have`file`, and optionally, `overwrite` as keys. `file` is the file path, and `overwrite` should be `true` when `file` should be `overwritten` with `data`, and `false` when `data` should be appended to `file`.
18
+
- Added tests that cover:
19
+
- The property accessors of `toml.Date`, `toml.Time`, `toml.DateTime`, and `toml.TimeOffset`.
20
+
-`toml.toJSON` and `toml.toYAML`.
21
+
22
+
### Changed
23
+
24
+
-`toml.tomlToJSON` and `toml.tomlToYAML` have been renamed to `toml.toJSON` and `toml.toYAML`.
25
+
- They have been renamed because they now have two functions: converting a TOML string to JSON/YAML (as before), or converting a table into JSON/YAML.
26
+
- The first parameter can be a string containing TOML (as before), or a table.
Copy file name to clipboardExpand all lines: README.md
+37-14Lines changed: 37 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
[](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-Linux.yml)
7
7
[](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-Windows.yml)
8
8
9
-
toml.lua is a [Lua](https://www.lua.org) wrapper around [toml++](https://github.com/marzer/tomlplusplus/), allowing you to parse and serialize [TOML](https://toml.io)files in Lua.
9
+
toml.lua is a [Lua](https://www.lua.org) wrapper around [toml++](https://github.com/marzer/tomlplusplus/), allowing you to parse and serialize [TOML](https://toml.io) in Lua.
10
10
11
11
## Table of Contents
12
12
@@ -33,18 +33,18 @@ toml.lua is a [Lua](https://www.lua.org) wrapper around [toml++](https://github.
inlineTable = { a = 1275892, b = "Hello, World!", c = true, d = 124.2548 }
@@ -349,6 +366,10 @@ else
349
366
end
350
367
```
351
368
369
+
### Inline Tables
370
+
371
+
Use `setmetatable(myTable, { inline = true })` to create an [inline table](https://toml.io/en/v1.0.0#inline-table).
372
+
352
373
### TOML Conversion
353
374
354
375
```lua
@@ -371,21 +392,23 @@ i = 1979-05-27T07:32:00-07:00
371
392
#### JSON
372
393
373
394
```lua
374
-
localjson=toml.tomlToJSON(tomlStr)
395
+
-- Convert from a string
396
+
localjson=toml.toJSON(tomlStr)
397
+
398
+
-- or from a table
399
+
json=toml.toJSON(toml.decode(tomlStr))
400
+
375
401
print(json)
376
402
```
377
403
378
404
#### YAML
379
405
380
406
```lua
381
-
localyaml=toml.tomlToYAML(tomlStr)
407
+
localyaml=toml.toYAML(tomlStr)
408
+
yaml=toml.toYAML(toml.decode(tomlStr))
382
409
print(yaml)
383
410
```
384
411
385
-
### Inline Tables
386
-
387
-
Use `setmetatable(myTable, { inline = true })` to create an [inline table](https://toml.io/en/v1.0.0#inline-table).
388
-
389
412
### Output Formatting
390
413
391
414
<!---
@@ -422,9 +445,9 @@ int3 = 0x169F
422
445
```
423
446
-->
424
447
425
-
#### Formatting TOML, JSON, YAML
448
+
#### Formatting TOML, JSON, or YAML
426
449
427
-
`toml.encode`, `toml.tomlToJSON`, and `toml.tomlToYAML` all take an optional second parameter: a table containing keys that disable or enable different formatting options.
450
+
`toml.encode`, `toml.encodeToFile`, `toml.toJSON`, and `toml.toYAML` all take an optional second parameter: a table containing keys that disable or enable different formatting options.
428
451
Passing an empty table removes all options, while not providing a table will use the default options.
0 commit comments