@apigames/json 22.1.0-dev.3 → 22.1.0-dev.7

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 API Games Limited
3
+ Copyright (c) 2022 API Games Limited
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,5 +1,10 @@
1
- API Games JSON Utilities
2
- ========================
1
+ # API Games JSON Utilities
2
+
3
+ ![](https://img.shields.io/badge/build-passing-brightgreen)
4
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/6aba1020060a467899666e3f1884d37f)](https://www.codacy.com/gh/apigames-public/json/dashboard?utm_source=github.com&utm_medium=referral&utm_content=apigames-public/json&utm_campaign=Badge_Grade)
5
+ [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/6aba1020060a467899666e3f1884d37f)](https://www.codacy.com/gh/apigames-public/json/dashboard?utm_source=github.com&utm_medium=referral&utm_content=apigames-public/json&utm_campaign=Badge_Coverage)
6
+ ![](https://img.shields.io/npm/v/@apigames/json)
7
+ ![](https://img.shields.io/badge/license-MIT-blue)
3
8
 
4
9
  JSON Utilities Library for the API Games Platform and SDKs.
5
10
 
@@ -7,7 +12,7 @@ JSON Utilities Library for the API Games Platform and SDKs.
7
12
 
8
13
  This package includes a set of utility functions that provide efficient and consistent JSON object manipulation capabilities.
9
14
 
10
- ### List of features
15
+ ## List of features
11
16
 
12
17
  * Provides the ability to append a JSON object with another sub document
13
18
  * Provides the ability to compare JSON objects
@@ -15,16 +20,16 @@ This package includes a set of utility functions that provide efficient and cons
15
20
  * Provides the ability to extract and redact elements from a JSON obejct
16
21
  * Provides the ability to evaluate JSON element types
17
22
 
18
- ### Download & Installation
23
+ ## Download & Installation
19
24
 
20
25
  ```shell
21
26
  $ npm i @apigames/json
22
27
  ```
23
28
 
24
- ### Authors or Acknowledgments
29
+ ## Authors or Acknowledgments
25
30
 
26
31
  * API Games Limited
27
32
 
28
- ### License
33
+ ## License
29
34
 
30
35
  This project is licensed under the MIT License
package/lib/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { append, areEqual, clone, extractAndRedact, hasProperty, isArray, isBoolean, isDate, isDefined, isDefinedAndNotNull, isEmpty, isError, isFalse, isInteger, isNumber, isObject, isRegExp, isString, isTrue, isUndefined, isUndefinedOrNull, redactUndefinedValues, stringify, } from './utils';
1
+ export { append, areEqual, clone, extractAndRedact, hasProperty, isArray, isArrayOfBooleans, isArrayOfDates, isArrayOfIntegers, isArrayOfNumbers, isArrayOfObjects, isArrayOfStrings, isBoolean, isDate, isDefined, isDefinedAndNotNull, isEmpty, isError, isFalse, isInteger, isNumber, isObject, isRegExp, isString, isTrue, isUndefined, isUndefinedOrNull, redactUndefinedValues, stringify, } from './utils';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringify = exports.redactUndefinedValues = exports.isUndefinedOrNull = exports.isUndefined = exports.isTrue = exports.isString = exports.isRegExp = exports.isObject = exports.isNumber = exports.isInteger = exports.isFalse = exports.isError = exports.isEmpty = exports.isDefinedAndNotNull = exports.isDefined = exports.isDate = exports.isBoolean = exports.isArray = exports.hasProperty = exports.extractAndRedact = exports.clone = exports.areEqual = exports.append = void 0;
3
+ exports.stringify = exports.redactUndefinedValues = exports.isUndefinedOrNull = exports.isUndefined = exports.isTrue = exports.isString = exports.isRegExp = exports.isObject = exports.isNumber = exports.isInteger = exports.isFalse = exports.isError = exports.isEmpty = exports.isDefinedAndNotNull = exports.isDefined = exports.isDate = exports.isBoolean = exports.isArrayOfStrings = exports.isArrayOfObjects = exports.isArrayOfNumbers = exports.isArrayOfIntegers = exports.isArrayOfDates = exports.isArrayOfBooleans = exports.isArray = exports.hasProperty = exports.extractAndRedact = exports.clone = exports.areEqual = exports.append = void 0;
4
4
  var utils_1 = require("./utils");
5
5
  Object.defineProperty(exports, "append", { enumerable: true, get: function () { return utils_1.append; } });
6
6
  Object.defineProperty(exports, "areEqual", { enumerable: true, get: function () { return utils_1.areEqual; } });
@@ -8,6 +8,12 @@ Object.defineProperty(exports, "clone", { enumerable: true, get: function () { r
8
8
  Object.defineProperty(exports, "extractAndRedact", { enumerable: true, get: function () { return utils_1.extractAndRedact; } });
9
9
  Object.defineProperty(exports, "hasProperty", { enumerable: true, get: function () { return utils_1.hasProperty; } });
10
10
  Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return utils_1.isArray; } });
11
+ Object.defineProperty(exports, "isArrayOfBooleans", { enumerable: true, get: function () { return utils_1.isArrayOfBooleans; } });
12
+ Object.defineProperty(exports, "isArrayOfDates", { enumerable: true, get: function () { return utils_1.isArrayOfDates; } });
13
+ Object.defineProperty(exports, "isArrayOfIntegers", { enumerable: true, get: function () { return utils_1.isArrayOfIntegers; } });
14
+ Object.defineProperty(exports, "isArrayOfNumbers", { enumerable: true, get: function () { return utils_1.isArrayOfNumbers; } });
15
+ Object.defineProperty(exports, "isArrayOfObjects", { enumerable: true, get: function () { return utils_1.isArrayOfObjects; } });
16
+ Object.defineProperty(exports, "isArrayOfStrings", { enumerable: true, get: function () { return utils_1.isArrayOfStrings; } });
11
17
  Object.defineProperty(exports, "isBoolean", { enumerable: true, get: function () { return utils_1.isBoolean; } });
12
18
  Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return utils_1.isDate; } });
