Comparing version
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
,package_ = require('../package.json') | ||
,parseValue = require('../lib/parse-value') | ||
; | ||
@@ -15,3 +16,3 @@ | ||
'<file> <key-path>', | ||
'<file> <key-path> <value> [--indent=<n|auto>]', | ||
'<file> <key-path> <value> [--indent=<n|auto>] [--json-value]', | ||
'<file> <key-path> --delete', | ||
@@ -23,2 +24,3 @@ ]; | ||
'-d --delete Delete the key-path', | ||
'-j --json-value Parse the input value as a JSON string (to set whole objects or arrays)', | ||
'-h --help Show this message with options', | ||
@@ -37,25 +39,5 @@ '-v --version Print the version number', | ||
if (args['<value>']) { | ||
var value = args['<value>']; | ||
var value = parseValue(args['<value>'], args['--json-value']); | ||
var indent = args['--indent']; | ||
switch(value) { | ||
case 'true': | ||
value = true; | ||
break; | ||
case 'false': | ||
value = false; | ||
break; | ||
case 'undefined': | ||
value = undefined; | ||
break; | ||
case 'null': | ||
value = null; | ||
break; | ||
} | ||
if (value == parseInt(value)) { | ||
value = parseInt(value); | ||
} | ||
else if(value == parseFloat(value)) { | ||
value = parseFloat(value); | ||
} | ||
try { | ||
@@ -62,0 +44,0 @@ dot_json.set(args['<key-path>'], value); |
@@ -59,3 +59,3 @@ var path = require('path'); | ||
catch (e) { | ||
_this._indent = 2 | ||
_this._indent = ' '; | ||
} | ||
@@ -62,0 +62,0 @@ } |
{ | ||
"name": "dot-json", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Easily edit a json file from the CLI or NodeJS", | ||
@@ -5,0 +5,0 @@ "main": "lib/dot-json.js", |
# dot-json | ||
[](https://travis-ci.org/maikelvl/dot-json) | ||
[](https://huntr.dev) | ||
--- | ||
@@ -13,3 +15,3 @@ | ||
```bash | ||
npm install --save dot-json | ||
npm install dot-json | ||
``` | ||
@@ -21,2 +23,3 @@ ### Use from the CLI | ||
dot-json myfile.json foo..bar baz | ||
dot-json myfile.json address '{"city":"Atlantis"}' --json-value | ||
``` | ||
@@ -30,3 +33,6 @@ myfile.json now looks like | ||
}, | ||
"foo.bar": "baz" | ||
"foo.bar": "baz", | ||
"address": { | ||
"city": "Atlantis" | ||
} | ||
} | ||
@@ -46,6 +52,7 @@ ``` | ||
Options: | ||
--indent=<n> Indent with <n> of white space characters [default: auto] | ||
-d --delete Delete the key-path | ||
-h --help Show this message with options | ||
-v --version Print the version number | ||
--indent=<n> Indent with <n> of white space characters [default: auto] [--json-value] | ||
-d --delete Delete the key-path | ||
-j --json-value Parse the input value as a JSON string (to set whole objects or arrays) | ||
-h --help Show this message with options | ||
-v --version Print the version number | ||
``` | ||
@@ -52,0 +59,0 @@ |
@@ -735,3 +735,3 @@ var expect = require('chai').expect; | ||
it("should be use 2 spaces indents by default when creating new file", function() { | ||
it("should use 2 spaces indents by default when creating new file", function() { | ||
var myfile = new DotJson(dir+'/new-2-space-indent-test.json'); | ||
@@ -738,0 +738,0 @@ myfile.set('user.name', 'John Doe').set('user.email', 'john@example.com'); |
38614
3.92%8
60%1178
1.46%135
5.47%