pyconf can read and write python config files non-destructively (preserves comments)
转到文件
AJ ONeal a0d1c7845c v1.1.7: fix broken link 2019-04-16 00:23:36 -06:00
.gitignore Initial commit 2015-12-14 22:51:47 -08:00
LICENSE update LICENSE 2018-09-03 13:43:02 -06:00
README.md update name to pyconf.js 2018-09-03 13:29:19 -06:00
example.conf v1.0.0 2015-12-14 23:07:04 -08:00
index.js Update Python value of null/undefined/empty. 2017-10-30 10:36:16 -07:00
package-lock.json v1.1.7: fix broken link 2019-04-16 00:23:36 -06:00
package.json v1.1.7: fix broken link 2019-04-16 00:23:36 -06:00
test.js test non-file 2015-12-14 23:10:32 -08:00

README.md

pyconf.js

formerly 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