@robinpath/ini
0.1.1Node.jsPublicParse, 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.parseto perform this operation - Convert object to INI string -- Use
ini.stringifyto perform this operation - Read and parse an INI file -- Use
ini.parseFileto perform this operation - Write object as INI to file -- Use
ini.writeFileto perform this operation - Get value by section and key from INI string -- Use
ini.getto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
parse | Parse an INI string to object | Nested object with sections |
stringify | Convert object to INI string | INI format string |
parseFile | Read and parse an INI file | Parsed INI object |
writeFile | Write object as INI to file | True on success |
get | Get value by section and key from INI string | Value or null |
set | Set value by section and key, return updated INI | Updated INI string |
getSections | Get all section names | Array of section names |
getKeys | Get all keys in a section | Array of keys |
removeSection | Remove a section from INI string | Updated INI string |
removeKey | Remove a key from a section | Updated INI string |
Functions
parse
Parse an INI string to object
Module: ini | Returns: object -- Nested object with sections
ini.parse "[db]\nhost=localhost"
| Parameter | Type | Required | Description |
|---|---|---|---|
iniString | string | Yes | INI format string |
stringify
Convert object to INI string
Module: ini | Returns: string -- INI format string
ini.stringify $config
| Parameter | Type | Required | Description |
|---|---|---|---|
obj | object | Yes | Object with sections |
parseFile
Read and parse an INI file
Module: ini | Returns: object -- Parsed INI object
ini.parseFile "config.ini"
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Path to INI file |
writeFile
Write object as INI to file
Module: ini | Returns: boolean -- True on success
ini.writeFile "config.ini" $obj
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Output file path |
obj | object | Yes | Object to write |
get
Get value by section and key from INI string
Module: ini | Returns: string -- Value or null
ini.get $ini "database" "host"
| Parameter | Type | Required | Description |
|---|---|---|---|
iniString | string | Yes | INI string |
section | string | Yes | Section name |
key | string | Yes | Key name |
set
Set value by section and key, return updated INI
Module: ini | Returns: string -- Updated INI string
ini.set $ini "database" "port" "5432"
| Parameter | Type | Required | Description |
|---|---|---|---|
iniString | string | Yes | INI string |
section | string | Yes | Section name |
key | string | Yes | Key name |
value | string | Yes | Value |
getSections
Get all section names
Module: ini | Returns: array -- Array of section names
ini.getSections $ini
| Parameter | Type | Required | Description |
|---|---|---|---|
iniString | string | Yes | INI string |
getKeys
Get all keys in a section
Module: ini | Returns: array -- Array of keys
ini.getKeys $ini "database"
| Parameter | Type | Required | Description |
|---|---|---|---|
iniString | string | Yes | INI string |
section | string | Yes | Section name |
removeSection
Remove a section from INI string
Module: ini | Returns: string -- Updated INI string
ini.removeSection $ini "old_section"
| Parameter | Type | Required | Description |
|---|---|---|---|
iniString | string | Yes | INI string |
section | string | Yes | Section to remove |
removeKey
Remove a key from a section
Module: ini | Returns: string -- Updated INI string
ini.removeKey $ini "database" "old_key"
| Parameter | Type | Required | Description |
|---|---|---|---|
iniString | string | Yes | INI string |
section | string | Yes | Section name |
key | string | Yes | Key to remove |
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 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)
| Version | Tag | Published |
|---|---|---|
| 0.1.1 | 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/ini
