@esm-test/guards 1.0.0-beta.5 → 1.0.0-beta.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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # 1.0.0-beta.7
2
+
3
+ - fixed index.d.ts fn name for throwNotStringOrEmpty
4
+
5
+ # 1.0.0-beta.6
6
+
7
+ - added throwEmpty (for strings)
8
+
9
+ - added aggregate guards
10
+ - throwUndefinedOrNull
11
+ - throwNotSetOrEmpty
12
+
13
+ # 1.0.0-beta.5
14
+
15
+ - added cjs dist output
16
+
1
17
  # 1.0.0-beta.3
2
18
 
3
19
  - moved package to @esm-test npm org
package/index.d.ts CHANGED
@@ -8,16 +8,24 @@ declare module '@esm-test/guards' {
8
8
  export function notAnyInstanceMessage(guardInstance: object, ...guardTypes: Object[]): string;
9
9
  export function throwNotAnyInstance(guardInstance: object, ...guardTypes: Object[]): void;
10
10
 
11
- export function nullMessage(guardName: string): string;
12
- export function throwNull(guardName: string, guard: object): void;
13
-
14
11
  export function notObjectKeyMessage(guardName: string, guard: object): string;
15
12
  export function throwNotObjectKey(guardName: string, guard: object, guardObjectKey: string): void;
16
-
13
+
17
14
  export function notTypeMessage(guardName: string, guardType: string): string;
18
15
  export function throwNotType(guardName: string, guard: object, guardType: string): void;
19
-
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
+
20
22
  export function undefinedMessage(guardName: string): string;
21
- export function throwUndefined(guardName: string, guard: object): void;
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 throwNotStringOrEmpty(guardName: string, guard: string): void;
22
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,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"}
@@ -8,7 +8,7 @@ const nullMessage = (guardName) => `${guardName} is null`;
8
8
  exports.nullMessage = nullMessage;
9
9
  /**
10
10
  * @param {string} guardName
11
- * @param {object} guard
11
+ * @param {import("@esm-test/guards").TGuardable} guard
12
12
  */
13
13
  const throwNull = (guardName, guard) => {
14
14
  const isNull = guard !== null;
@@ -8,7 +8,7 @@ const undefinedMessage = (guardName) => `${guardName} is not defined`;
8
8
  exports.undefinedMessage = undefinedMessage;
9
9
  /**
10
10
  * @param {string} guardName
11
- * @param {object} guard
11
+ * @param {import("@esm-test/guards").TGuardable} guard
12
12
  */
13
13
  const throwUndefined = (guardName, guard) => {
14
14
  const isDefined = guard !== undefined;
@@ -14,10 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./guardAggregates.cjs"), exports);
17
18
  __exportStar(require("./guardComplexObject.cjs"), exports);
18
- __exportStar(require("./guardObjectKey.cjs"), exports);
19
+ __exportStar(require("./guardEmpty.cjs"), exports);
19
20
  __exportStar(require("./guardInstance.cjs"), exports);
20
21
  __exportStar(require("./guardNull.cjs"), exports);
22
+ __exportStar(require("./guardObjectKey.cjs"), exports);
21
23
  __exportStar(require("./guardType.cjs"), exports);
22
24
  __exportStar(require("./guardUndefined.cjs"), exports);
23
25
  //# sourceMappingURL=index.cjs.map
@@ -1 +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"}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@esm-test/guards",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "A js utility library for guarding objects, instances and types",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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
+ }
@@ -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';