Socket
Socket
Sign inDemoInstall

cjson

Package Overview
Dependencies
2
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.2 to 0.3.3

LICENSE

3

index.js

@@ -215,2 +215,5 @@ var fs = require('fs'),

// replace BOM Character
data = data.replace(/\ufeff/g, '');
if (options.replace) {

@@ -217,0 +220,0 @@ data = exports.replace(data, options.replace);

2

package.json
{
"name": "cjson",
"description": "cjson - Commented JavaScript Object Notation. It is a json loader, which parses only valid json files, but with comments enabled. Useful for loading configs.",
"version": "0.3.2",
"version": "0.3.3",
"repository": "git://github.com/kof/node-cjson.git",

@@ -6,0 +6,0 @@ "keywords": [

@@ -16,13 +16,14 @@ [![build status](https://secure.travis-ci.org/kof/node-cjson.png)](http://travis-ci.org/kof/node-cjson)

/*
* This is my app configuration file.
*
*/
{
"host": "localhost",
// app is listening on this port
"port": 8888
}
```javascript
/*
* This is my app configuration file.
*
*/
{
"host": "localhost",
// app is listening on this port
"port": 8888
}
```
## API

@@ -42,54 +43,56 @@

`options` defaults:
```javascript
{
// merge all passed/found config files, see `cjson.extend`
merge: false,
// allows you to do some string replacements, see `cjson.replace`.
replace: null,
// freeze config recursively, see `cjson.freeze`
freeze: false,
// you can use any other extension for your config files, f.e. .cjson
ext: '.json',
// you can use any parser you want. the default uses JSON.parse for maximum
// speed, if it throws it uses uses an alternative parser to give more
// helpful errors
parse: jph.parse
}
```
{
// merge all passed/found config files, see `cjson.extend`
merge: false,
// allows you to do some string replacements, see `cjson.replace`.
replace: null,
// freeze config recursively, see `cjson.freeze`
freeze: false,
// you can use any other extension for your config files, f.e. .cjson
ext: '.json',
// you can use any parser you want. the default uses JSON.parse for maximum
// speed, if it throws it uses uses an alternative parser to give more
// helpful errors
parse: jph.parse
}
Examples:
// just one config
var conf = cjson.load('/path/to/your/config.json');
```javascript
// just one config
var conf = cjson.load('/path/to/your/config.json');
// array of configs
var conf = cjson.load(['/path/to/your/config1.json', '/path/to/your/config2.json']);
// array of configs
var conf = cjson.load(['/path/to/your/config1.json', '/path/to/your/config2.json']);
//output
{
config1: {key1: 'value1'}
config2: {key2: 'value2'}
}
//output
{
config1: {key1: 'value1'}
config2: {key2: 'value2'}
}
// use optional merge parameter
// array of configs
var conf = cjson.load(['/path/to/your/config1.json', '/path/to/your/config2.json'], true);
// use optional merge parameter
// array of configs
var conf = cjson.load(['/path/to/your/config1.json', '/path/to/your/config2.json'], true);
// output
{
key1: 'value1',
key2: 'value2'
}
// output
{
key1: 'value1',
key2: 'value2'
}
// load all config files from a directory
var conf = cjson.load('/path/to/your/configs');
// load all config files from a directory
var conf = cjson.load('/path/to/your/configs');
// overwriting dev config with production
var paths = ['/path/to/conf.json'];
if (process.env.NODE_ENV ==='production') {
paths.push('/path/to/conf-prod.json');
}
var conf = cjson.load(paths, true);
// overwriting dev config with production
var paths = ['/path/to/conf.json'];
if (process.env.NODE_ENV ==='production') {
paths.push('/path/to/conf-prod.json');
}
var conf = cjson.load(paths, true);
```

@@ -107,3 +110,5 @@ ### cjson.extend([deep], target, object1, [objectN])

var object = cjson.extend({}, object1, object2);
```javascript
var object = cjson.extend({}, object1, object2);
```

@@ -127,6 +132,6 @@ ### cjson.decomment(str)

Example:
var str = '{"path": "{{root}}/src"}'; // json file contents
cjson.replace(str, {root: '/usr'}); // '{"path": "/usr/src"}'
```javascript
var str = '{"path": "{{root}}/src"}'; // json file contents
cjson.replace(str, {root: '/usr'}); // '{"path": "/usr/src"}'
```
### cjson.freeze(obj)

@@ -133,0 +138,0 @@

@@ -18,3 +18,4 @@ var a = require('assert');

conf7: {"key": "{{root}}/src"},
conf8: {}
conf8: {},
conf10: {"test":"valid JSON, except for the the hidden BOM character"},
};

@@ -42,2 +43,4 @@

a.deepEqual(cjson.load(fixtures + '/conf10.json'), data.conf10, 'BOM character');
var data1 = {

@@ -107,4 +110,4 @@ conf1: {key: 'value'},

a.deepEqual(data1, data2, 'data1 wasn\'t changed');
}())
}());
console.log('All tests passed.');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc