Code Monkey home page Code Monkey logo

47bfbb7dcd51707057a579114cf0085deadbf6c2a0477ae0feb8489d90001a29's Introduction

node-config-python

Read and write python config files non-destructively (preserves comments and line-order)

Turns this kind of thing:

foo = True
bar = None
baz = whatever
qux = apples,bananas

Into this kind of thing:

{ foo: true
, bar: null
, baz: "whatever"
, qux: ["apples", "bananas"]
}

(comments are stored in meta-data keys __lines and __keys)

Install

npm install --save pyconf

Usage

var pyconf = require('pyconf');

// alias for fs.readFile() then pyconf.parse()
pyconf.readFile("/path/to/foo.conf", function (err, obj) {
  console.log(obj);
});

// alias for pyconf.stringify() then safeReplace.writeFile()
pyconf.writeFile("/path/to/foo.conf", obj, function (err, obj) {
  console.log("wrote file");
});

Note: the writeFile function uses safe-replace so that it will work even in environments where race conditions are possible and will also create a backup file whatever.conf.bak of the config being overwritten.

API

pyconf
  .parse(str, cb)                   // => err, object
  
  .stringify(obj, cb)               // => err, text
  
  .readFile(filename, cb)           // => err, object
  
  .writeFile(filename, obj, cb)     // => err 

47bfbb7dcd51707057a579114cf0085deadbf6c2a0477ae0feb8489d90001a29's People

Contributors

mozilla-github-standards avatar

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.