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

ini-processor

v1.0.0

Published

Parses INI files to json, and can convert them back to INI code.

Downloads

7

Readme

INI file processor

What this does

Lets you read INI files, get values from them, and you can generate custom INI files with this.

How its formatted when parsed

This is the INI file:

[Label Name]
; Test strings.
testString = String
testStringSpaces = String with spaces
; Test numbers.
testNumber = 1
testNumberFloat = 1.2345653234
testNumberNaN = NaN
; Test booleans.
testBoolTrue = true
testBoolFalse = false

And when pharsed, it becomes this array:

[
  { type: 'section', label: 'Label Name' },
  { type: 'comment', comment: ' Test strings.' },
  { type: 'variable', name: 'testString', value: 'String' },
  {
    type: 'variable',
    name: 'testStringSpaces',
    value: 'String with spaces'
  },
  { type: 'comment', comment: ' Test numbers.' },
  { type: 'variable', name: 'testNumber', value: 1 },
  { type: 'variable', name: 'testNumberFloat', value: 1.2345653234 },
  { type: 'variable', name: 'testNumberNaN', value: NaN },
  { type: 'comment', comment: ' Test booleans.' },
  { type: 'variable', name: 'testBoolTrue', value: true },
  { type: 'variable', name: 'testBoolFalse', value: false }
]

The type represents what type of part it is of the INI. Each type has its own properties, they are described below.

Parsed formats

Section

The section type indicates a "section" of the ini. How a section looks like in INI file format: [Foo Bar].

Properties:

  • label - The sections label.

Variable

The variable type indicates a variable of the ini. How a section looks like in INI file format: Foo=Bar.

Properties:

  • name - The variables name, before the equals sign.
  • value - The variables value, after the equals sign.

Comment

The comment type indicates a comment of the ini. How a section looks like in INI file format: ; Comment.

Properties:

  • comment - The comments text.

Newline

The \n newline character, used to create spacings between value names. Must have ignoreNewLines set to false on options on the "from" function.

Properties: none

API

Basic API usage API. If you want to view the full API, check the source code.

from (String containing INI code, options)

This converts the provided INI string to a parsed JSON array, formatted like shown in the "How its formatted when parsed" section above. Provide a JSON object to options to pass in custom arguments to change how stuff is parsed.

Options:

  • convertValues - Default: true - Convert variable value from strings to numbers, floats, booleans, etc. If possible.
  • ignoreComments - Default: false - If true, ignore the ; Comment label part of the INI string, don't add comments to the returned array.
  • ignoreNewLines - Default: true - If true, ignore adding newline objects to the array. Usefull for making sure when you convert it back to INI string (using the to function), its formatted close as possible to its read string version.

Returns: array

to (Parsed INI array, Experimental - Extra Pretty Code)

This converts the JSON array returned from the "from" function, back into an array. If "Experimental - Extra Pretty Code" is true, then this adds a spacing between variables and comments when sections are used. Like this: ``````

Returns: INI file string

readValue (Parsed INI array, Variable Name)

This returns the value of the Variable Name if found. Otherwise, it returns undefined.

Returns: Value of provided variable name

readValueFromSection (Parsed INI array, Variable Name, Section Name)

Like above, but with Section Name provided. This returns the value of the Variable Name in the specified Section Name if found. Otherwise, it returns undefined.

Returns: Value of provided variable name from Section Name

setValue (Parsed INI array, Variable Name, New variable value)

This sets the variable value to the specified new variable value.

Returns: nothing

setValueFromSection (Parsed INI array, Variable Name, Section Name, New variable value)

Like above, but with Section Name provided. This sets the variable value to the specified New Variable Value inside the specified Section Name.

This sets the variable value to the specified new variable value. Returns: nothing