ini
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
INI is a powerful npm package for Node.js, utilized as an INI encoder and decoder. INI files are simple text files with a basic structure used in Windows OS for configuration of software applications. The INI parser and serializer offered by this package comes in handy for dealing with this kind of text file. The package provides features to parse INI format text to a conveniently usable JavaScript object and serialize JavaScript objects back to INI format text. It treats sections as nested objects, and the items that appear before the first heading are saved directly onto the object.
Using INI for reading, manipulating, and writing an INI file in Node.js is pretty straightforward. Here's a simple JavaScript code usage example:
var fs = require('fs')
, ini = require('ini')
var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
config.scope = 'local'
config.database.database = 'use_another_database'
config.paths.default.tmpdir = '/tmp'
delete config.paths.default.datadir
config.paths.default.array.push('fourth value')
fs.writeFileSync('./config_modified.ini', ini.stringify(config, { section: 'section' }))
In this example, it first reads and decodes the INI file called 'config.ini' into a JavaScript object using fs.readFileSync()
and ini.parse()
. Then it modifies some properties of the JavaScript object. After making the changes, it encodes the object back into an INI-formatted string using ini.stringify()
and writes this string into a new file named 'config_modified.ini' with fs.writeFileSync()
.
As outlined in the package's Readme, the official documentation for INI is available on its GitHub page (https://github.com/npm/ini). The documentation provides a comprehensive guide and explains how to leverage its API, including methods such as decode
, encode
, parse
, stringify
, safe
, and unsafe
. The API section of the documentation enumerates the purpose and usage of these functions, along with the details of their optional parameters.