Modules@robinpath/ini
ini

@robinpath/ini

0.1.1Node.jsPublic

Parse, stringify, read, and write INI configuration files

Ini

Parse, stringify, read, and write INI configuration files

Package: @robinpath/ini | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the ini module when you need to:

  • Parse an INI string to object -- Use ini.parse to perform this operation
  • Convert object to INI string -- Use ini.stringify to perform this operation
  • Read and parse an INI file -- Use ini.parseFile to perform this operation
  • Write object as INI to file -- Use ini.writeFile to perform this operation
  • Get value by section and key from INI string -- Use ini.get to perform this operation

Quick Reference

FunctionDescriptionReturns
parseParse an INI string to objectNested object with sections
stringifyConvert object to INI stringINI format string
parseFileRead and parse an INI fileParsed INI object
writeFileWrite object as INI to fileTrue on success
getGet value by section and key from INI stringValue or null
setSet value by section and key, return updated INIUpdated INI string
getSectionsGet all section namesArray of section names
getKeysGet all keys in a sectionArray of keys
removeSectionRemove a section from INI stringUpdated INI string
removeKeyRemove a key from a sectionUpdated INI string

Functions

parse

Parse an INI string to object

Module: ini | Returns: object -- Nested object with sections

ini.parse "[db]\nhost=localhost"
ParameterTypeRequiredDescription
iniStringstringYesINI format string

stringify

Convert object to INI string

Module: ini | Returns: string -- INI format string

ini.stringify $config
ParameterTypeRequiredDescription
objobjectYesObject with sections

parseFile

Read and parse an INI file

Module: ini | Returns: object -- Parsed INI object

ini.parseFile "config.ini"
ParameterTypeRequiredDescription
filePathstringYesPath to INI file

writeFile

Write object as INI to file

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

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

get

Get value by section and key from INI string

Module: ini | Returns: string -- Value or null

ini.get $ini "database" "host"
ParameterTypeRequiredDescription
iniStringstringYesINI string
sectionstringYesSection name
keystringYesKey name

set

Set value by section and key, return updated INI

Module: ini | Returns: string -- Updated INI string

ini.set $ini "database" "port" "5432"
ParameterTypeRequiredDescription
iniStringstringYesINI string
sectionstringYesSection name
keystringYesKey name
valuestringYesValue

getSections

Get all section names

Module: ini | Returns: array -- Array of section names

ini.getSections $ini
ParameterTypeRequiredDescription
iniStringstringYesINI string

getKeys

Get all keys in a section

Module: ini | Returns: array -- Array of keys

ini.getKeys $ini "database"
ParameterTypeRequiredDescription
iniStringstringYesINI string
sectionstringYesSection name

removeSection

Remove a section from INI string

Module: ini | Returns: string -- Updated INI string

ini.removeSection $ini "old_section"
ParameterTypeRequiredDescription
iniStringstringYesINI string
sectionstringYesSection to remove

removeKey

Remove a key from a section

Module: ini | Returns: string -- Updated INI string

ini.removeKey $ini "database" "old_key"
ParameterTypeRequiredDescription
iniStringstringYesINI string
sectionstringYesSection name
keystringYesKey to remove

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 ini.parse "[db]\nhost=localhost"
  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 ini.get $ini "database" "host"
  each $item in $result
    print $item
  end
enddo

2. Multi-step Ini workflow

Chain multiple ini operations together.

@desc "Parse, stringify, and more"
do
  set $r_parse as ini.parse "[db]\nhost=localhost"
  set $r_stringify as ini.stringify $config
  set $r_parseFile as ini.parseFile "config.ini"
  print "All operations complete"
enddo

3. Safe parse with validation

Check results before proceeding.

@desc "Parse and validate result"
do
  set $result as ini.parse "[db]\nhost=localhost"
  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.1latest1 months ago
Install
$ robinpath add @robinpath/ini

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size4.3 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities