@apigames/json 24.1.4 → 24.1.6
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/lib/utils.js +30 -31
- package/package.json +10 -10
package/lib/utils.js
CHANGED
|
@@ -1,74 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isDefined = isDefined;
|
|
4
|
+
exports.isDefinedAndNotNull = isDefinedAndNotNull;
|
|
5
|
+
exports.isUndefined = isUndefined;
|
|
6
|
+
exports.isUndefinedOrNull = isUndefinedOrNull;
|
|
7
|
+
exports.isArray = isArray;
|
|
8
|
+
exports.isBoolean = isBoolean;
|
|
9
|
+
exports.isDate = isDate;
|
|
10
|
+
exports.isError = isError;
|
|
11
|
+
exports.isFalse = isFalse;
|
|
12
|
+
exports.isFalseOrUndefined = isFalseOrUndefined;
|
|
13
|
+
exports.isNumber = isNumber;
|
|
14
|
+
exports.isInteger = isInteger;
|
|
15
|
+
exports.isObject = isObject;
|
|
16
|
+
exports.isEmpty = isEmpty;
|
|
17
|
+
exports.isRegExp = isRegExp;
|
|
18
|
+
exports.isString = isString;
|
|
19
|
+
exports.isArrayOfBooleans = isArrayOfBooleans;
|
|
20
|
+
exports.isArrayOfDates = isArrayOfDates;
|
|
21
|
+
exports.isArrayOfIntegers = isArrayOfIntegers;
|
|
22
|
+
exports.isArrayOfNumbers = isArrayOfNumbers;
|
|
23
|
+
exports.isArrayOfStrings = isArrayOfStrings;
|
|
24
|
+
exports.isArrayOfObjects = isArrayOfObjects;
|
|
25
|
+
exports.isTrue = isTrue;
|
|
26
|
+
exports.hasProperty = hasProperty;
|
|
27
|
+
exports.append = append;
|
|
28
|
+
exports.areEqual = areEqual;
|
|
29
|
+
exports.redactUndefinedValues = redactUndefinedValues;
|
|
30
|
+
exports.clone = clone;
|
|
31
|
+
exports.stringify = stringify;
|
|
32
|
+
exports.extractAndRedact = extractAndRedact;
|
|
4
33
|
const deepEqual = require('deep-equal');
|
|
5
34
|
const clonedeep = require('lodash.clonedeep');
|
|
6
35
|
function isDefined(value) {
|
|
7
36
|
return (value !== undefined);
|
|
8
37
|
}
|
|
9
|
-
exports.isDefined = isDefined;
|
|
10
38
|
function isDefinedAndNotNull(value) {
|
|
11
39
|
return (value !== undefined) && (value !== null);
|
|
12
40
|
}
|
|
13
|
-
exports.isDefinedAndNotNull = isDefinedAndNotNull;
|
|
14
41
|
function isUndefined(value) {
|
|
15
42
|
return (value === undefined);
|
|
16
43
|
}
|
|
17
|
-
exports.isUndefined = isUndefined;
|
|
18
44
|
function isUndefinedOrNull(value) {
|
|
19
45
|
return (value === undefined) || (value === null);
|
|
20
46
|
}
|
|
21
|
-
exports.isUndefinedOrNull = isUndefinedOrNull;
|
|
22
47
|
function isArray(value) {
|
|
23
48
|
return isDefinedAndNotNull(value) && (typeof value === 'object')
|
|
24
49
|
&& (value.constructor === Array);
|
|
25
50
|
}
|
|
26
|
-
exports.isArray = isArray;
|
|
27
51
|
function isBoolean(value) {
|
|
28
52
|
return isDefinedAndNotNull(value) && (typeof value === 'boolean');
|
|
29
53
|
}
|
|
30
|
-
exports.isBoolean = isBoolean;
|
|
31
54
|
function isDate(value) {
|
|
32
55
|
return isDefinedAndNotNull(value) && (value instanceof Date);
|
|
33
56
|
}
|
|
34
|
-
exports.isDate = isDate;
|
|
35
57
|
function isError(value) {
|
|
36
58
|
return isDefinedAndNotNull(value) && (value instanceof Error) && (typeof value.message !== 'undefined');
|
|
37
59
|
}
|
|
38
|
-
exports.isError = isError;
|
|
39
60
|
function isFalse(value) {
|
|
40
61
|
return isBoolean(value) && (value === false);
|
|
41
62
|
}
|
|
42
|
-
exports.isFalse = isFalse;
|
|
43
63
|
function isFalseOrUndefined(value) {
|
|
44
64
|
return isUndefined(value) || (isBoolean(value) && (value === false));
|
|
45
65
|
}
|
|
46
|
-
exports.isFalseOrUndefined = isFalseOrUndefined;
|
|
47
66
|
function isNumber(value) {
|
|
48
67
|
return isDefinedAndNotNull(value) && (typeof value === 'number') && isFinite(value);
|
|
49
68
|
}
|
|
50
|
-
exports.isNumber = isNumber;
|
|
51
69
|
function isInteger(value) {
|
|
52
70
|
return isNumber(value) && (value % 1 === 0);
|
|
53
71
|
}
|
|
54
|
-
exports.isInteger = isInteger;
|
|
55
72
|
function isObject(value) {
|
|
56
73
|
return isDefinedAndNotNull(value) && (typeof value === 'object')
|
|
57
74
|
&& ((value.constructor === Object) || ((value instanceof Object) && (!isArray(value))));
|
|
58
75
|
}
|
|
59
|
-
exports.isObject = isObject;
|
|
60
76
|
function isEmpty(document) {
|
|
61
77
|
return (isUndefined(document)) || (isObject(document) && (Object.keys(document).length === 0));
|
|
62
78
|
}
|
|
63
|
-
exports.isEmpty = isEmpty;
|
|
64
79
|
function isRegExp(value) {
|
|
65
80
|
return isDefinedAndNotNull(value) && (typeof value === 'object') && (value.constructor === RegExp);
|
|
66
81
|
}
|
|
67
|
-
exports.isRegExp = isRegExp;
|
|
68
82
|
function isString(value) {
|
|
69
83
|
return isDefinedAndNotNull(value) && ((typeof value === 'string') || (value instanceof String));
|
|
70
84
|
}
|
|
71
|
-
exports.isString = isString;
|
|
72
85
|
function isArrayOfBooleans(values) {
|
|
73
86
|
if (isArray(values)) {
|
|
74
87
|
for (const value of values)
|
|
@@ -78,7 +91,6 @@ function isArrayOfBooleans(values) {
|
|
|
78
91
|
}
|
|
79
92
|
return false;
|
|
80
93
|
}
|
|
81
|
-
exports.isArrayOfBooleans = isArrayOfBooleans;
|
|
82
94
|
function isArrayOfDates(values) {
|
|
83
95
|
if (isArray(values)) {
|
|
84
96
|
for (const value of values)
|
|
@@ -88,7 +100,6 @@ function isArrayOfDates(values) {
|
|
|
88
100
|
}
|
|
89
101
|
return false;
|
|
90
102
|
}
|
|
91
|
-
exports.isArrayOfDates = isArrayOfDates;
|
|
92
103
|
function isArrayOfIntegers(values) {
|
|
93
104
|
if (isArray(values)) {
|
|
94
105
|
for (const value of values)
|
|
@@ -98,7 +109,6 @@ function isArrayOfIntegers(values) {
|
|
|
98
109
|
}
|
|
99
110
|
return false;
|
|
100
111
|
}
|
|
101
|
-
exports.isArrayOfIntegers = isArrayOfIntegers;
|
|
102
112
|
function isArrayOfNumbers(values) {
|
|
103
113
|
if (isArray(values)) {
|
|
104
114
|
for (const value of values)
|
|
@@ -108,7 +118,6 @@ function isArrayOfNumbers(values) {
|
|
|
108
118
|
}
|
|
109
119
|
return false;
|
|
110
120
|
}
|
|
111
|
-
exports.isArrayOfNumbers = isArrayOfNumbers;
|
|
112
121
|
function isArrayOfStrings(values) {
|
|
113
122
|
if (isArray(values)) {
|
|
114
123
|
for (const value of values)
|
|
@@ -118,7 +127,6 @@ function isArrayOfStrings(values) {
|
|
|
118
127
|
}
|
|
119
128
|
return false;
|
|
120
129
|
}
|
|
121
|
-
exports.isArrayOfStrings = isArrayOfStrings;
|
|
122
130
|
function isArrayOfObjects(values) {
|
|
123
131
|
if (isArray(values)) {
|
|
124
132
|
for (const value of values)
|
|
@@ -128,15 +136,12 @@ function isArrayOfObjects(values) {
|
|
|
128
136
|
}
|
|
129
137
|
return false;
|
|
130
138
|
}
|
|
131
|
-
exports.isArrayOfObjects = isArrayOfObjects;
|
|
132
139
|
function isTrue(value) {
|
|
133
140
|
return isBoolean(value) && (value === true);
|
|
134
141
|
}
|
|
135
|
-
exports.isTrue = isTrue;
|
|
136
142
|
function hasProperty(obj, property) {
|
|
137
143
|
return isDefined(obj) && isObject(obj) && Object.prototype.hasOwnProperty.call(obj, property);
|
|
138
144
|
}
|
|
139
|
-
exports.hasProperty = hasProperty;
|
|
140
145
|
function append(document, extensionDocument) {
|
|
141
146
|
const doc = document || {};
|
|
142
147
|
const extensionDoc = extensionDocument || {};
|
|
@@ -167,11 +172,9 @@ function append(document, extensionDocument) {
|
|
|
167
172
|
}
|
|
168
173
|
return doc;
|
|
169
174
|
}
|
|
170
|
-
exports.append = append;
|
|
171
175
|
function areEqual(firstObject, secondObject) {
|
|
172
176
|
return deepEqual(firstObject, secondObject);
|
|
173
177
|
}
|
|
174
|
-
exports.areEqual = areEqual;
|
|
175
178
|
function redactUndefinedValues(document) {
|
|
176
179
|
if (isArray(document)) {
|
|
177
180
|
for (let index = document.length - 1; index >= 0; index--) {
|
|
@@ -196,7 +199,6 @@ function redactUndefinedValues(document) {
|
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
}
|
|
199
|
-
exports.redactUndefinedValues = redactUndefinedValues;
|
|
200
202
|
function clone(value, shouldRedactUndefinedValues = true) {
|
|
201
203
|
if (value) {
|
|
202
204
|
const clonedDocument = clonedeep(value);
|
|
@@ -207,7 +209,6 @@ function clone(value, shouldRedactUndefinedValues = true) {
|
|
|
207
209
|
}
|
|
208
210
|
return undefined;
|
|
209
211
|
}
|
|
210
|
-
exports.clone = clone;
|
|
211
212
|
function stringify(obj, indent = 4, linePrefix = '', quoteFieldNames = true) {
|
|
212
213
|
const lines = JSON.stringify(obj, null, indent).split('\n');
|
|
213
214
|
if (linePrefix !== '') {
|
|
@@ -226,7 +227,6 @@ function stringify(obj, indent = 4, linePrefix = '', quoteFieldNames = true) {
|
|
|
226
227
|
}
|
|
227
228
|
return lines.join('\n');
|
|
228
229
|
}
|
|
229
|
-
exports.stringify = stringify;
|
|
230
230
|
function extractAndRedact(document, propertyName) {
|
|
231
231
|
if (Object.prototype.hasOwnProperty.call(document, propertyName)) {
|
|
232
232
|
const value = clone(document[propertyName]);
|
|
@@ -235,4 +235,3 @@ function extractAndRedact(document, propertyName) {
|
|
|
235
235
|
}
|
|
236
236
|
return undefined;
|
|
237
237
|
}
|
|
238
|
-
exports.extractAndRedact = extractAndRedact;
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"description": "API Games JSON Utilities",
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"version": "24.1.
|
|
16
|
+
"version": "24.1.6",
|
|
17
17
|
"main": "lib/index.js",
|
|
18
18
|
"types": "lib/index.d.ts",
|
|
19
19
|
"scripts": {
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"lodash.clonedeep": "^4.5.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/jest": "^29.5.
|
|
42
|
-
"@types/node": "^20.
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
44
|
-
"@typescript-eslint/parser": "^7.
|
|
41
|
+
"@types/jest": "^29.5.14",
|
|
42
|
+
"@types/node": "^20.17.6",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
44
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
45
45
|
"eslint": "^8.57.0",
|
|
46
46
|
"eslint-config-airbnb": "^19.0.4",
|
|
47
|
-
"eslint-plugin-import": "^2.
|
|
48
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
49
|
-
"eslint-plugin-react": "^7.
|
|
47
|
+
"eslint-plugin-import": "^2.31.0",
|
|
48
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
49
|
+
"eslint-plugin-react": "^7.37.2",
|
|
50
50
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
51
51
|
"jest": "^29.7.0",
|
|
52
|
-
"ts-jest": "^29.
|
|
53
|
-
"typescript": "^5.
|
|
52
|
+
"ts-jest": "^29.2.5",
|
|
53
|
+
"typescript": "^5.6.3"
|
|
54
54
|
},
|
|
55
55
|
"eslintConfig": {},
|
|
56
56
|
"repository": {
|