1.6.1 ā€¢ Published 11 months ago

js-ini-parser v1.6.1

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

ini parser

A simple parser for ini files. Preserve comments and support global section.
npm version npm downloads codecov example workflow

šŸš§ 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.

1.6.1

11 months ago

1.6.0

11 months ago

1.5.0

11 months ago

1.4.0

12 months ago

1.3.0

12 months ago

1.1.3

12 months ago

1.1.1

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago