Modules@robinpath/toml
toml

@robinpath/toml

0.1.4Node.jsPublic

Parse, 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.parse to perform this operation
  • Convert object to TOML string -- Use toml.stringify to perform this operation
  • Read and parse a TOML file -- Use toml.parseFile to perform this operation
  • Write object as TOML to file -- Use toml.writeFile to perform this operation
  • Get nested value by dot path from TOML string -- Use toml.get to perform this operation

Quick Reference

FunctionDescriptionReturns
parseParse a TOML string to objectParsed object
stringifyConvert object to TOML stringTOML string
parseFileRead and parse a TOML fileParsed object
writeFileWrite object as TOML to fileTrue on success
getGet nested value by dot path from TOML stringValue at path
isValidCheck if string is valid TOMLTrue if valid TOML
toJSONConvert TOML string to JSON stringJSON string
fromJSONConvert JSON string to TOML stringTOML string

Functions

parse

Parse a TOML string to object

Module: toml | Returns: object -- Parsed object

toml.parse "title = \"My App\""
ParameterTypeRequiredDescription
tomlStringstringYesTOML string

stringify

Convert object to TOML string

Module: toml | Returns: string -- TOML string

toml.stringify $config
ParameterTypeRequiredDescription
objobjectYesObject to convert

parseFile

Read and parse a TOML file

Module: toml | Returns: object -- Parsed object

toml.parseFile "config.toml"
ParameterTypeRequiredDescription
filePathstringYesPath to TOML file

writeFile

Write object as TOML to file

Module: toml | Returns: boolean -- True on success

toml.writeFile "config.toml" $obj
ParameterTypeRequiredDescription
filePathstringYesOutput file path
objobjectYesObject to write

get

Get nested value by dot path from TOML string

Module: toml | Returns: any -- Value at path

toml.get $toml "database.host"
ParameterTypeRequiredDescription
tomlStringstringYesTOML string
pathstringYesDot-separated path

isValid

Check if string is valid TOML

Module: toml | Returns: boolean -- True if valid TOML

toml.isValid "key = 1"
ParameterTypeRequiredDescription
strstringYesString to check

toJSON

Convert TOML string to JSON string

Module: toml | Returns: string -- JSON string

toml.toJSON $toml
ParameterTypeRequiredDescription
tomlStringstringYesTOML string

fromJSON

Convert JSON string to TOML string

Module: toml | Returns: string -- TOML string

toml.fromJSON $json
ParameterTypeRequiredDescription
jsonStringstringYesJSON string

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(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)

VersionTagPublished
0.1.4latest1 months ago
Install
$ robinpath add @robinpath/toml

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.4
LicenseMIT
Unpacked Size3.7 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities