@robinpath/toml
0.1.4Node.jsPublicParse, stringify, and manipulate TOML configuration files
Toml
Parse, stringify, and manipulate TOML configuration files
Package: @robinpath/toml | Category: Utility | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the toml module when you need to:
- Parse a TOML string to object -- Use
toml.parseto perform this operation - Convert object to TOML string -- Use
toml.stringifyto perform this operation - Read and parse a TOML file -- Use
toml.parseFileto perform this operation - Write object as TOML to file -- Use
toml.writeFileto perform this operation - Get nested value by dot path from TOML string -- Use
toml.getto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
parse | Parse a TOML string to object | Parsed object |
stringify | Convert object to TOML string | TOML string |
parseFile | Read and parse a TOML file | Parsed object |
writeFile | Write object as TOML to file | True on success |
get | Get nested value by dot path from TOML string | Value at path |
isValid | Check if string is valid TOML | True if valid TOML |
toJSON | Convert TOML string to JSON string | JSON string |
fromJSON | Convert JSON string to TOML string | TOML string |
Functions
parse
Parse a TOML string to object
Module: toml | Returns: object -- Parsed object
toml.parse "title = \"My App\""
| Parameter | Type | Required | Description |
|---|---|---|---|
tomlString | string | Yes | TOML string |
stringify
Convert object to TOML string
Module: toml | Returns: string -- TOML string
toml.stringify $config
| Parameter | Type | Required | Description |
|---|---|---|---|
obj | object | Yes | Object to convert |
parseFile
Read and parse a TOML file
Module: toml | Returns: object -- Parsed object
toml.parseFile "config.toml"
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Path to TOML file |
writeFile
Write object as TOML to file
Module: toml | Returns: boolean -- True on success
toml.writeFile "config.toml" $obj
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Output file path |
obj | object | Yes | Object to write |
get
Get nested value by dot path from TOML string
Module: toml | Returns: any -- Value at path
toml.get $toml "database.host"
| Parameter | Type | Required | Description |
|---|---|---|---|
tomlString | string | Yes | TOML string |
path | string | Yes | Dot-separated path |
isValid
Check if string is valid TOML
Module: toml | Returns: boolean -- True if valid TOML
toml.isValid "key = 1"
| Parameter | Type | Required | Description |
|---|---|---|---|
str | string | Yes | String to check |
toJSON
Convert TOML string to JSON string
Module: toml | Returns: string -- JSON string
toml.toJSON $toml
| Parameter | Type | Required | Description |
|---|---|---|---|
tomlString | string | Yes | TOML string |
fromJSON
Convert JSON string to TOML string
Module: toml | Returns: string -- TOML string
toml.fromJSON $json
| Parameter | Type | Required | Description |
|---|---|---|---|
jsonString | string | Yes | JSON string |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
| (standard errors) | Check function parameters and authentication |
@desc "Parse and validate result"
do
set $result as toml.parse "title = \"My App\""
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. List and iterate
Retrieve all items and loop through them.
@desc "Get and iterate results"
do
set $result as toml.get $toml "database.host"
each $item in $result
print $item
end
enddo
2. Multi-step Toml workflow
Chain multiple toml operations together.
@desc "Parse, stringify, and more"
do
set $r_parse as toml.parse "title = \"My App\""
set $r_stringify as toml.stringify $config
set $r_parseFile as toml.parseFile "config.toml"
print "All operations complete"
enddo
3. Safe parse with validation
Check results before proceeding.
@desc "Parse and validate result"
do
set $result as toml.parse "title = \"My App\""
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.4 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/toml
