https://github.com/orlin/sourcegate
have any json-like object you want
https://github.com/orlin/sourcegate
Last synced: 2 months ago
JSON representation
have any json-like object you want
- Host: GitHub
- URL: https://github.com/orlin/sourcegate
- Owner: orlin
- Created: 2013-04-12T11:36:08.000Z (about 12 years ago)
- Default Branch: active
- Last Pushed: 2016-05-01T16:55:47.000Z (about 9 years ago)
- Last Synced: 2024-04-24T15:10:02.186Z (about 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sourcegate [](http://travis-ci.org/orlin/sourcegate)
[](https://www.npmjs.org/package/sourcegate)
## Use
Give it an array of paths to json files or objects.
They will be deep-merged, left to right, using [n-deep-merge](https://github.com/eclifford/n-deep-merge).
It does not mutate any given vars, instead returns a new object.
Array merges have union semantics.
Files not found are for now simply ignored.
Comments are allowed in json files thanks to [strip-json-comments](https://www.npmjs.com/package/strip-json-comments).```javascript
var sg = require('sourcegate');
var merged = sg(['initialize.json', 'customize/config.json', {c: 3}])
```If you are using this to write linter rules, and even if not,
you should look into [hal-rc](https://github.com/orlin/hal-rc) or best
[beverage](https://github.com/orlin/beverage).### Configure
Sourcegate takes a second argument with the following default options:
```javascript
{
root: process.cwd(),
relative: true,
merge: true,
write: {
path: '', // a file name or path is required to enable writing it
options: {},
root: process.cwd(), // optional
relative: true // optional
},
async: false // always the case so far...
}
```If the root path is set, it can be relative (by default), or absolute.
Notice that merging is actually optional. That was added for the tests,
though it could be useful elsewhere for simply loading files to memory.The `write` is optional, enabled by `write.path`. The `options` are handed to [node](https://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback).
The `write.root` and `write.relative` are same as the ones used for reading,
unless explicitly made different.## Missing
Some day there may be an async implementation.
I so far use it only for workflow tasks, thus async hasn't been needed.## Test [](https://travis-ci.org/orlin/sourcegate)
```sh
npm test
```## Dependencies
[](https://david-dm.org/orlin/sourcegate)
[](https://david-dm.org/orlin/sourcegate#info=devDependencies)## Unlicensed
This is free and unencumbered public domain software.
For more information, see [UNLICENSE](http://unlicense.org).