Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nvim-neorocks/toml-edit.lua
Edit toml files while preserving whitespace and formatting from Lua.
https://github.com/nvim-neorocks/toml-edit.lua
Last synced: 7 days ago
JSON representation
Edit toml files while preserving whitespace and formatting from Lua.
- Host: GitHub
- URL: https://github.com/nvim-neorocks/toml-edit.lua
- Owner: nvim-neorocks
- License: mit
- Created: 2023-09-03T14:34:41.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-24T17:49:34.000Z (20 days ago)
- Last Synced: 2024-10-31T12:39:43.481Z (13 days ago)
- Language: Rust
- Size: 73.2 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# toml-edit.lua
[![LuaRocks][luarocks-shield]][luarocks-url]
Edit toml files while preserving whitespace and formatting from Lua.
## Usage
The `parse` function creates a table with metatable,
which can be converted back to toml (preserving comments)
using `tostring`:```lua
local toml_content = [[
[rocks]
# Some comment
"toml-edit" = "1.0.0"
]]
local toml_edit = require("toml_edit")
local toml_tbl = toml_edit.parse(toml_content)
toml_tbl.rocks["toml-edit"] = "2.0.0"
print(tostring(toml_tbl))
-- outputs:
-- [rocks]
-- # Some comment
-- "toml-edit" = "2.0.0"
```The `parse_as_tbl` function parses toml as a regular lua table:
```lua
local toml_content = [[
[rocks]
"toml-edit" = "1.0.0"
]]
local toml_edit = require("toml_edit")
local lua_tbl = toml_edit.parse_as_tbl(toml_content)
print(tostring(toml_tbl))
-- outputs: table: 0x7ff975807668
```> [!TIP]
>
> - Use `parse` when you need to modify the toml, and you are accessing or
> setting fields by name.
> - Use `parse_as_tbl` when you need to perform operations that don't access
> fields by name (e.g. iterating over key/value pairs).## Development
### To run tests:
Using Nix:
```console
nix flake check -L
```Using luarocks:
```console
mkdir luarocks
luarocks make --tree=luarocks
luarocks test
```> [!NOTE]
>
> You may need to `luarocks install --local luarocks-build-rust-mlua`.[luarocks-shield]: https://img.shields.io/luarocks/v/neorg/toml-edit?logo=lua&color=purple&style=for-the-badge
[luarocks-url]: https://luarocks.org/modules/neorg/toml-edit