13
19
  Object.defineProperty(exports, "isDefined", { enumerable: true, get: function () { return utils_1.isDefined; } });
package/lib/utils.d.ts CHANGED
@@ -1,8 +1,10 @@
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;
1
5
  export declare function isArray(value: any): value is Array<any>;
2
6
  export declare function isBoolean(value: any): value is boolean;
3
7
  export declare function isDate(value: any): value is Date;
4
- export declare function isDefined(value: any): boolean;
5
- export declare function isDefinedAndNotNull(value: any): boolean;
6
8
  export declare function isError(value: any): value is Error;
7
9
  export declare function isFalse(value: any): boolean;
8
10
  export declare function isNumber(value: any): value is number;
@@ -11,9 +13,13 @@ export declare function isObject(value: any): value is Object;
11
13
  export declare function isEmpty(document: any): boolean;
12
14
  export declare function isRegExp(value: any): value is RegExp;
13
15
  export declare function isString(value: any): value is string;
16
+ export declare function isArrayOfBooleans(values: any): values is boolean[];
17
+ export declare function isArrayOfDates(values: any): values is Date[];
18
+ export declare function isArrayOfIntegers(values: any): values is number[];
19
+ export declare function isArrayOfNumbers(values: any): values is number[];
20
+ export declare function isArrayOfStrings(values: any): values is string[];
21
+ export declare function isArrayOfObjects(values: any): values is object[];
14
22
  export declare function isTrue(value: any): boolean;
15
- export declare function isUndefined(value: any): boolean;
16
- export declare function isUndefinedOrNull(value: any): boolean;
17
23
  export declare function hasProperty(obj: any, property: string): boolean;
18
24
  export declare function append(document: any, extensionDocument: any): any;
19
25
  export declare function areEqual(firstObject: any, secondObject: any): boolean;
package/lib/utils.js CHANGED
@@ -1,31 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractAndRedact = exports.stringify = exports.clone = exports.redactUndefinedValues = exports.areEqual = exports.append = exports.hasProperty = exports.isUndefinedOrNull = exports.isUndefined = exports.isTrue = exports.isString = exports.isRegExp = exports.isEmpty = exports.isObject = exports.isInteger = exports.isNumber = exports.isFalse = exports.isError = exports.isDefinedAndNotNull = exports.isDefined = exports.isDate = exports.isBoolean = exports.isArray = void 0;
3
+ exports.extractAndRedact = exports.stringify = exports.clone = exports.redactUndefinedValues = exports.areEqual = exports.append = exports.hasProperty = exports.isTrue = exports.isArrayOfObjects = exports.isArrayOfStrings = exports.isArrayOfNumbers = exports.isArrayOfIntegers = exports.isArrayOfDates = exports.isArrayOfBooleans = exports.isString = exports.isRegExp = exports.isEmpty = exports.isObject = exports.isInteger = exports.isNumber = exports.isFalse = exports.isError = exports.isDate = exports.isBoolean = exports.isArray = exports.isUndefinedOrNull = exports.isUndefined = exports.isDefinedAndNotNull = exports.isDefined = void 0;
4
4
  const deepEqual = require('deep-equal');
