js-ini-parser
v1.6.1
Published
A simple ini parser that save comments and spaces
Downloads
105
Maintainers
Readme
ini parser
A simple parser for ini files. Preserve comments and support global section.
🚧 This project is under development.
Table of Contents
Installation
Install package:
# npm
npm install js-ini-parser
# yarn
yarn add js-ini-parser
# pnpm
pnpm install js-ini-parser
Import:
// ESM
import { parseIni } from "js-ini-parser";
// CommonJS
const { parseIni } = require("js-ini-parser");
Usage
API
- parseIni(text, options)
- stringifyIni(object, options)
Parse text input to object
import { parseIni } from "js-ini-parser";
const ini = `
[server]
; this is a comment
host =
port = 8080
`;
const options = {
allowGlobalSection: true,
globalSectionName: 'global'
}
const parsed = parseIni(ini, options);
console.log(parsed);
Parse text from file to object
import * as fs from "node:fs/promises";
import { parseIni } from "js-ini-parser";
const options = {
allowGlobalSection: true,
globalSectionName: 'global'
}
const fileContent = await fs.readFile("./config.ini", "utf-8");
const parsed = parseIni(fileContent, options);
Edit object and convert to text
import { parse, stringify } from "js-ini-parser";
const ini = `
[server]
; this is a comment
host =
port = 8080
`;
const options = {
allowGlobalSection: true,
globalSectionName: 'global'
}
const parsed = parseIni(ini, options);
// edit object
parsed.server.host = 'localhost'
// convert to text
const text = stringifyIni(parsed, {})
Contributing
- Clone this repository
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
License
Published under MIT License.