Giter Site home page Giter Site logo

editorconfig-parser's Introduction

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 guarantees 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, through 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'
    }]
]

editorconfig-parser's People

Contributors

catdad avatar

Watchers

 avatar  avatar  avatar

editorconfig-parser's Issues

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.