5
5
  const clonedeep = require('lodash.clonedeep');
6
+ function isDefined(value) {
7
+ return (value !== undefined);
8
+ }
9
+ exports.isDefined = isDefined;
10
+ function isDefinedAndNotNull(value) {
11
+ return (value !== undefined) && (value !== null);
12
+ }
13
+ exports.isDefinedAndNotNull = isDefinedAndNotNull;
14
+ function isUndefined(value) {
15
+ return (value === undefined);
16
+ }
17
+ exports.isUndefined = isUndefined;
18
+ function isUndefinedOrNull(value) {
19
+ return (value === undefined) || (value === null);
20
+ }
21
+ exports.isUndefinedOrNull = isUndefinedOrNull;
6
22
  function isArray(value) {
7
- return ((value !== null) && ((value !== undefined))) && (typeof value === 'object')
23
+ return isDefinedAndNotNull(value) && (typeof value === 'object')
8
24
  && (value.constructor === Array);
9
25
  }
10
26
  exports.isArray = isArray;
11
27
  function isBoolean(value) {
12
- return ((value !== null) && ((value !== undefined))) && (typeof value === 'boolean');
28
+ return isDefinedAndNotNull(value) && (typeof value === 'boolean');
13
29
  }
14
30
  exports.isBoolean = isBoolean;
15
31
  function isDate(value) {
16
- return ((value !== null) && ((value !== undefined))) && (value instanceof Date);
32
+ return isDefinedAndNotNull(value) && (value instanceof Date);
17
33
  }
18
34
  exports.isDate = isDate;
19
- function isDefined(value) {
20
- return (value !== undefined);
21
- }
22
- exports.isDefined = isDefined;
23
- function isDefinedAndNotNull(value) {
24
- return (value !== undefined) && (value !== null);
25
- }
26
- exports.isDefinedAndNotNull = isDefinedAndNotNull;
27
35
  function isError(value) {
28
- return ((value !== null) && ((value !== undefined))) && (value instanceof Error) && (typeof value.message !== 'undefined');
36
+ return isDefinedAndNotNull(value) && (value instanceof Error) && (typeof value.message !== 'undefined');
29
37
  }
30
38
  exports.isError = isError;
