New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

editorconfig-parser

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

editorconfig-parser

parse and serialize editorconfog files

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

editorconfig parser

Build Test Coverage Code Climate Downloads Version Dependency Status

Parse and serialize .editorconfig files.

Install

npm install editorconfig-parser

Use

The following fuctions are available for general use:

  • parse({String} str){Object}: parse an editorconfig file to an object.
  • serialize({Object} obj){String}: serialize an object to an editorconfig file.
var fs = require('fs');
var ec = require('editorconfig-parser');

// read a file from disk
var file = fs.readFileSync('.editorconfig', 'utf8');

var obj = ec.parse(file);
// modify object
var str = ec.serialize(obj);

// write the new file
fs.writeFileSync('.editorconfig', str);

Example of a parsed editorconfig object:

{
    root: 'true',
    '*': {
        indent_style: 'space',
        indent_size: '4',
        end_of_line: 'lf',
        charset: 'utf-8',
        insert_final_newline: 'true'
    },
    '{package.json,*.yml}': {
        indent_style: 'space',
        indent_size: '2',
        insert_final_newline: 'true'
    }
};

Editorconfig itself uses a modified parser that provides the content in an array instead of an object. Theoretically, this is safer, since it absolutely guaranteed order. Unless you are doing something crazy though, the object above will do just fine and will be much easier to manipulate than the array. However, this module will support parsing and serializing the array-based version as well, though the following methods:

  • parseRaw({String} str){Array}: parse an editorconfig file to an array.
  • serializeRaw({Array} arr){String}: serialize an array to an editorconfig file.
var fs = require('fs');
var ec = require('editorconfig-parser');

// read a file from disk
var file = fs.readFileSync('.editorconfig', 'utf8');

var arr = ec.parseRaw(file);
// modify array
var str = ec.serializeRaw(arr);

// write the new file
fs.writeFileSync('.editorconfig', str);

Example of a parsed editorconfig array:

[ 
    [ null, { root: 'true' } ],
    [ '*', {
        indent_style: 'space',
        indent_size: '4',
        end_of_line: 'lf',
        charset: 'utf-8',
        insert_final_newline: 'true'
    }],
    [ '{package.json,*.yml}', {
        indent_style: 'space',
        indent_size: '2',
        insert_final_newline: 'true'
    }]
]

Keywords

editorconfig

FAQs

Package last updated on 17 Jul 2016

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