@esm-test/guards 1.0.0-beta.4 → 1.0.0-beta.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/CHANGELOG.md CHANGED
@@ -1,11 +1,23 @@
1
- # 1.0.0-beta.3
2
-
3
- - moved package to @esm-test npm org
4
-
5
- # 1.0.0-beta.2
6
-
7
- - Fixed package repo link
8
-
9
- # 1.0.0-beta.1
10
-
1
+ # 1.0.0-beta.6
2
+
3
+ - added throwEmpty (for strings)
4
+
5
+ - added aggregate guards
6
+ - throwUndefinedOrNull
7
+ - throwNotSetOrEmpty
8
+
9
+ # 1.0.0-beta.5
10
+
11
+ - added cjs dist output
12
+
13
+ # 1.0.0-beta.3
14
+
15
+ - moved package to @esm-test npm org
16
+
17
+ # 1.0.0-beta.2
18
+
19
+ - Fixed package repo link
20
+
21
+ # 1.0.0-beta.1
22
+
11
23
  - init commit extracted from [esm-test-parser](https://gitlab.com/esm-test-group/esm-test-parser)
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![Pipeline status](https://gitlab.com/esm-test-group/esm-test-guards/badges/master/pipeline.svg)](https://gitlab.com/esm-test-group/esm-test-guards/-/pipelines)
4
4
  [![The ISC license](https://img.shields.io/badge/license-ISC-orange.png?color=blue&style=flat-square)](http://opensource.org/licenses/ISC)
5
- [![NPM version](https://img.shields.io/npm/v/esm-test-guards.svg)](https://www.npmjs.org/package/esm-test-guards)
6
- [![NPM downloads](https://img.shields.io/npm/dm/esm-test-guards.svg)](https://npmjs.org/package/esm-test-guards "View this project on NPM")
5
+ [![NPM version](https://img.shields.io/npm/v/@esm-test/guards.svg)](https://www.npmjs.org/package/@esm-test/guards)
6
+ [![NPM downloads](https://img.shields.io/npm/dm/@esm-test/guards.svg)](https://npmjs.org/package/@esm-test/guards "View this project on NPM")
7
7
 
8
8
  [![BuyMeACoffee](https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png)](https://www.buymeacoffee.com/peterf)
9
9
 
package/index.d.ts CHANGED
@@ -1,23 +1,31 @@
1
- declare module '@esm-test/guards' {
2
-
3
- export function notComplexObjectMessage(guardName: string): string;
4
- export function throwNotComplexObject(guardName: string, guard: object): void;
5
-
6
- export function notInstanceMessage(guardName: string, guardType: Object): string;
7
- export function throwNotInstance(guardName: string, guard: object, guardType: Object): void;
8
- export function notAnyInstanceMessage(guardInstance: object, ...guardTypes: Object[]): string;
9
- export function throwNotAnyInstance(guardInstance: object, ...guardTypes: Object[]): void;
10
-
11
- export function nullMessage(guardName: string): string;
12
- export function throwNull(guardName: string, guard: object): void;
13
-
14
- export function notObjectKeyMessage(guardName: string, guard: object): string;
15
- export function throwNotObjectKey(guardName: string, guard: object, guardObjectKey: string): void;
16
-
17
- export function notTypeMessage(guardName: string, guardType: string): string;
18
- export function throwNotType(guardName: string, guard: object, guardType: string): void;
19
-
20
- export function undefinedMessage(guardName: string): string;
21
- export function throwUndefined(guardName: string, guard: object): void;
22
-
1
+ declare module '@esm-test/guards' {
2
+
3
+ export function notComplexObjectMessage(guardName: string): string;
4
+ export function throwNotComplexObject(guardName: string, guard: object): void;
5
+
6
+ export function notInstanceMessage(guardName: string, guardType: Object): string;
7
+ export function throwNotInstance(guardName: string, guard: object, guardType: Object): void;
8
+ export function notAnyInstanceMessage(guardInstance: object, ...guardTypes: Object[]): string;
9
+ export function throwNotAnyInstance(guardInstance: object, ...guardTypes: Object[]): void;
10
+
11
+ export function notObjectKeyMessage(guardName: string, guard: object): string;
12
+ export function throwNotObjectKey(guardName: string, guard: object, guardObjectKey: string): void;
13
+
14
+ export function notTypeMessage(guardName: string, guardType: string): string;
15
+ export function throwNotType(guardName: string, guard: object, guardType: string): void;
16
+
17
+ export type TGuardable = object | string | number | boolean | bigint | symbol | null | undefined;
18
+
19
+ export function nullMessage(guardName: string): string;
20
+ export function throwNull(guardName: string, guard: TGuardable): void;
21
+
22
+ export function undefinedMessage(guardName: string): string;
23
+ export function throwUndefined(guardName: string, guard: TGuardable): void;
24
+
25
+ export function emptyMessage(guardName: string): string;
26
+ export function throwEmpty(guardName: string, guard: string): void;
27
+
28
+ export function throwUndefinedOrNull(guardName: string, guard: TGuardable): void;
29
+ export function throwNotSetOrEmpty(guardName: string, guard: string): void;
30
+
23
31
  }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwNotStringOrEmpty = exports.throwUndefinedOrNull = void 0;
4
+ const guardEmpty_js_1 = require("./guardEmpty.cjs");
5
+ const guardNull_js_1 = require("./guardNull.cjs");
6
+ const guardType_js_1 = require("./guardType.cjs");
7
+ const guardUndefined_js_1 = require("./guardUndefined.cjs");
8
+ /**
9
+ * @param {string} guardName
10
+ * @param {import("@esm-test/guards").TGuardable} guard
11
+ */
12
+ const throwUndefinedOrNull = (guardName, guard) => {
13
+ (0, guardUndefined_js_1.throwUndefined)(guardName, guard);
14
+ (0, guardNull_js_1.throwNull)(guardName, guard);
15
+ };
16
+ exports.throwUndefinedOrNull = throwUndefinedOrNull;
17
+ /**
18
+ * @param {string} guardName
19
+ * @param {string} guard
20
+ */
21
+ const throwNotStringOrEmpty = (guardName, guard) => {
22
+ (0, guardUndefined_js_1.throwUndefined)(guardName, guard);
23
+ (0, guardNull_js_1.throwNull)(guardName, guard);
24
+ (0, guardType_js_1.throwNotType)(guardName, guard, 'string');
25
+ (0, guardEmpty_js_1.throwEmpty)(guardName, guard);
26
+ };
27
+ exports.throwNotStringOrEmpty = throwNotStringOrEmpty;
28
+ //# sourceMappingURL=guardAggregates.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardAggregates.cjs","sourceRoot":"","sources":["../../src/guardAggregates.js"],"names":[],"mappings":";;;AAAA,mDAA6C;AAC7C,iDAA2C;AAC3C,iDAA8C;AAC9C,2DAAqD;AAErD;;;GAGG;AACI,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;IACvD,IAAA,kCAAc,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACjC,IAAA,wBAAS,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAA;AAHY,QAAA,oBAAoB,wBAGhC;AAED;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;IACxD,IAAA,kCAAc,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACjC,IAAA,wBAAS,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5B,IAAA,2BAAY,EAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;IACxC,IAAA,0BAAU,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAA;AALY,QAAA,qBAAqB,yBAKjC"}
@@ -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,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwEmpty = exports.emptyMessage = void 0;
4
+ /**
5
+ * @param {string} guardName
6
+ */
7
+ const emptyMessage = (guardName) => `${guardName} is empty`;
8
+ exports.emptyMessage = emptyMessage;
9
+ /**
10
+ * @param {string} guardName
11
+ * @param {string} guard
12
+ */
13
+ const throwEmpty = (guardName, guard) => {
14
+ const isEmpty = guard === '';
15
+ if (isEmpty) {
16
+ throw new Error((0, exports.emptyMessage)(guardName));
17
+ }
18
+ };
19
+ exports.throwEmpty = throwEmpty;
20
+ //# sourceMappingURL=guardEmpty.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardEmpty.cjs","sourceRoot":"","sources":["../../src/guardEmpty.js"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,SAAS,WAAW,CAAC;AAAtD,QAAA,YAAY,gBAA0C;AAEnE;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;IAC7C,MAAM,OAAO,GAAG,KAAK,KAAK,EAAE,CAAC;IAC7B,IAAI,OAAO,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,IAAA,oBAAY,EAAC,SAAS,CAAC,CAAC,CAAC;KAC1C;AACH,CAAC,CAAA;AALY,QAAA,UAAU,cAKtB"}
@@ -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 {import("@esm-test/guards").TGuardable} 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 {import("@esm-test/guards").TGuardable} 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,25 @@
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("./guardAggregates.cjs"), exports);
18
+ __exportStar(require("./guardComplexObject.cjs"), exports);
19
+ __exportStar(require("./guardEmpty.cjs"), exports);
20
+ __exportStar(require("./guardInstance.cjs"), exports);
21
+ __exportStar(require("./guardNull.cjs"), exports);
22
+ __exportStar(require("./guardObjectKey.cjs"), exports);
23
+ __exportStar(require("./guardType.cjs"), exports);
24
+ __exportStar(require("./guardUndefined.cjs"), exports);
25
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,0DAAwC;AACxC,kDAAgC;AAChC,qDAAmC;AACnC,iDAA+B;AAC/B,sDAAoC;AACpC,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",
3
+ "version": "1.0.0-beta.6",
4
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.js",
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.11.18",
18
+ "@types/node": "20.5.3",
18
19
  "assert": "2.0.0",
19
- "c8": "7.12.0",
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.5",
25
- "rimraf": "4.1.2",
25
+ "npm-build-tasks": "1.0.0-alpha.10",
26
+ "rimraf": "5.0.1",
26
27
  "source-map-support": "0.5.21",
27
- "typescript": "4.9.5"
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",
@@ -0,0 +1,24 @@
1
+ import { throwEmpty } from "./guardEmpty.js";
2
+ import { throwNull } from "./guardNull.js";
3
+ import { throwNotType } from "./guardType.js";
4
+ import { throwUndefined } from "./guardUndefined.js";
5
+
6
+ /**
7
+ * @param {string} guardName
8
+ * @param {import("@esm-test/guards").TGuardable} guard
9
+ */
10
+ export const throwUndefinedOrNull = (guardName, guard) => {
11
+ throwUndefined(guardName, guard);
12
+ throwNull(guardName, guard);
13
+ }
14
+
15
+ /**
16
+ * @param {string} guardName
17
+ * @param {string} guard
18
+ */
19
+ export const throwNotStringOrEmpty = (guardName, guard) => {
20
+ throwUndefined(guardName, guard);
21
+ throwNull(guardName, guard);
22
+ throwNotType(guardName, guard, 'string')
23
+ throwEmpty(guardName, guard);
24
+ }
@@ -10,14 +10,18 @@ export const notComplexObjectMessage = (guardName) => (
10
10
  * @param {object} guard
11
11
  */
12
12
  export const throwNotComplexObject = (guardName, guard) => {
13
- const isDefined = guard !== undefined && guard !== null;
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
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @param {string} guardName
3
+ */
4
+ export const emptyMessage = (guardName) => `${guardName} is empty`;
5
+
6
+ /**
7
+ * @param {string} guardName
8
+ * @param {string} guard
9
+ */
10
+ export const throwEmpty = (guardName, guard) => {
11
+ const isEmpty = guard === '';
12
+ if (isEmpty) {
13
+ throw new Error(emptyMessage(guardName));
14
+ }
15
+ }
package/src/guardNull.js CHANGED
@@ -5,7 +5,7 @@ export const nullMessage = (guardName) => `${guardName} is null`;
5
5
 
6
6
  /**
7
7
  * @param {string} guardName
8
- * @param {object} guard
8
+ * @param {import("@esm-test/guards").TGuardable} guard
9
9
  */
10
10
  export const throwNull = (guardName, guard) => {
11
11
  const isNull = guard !== null;
@@ -5,7 +5,7 @@ export const undefinedMessage = (guardName) => `${guardName} is not defined`;
5
5
 
6
6
  /**
7
7
  * @param {string} guardName
8
- * @param {object} guard
8
+ * @param {import("@esm-test/guards").TGuardable} guard
9
9
  */
10
10
  export const throwUndefined = (guardName, guard) => {
11
11
  const isDefined = guard !== undefined;
package/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
+ export * from './guardAggregates.js';
1
2
  export * from './guardComplexObject.js';
2
- export * from './guardObjectKey.js';
3
+ export * from './guardEmpty.js';
3
4
  export * from './guardInstance.js';
4
5
  export * from './guardNull.js';
6
+ export * from './guardObjectKey.js';
5
7
  export * from './guardType.js';
6
8
  export * from './guardUndefined.js';