31
39
  function isFalse(value) {
@@ -33,7 +41,7 @@ function isFalse(value) {
33
41
  }
34
42
  exports.isFalse = isFalse;
35
43
  function isNumber(value) {
36
- return ((value !== null) && ((value !== undefined))) && (typeof value === 'number') && isFinite(value);
44
+ return isDefinedAndNotNull(value) && (typeof value === 'number') && isFinite(value);
37
45
  }
38
46
  exports.isNumber = isNumber;
39
47
  function isInteger(value) {
@@ -41,34 +49,86 @@ function isInteger(value) {
41
49
  }
42
50
  exports.isInteger = isInteger;
43
51
  function isObject(value) {
44
- return ((value !== null) && ((value !== undefined))) && (typeof value === 'object')
52
+ return isDefinedAndNotNull(value) && (typeof value === 'object')
45
53
  && ((value.constructor === Object) || ((value instanceof Object) && (!isArray(value))));
46
54
  }
47
55
  exports.isObject = isObject;
48
56
  function isEmpty(document) {
49
- return (!document) || (isObject(document) && (Object.keys(document).length === 0));
57
+ return (isUndefined(document)) || (isObject(document) && (Object.keys(document).length === 0));
50
58
  }
51
59
  exports.isEmpty = isEmpty;
52
60
  function isRegExp(value) {
53
- return ((value !== null) && ((value !== undefined))) && (typeof value === 'object') && (value.constructor === RegExp);
61
+ return isDefinedAndNotNull(value) && (typeof value === 'object') && (value.constructor === RegExp);
54
62
  }
55
63
  exports.isRegExp = isRegExp;
56
64
  function isString(value) {
57
- return ((value !== null) && ((value !== undefined))) && ((typeof value === 'string') || (value instanceof String));
65
+ return isDefinedAndNotNull(value) && ((typeof value === 'string') || (value instanceof String));
58
66
  }
59
67
  exports.isString = isString;
68
+ function isArrayOfBooleans(values) {
69
+ if (isArray(values)) {
70
+ for (const value of values)
71
+ if (!isBoolean(value))
72
+ return false;
73
+ return true;
74
+ }
75
+ return false;
76
+ }
77
+ exports.isArrayOfBooleans = isArrayOfBooleans;
78
+ function isArrayOfDates(values) {
79
+ if (isArray(values)) {
80
+ for (const value of values)
81
+ if (!isDate(value))
82
+ return false;
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+ exports.isArrayOfDates = isArrayOfDates;
88
+ function isArrayOfIntegers(values) {
89
+ if (isArray(values)) {
90
+ for (const value of values)
91
+ if (!isInteger(value))
92
+ return false;
93
+ return true;
94
+ }
95
+ return false;
96
+ }
97
+ exports.isArrayOfIntegers = isArrayOfIntegers;
98
+ function isArrayOfNumbers(values) {
99
+ if (isArray(values)) {
100
+ for (const value of values)
101
+ if (!isNumber(value))
102
+ return false;
103
+ return true;
104
+ }
105
+ return false;
106
+ }
107
+ exports.isArrayOfNumbers = isArrayOfNumbers;
108
+ function isArrayOfStrings(values) {
109
+ if (isArray(values)) {
110
+ for (const value of values)
111
+ if (!isString(value))
112
+ return false;
113
+ return true;
114
+ }
115
+ return false;
116
+ }
117
+ exports.isArrayOfStrings = isArrayOfStrings;
118
+ function isArrayOfObjects(values) {
119
+ if (isArray(values)) {
120
+ for (const value of values)
121
+ if (!isObject(value))
122
+ return false;
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+ exports.isArrayOfObjects = isArrayOfObjects;
60
128
  function isTrue(value) {
61
129
  return isBoolean(value) && (value === true);
62
130
  }
63
131
  exports.isTrue = isTrue;
64
- function isUndefined(value) {
65
- return (value === undefined);
66
- }
67
- exports.isUndefined = isUndefined;
68
- function isUndefinedOrNull(value) {
69
- return (value === undefined) || (value === null);
70
- }
71
- exports.isUndefinedOrNull = isUndefinedOrNull;
72
132
  function hasProperty(obj, property) {
73
133
  return isDefined(obj) && isObject(obj) && Object.prototype.hasOwnProperty.call(obj, property);
74
134
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "API Games Limited",
4
4
  "description": "API Games JSON Utilities",
5
5
  "license": "MIT",
6
- "version": "22.1.0-dev.3",
6
+ "version": "22.1.0-dev.7",
7
7
  "main": "lib/index.js",
8
8
  "types": "lib/index.d.ts",
9
9
  "scripts": {
@@ -28,17 +28,17 @@
28
28
  "lodash.clonedeep": "4.5.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/jest": "27.0.3",
32
- "@types/node": "14.18.0",
33
- "@typescript-eslint/eslint-plugin": "5.7.0",
34
- "@typescript-eslint/parser": "5.7.0",
35
- "eslint": "8.4.1",
36
- "eslint-config-airbnb": "19.0.2",
37
- "eslint-plugin-import": "2.25.3",
31
+ "@types/jest": "27.4.0",
32
+ "@types/node": "14.18.5",
33
+ "@typescript-eslint/eslint-plugin": "5.9.1",
34
+ "@typescript-eslint/parser": "5.9.1",
35
+ "eslint": "8.6.0",
36
+ "eslint-config-airbnb": "19.0.4",
37
+ "eslint-plugin-import": "2.25.4",
38
38
  "eslint-plugin-jsx-a11y": "6.5.1",
39
- "eslint-plugin-react": "7.27.1",
39
+ "eslint-plugin-react": "7.28.0",
40
40
  "eslint-plugin-react-hooks": "4.3.0",
41
- "jest": "27.4.5",
41
+ "jest": "27.4.7",
42
42
  "ts-jest": "27.1.2",
43
43
  "typescript": "4.5.4"
44
44
  },
@@ -0,0 +1,7 @@
1
+ export CODACY_API_TOKEN=zLmkgxu0V5R3qEbGrbbm
2
+ export CODACY_ORGANIZATION_PROVIDER=gh
3
+ export CODACY_USERNAME=apigames-public
4
+ export CODACY_PROJECT_NAME=json
5
+
6
+ bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage/clover.xml
7
+