Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ini-simple-parser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ini-simple-parser

A simple, fast and configurable INI parser.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22K
increased by2.27%
Maintainers
1
Weekly downloads
 
Created
Source

INI Simple Parser

A simple, fast and configurable INI parser.

Install

npm install --save ini-simple-parser

Usage

The following options are supported:

type Options = {
  inferBooleans?: boolean, // Interpret true/TRUE/false/FALSE as booleans
  inferNulls?: boolean, // Interpret null/NULL as nulls
  inferNumbers?: boolean, // Interpret some strings that can be parsed as numbers as numbers
  inferStrings?: boolean, // Automatically remove wrapping quotes from strings
  inlineComments?: boolean // Automatically remove inline comments
};

This is how you'd use it:

import parse from 'ini-simple-parser';

// Let's define some initial string to parse

const INPUT = `
  root=true
  notRoot="false"

  ; last modified 1 April 2001 by John Doe
  [owner]
  name=John Doe
  organization=Acme Widgets Inc.

  [database]
  # use IP address in case network name resolution is not working
  server = 192.0.2.62
  port = 143
  file = "payroll.dat"
  extra1 = something ; Inline comment
  extra2 = something else # Inline comment
  null = null
  nil = "0"
`;

// Let's parse it normally, without setting any options

const parsed = parse ( INPUT );
// {
//   root: 'true',
//   notRoot: '"false"',
//   owner: {
//     name: 'John Doe',
//     organization: 'Acme Widgets Inc.'
//   },
//   database: {
//     server: '192.0.2.62',
//     port: '143',
//     file: '"payroll.dat"',
//     extra1: 'something ; Inline comment',
//     extra2: 'something else # Inline comment',
//     null: 'null',
//     nil: '"0"'
//   }
// }

// Let's parse with every option enabled

const parsed = parse ( INPUT, {
  inferBooleans: true,
  inferNulls: true,
  inferNumbers: true,
  inferStrings: true,
  inlineComments: true
});
// {
//   root: true,
//   notRoot: 'false',
//   owner: {
//     name: 'John Doe',
//     organization: 'Acme Widgets Inc.'
//   },
//   database: {
//     server: '192.0.2.62',
//     port: 143,
//     file: 'payroll.dat',
//     extra1: 'something',
//     extra2: 'something else',
//     null: null,
//     nil: '0'
//   }
// }

License

MIT © Fabio Spampinato

Keywords

FAQs

Package last updated on 14 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc