https://github.com/tariibaba/ini-data
Parse INI configuration data to an object in Javascript
https://github.com/tariibaba/ini-data
ini ini-parser javascript typescript
Last synced: about 2 months ago
JSON representation
Parse INI configuration data to an object in Javascript
- Host: GitHub
- URL: https://github.com/tariibaba/ini-data
- Owner: tariibaba
- Created: 2021-12-16T12:10:24.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-01T18:39:36.000Z (almost 3 years ago)
- Last Synced: 2025-02-26T08:18:08.386Z (over 1 year ago)
- Topics: ini, ini-parser, javascript, typescript
- Language: TypeScript
- Homepage:
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ini-data
## ⛔️ **Warning**: This library was created primarily for educational purposes, and is currently unstable
INI parser and serializer for JavaScript.
## Usage
### parse()
Let's say you have this INI file (named **config.ini**):
```
; this is a comment
key = value
[details]
user = root
password = thepassword
[database.main.values]
key1 = value1
key2 = value2
```
You can parse the file into an object like so:
```javascript
const fs = require('fs');
const iniConfig = require('ini-data');
const text = fs.readFileSync('ini.config', 'utf-8');
const obj = iniConfig.parse(text);
console.log(obj.key); // value
console.log(obj.details.password); // thepassword
console.log(obj.database.main.values.key1); // value1
```
### stringify()
```javascript
const ini = require('ini-data');
const fs = require('fs');
const obj = {
user: {
name: 'root',
password: 'thepassword',
details: {
item1: 'value1',
},
},
key: 'value',
};
fs.writeFileSync('data.ini', ini.stringify(obj));
```
**data.ini** will contain the following INI data:
```
key = value
[user]
name = root
password = thepassword
[user.details]
item1 = value1
```