GithubHelp home page GithubHelp logo

shmaml's Introduction

License: MIT Build Status

SHMAML

Parse .ini files into JSON objects. Support lists.

Install

$ npm install shmaml

Use

const parse = require('shmaml');

const resultPromise = parse('../path/to/config.ini');
// or:
const result = parse.sync('../path/to/config.ini');

ย 

Example config.ini + list:

username = me
pasword = 1234

[SectionA]
  key=value

[SectionB]
  key=value
  list=[
      item1,
      item2,
      item3
  ]

Becomes:

result = {
  username: 'me',
  pasword: 1234,
  SectionA: {
    key: 'value',
  },
  SectionB: {
    key: 'value',
    list: ['item1', 'item2', 'item3']
  },
}

Convention

  • key-value pairs are noted with an equal sign.

    key="value"
  • Quoting values is optional. Strings are used as default.

    ; These are all the same:
    key=value
    key='value'
    key="value"
  • Unquoted numbers are parsed as numbers. Use single/double quotes to make number values parsed as strings.

    number = 55
    string = '55'
    string = "55"
  • Unquoted booleans are parsed as booleans. Use single/double quotes to make boolean values parsed as strings. CaSe InSeNsITiVe.

    bool = TRUE
    bool = false
    string = 'true'
    string = "false"
  • Sections are noted with wrapping square brackets.

    [categoryA]
        key="value"
    [categoryB]
        key="value"
  • Lists are also noted with wrapping square brackets when come after a key=.

    [categoryA]
        key="value"
        list=[item1, item2, item3]
  • Multiline lists are also supported.

    [categoryA]
        multilineList=[
            item1,
            item2,
            item3
        ]
        key="value"

NOTE: Nested lists are NOT supported.
list=[A, [B, [C, D]], E]

  • Comments are ignored, obviously. Use quotes to work with semicolons:

    ; line comment
    [category]
        key1=value1 ; inline comment
        key2='quoted ; semicolon'
        key3="double quoted ; semicolon"
  • Whitespace (including tabs) is trimmed:

    ;Same
    [sectionA]
    [ sectionA ]
    ;Same
    key= value
    key =value
    key  =  value
    [sectionA]
    key=value
    
    ;Same as
    
    [sectionA]
        key=value   
  • Preserve whitespace using quotes:

    [' section   ']
    key="  value "
    {
        " section   ": {
            key: "  value "
        }
    }
  • Duplicates.
    Duplicated section names are merged to the same object.

    [sectionA]
        key1=value1
    [sectionA]
        key2=value2
    result = {
        SectionA: {
            key1: 'value1',
            key2: 'value2',
        },
    }

    Duplicated key names in the same section: the later overwrites the former.

    sameKey=value1
    sameKey=value2
    sameKey=value3
    result = {
        sameKey: 'value3'
    }

shmaml's People

Stargazers

Anton avatar Christopher Ribeiro avatar  avatar

Watchers

James Cloos avatar Taitu Lizenbaum avatar

Forkers

0leg0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.