json-stringify-extended
Advanced tools
+1
-1
| { | ||
| "name": "json-stringify-extended", | ||
| "version": "1.0.4", | ||
| "version": "1.0.5", | ||
| "dependencies": { | ||
@@ -5,0 +5,0 @@ "uglify-es": "^3.3.9" |
+106
-106
@@ -12,7 +12,7 @@ # json-stringify-extended | ||
| - Stringify more than primitive types into JSON format | ||
| - Stringify more primitive types into JSON format | ||
| - Stringify in JavaScript Object | ||
| - Use not yet defined types (like enums) | ||
| - Use not yet defined types (e.g. enums) | ||
| - Avoid useless quotes | ||
| - Choose to throw exception or not in circularity references | ||
| - Choose to throw exception, or not in circularity references | ||
@@ -31,16 +31,16 @@ ## Installing | ||
| const data = { | ||
| a: 'basic set, default options', | ||
| b: 1, | ||
| c: true, | ||
| d: function (a, b) { console.log(a + b) }, | ||
| e: {a: 0, b: 0.1, c: -2}, | ||
| f: ['a', 'b', 'c'], | ||
| g: new Date('2017-01-01'), | ||
| h: /a|b/, | ||
| i: null, | ||
| j: Infinity, | ||
| k: NaN, | ||
| l: undefined, | ||
| m: stringify.deferred('my.enum.VALUE'), | ||
| n: Buffer.from('7468697320697320612074c3a97374', 'hex') | ||
| a: 'basic set, default options', | ||
| b: 1, | ||
| c: true, | ||
| d: function (a, b) { console.log(a + b) }, | ||
| e: {a: 0, b: 0.1, c: -2}, | ||
| f: ['a', 'b', 'c'], | ||
| g: new Date('2017-01-01'), | ||
| h: /a|b/, | ||
| i: null, | ||
| j: Infinity, | ||
| k: NaN, | ||
| l: undefined, | ||
| m: stringify.deferred('my.enum.VALUE'), | ||
| n: Buffer.from('7468697320697320612074c3a97374', 'hex') | ||
| } | ||
@@ -52,24 +52,24 @@ | ||
| { | ||
| a:"basic set, default options", | ||
| b:1, | ||
| c:true, | ||
| d:function (a, b) { console.log(a + b) }, | ||
| e:{ | ||
| a:0, | ||
| b:0.1, | ||
| c:-2 | ||
| }, | ||
| f:[ | ||
| "a", | ||
| "b", | ||
| "c" | ||
| ], | ||
| g:new Date("2017-01-01T00:00:00.000Z"), | ||
| h:/a|b/, | ||
| i:null, | ||
| j:Infinity, | ||
| k:NaN, | ||
| l:undefined, | ||
| m:my.enum.VALUE, | ||
| n:Buffer.from("dGhpcyBpcyBhIHTDqXN0") | ||
| a:"basic set, default options", | ||
| b:1, | ||
| c:true, | ||
| d:function (a, b) { console.log(a + b) }, | ||
| e:{ | ||
| a:0, | ||
| b:0.1, | ||
| c:-2 | ||
| }, | ||
| f:[ | ||
| "a", | ||
| "b", | ||
| "c" | ||
| ], | ||
| g:new Date("2017-01-01T00:00:00.000Z"), | ||
| h:/a|b/, | ||
| i:null, | ||
| j:Infinity, | ||
| k:NaN, | ||
| l:undefined, | ||
| m:my.enum.VALUE, | ||
| n:Buffer.from("dGhpcyBpcyBhIHTDqXN0") | ||
| } | ||
@@ -81,5 +81,5 @@ | ||
| * ``String`` | ||
| * ``Number`` | ||
| * ``Boolean`` | ||
| * ``string`` | ||
| * ``number`` | ||
| * ``noolean`` | ||
| * ``function`` | ||
@@ -95,7 +95,7 @@ * ``Object`` | ||
| * ``undefined`` | ||
| * not-yet-defined using ``stringify.deferred`` | ||
| * Not-yet defined using ``stringify.deferred`` | ||
| ## API docs | ||
| ### stringify(data[, options]) | ||
| ### stringify (data[, options]) | ||
@@ -110,12 +110,12 @@ Stringify data into string | ||
| Options to adjust result format. | ||
| Parameters to configure result format. | ||
| You can also use prepared options: | ||
| You can also use this prepared options: | ||
| - ``stringify.options.json`` | ||
| format to regular JSON format | ||
| format to regular JSON format | ||
| - ``stringify.options.standadjs`` | ||
| format using standadjs rules | ||
| format using standadjs rules | ||
| - ``stringify.options.compact`` | ||
| format without folding, quotes and spaces | ||
| format without folding, quotes and spaces | ||
@@ -125,3 +125,3 @@ **example** | ||
| const data = {a: 'string', b: false, c: [0, 1, 2]} | ||
| console.log(stringify(data, stringify.options.compact)) | ||
| console.log (stringify (data, stringify.options.compact)) | ||
| // output | ||
@@ -135,3 +135,3 @@ {a:'string',b:false,c:[0,1,2]} | ||
| Works in safe mode, so will not throws exception for circularity. | ||
| Works in safe mode, so it will not throws exception for circularity. | ||
@@ -142,3 +142,3 @@ ##### options.endline | ||
| Endline string, should be only spacing chars as `\n` or `\r\n`. Set to empty string `''` for one line output. | ||
| Endline string should contain spacing chars as `\n` or `\r\n`. Set to empty string `''` for one line output. | ||
@@ -149,3 +149,3 @@ ##### options.spacing | ||
| Indentation string, should contains only spacing chars as `\t` or spaces ` `. | ||
| Indentation string should contains only spacing chars as `\t` or spaces ` `. | ||
@@ -156,3 +156,3 @@ ##### options.compress | ||
| Compress data for ``function`` and ``Date`` discard ``null`` and ``undefined`` values, but don't remove spaces and useless quotes. | ||
| Compress data for ``function`` and ``Date`` discard ``null`` and ``undefined`` values, and keep spaces and useless quotes. | ||
@@ -164,5 +164,5 @@ | ||
| Use function to filter by ``key`` and/or ``value`` each element. | ||
| Return ``true`` to keep element or ``false`` to discard. | ||
| ``filter`` is applied before ``replace``. | ||
| Use the function to filter ``key`` and/or ``value`` of each element. | ||
| Return ``true`` to save element or ``false`` to discard. | ||
| ``filter`` applies before ``replace``. | ||
@@ -172,21 +172,21 @@ **example** | ||
| const data = { | ||
| user: 'alice', | ||
| password: 'it-s-a-secret', | ||
| id: 1, | ||
| meta: ['1', 1], | ||
| greet: function() { return 'hi' } | ||
| user: 'alice', | ||
| password: 'it-s-a-secret', | ||
| id: 1, | ||
| meta: ['1', 1], | ||
| greet: function() { return 'hi' } | ||
| } | ||
| const options = { | ||
| filter: function (key, value) { | ||
| if (key === 'password') { | ||
| return false | ||
| } | ||
| if (value === 1) { | ||
| return false | ||
| } | ||
| if (typeof value === 'function') { | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
| filter: function (key, value) { | ||
| if (key === 'password') { | ||
| return false | ||
| } | ||
| if (value === 1) { | ||
| return false | ||
| } | ||
| if (typeof value === 'function') { | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
| } | ||
@@ -196,6 +196,6 @@ console.log(stringify(data, options)) | ||
| { | ||
| user:"alice", | ||
| meta:[ | ||
| "1" | ||
| ] | ||
| user:"alice", | ||
| meta:[ | ||
| "1" | ||
| ] | ||
| } | ||
@@ -208,5 +208,5 @@ ```` | ||
| Use function to replace ``key`` and/or ``value`` of each element. | ||
| Must return an object ``{key, value}``. | ||
| ``filter`` is applied before ``replace``. | ||
| Use the function to replace ``key`` and/or ``value`` of each element. | ||
| Have to return an object ``{key, value}``. | ||
| ``filter`` applies before ``replace``. | ||
@@ -216,17 +216,17 @@ **example** | ||
| const data = { | ||
| user: 'alice', | ||
| password: 'it-s-a-secret', | ||
| id: 1, | ||
| meta: ['1', 1] | ||
| user: 'alice', | ||
| password: 'it-s-a-secret', | ||
| id: 1, | ||
| meta: ['1', 1] | ||
| } | ||
| const options = { | ||
| replace: function (key, value) { | ||
| if (key === 'password') { | ||
| return {key: 'secret', value: '***'} | ||
| } | ||
| if (value === 1) { | ||
| return {key, value: 'one'} | ||
| } | ||
| return {key, value} | ||
| } | ||
| replace: function (key, value) { | ||
| if (key === 'password') { | ||
| return {key: 'secret', value: '***'} | ||
| } | ||
| if (value === 1) { | ||
| return {key, value: 'one'} | ||
| } | ||
| return {key, value} | ||
| } | ||
| } | ||
@@ -236,9 +236,9 @@ console.log(stringify(data, options)) | ||
| { | ||
| user:"alice", | ||
| secret:"***", | ||
| id:"one", | ||
| meta:[ | ||
| "1", | ||
| "one" | ||
| ] | ||
| user:"alice", | ||
| secret:"***", | ||
| id:"one", | ||
| meta:[ | ||
| "1", | ||
| "one" | ||
| ] | ||
| } | ||
@@ -251,3 +251,3 @@ ```` | ||
| Character used for quote keys, default is `null`, means no quotes in keys. Should be `"` or `'` or `null` | ||
| The character to be used for quote is the “ key, the default is `null`, meaning no quotes in keys. And `"` or `'` or `null` means there is a quote. | ||
@@ -258,3 +258,3 @@ ##### options.valueQuote | ||
| Character used for quote values, default is `'`. Should be `"` or `'` | ||
| The character to be used for quote values default is `'`. Must be `"` or `'`. | ||
@@ -265,3 +265,3 @@ ##### options.keySpace | ||
| Add a space beetwen `key:` and `value`. | ||
| Add a space between key:` and `value`. | ||
@@ -272,3 +272,3 @@ ##### options.discard | ||
| Discard `null` and ``undefined`` values. | ||
| Discard the values `null` and ``undefined``. | ||
@@ -281,3 +281,3 @@ --- | ||
| - [ ] browser support | ||
| - (see)[https://www.contentful.com/blog/2017/04/04/es6-modules-support-lands-in-browsers-is-it-time-to-rethink-bundling/] | ||
| - (see)[https://www.contentful.com/blog/2017/04/04/es6-modules-support-lands-in-browsers-is-it-time-to-rethink-bundling/] | ||
@@ -284,0 +284,0 @@ --- |
15444
-0.12%