flex-json 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FlexJsonClass.js +17 -12
- package/README.md +8 -8
- package/get/index.js +11 -0
- package/package.json +2 -2
package/FlexJsonClass.js
CHANGED
|
@@ -3,6 +3,7 @@ const FlexJsonPosition = require("./FlexJsonPosition.js");
|
|
|
3
3
|
const FlexJsonMeta = require("./FlexJsonMeta.js");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const StringBuilder = require("string-builder");
|
|
6
|
+
const { trackingStats } = require( "./get/index.js");
|
|
6
7
|
|
|
7
8
|
class FlexJson {
|
|
8
9
|
_status = 0;
|
|
@@ -40,12 +41,18 @@ class FlexJson {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
// get trackingStats() {
|
|
45
|
+
// if (this._meta == null) return false;
|
|
46
|
+
// if (this._meta.stats == null) return false;
|
|
47
|
+
// return true;
|
|
48
|
+
// }
|
|
49
|
+
// use the imported trackingStats function instead
|
|
50
|
+
|
|
43
51
|
get trackingStats() {
|
|
44
|
-
|
|
45
|
-
if (this._meta.stats == null) return false;
|
|
46
|
-
return true;
|
|
52
|
+
return trackingStats(this._meta);
|
|
47
53
|
}
|
|
48
54
|
|
|
55
|
+
|
|
49
56
|
get statusMsg() {
|
|
50
57
|
if (this._meta != null) {
|
|
51
58
|
if (this._meta.statusMsg != null) {
|
|
@@ -344,7 +351,7 @@ class FlexJson {
|
|
|
344
351
|
v(idx, dotNotation = true) {
|
|
345
352
|
//if (trackingStats) { IncStats("stat_Value_get"); } // FUTURE-NEW
|
|
346
353
|
if (!idx) {
|
|
347
|
-
//
|
|
354
|
+
// return the value of this item
|
|
348
355
|
if (!this.ValidateValue()) {
|
|
349
356
|
return null;
|
|
350
357
|
} // *** Unable to validate/Deserialize the value
|
|
@@ -356,7 +363,6 @@ class FlexJson {
|
|
|
356
363
|
} else {
|
|
357
364
|
return this.i(idx, dotNotation).v();
|
|
358
365
|
}
|
|
359
|
-
return null;
|
|
360
366
|
}
|
|
361
367
|
|
|
362
368
|
get thisValue() {
|
|
@@ -383,7 +389,7 @@ class FlexJson {
|
|
|
383
389
|
toJsonArray(idx, dotNotation = true) {
|
|
384
390
|
//if (trackingStats) { IncStats("stat_Value_get"); } // FUTURE-NEW
|
|
385
391
|
if (!idx) {
|
|
386
|
-
//
|
|
392
|
+
// return the value of this item
|
|
387
393
|
if (!this.ValidateValue()) {
|
|
388
394
|
return null;
|
|
389
395
|
} // *** Unable to validate/Deserialize the value
|
|
@@ -1727,22 +1733,21 @@ class FlexJson {
|
|
|
1727
1733
|
case "bigint":
|
|
1728
1734
|
case "number":
|
|
1729
1735
|
return "number";
|
|
1730
|
-
|
|
1736
|
+
|
|
1731
1737
|
case "boolean":
|
|
1732
1738
|
return "boolean";
|
|
1733
|
-
|
|
1739
|
+
|
|
1734
1740
|
case "object": // must be FlexJson object or it is not a true "object"
|
|
1735
1741
|
return ""; // indicates an error/invlid type
|
|
1736
|
-
|
|
1742
|
+
|
|
1737
1743
|
case "FlexJson":
|
|
1738
1744
|
return FlexJson.jsonType;
|
|
1739
|
-
|
|
1745
|
+
|
|
1740
1746
|
case "function":
|
|
1741
1747
|
return ""; // indicate error/invalid type
|
|
1742
|
-
|
|
1748
|
+
|
|
1743
1749
|
default:
|
|
1744
1750
|
return "string";
|
|
1745
|
-
break;
|
|
1746
1751
|
}
|
|
1747
1752
|
}
|
|
1748
1753
|
}
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# flex-json
|
|
2
2
|
|
|
3
3
|
## Flexible JSON manipulation library for JavaScript.
|
|
4
4
|
|
|
@@ -97,27 +97,27 @@ It is simply Json with comments! FlexJson was written to make JSON config files
|
|
|
97
97
|
- Includes comments in both /* */ and // notation
|
|
98
98
|
- Simple to edit Json files
|
|
99
99
|
- Allows for other JavaScript like features such as using either single quotes or double quotes.
|
|
100
|
-
- Can also be used within Node.js apps for other uses such as reading/writing JSON to/from database records and parsing loosely
|
|
100
|
+
- Can also be used within Node.js apps for other uses such as reading/writing JSON to/from database records and parsing loosely formatted Json in web page content.
|
|
101
101
|
|
|
102
102
|
## How the library works
|
|
103
103
|
|
|
104
104
|
### Flex-json syntax
|
|
105
105
|
|
|
106
|
-
BTW
|
|
106
|
+
BTW flex-json as a standard of syntax is not really all that new - it is very much in existence within JavaScript and other syntax standards. Here we just make it available in a library and to facilitate config file parsing and editing.
|
|
107
107
|
|
|
108
108
|
### Strict Mode
|
|
109
109
|
|
|
110
|
-
When in strict mode, the
|
|
110
|
+
When in strict mode, the flex-json library reads JSON files in standard JSON format. Comments are not valid and double quotes are required around strings.
|
|
111
111
|
|
|
112
112
|
Note: If the library is flagged to preserve spacing, Json that has been read in from a file will be written with the same formatting. In other words, the carriage returns and white space are captured during the parsing process and used to re-format the output during the write process.
|
|
113
113
|
|
|
114
114
|
### Flex Mode
|
|
115
115
|
|
|
116
|
-
When in flex mode, the
|
|
116
|
+
When in flex mode, the flex-json library has the following features:
|
|
117
117
|
|
|
118
|
-
- Like JavaScript, comments can be surrounded by
|
|
118
|
+
- Like JavaScript, comments can be surrounded by /* (start of comment) and */ (end of comment)
|
|
119
119
|
|
|
120
|
-
- Like
|
|
120
|
+
- Like JavaScript, when a "//" is encountered, the remainder of the line is considered to be a comment
|
|
121
121
|
|
|
122
122
|
- Strings do not require quotes unless they contain special characters
|
|
123
123
|
|
|
@@ -152,7 +152,7 @@ __example 3:__
|
|
|
152
152
|
]
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
__Note__ that {number:"2"} is not the same as {number:2} because
|
|
155
|
+
__Note__ that {number:"2"} is not the same as {number:2} because flex-json will see that the 2 without quotes is a valid number and load it as a numeric.
|
|
156
156
|
|
|
157
157
|
### Contributing
|
|
158
158
|
|
package/get/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flex-json",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "This is a library that makes each 'Node' in the JSON Object/Array a JSON Object with a Key/Value pair.",
|
|
5
5
|
"main": "FlexJsonClass.js",
|
|
6
6
|
"authors": "[michael njuguna michaelnjuguna184@gmail.com, ted tyree tedtyree@gmail.com]",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"JSON Object",
|
|
10
10
|
"JSON Array",
|
|
11
11
|
"JSON Object Array",
|
|
12
|
-
"
|
|
12
|
+
"flex-json"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"string-builder": "^0.1.8"
|