npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jedmao/ini-parser

v0.2.4

Published

A highly forgiving and configurable INI parser for the informal INI file format.

Downloads

35

Readme

@jedmao/ini-parser

NPM version npm license Travis Build Status codecov Dependency Status

npm

A highly forgiving and configurable INI parser for the informal INI file format.

Introduction

The INI file format is informal. Different parsers behave differently, in that they support different features. This parser aims to be a bit more flexible and configurable to suite your needs, whatever they may be. Also, it assumes INI files out there in the wild could have some pretty crazy things in them. This parser does its best to understand whatever crazy you throw at it.

No dependencies on Node.js here, so you should be able to use it in the browser.

Usage

; example.ini

a=b

[c]
d:e

[c]
f=g
import { readFileSync } from "fs";
import Parser from "@jedmao/ini-parser";

const { configure, parse } = new Parser(/* config */);

parse(fs.readFileSync("./example.ini"));

See Parser#parse API.

Result

[
  {
    "a": "b"
  },
  [
    [
      "c",
      {
        "d": "e"
      }
    ],
    [
      "c",
      {
        "f": "g"
      }
    ]
  ]
]

API

import Parser from "@jedmao/ini-parser";

new Parser( options?: ParseOptions )

Class constructor. Accepts ParseOptions for initial configuration.

Parser#configure( options?: ParseOptions )

Sets configuration options, preserving existing configuration and overriding only the new keys you provide.

Parser#resetConfiguration()

Resets configuration to default settings as if you created a new Parser().

Parser#parse( contents?: string )

Parses INI file contents as a string. The result will be an array:

  • Index 0 will have any/all root properties.
  • Index 1 will have an array of any/all sections that follow.

Note: repeated sections will also be repeated in the array.

See Usage for an example.

interface ParseOptions

interface ParseOptions {
  /**
   * Indicates accepted comment chars. Only works if you specify single-char
   * comment values in RegExp form. A setting of `false` turns off comments
   * completely, treating comment chars as normal string values.
   * @default {RegExp} /[#;]/
   */
  comment?: RegExp | false;
  /**
   * Accepts comment chars in a property key or value. If a space
   * follows the comment char, it is considered an actual comment.
   * Example: "#k;=#v; #z" -> { "#k;": "#v;" }
   * @default {false} false
   */
  isCommentCharInProp?: boolean;
  /**
   * Indicates accepted delimiter chars. Only works if you specify
   * single-char delimiter values in RegExp form.
   * @default {RegExp} /[=:]/
   */
  delimiter?: RegExp;
  /**
   * Indicates accepted newline sequences in the form of a RegExp.
   * @default {RegExp} /\r?\n/
   */
  newline?: RegExp;
  /**
   * By default, attempts to parse property values with `JSON.parse`.
   * If unsuccessful, returns property value as a string. You may also
   * provide your own resolve function here for custom property value
   * resolution.
   * @default {true} true
   */
  resolve?: boolean | ResolveCallback;
}

interface ResolveCallback

interface ResolveCallback {
  (value: string, key?: string, fallback?: typeof parseValue): any;
}

parseValue( value: string )

Attempts to parse a string value with JSON.parse. If unsuccessful, returns input string untouched.

Testing

Run the following command:

$ npm test

This will build scripts, run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.

Watching

For much faster development cycles, run the following commands in 2 separate processes:

npm run build:watch

Compiles TypeScript source into the ./dist folder and watches for changes.

$ npm run watch

Runs the tests in the ./dist folder and watches for changes.