🚧 This project is under development.
Install package:
# npm
npm install js-ini-parser
# yarn
yarn add js-ini-parser
# pnpm
pnpm install js-ini-parser
Import:
// ESM
import { parseIni, stringifyIni } from "js-ini-parser";
// CommonJS
const { parseIni, stringifyIni } = require("js-ini-parser");
- parseIni(text, ParserOptions)
- stringifyIni(object, {})
allowGlobalSection
:boolean
- Allow global section (default: false)globalSectionName
:string
- Name of the global section (default: global)allowEmptyValue
:boolean
- Allow empty value (default: false)debug
:boolean
- Enable debug mode (default: false)
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);
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);
⚠️ ️ Not available yet but will be soon !
Currently, you can edit the object manually and stringify it back to text using stringifyIni
- In the future, you will be able to edit the object using the API (addComment, updateKeyValue, etc...)
- Or by accessing to data like this: parsed.server.host = 'localhost'
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);
// convert to text
const text = stringifyIni(parsed, {})
- Clone this repository
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
Published under MIT License.