@esm-test/guards 1.0.0-beta.3 → 1.0.0-beta.5
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/CHANGELOG.md +4 -0
- package/README.md +8 -2
- package/index.d.ts +1 -1
- package/legacy/src/guardComplexObject.cjs +30 -0
- package/legacy/src/guardComplexObject.cjs.map +1 -0
- package/legacy/src/guardInstance.cjs +44 -0
- package/legacy/src/guardInstance.cjs.map +1 -0
- package/legacy/src/guardNull.cjs +20 -0
- package/legacy/src/guardNull.cjs.map +1 -0
- package/legacy/src/guardObjectKey.cjs +22 -0
- package/legacy/src/guardObjectKey.cjs.map +1 -0
- package/legacy/src/guardType.cjs +22 -0
- package/legacy/src/guardType.cjs.map +1 -0
- package/legacy/src/guardUndefined.cjs +20 -0
- package/legacy/src/guardUndefined.cjs.map +1 -0
- package/legacy/src/index.cjs +23 -0
- package/legacy/src/index.cjs.map +1 -0
- package/package.json +10 -8
- package/src/guardComplexObject.js +12 -8
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://gitlab.com/esm-test-group/esm-test-guards/-/pipelines)
|
|
4
4
|
[](http://opensource.org/licenses/ISC)
|
|
5
|
-
[](https://www.npmjs.org/package/@esm-test/guards)
|
|
6
|
+
[](https://npmjs.org/package/@esm-test/guards "View this project on NPM")
|
|
7
7
|
|
|
8
8
|
[](https://www.buymeacoffee.com/peterf)
|
|
9
|
+
|
|
10
|
+
A js utility library for guarding objects, instances and types
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @esm-test/guards
|
|
14
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isComplexObject = exports.throwNotComplexObject = exports.notComplexObjectMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} guardName
|
|
6
|
+
*/
|
|
7
|
+
const notComplexObjectMessage = (guardName) => (`'${guardName}' must be a complex object`);
|
|
8
|
+
exports.notComplexObjectMessage = notComplexObjectMessage;
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} guardName
|
|
11
|
+
* @param {object} guard
|
|
12
|
+
*/
|
|
13
|
+
const throwNotComplexObject = (guardName, guard) => {
|
|
14
|
+
if ((0, exports.isComplexObject)(guard) === false) {
|
|
15
|
+
throw new Error((0, exports.notComplexObjectMessage)(guardName));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.throwNotComplexObject = throwNotComplexObject;
|
|
19
|
+
/**
|
|
20
|
+
* @param {object} value
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
const isComplexObject = (value) => {
|
|
24
|
+
const isDefined = value !== undefined && value !== null;
|
|
25
|
+
return isDefined
|
|
26
|
+
&& value.constructor
|
|
27
|
+
&& value.constructor === Object;
|
|
28
|
+
};
|
|
29
|
+
exports.isComplexObject = isComplexObject;
|
|
30
|
+
//# sourceMappingURL=guardComplexObject.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardComplexObject.cjs","sourceRoot":"","sources":["../../src/guardComplexObject.js"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,uBAAuB,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CACpD,IAAI,SAAS,4BAA4B,CAC1C,CAAA;AAFY,QAAA,uBAAuB,2BAEnC;AAED;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;IACxD,IAAI,IAAA,uBAAe,EAAC,KAAK,CAAC,KAAK,KAAK,EAAE;QACpC,MAAM,IAAI,KAAK,CAAC,IAAA,+BAAuB,EAAC,SAAS,CAAC,CAAC,CAAC;KACrD;AACH,CAAC,CAAA;AAJY,QAAA,qBAAqB,yBAIjC;AAED;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,EAAE;IACvC,MAAM,SAAS,GAAG,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;IACxD,OAAO,SAAS;WACX,KAAK,CAAC,WAAW;WACjB,KAAK,CAAC,WAAW,KAAK,MAAM,CAAC;AACpC,CAAC,CAAA;AALY,QAAA,eAAe,mBAK3B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwNotAnyInstance = exports.notAnyInstanceMessage = exports.throwNotInstance = exports.notInstanceMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} guardName
|
|
6
|
+
* @param {Object} guardType
|
|
7
|
+
*/
|
|
8
|
+
const notInstanceMessage = (guardName, guardType) => (`'${guardName}' must be an instance of '${guardType.name}'`);
|
|
9
|
+
exports.notInstanceMessage = notInstanceMessage;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} guardName
|
|
12
|
+
* @param {object} guard
|
|
13
|
+
* @param {Object} guardType
|
|
14
|
+
*/
|
|
15
|
+
const throwNotInstance = (guardName, guard, guardType) => {
|
|
16
|
+
const isInstance = guard instanceof guardType;
|
|
17
|
+
if (isInstance === false) {
|
|
18
|
+
throw new Error((0, exports.notInstanceMessage)(guardName, guardType));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.throwNotInstance = throwNotInstance;
|
|
22
|
+
/**
|
|
23
|
+
* @param {object} guardInstance
|
|
24
|
+
* @param {Object[]} guardTypes
|
|
25
|
+
*/
|
|
26
|
+
const notAnyInstanceMessage = (guardInstance, ...guardTypes) => {
|
|
27
|
+
const typeNames = guardTypes.map(t => t.name).join('|');
|
|
28
|
+
return `'${guardInstance.constructor.name}' must be an instance of either '${typeNames}'`;
|
|
29
|
+
};
|
|
30
|
+
exports.notAnyInstanceMessage = notAnyInstanceMessage;
|
|
31
|
+
/**
|
|
32
|
+
* @param {object} guardInstance
|
|
33
|
+
* @param {Object[]} guardTypes
|
|
34
|
+
*/
|
|
35
|
+
const throwNotAnyInstance = (guardInstance, ...guardTypes) => {
|
|
36
|
+
for (let i = 0; i < guardTypes.length; i++) {
|
|
37
|
+
const isInstance = guardInstance instanceof guardTypes[i];
|
|
38
|
+
if (isInstance)
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
throw new Error((0, exports.notAnyInstanceMessage)(guardInstance, ...guardTypes));
|
|
42
|
+
};
|
|
43
|
+
exports.throwNotAnyInstance = throwNotAnyInstance;
|
|
44
|
+
//# sourceMappingURL=guardInstance.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardInstance.cjs","sourceRoot":"","sources":["../../src/guardInstance.js"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAC1D,IAAI,SAAS,6BAA6B,SAAS,CAAC,IAAI,GAAG,CAC5D,CAAA;AAFY,QAAA,kBAAkB,sBAE9B;AAED;;;;GAIG;AACI,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;IAC9D,MAAM,UAAU,GAAG,KAAK,YAAY,SAAS,CAAC;IAC9C,IAAI,UAAU,KAAK,KAAK,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,IAAA,0BAAkB,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;KAC3D;AACH,CAAC,CAAA;AALY,QAAA,gBAAgB,oBAK5B;AAED;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,aAAa,EAAE,GAAG,UAAU,EAAE,EAAE;IACpE,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxD,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,oCAAoC,SAAS,GAAG,CAAA;AAC3F,CAAC,CAAA;AAHY,QAAA,qBAAqB,yBAGjC;AAED;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CAAC,aAAa,EAAE,GAAG,UAAU,EAAE,EAAE;IAClE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,UAAU,GAAG,aAAa,YAAY,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1D,IAAI,UAAU;YAAE,OAAO;KACxB;IACD,MAAM,IAAI,KAAK,CACb,IAAA,6BAAqB,EAAC,aAAa,EAAE,GAAG,UAAU,CAAC,CACpD,CAAC;AACJ,CAAC,CAAA;AARY,QAAA,mBAAmB,uBAQ/B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwNull = exports.nullMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} guardName
|
|
6
|
+
*/
|
|
7
|
+
const nullMessage = (guardName) => `${guardName} is null`;
|
|
8
|
+
exports.nullMessage = nullMessage;
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} guardName
|
|
11
|
+
* @param {object} guard
|
|
12
|
+
*/
|
|
13
|
+
const throwNull = (guardName, guard) => {
|
|
14
|
+
const isNull = guard !== null;
|
|
15
|
+
if (isNull === false) {
|
|
16
|
+
throw new Error((0, exports.nullMessage)(guardName));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.throwNull = throwNull;
|
|
20
|
+
//# sourceMappingURL=guardNull.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardNull.cjs","sourceRoot":"","sources":["../../src/guardNull.js"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,SAAS,UAAU,CAAC;AAApD,QAAA,WAAW,eAAyC;AAEjE;;;GAGG;AACI,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;IAC5C,MAAM,MAAM,GAAG,KAAK,KAAK,IAAI,CAAC;IAC9B,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,IAAA,mBAAW,EAAC,SAAS,CAAC,CAAC,CAAC;KACzC;AACH,CAAC,CAAA;AALY,QAAA,SAAS,aAKrB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwNotObjectKey = exports.notObjectKeyMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} guardName
|
|
6
|
+
* @param {object} guard
|
|
7
|
+
*/
|
|
8
|
+
const notObjectKeyMessage = (guardName, guard) => (`'${guardName}' must be one of '${Object.keys(guard).join(', ')}'`);
|
|
9
|
+
exports.notObjectKeyMessage = notObjectKeyMessage;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} guardName
|
|
12
|
+
* @param {object} guard
|
|
13
|
+
* @param {string} guardObjectKey
|
|
14
|
+
*/
|
|
15
|
+
const throwNotObjectKey = (guardName, guard, guardObjectKey) => {
|
|
16
|
+
const hasKey = Object.hasOwn(guard, guardObjectKey);
|
|
17
|
+
if (hasKey === false) {
|
|
18
|
+
throw new Error((0, exports.notObjectKeyMessage)(guardName, guard));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.throwNotObjectKey = throwNotObjectKey;
|
|
22
|
+
//# sourceMappingURL=guardObjectKey.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardObjectKey.cjs","sourceRoot":"","sources":["../../src/guardObjectKey.js"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,CACvD,IAAI,SAAS,qBAAqB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACnE,CAAA;AAFY,QAAA,mBAAmB,uBAE/B;AAED;;;;GAIG;AACI,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;IACpE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACpD,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,IAAA,2BAAmB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;KACxD;AACH,CAAC,CAAA;AALY,QAAA,iBAAiB,qBAK7B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwNotType = exports.notTypeMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} guardName
|
|
6
|
+
* @param {string} guardType
|
|
7
|
+
*/
|
|
8
|
+
const notTypeMessage = (guardName, guardType) => (`'${guardName}' must be a type of '${guardType}'`);
|
|
9
|
+
exports.notTypeMessage = notTypeMessage;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} guardName
|
|
12
|
+
* @param {object} guard
|
|
13
|
+
* @param {string} guardType
|
|
14
|
+
*/
|
|
15
|
+
const throwNotType = (guardName, guard, guardType) => {
|
|
16
|
+
const isType = typeof guard === guardType;
|
|
17
|
+
if (isType === false) {
|
|
18
|
+
throw new Error((0, exports.notTypeMessage)(guardName, guardType));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.throwNotType = throwNotType;
|
|
22
|
+
//# sourceMappingURL=guardType.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardType.cjs","sourceRoot":"","sources":["../../src/guardType.js"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CACtD,IAAI,SAAS,wBAAwB,SAAS,GAAG,CAClD,CAAA;AAFY,QAAA,cAAc,kBAE1B;AAED;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;IAC1D,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,SAAS,CAAC;IAC1C,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,IAAA,sBAAc,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;KACvD;AACH,CAAC,CAAA;AALY,QAAA,YAAY,gBAKxB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwUndefined = exports.undefinedMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} guardName
|
|
6
|
+
*/
|
|
7
|
+
const undefinedMessage = (guardName) => `${guardName} is not defined`;
|
|
8
|
+
exports.undefinedMessage = undefinedMessage;
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} guardName
|
|
11
|
+
* @param {object} guard
|
|
12
|
+
*/
|
|
13
|
+
const throwUndefined = (guardName, guard) => {
|
|
14
|
+
const isDefined = guard !== undefined;
|
|
15
|
+
if (isDefined === false) {
|
|
16
|
+
throw new Error((0, exports.undefinedMessage)(guardName));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.throwUndefined = throwUndefined;
|
|
20
|
+
//# sourceMappingURL=guardUndefined.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardUndefined.cjs","sourceRoot":"","sources":["../../src/guardUndefined.js"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,SAAS,iBAAiB,CAAC;AAAhE,QAAA,gBAAgB,oBAAgD;AAE7E;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;IACjD,MAAM,SAAS,GAAG,KAAK,KAAK,SAAS,CAAC;IACtC,IAAI,SAAS,KAAK,KAAK,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,IAAA,wBAAgB,EAAC,SAAS,CAAC,CAAC,CAAC;KAC9C;AACH,CAAC,CAAA;AALY,QAAA,cAAc,kBAK1B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./guardComplexObject.cjs"), exports);
|
|
18
|
+
__exportStar(require("./guardObjectKey.cjs"), exports);
|
|
19
|
+
__exportStar(require("./guardInstance.cjs"), exports);
|
|
20
|
+
__exportStar(require("./guardNull.cjs"), exports);
|
|
21
|
+
__exportStar(require("./guardType.cjs"), exports);
|
|
22
|
+
__exportStar(require("./guardUndefined.cjs"), exports);
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,sDAAoC;AACpC,qDAAmC;AACnC,iDAA+B;AAC/B,iDAA+B;AAC/B,sDAAoC"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esm-test/guards",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "A js library for
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
|
+
"description": "A js utility library for guarding objects, instances and types",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"main": "./src/index.
|
|
8
|
+
"main": "./legacy/src/index.cjs",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"types": "./index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
"import": "./src/index.js",
|
|
13
|
+
"require": "./legacy/src/index.cjs",
|
|
13
14
|
"types": "./index.d.ts"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"@types/mocha": "10.0.1",
|
|
17
|
-
"@types/node": "
|
|
18
|
+
"@types/node": "20.5.3",
|
|
18
19
|
"assert": "2.0.0",
|
|
19
|
-
"c8": "
|
|
20
|
+
"c8": "8.0.1",
|
|
20
21
|
"js-yaml": "4.1.0",
|
|
21
22
|
"jshint": "2.13.6",
|
|
22
23
|
"mocha": "10.2.0",
|
|
23
24
|
"mocha-ui-esm": "1.0.0-beta.14",
|
|
24
|
-
"npm-build-tasks": "1.0.0-alpha.
|
|
25
|
-
"rimraf": "
|
|
25
|
+
"npm-build-tasks": "1.0.0-alpha.10",
|
|
26
|
+
"rimraf": "5.0.1",
|
|
26
27
|
"source-map-support": "0.5.21",
|
|
27
|
-
"typescript": "
|
|
28
|
+
"typescript": "5.1.6"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
31
|
"clean": "rimraf ./out",
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"fresh": "npm-build-task",
|
|
33
34
|
"generate:types": "npm-build-task",
|
|
34
35
|
"test": "npm-build-task",
|
|
36
|
+
"transform:legacy": "npm-build-task",
|
|
35
37
|
"prepublishOnly": "npm-build-task"
|
|
36
38
|
},
|
|
37
39
|
"author": "pflannery",
|
|
@@ -10,14 +10,18 @@ export const notComplexObjectMessage = (guardName) => (
|
|
|
10
10
|
* @param {object} guard
|
|
11
11
|
*/
|
|
12
12
|
export const throwNotComplexObject = (guardName, guard) => {
|
|
13
|
-
|
|
14
|
-
const isType = isDefined && typeof guard === "object";
|
|
15
|
-
const isComplexObject = isDefined
|
|
16
|
-
&& isType
|
|
17
|
-
&& guard.constructor
|
|
18
|
-
&& guard.constructor === Object;
|
|
19
|
-
|
|
20
|
-
if (isComplexObject === false) {
|
|
13
|
+
if (isComplexObject(guard) === false) {
|
|
21
14
|
throw new Error(notComplexObjectMessage(guardName));
|
|
22
15
|
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {object} value
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export const isComplexObject = (value) => {
|
|
23
|
+
const isDefined = value !== undefined && value !== null;
|
|
24
|
+
return isDefined
|
|
25
|
+
&& value.constructor
|
|
26
|
+
&& value.constructor === Object;
|
|
23
27
|
}
|