A professional INI file parser for Node.js with CLI support. Parse INI configuration files into structured JavaScript objects with support for sections, multi-line values, comments and global keys.
Library Usage (JavaScript):
const { parse } = require('@notfounnd/ini-parser');
const content = `
# Database configuration
[database]
host=localhost
port=5432
`;
const result = parse(content);
console.log(result); // { database: { host: ['localhost'], port: ['5432'] } }CLI Usage:
ini-parser config.ini # Parse and output JSON
ini-parser config.ini --output data.json # Save to file
ini-parser config.ini --check # Validate file- π¦ Library & CLI: Use as a Node.js module or command-line tool
- π§ INI Standard Support: Sections, key-value pairs, comments (
#and;) - π Multi-line Values: Indented continuation lines
- π Global Keys: Keys outside of sections
- π― Flexible Output: Simplified or metadata format
- β Validation: File checking with statistics
- π¨ Colored Output: User-friendly CLI messages
- β‘ Zero Config: Works out of the box
- π§ͺ Well Tested: Comprehensive test suite
npm install @notfounnd/ini-parsernpm install -g @notfounnd/ini-parserconst { parse } = require('@notfounnd/ini-parser');
// Example INI content
const content = `
# Database configuration
[database]
host=localhost
port=5432
name=myapp
[server]
port=3000
workers=4 8 16 32
`;
// Parse with simplified format (default)
const result = parse(content);
console.log(result);
// Output:
// {
// database: {
// host: ['localhost'],
// port: ['5432'],
// name: ['myapp']
// },
// server: {
// port: ['3000'],
// workers: ['4', '8', '16', '32']
// }
// }
// Parse with metadata format
const metaResult = parse(content, { meta: true });
console.log(metaResult);
// Output includes type information:
// {
// database: {
// type: 'section',
// content: {
// host: { type: 'configuration', content: ['localhost'] },
// port: { type: 'configuration', content: ['5432'] },
// name: { type: 'configuration', content: ['myapp'] }
// }
// },
// ...
// }# Parse INI file and output to stdout
ini-parser config.ini
# Save output to JSON file
ini-parser config.ini --output result.json
# Parse with metadata format
ini-parser config.ini --meta
# Validate file and show statistics
ini-parser config.ini --check
# Save to file without stdout (quiet mode)
ini-parser config.ini --output result.json --quiet
# Show version
ini-parser --version
# Show help
ini-parser --help- API Reference - Detailed library API documentation
- CLI Reference - Complete CLI usage guide
- Parser Rules - INI parser behavior and rules
Parses INI file content into a structured JavaScript object.
Parameters:
content(string): The INI file content as a stringoptions(object, optional):meta(boolean): Iftrue, returns metadata format with type information; iffalse, returns simplified format (default:false)
Returns: object - Parsed INI data
Output Formats:
- Simplified Format (default): Clean object structure with arrays of values
{
section: {
key: ['value1', 'value2']
}
}- Metadata Format (
meta: true): Includes type information for advanced use cases
{
section: {
type: 'section',
content: {
key: {
type: 'configuration',
content: ['value1', 'value2']
}
}
}
}Supported Features:
- β
Sections:
[section_name] - β
Key-value pairs:
key=value - β Multi-line values (indented continuation)
- β Global keys (outside of sections)
- β
Comments:
#and;at line start - β
Inline comments:
key=value # comment - β Automatic value splitting by spaces
- β Empty value handling
ini-parser <file> [options]<file>: Path to INI file (required)
| Flag | Alias | Description |
|---|---|---|
--output <file> |
-o |
Save output to JSON file |
--meta |
- | Return metadata format with type information |
--quiet |
-q |
Suppress stdout output when saving to file |
--check |
- | Check INI file and display statistics without full output |
--version |
-v |
Output the current version |
--help |
-h |
Display help information |
0: Success1: File error (not found, not readable, parse error)2: Argument error (invalid arguments, missing file)
# Basic parsing
ini-parser config.ini
# Save to file
ini-parser config.ini -o output.json
# Validate file
ini-parser config.ini --check
# Output:
# [ SUCCESS ] File found: config.ini
# [ SUCCESS ] File readable: yes
# [ SUCCESS ] Parsed successfully: 3 sections, 12 keys
# Quiet mode (save without stdout)
ini-parser config.ini --output data.json --quiet
# Metadata format
ini-parser config.ini --meta --output meta.json# Global configuration
debug=true
log_level=info
[database]
host=localhostParsed result:
{
debug: ['true'],
log_level: ['info'],
database: {
host: ['localhost']
}
}[paths]
include=
/usr/local/bin
/usr/bin
/binParsed result:
{
paths: {
include: ['/usr/local/bin', '/usr/bin', '/bin']
}
}[server]
ports=8080 8081 8082Parsed result:
{
server: {
ports: ['8080', '8081', '8082']
}
}# This is a comment
; This is also a comment
[section]
key=value # inline commentParsed result:
{
section: {
key: ['value']
}
}- Node.js >= 18.0.0
- npm >= 9.0.0
# Clone repository
git clone https://github.com/notfounnd/ini-parser.git
cd ini-parser
# Install dependencies
npm install
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run linter
npm run lint:check
# Format code
npm run formatini-parser/
βββ bin/ # CLI executable
βββ src/
β βββ lib/ # Library code (parser.js)
β βββ cli/ # CLI implementation
βββ test/ # Test suites
βββ docs/ # Documentation
βββ package.json
This project uses GitHub Actions for continuous integration and deployment with a Trunk-Based Development strategy.
-
Feature CI (
ci-feature.yml): Runs on push to any branch exceptmaster- Tests on Node.js 18.x, 20.x, 22.x
- Runs ESLint, Prettier, and Jest tests
-
Master CI/CD (
ci-master.yml): Runs on push tomaster(via PR merge)- Tests on Node.js 18.x, 20.x, 22.x
- Builds production artifact (.tgz) with Node.js 22.x
- Runs E2E tests with installed package (8 tests)
-
Release (
release.yml): Manual trigger only (workflow_dispatch)- Calculates version from conventional commits
- Generates/updates CHANGELOG.md
- Publishes to NPM
- Creates GitHub Release
The master branch is protected with the following rules:
- β Squash merge only (maintains linear history)
- β Pull request required (no direct pushes)
- β Status checks required (CI must pass)
- β Branches must be up to date
- β Conversation resolution required
- β Rules enforced for administrators
This project follows Trunk-Based Development with manual releases:
- Development: Work on feature branches
- Pull Request: Squash merge to
master(triggers Master CI/CD) - Release: Manual workflow trigger with dry-run option
- Automation:
release-ithandles versioning, changelog, and publishing
Release Strategy:
- Version calculated from conventional commits (feat β MINOR, fix β PATCH)
- Changelog auto-generated from commit history
- Package built and tested with E2E validation before release
- GitHub Release created with changelog notes
Contributions are welcome! This project is actively maintained and we appreciate your help.
How to contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Guidelines:
- Follow existing code style (ESLint + Prettier configured)
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass (
npm test)
For detailed contribution guidelines, see CONTRIBUTING.md.
This project is licensed under the MIT License - see the LICENSE file for details.
- Repository: github.com/notfounnd/ini-parser
- Issues: github.com/notfounnd/ini-parser/issues
- Changelog: CHANGELOG.md
- Author: JΓΊnior Sbrissa
Made with β€οΈ by JΓΊnior Sbrissa | ErrΓΈr 404 | NotFounnd