@apigames/json 25.1.0 → 25.1.2
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/boolean/index.d.ts +3 -0
- package/lib/boolean/index.js +16 -0
- package/lib/clone-and-extract/index.d.ts +2 -0
- package/lib/clone-and-extract/index.js +24 -0
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +37 -0
- package/lib/equality/index.d.ts +1 -0
- package/lib/equality/index.js +7 -0
- package/lib/index.d.ts +6 -1
- package/lib/index.js +37 -32
- package/lib/object/index.d.ts +4 -0
- package/lib/object/index.js +68 -0
- package/lib/type-guards/index.d.ts +15 -0
- package/lib/type-guards/index.js +101 -0
- package/package.json +8 -10
- package/lib/utils.d.ts +0 -30
- package/lib/utils.js +0 -237
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFalse = isFalse;
|
|
4
|
+
exports.isFalseOrUndefined = isFalseOrUndefined;
|
|
5
|
+
exports.isTrue = isTrue;
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
const type_guards_1 = require("../type-guards");
|
|
8
|
+
function isFalse(value) {
|
|
9
|
+
return (0, type_guards_1.isBoolean)(value) && (value === false);
|
|
10
|
+
}
|
|
11
|
+
function isFalseOrUndefined(value) {
|
|
12
|
+
return (0, common_1.isUndefined)(value) || ((0, type_guards_1.isBoolean)(value) && (value === false));
|
|
13
|
+
}
|
|
14
|
+
function isTrue(value) {
|
|
15
|
+
return (0, type_guards_1.isBoolean)(value) && (value === true);
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clone = clone;
|
|
4
|
+
exports.extractAndRedact = extractAndRedact;
|
|
5
|
+
const object_1 = require("../object");
|
|
6
|
+
const clonedeep = require('lodash.clonedeep');
|
|
7
|
+
function clone(value, shouldRedactUndefinedValues = true) {
|
|
8
|
+
if (value) {
|
|
9
|
+
const clonedDocument = clonedeep(value);
|
|
10
|
+
if (shouldRedactUndefinedValues) {
|
|
11
|
+
(0, object_1.redactUndefinedValues)(clonedDocument);
|
|
12
|
+
}
|
|
13
|
+
return clonedDocument;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
function extractAndRedact(document, propertyName) {
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(document, propertyName)) {
|
|
19
|
+
const value = clone(document[propertyName]);
|
|
20
|
+
delete document[propertyName];
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function isDefined(value: any): boolean;
|
|
2
|
+
export declare function isDefinedAndNotNull(value: any): boolean;
|
|
3
|
+
export declare function isUndefined(value: any): boolean;
|
|
4
|
+
export declare function isUndefinedOrNull(value: any): boolean;
|
|
5
|
+
export declare function stringify(obj: any, indent?: number, linePrefix?: string, quoteFieldNames?: boolean): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDefined = isDefined;
|
|
4
|
+
exports.isDefinedAndNotNull = isDefinedAndNotNull;
|
|
5
|
+
exports.isUndefined = isUndefined;
|
|
6
|
+
exports.isUndefinedOrNull = isUndefinedOrNull;
|
|
7
|
+
exports.stringify = stringify;
|
|
8
|
+
function isDefined(value) {
|
|
9
|
+
return (value !== undefined);
|
|
10
|
+
}
|
|
11
|
+
function isDefinedAndNotNull(value) {
|
|
12
|
+
return (value !== undefined) && (value !== null);
|
|
13
|
+
}
|
|
14
|
+
function isUndefined(value) {
|
|
15
|
+
return (value === undefined);
|
|
16
|
+
}
|
|
17
|
+
function isUndefinedOrNull(value) {
|
|
18
|
+
return (value === undefined) || (value === null);
|
|
19
|
+
}
|
|
20
|
+
function stringify(obj, indent = 4, linePrefix = '', quoteFieldNames = true) {
|
|
21
|
+
const lines = JSON.stringify(obj, null, indent).split('\n');
|
|
22
|
+
if (linePrefix !== '') {
|
|
23
|
+
for (let i = 1; i < lines.length; i++) {
|
|
24
|
+
lines[i] = linePrefix + lines[i];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!quoteFieldNames) {
|
|
28
|
+
for (let i = 1; i < lines.length - 1; i++) {
|
|
29
|
+
if ((lines[i].match(/:/g) || []).length > 0) {
|
|
30
|
+
const valuePair = lines[i].split(':');
|
|
31
|
+
valuePair[0] = valuePair[0].replace(/"/g, '');
|
|
32
|
+
lines[i] = valuePair.join(':');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return lines.join('\n');
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function areEqual(firstObject: any, secondObject: any): boolean;
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { isFalse, isFalseOrUndefined, isTrue } from './boolean';
|
|
2
|
+
export { clone, extractAndRedact } from './clone-and-extract';
|
|
3
|
+
export { isDefined, isDefinedAndNotNull, isUndefined, isUndefinedOrNull, stringify, } from './common';
|
|
4
|
+
export { areEqual } from './equality';
|
|
5
|
+
export { append, hasProperty, isEmpty, redactUndefinedValues, } from './object';
|
|
6
|
+
export { isArray, isArrayOfBooleans, isArrayOfDates, isArrayOfIntegers, isArrayOfNumbers, isArrayOfObjects, isArrayOfStrings, isBoolean, isDate, isError, isInteger, isNumber, isObject, isRegExp, isString, } from './type-guards';
|
package/lib/index.js
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
Object.defineProperty(exports, "
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
Object.defineProperty(exports, "
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
Object.defineProperty(exports, "
|
|
15
|
-
Object.defineProperty(exports, "
|
|
16
|
-
Object.defineProperty(exports, "
|
|
17
|
-
|
|
18
|
-
Object.defineProperty(exports, "
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(exports, "
|
|
21
|
-
Object.defineProperty(exports, "
|
|
22
|
-
Object.defineProperty(exports, "
|
|
23
|
-
Object.defineProperty(exports, "
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
-
Object.defineProperty(exports, "
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
Object.defineProperty(exports, "
|
|
29
|
-
Object.defineProperty(exports, "
|
|
30
|
-
Object.defineProperty(exports, "
|
|
31
|
-
Object.defineProperty(exports, "
|
|
32
|
-
Object.defineProperty(exports, "
|
|
33
|
-
Object.defineProperty(exports, "
|
|
34
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.isString = exports.isRegExp = exports.isObject = exports.isNumber = exports.isInteger = exports.isError = exports.isDate = exports.isBoolean = exports.isArrayOfStrings = exports.isArrayOfObjects = exports.isArrayOfNumbers = exports.isArrayOfIntegers = exports.isArrayOfDates = exports.isArrayOfBooleans = exports.isArray = exports.redactUndefinedValues = exports.isEmpty = exports.hasProperty = exports.append = exports.areEqual = exports.stringify = exports.isUndefinedOrNull = exports.isUndefined = exports.isDefinedAndNotNull = exports.isDefined = exports.extractAndRedact = exports.clone = exports.isTrue = exports.isFalseOrUndefined = exports.isFalse = void 0;
|
|
4
|
+
var boolean_1 = require("./boolean");
|
|
5
|
+
Object.defineProperty(exports, "isFalse", { enumerable: true, get: function () { return boolean_1.isFalse; } });
|
|
6
|
+
Object.defineProperty(exports, "isFalseOrUndefined", { enumerable: true, get: function () { return boolean_1.isFalseOrUndefined; } });
|
|
7
|
+
Object.defineProperty(exports, "isTrue", { enumerable: true, get: function () { return boolean_1.isTrue; } });
|
|
8
|
+
var clone_and_extract_1 = require("./clone-and-extract");
|
|
9
|
+
Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return clone_and_extract_1.clone; } });
|
|
10
|
+
Object.defineProperty(exports, "extractAndRedact", { enumerable: true, get: function () { return clone_and_extract_1.extractAndRedact; } });
|
|
11
|
+
var common_1 = require("./common");
|
|
12
|
+
Object.defineProperty(exports, "isDefined", { enumerable: true, get: function () { return common_1.isDefined; } });
|
|
13
|
+
Object.defineProperty(exports, "isDefinedAndNotNull", { enumerable: true, get: function () { return common_1.isDefinedAndNotNull; } });
|
|
14
|
+
Object.defineProperty(exports, "isUndefined", { enumerable: true, get: function () { return common_1.isUndefined; } });
|
|
15
|
+
Object.defineProperty(exports, "isUndefinedOrNull", { enumerable: true, get: function () { return common_1.isUndefinedOrNull; } });
|
|
16
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return common_1.stringify; } });
|
|
17
|
+
var equality_1 = require("./equality");
|
|
18
|
+
Object.defineProperty(exports, "areEqual", { enumerable: true, get: function () { return equality_1.areEqual; } });
|
|
19
|
+
var object_1 = require("./object");
|
|
20
|
+
Object.defineProperty(exports, "append", { enumerable: true, get: function () { return object_1.append; } });
|
|
21
|
+
Object.defineProperty(exports, "hasProperty", { enumerable: true, get: function () { return object_1.hasProperty; } });
|
|
22
|
+
Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return object_1.isEmpty; } });
|
|
23
|
+
Object.defineProperty(exports, "redactUndefinedValues", { enumerable: true, get: function () { return object_1.redactUndefinedValues; } });
|
|
24
|
+
var type_guards_1 = require("./type-guards");
|
|
25
|
+
Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return type_guards_1.isArray; } });
|
|
26
|
+
Object.defineProperty(exports, "isArrayOfBooleans", { enumerable: true, get: function () { return type_guards_1.isArrayOfBooleans; } });
|
|
27
|
+
Object.defineProperty(exports, "isArrayOfDates", { enumerable: true, get: function () { return type_guards_1.isArrayOfDates; } });
|
|
28
|
+
Object.defineProperty(exports, "isArrayOfIntegers", { enumerable: true, get: function () { return type_guards_1.isArrayOfIntegers; } });
|
|
29
|
+
Object.defineProperty(exports, "isArrayOfNumbers", { enumerable: true, get: function () { return type_guards_1.isArrayOfNumbers; } });
|
|
30
|
+
Object.defineProperty(exports, "isArrayOfObjects", { enumerable: true, get: function () { return type_guards_1.isArrayOfObjects; } });
|
|
31
|
+
Object.defineProperty(exports, "isArrayOfStrings", { enumerable: true, get: function () { return type_guards_1.isArrayOfStrings; } });
|
|
32
|
+
Object.defineProperty(exports, "isBoolean", { enumerable: true, get: function () { return type_guards_1.isBoolean; } });
|
|
33
|
+
Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return type_guards_1.isDate; } });
|
|
34
|
+
Object.defineProperty(exports, "isError", { enumerable: true, get: function () { return type_guards_1.isError; } });
|
|
35
|
+
Object.defineProperty(exports, "isInteger", { enumerable: true, get: function () { return type_guards_1.isInteger; } });
|
|
36
|
+
Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return type_guards_1.isNumber; } });
|
|
37
|
+
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return type_guards_1.isObject; } });
|
|
38
|
+
Object.defineProperty(exports, "isRegExp", { enumerable: true, get: function () { return type_guards_1.isRegExp; } });
|
|
39
|
+
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return type_guards_1.isString; } });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isEmpty(document: any): boolean;
|
|
2
|
+
export declare function hasProperty(obj: any, property: string): boolean;
|
|
3
|
+
export declare function append(document: any, extensionDocument: any): any;
|
|
4
|
+
export declare function redactUndefinedValues(document: any): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEmpty = isEmpty;
|
|
4
|
+
exports.hasProperty = hasProperty;
|
|
5
|
+
exports.append = append;
|
|
6
|
+
exports.redactUndefinedValues = redactUndefinedValues;
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
const type_guards_1 = require("../type-guards");
|
|
9
|
+
function isEmpty(document) {
|
|
10
|
+
return ((0, common_1.isUndefined)(document)) || ((0, type_guards_1.isObject)(document) && (Object.keys(document).length === 0));
|
|
11
|
+
}
|
|
12
|
+
function hasProperty(obj, property) {
|
|
13
|
+
return (0, common_1.isDefined)(obj) && (0, type_guards_1.isObject)(obj) && Object.prototype.hasOwnProperty.call(obj, property);
|
|
14
|
+
}
|
|
15
|
+
function append(document, extensionDocument) {
|
|
16
|
+
const doc = document || {};
|
|
17
|
+
const extensionDoc = extensionDocument || {};
|
|
18
|
+
const sourceKeys = Object.keys(extensionDoc);
|
|
19
|
+
for (let i = 0; i < sourceKeys.length; i++) {
|
|
20
|
+
if ((0, type_guards_1.isArray)(extensionDoc[sourceKeys[i]])) {
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(doc, sourceKeys[i])) {
|
|
22
|
+
const sourceSet = new Set(doc[sourceKeys[i]]);
|
|
23
|
+
const extensionSet = new Set(extensionDoc[sourceKeys[i]]);
|
|
24
|
+
const mergedSet = new Set([...Array.from(sourceSet), ...Array.from(extensionSet)]);
|
|
25
|
+
doc[sourceKeys[i]] = [...Array.from(mergedSet)];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
doc[sourceKeys[i]] = extensionDoc[sourceKeys[i]];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if ((0, type_guards_1.isObject)(extensionDoc[sourceKeys[i]])) {
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(doc, sourceKeys[i])) {
|
|
33
|
+
append(doc[sourceKeys[i]], extensionDoc[sourceKeys[i]]);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
doc[sourceKeys[i]] = extensionDoc[sourceKeys[i]];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
doc[sourceKeys[i]] = extensionDoc[sourceKeys[i]];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return doc;
|
|
44
|
+
}
|
|
45
|
+
function redactUndefinedValues(document) {
|
|
46
|
+
if ((0, type_guards_1.isArray)(document)) {
|
|
47
|
+
for (let index = document.length - 1; index >= 0; index--) {
|
|
48
|
+
if ((0, common_1.isDefined)(document[index])) {
|
|
49
|
+
redactUndefinedValues(document[index]);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
document = document.splice(index, 1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if ((0, type_guards_1.isObject)(document)) {
|
|
57
|
+
for (const key in document) {
|
|
58
|
+
if (Object.prototype.hasOwnProperty.call(document, key)) {
|
|
59
|
+
if ((0, common_1.isDefined)(document[key])) {
|
|
60
|
+
redactUndefinedValues(document[key]);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
delete document[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function isArray(value: any): value is Array<any>;
|
|
2
|
+
export declare function isBoolean(value: any): value is boolean;
|
|
3
|
+
export declare function isDate(value: any): value is Date;
|
|
4
|
+
export declare function isError(value: any): value is Error;
|
|
5
|
+
export declare function isNumber(value: any): value is number;
|
|
6
|
+
export declare function isInteger(value: any): value is number;
|
|
7
|
+
export declare function isObject(value: any): value is Object;
|
|
8
|
+
export declare function isRegExp(value: any): value is RegExp;
|
|
9
|
+
export declare function isString(value: any): value is string;
|
|
10
|
+
export declare function isArrayOfBooleans(values: any): values is boolean[];
|
|
11
|
+
export declare function isArrayOfDates(values: any): values is Date[];
|
|
12
|
+
export declare function isArrayOfIntegers(values: any): values is number[];
|
|
13
|
+
export declare function isArrayOfNumbers(values: any): values is number[];
|
|
14
|
+
export declare function isArrayOfStrings(values: any): values is string[];
|
|
15
|
+
export declare function isArrayOfObjects(values: any): values is object[];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isArray = isArray;
|
|
4
|
+
exports.isBoolean = isBoolean;
|
|
5
|
+
exports.isDate = isDate;
|
|
6
|
+
exports.isError = isError;
|
|
7
|
+
exports.isNumber = isNumber;
|
|
8
|
+
exports.isInteger = isInteger;
|
|
9
|
+
exports.isObject = isObject;
|
|
10
|
+
exports.isRegExp = isRegExp;
|
|
11
|
+
exports.isString = isString;
|
|
12
|
+
exports.isArrayOfBooleans = isArrayOfBooleans;
|
|
13
|
+
exports.isArrayOfDates = isArrayOfDates;
|
|
14
|
+
exports.isArrayOfIntegers = isArrayOfIntegers;
|
|
15
|
+
exports.isArrayOfNumbers = isArrayOfNumbers;
|
|
16
|
+
exports.isArrayOfStrings = isArrayOfStrings;
|
|
17
|
+
exports.isArrayOfObjects = isArrayOfObjects;
|
|
18
|
+
const common_1 = require("../common");
|
|
19
|
+
function isArray(value) {
|
|
20
|
+
return (0, common_1.isDefinedAndNotNull)(value) && (typeof value === 'object')
|
|
21
|
+
&& (value.constructor === Array);
|
|
22
|
+
}
|
|
23
|
+
function isBoolean(value) {
|
|
24
|
+
return (0, common_1.isDefinedAndNotNull)(value) && (typeof value === 'boolean');
|
|
25
|
+
}
|
|
26
|
+
function isDate(value) {
|
|
27
|
+
return (0, common_1.isDefinedAndNotNull)(value) && (value instanceof Date);
|
|
28
|
+
}
|
|
29
|
+
function isError(value) {
|
|
30
|
+
return (0, common_1.isDefinedAndNotNull)(value) && (value instanceof Error) && (typeof value.message !== 'undefined');
|
|
31
|
+
}
|
|
32
|
+
function isNumber(value) {
|
|
33
|
+
return (0, common_1.isDefinedAndNotNull)(value) && (typeof value === 'number') && isFinite(value);
|
|
34
|
+
}
|
|
35
|
+
function isInteger(value) {
|
|
36
|
+
return isNumber(value) && (value % 1 === 0);
|
|
37
|
+
}
|
|
38
|
+
function isObject(value) {
|
|
39
|
+
return (0, common_1.isDefinedAndNotNull)(value) && (typeof value === 'object')
|
|
40
|
+
&& ((value.constructor === Object) || ((value instanceof Object) && (!isArray(value))));
|
|
41
|
+
}
|
|
42
|
+
function isRegExp(value) {
|
|
43
|
+
return (0, common_1.isDefinedAndNotNull)(value) && (typeof value === 'object') && (value.constructor === RegExp);
|
|
44
|
+
}
|
|
45
|
+
function isString(value) {
|
|
46
|
+
return (0, common_1.isDefinedAndNotNull)(value) && ((typeof value === 'string') || (value instanceof String));
|
|
47
|
+
}
|
|
48
|
+
function isArrayOfBooleans(values) {
|
|
49
|
+
if (isArray(values)) {
|
|
50
|
+
for (const value of values)
|
|
51
|
+
if (!isBoolean(value))
|
|
52
|
+
return false;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function isArrayOfDates(values) {
|
|
58
|
+
if (isArray(values)) {
|
|
59
|
+
for (const value of values)
|
|
60
|
+
if (!isDate(value))
|
|
61
|
+
return false;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
function isArrayOfIntegers(values) {
|
|
67
|
+
if (isArray(values)) {
|
|
68
|
+
for (const value of values)
|
|
69
|
+
if (!isInteger(value))
|
|
70
|
+
return false;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
function isArrayOfNumbers(values) {
|
|
76
|
+
if (isArray(values)) {
|
|
77
|
+
for (const value of values)
|
|
78
|
+
if (!isNumber(value))
|
|
79
|
+
return false;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
function isArrayOfStrings(values) {
|
|
85
|
+
if (isArray(values)) {
|
|
86
|
+
for (const value of values)
|
|
87
|
+
if (!isString(value))
|
|
88
|
+
return false;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
function isArrayOfObjects(values) {
|
|
94
|
+
if (isArray(values)) {
|
|
95
|
+
for (const value of values)
|
|
96
|
+
if (!isObject(value))
|
|
97
|
+
return false;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"description": "API Games JSON Utilities",
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"version": "25.1.
|
|
16
|
+
"version": "25.1.2",
|
|
17
17
|
"main": "lib/index.js",
|
|
18
18
|
"types": "lib/index.d.ts",
|
|
19
19
|
"scripts": {
|
|
@@ -39,18 +39,16 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^30.0.0",
|
|
42
|
-
"@types/node": "^24.
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
44
|
-
"@typescript-eslint/parser": "^8.
|
|
42
|
+
"@types/node": "^24.10.9",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
44
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
45
45
|
"eslint": "^8.57.1",
|
|
46
|
-
"eslint-config-airbnb": "^
|
|
46
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
47
47
|
"eslint-plugin-import": "^2.32.0",
|
|
48
48
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"ts-jest": "^29.4.4",
|
|
53
|
-
"typescript": "^5.9.2"
|
|
49
|
+
"jest": "^30.2.0",
|
|
50
|
+
"ts-jest": "^29.4.6",
|
|
51
|
+
"typescript": "^5.9.3"
|
|
54
52
|
},
|
|
55
53
|
"eslintConfig": {},
|
|
56
54
|
"repository": {
|
package/lib/utils.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export declare function isDefined(value: any): boolean;
|
|
2
|
-
export declare function isDefinedAndNotNull(value: any): boolean;
|
|
3
|
-
export declare function isUndefined(value: any): boolean;
|
|
4
|
-
export declare function isUndefinedOrNull(value: any): boolean;
|
|
5
|
-
export declare function isArray(value: any): value is Array<any>;
|
|
6
|
-
export declare function isBoolean(value: any): value is boolean;
|
|
7
|
-
export declare function isDate(value: any): value is Date;
|
|
8
|
-
export declare function isError(value: any): value is Error;
|
|
9
|
-
export declare function isFalse(value: any): boolean;
|
|
10
|
-
export declare function isFalseOrUndefined(value: any): boolean;
|
|
11
|
-
export declare function isNumber(value: any): value is number;
|
|
12
|
-
export declare function isInteger(value: any): value is number;
|
|
13
|
-
export declare function isObject(value: any): value is Object;
|
|
14
|
-
export declare function isEmpty(document: any): boolean;
|
|
15
|
-
export declare function isRegExp(value: any): value is RegExp;
|
|
16
|
-
export declare function isString(value: any): value is string;
|
|
17
|
-
export declare function isArrayOfBooleans(values: any): values is boolean[];
|
|
18
|
-
export declare function isArrayOfDates(values: any): values is Date[];
|
|
19
|
-
export declare function isArrayOfIntegers(values: any): values is number[];
|
|
20
|
-
export declare function isArrayOfNumbers(values: any): values is number[];
|
|
21
|
-
export declare function isArrayOfStrings(values: any): values is string[];
|
|
22
|
-
export declare function isArrayOfObjects(values: any): values is object[];
|
|
23
|
-
export declare function isTrue(value: any): boolean;
|
|
24
|
-
export declare function hasProperty(obj: any, property: string): boolean;
|
|
25
|
-
export declare function append(document: any, extensionDocument: any): any;
|
|
26
|
-
export declare function areEqual(firstObject: any, secondObject: any): boolean;
|
|
27
|
-
export declare function redactUndefinedValues(document: any): void;
|
|
28
|
-
export declare function clone(value: any, shouldRedactUndefinedValues?: boolean): any;
|
|
29
|
-
export declare function stringify(obj: any, indent?: number, linePrefix?: string, quoteFieldNames?: boolean): string;
|
|
30
|
-
export declare function extractAndRedact(document: any, propertyName: string): any;
|
package/lib/utils.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
33
|
-
const deepEqual = require('deep-equal');
|
|
34
|
-
const clonedeep = require('lodash.clonedeep');
|
|
35
|
-
function isDefined(value) {
|
|
36
|
-
return (value !== undefined);
|
|
37
|
-
}
|
|
38
|
-
function isDefinedAndNotNull(value) {
|
|
39
|
-
return (value !== undefined) && (value !== null);
|
|
40
|
-
}
|
|
41
|
-
function isUndefined(value) {
|
|
42
|
-
return (value === undefined);
|
|
43
|
-
}
|
|
44
|
-
function isUndefinedOrNull(value) {
|
|
45
|
-
return (value === undefined) || (value === null);
|
|
46
|
-
}
|
|
47
|
-
function isArray(value) {
|
|
48
|
-
return isDefinedAndNotNull(value) && (typeof value === 'object')
|
|
49
|
-
&& (value.constructor === Array);
|
|
50
|
-
}
|
|
51
|
-
function isBoolean(value) {
|
|
52
|
-
return isDefinedAndNotNull(value) && (typeof value === 'boolean');
|
|
53
|
-
}
|
|
54
|
-
function isDate(value) {
|
|
55
|
-
return isDefinedAndNotNull(value) && (value instanceof Date);
|
|
56
|
-
}
|
|
57
|
-
function isError(value) {
|
|
58
|
-
return isDefinedAndNotNull(value) && (value instanceof Error) && (typeof value.message !== 'undefined');
|
|
59
|
-
}
|
|
60
|
-
function isFalse(value) {
|
|
61
|
-
return isBoolean(value) && (value === false);
|
|
62
|
-
}
|
|
63
|
-
function isFalseOrUndefined(value) {
|
|
64
|
-
return isUndefined(value) || (isBoolean(value) && (value === false));
|
|
65
|
-
}
|
|
66
|
-
function isNumber(value) {
|
|
67
|
-
return isDefinedAndNotNull(value) && (typeof value === 'number') && isFinite(value);
|
|
68
|
-
}
|
|
69
|
-
function isInteger(value) {
|
|
70
|
-
return isNumber(value) && (value % 1 === 0);
|
|
71
|
-
}
|
|
72
|
-
function isObject(value) {
|
|
73
|
-
return isDefinedAndNotNull(value) && (typeof value === 'object')
|
|
74
|
-
&& ((value.constructor === Object) || ((value instanceof Object) && (!isArray(value))));
|
|
75
|
-
}
|
|
76
|
-
function isEmpty(document) {
|
|
77
|
-
return (isUndefined(document)) || (isObject(document) && (Object.keys(document).length === 0));
|
|
78
|
-
}
|
|
79
|
-
function isRegExp(value) {
|
|
80
|
-
return isDefinedAndNotNull(value) && (typeof value === 'object') && (value.constructor === RegExp);
|
|
81
|
-
}
|
|
82
|
-
function isString(value) {
|
|
83
|
-
return isDefinedAndNotNull(value) && ((typeof value === 'string') || (value instanceof String));
|
|
84
|
-
}
|
|
85
|
-
function isArrayOfBooleans(values) {
|
|
86
|
-
if (isArray(values)) {
|
|
87
|
-
for (const value of values)
|
|
88
|
-
if (!isBoolean(value))
|
|
89
|
-
return false;
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
function isArrayOfDates(values) {
|
|
95
|
-
if (isArray(values)) {
|
|
96
|
-
for (const value of values)
|
|
97
|
-
if (!isDate(value))
|
|
98
|
-
return false;
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
function isArrayOfIntegers(values) {
|
|
104
|
-
if (isArray(values)) {
|
|
105
|
-
for (const value of values)
|
|
106
|
-
if (!isInteger(value))
|
|
107
|
-
return false;
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
function isArrayOfNumbers(values) {
|
|
113
|
-
if (isArray(values)) {
|
|
114
|
-
for (const value of values)
|
|
115
|
-
if (!isNumber(value))
|
|
116
|
-
return false;
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
function isArrayOfStrings(values) {
|
|
122
|
-
if (isArray(values)) {
|
|
123
|
-
for (const value of values)
|
|
124
|
-
if (!isString(value))
|
|
125
|
-
return false;
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
function isArrayOfObjects(values) {
|
|
131
|
-
if (isArray(values)) {
|
|
132
|
-
for (const value of values)
|
|
133
|
-
if (!isObject(value))
|
|
134
|
-
return false;
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
function isTrue(value) {
|
|
140
|
-
return isBoolean(value) && (value === true);
|
|
141
|
-
}
|
|
142
|
-
function hasProperty(obj, property) {
|
|
143
|
-
return isDefined(obj) && isObject(obj) && Object.prototype.hasOwnProperty.call(obj, property);
|
|
144
|
-
}
|
|
145
|
-
function append(document, extensionDocument) {
|
|
146
|
-
const doc = document || {};
|
|
147
|
-
const extensionDoc = extensionDocument || {};
|
|
148
|
-
const sourceKeys = Object.keys(extensionDoc);
|
|
149
|
-
for (let i = 0; i < sourceKeys.length; i++) {
|
|
150
|
-
if (isArray(extensionDoc[sourceKeys[i]])) {
|
|
151
|
-
if (Object.prototype.hasOwnProperty.call(doc, sourceKeys[i])) {
|
|
152
|
-
const sourceSet = new Set(doc[sourceKeys[i]]);
|
|
153
|
-
const extensionSet = new Set(extensionDoc[sourceKeys[i]]);
|
|
154
|
-
const mergedSet = new Set([...Array.from(sourceSet), ...Array.from(extensionSet)]);
|
|
155
|
-
doc[sourceKeys[i]] = [...Array.from(mergedSet)];
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
doc[sourceKeys[i]] = extensionDoc[sourceKeys[i]];
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
else if (isObject(extensionDoc[sourceKeys[i]])) {
|
|
162
|
-
if (Object.prototype.hasOwnProperty.call(doc, sourceKeys[i])) {
|
|
163
|
-
append(doc[sourceKeys[i]], extensionDoc[sourceKeys[i]]);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
doc[sourceKeys[i]] = extensionDoc[sourceKeys[i]];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
doc[sourceKeys[i]] = extensionDoc[sourceKeys[i]];
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return doc;
|
|
174
|
-
}
|
|
175
|
-
function areEqual(firstObject, secondObject) {
|
|
176
|
-
return deepEqual(firstObject, secondObject);
|
|
177
|
-
}
|
|
178
|
-
function redactUndefinedValues(document) {
|
|
179
|
-
if (isArray(document)) {
|
|
180
|
-
for (let index = document.length - 1; index >= 0; index--) {
|
|
181
|
-
if (isDefined(document[index])) {
|
|
182
|
-
redactUndefinedValues(document[index]);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
document = document.splice(index, 1);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else if (isObject(document)) {
|
|
190
|
-
for (const key in document) {
|
|
191
|
-
if (Object.prototype.hasOwnProperty.call(document, key)) {
|
|
192
|
-
if (isDefined(document[key])) {
|
|
193
|
-
redactUndefinedValues(document[key]);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
delete document[key];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
function clone(value, shouldRedactUndefinedValues = true) {
|
|
203
|
-
if (value) {
|
|
204
|
-
const clonedDocument = clonedeep(value);
|
|
205
|
-
if (shouldRedactUndefinedValues) {
|
|
206
|
-
redactUndefinedValues(clonedDocument);
|
|
207
|
-
}
|
|
208
|
-
return clonedDocument;
|
|
209
|
-
}
|
|
210
|
-
return undefined;
|
|
211
|
-
}
|
|
212
|
-
function stringify(obj, indent = 4, linePrefix = '', quoteFieldNames = true) {
|
|
213
|
-
const lines = JSON.stringify(obj, null, indent).split('\n');
|
|
214
|
-
if (linePrefix !== '') {
|
|
215
|
-
for (let i = 1; i < lines.length; i++) {
|
|
216
|
-
lines[i] = linePrefix + lines[i];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (!quoteFieldNames) {
|
|
220
|
-
for (let i = 1; i < lines.length - 1; i++) {
|
|
221
|
-
if ((lines[i].match(/:/g) || []).length > 0) {
|
|
222
|
-
const valuePair = lines[i].split(':');
|
|
223
|
-
valuePair[0] = valuePair[0].replace(/"/g, '');
|
|
224
|
-
lines[i] = valuePair.join(':');
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return lines.join('\n');
|
|
229
|
-
}
|
|
230
|
-
function extractAndRedact(document, propertyName) {
|
|
231
|
-
if (Object.prototype.hasOwnProperty.call(document, propertyName)) {
|
|
232
|
-
const value = clone(document[propertyName]);
|
|
233
|
-
delete document[propertyName];
|
|
234
|
-
return value;
|
|
235
|
-
}
|
|
236
|
-
return undefined;
|
|
237
|
-
}
|