@esm-test/guards 1.0.0-beta.10

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +67 -0
  3. package/dist/index.min.js +2 -0
  4. package/dist/index.min.js.map +7 -0
  5. package/dist/types/src/guardAggregates.d.ts +17 -0
  6. package/dist/types/src/guardAggregates.d.ts.map +1 -0
  7. package/dist/types/src/guardComplexObject.d.ts +25 -0
  8. package/dist/types/src/guardComplexObject.d.ts.map +1 -0
  9. package/dist/types/src/guardEmpty.d.ts +16 -0
  10. package/dist/types/src/guardEmpty.d.ts.map +1 -0
  11. package/dist/types/src/guardInstance.d.ts +38 -0
  12. package/dist/types/src/guardInstance.d.ts.map +1 -0
  13. package/dist/types/src/guardNull.d.ts +16 -0
  14. package/dist/types/src/guardNull.d.ts.map +1 -0
  15. package/dist/types/src/guardObjectKey.d.ts +18 -0
  16. package/dist/types/src/guardObjectKey.d.ts.map +1 -0
  17. package/dist/types/src/guardType.d.ts +22 -0
  18. package/dist/types/src/guardType.d.ts.map +1 -0
  19. package/dist/types/src/guardUndefined.d.ts +16 -0
  20. package/dist/types/src/guardUndefined.d.ts.map +1 -0
  21. package/dist/types/src/index.d.ts +9 -0
  22. package/dist/types/src/index.d.ts.map +1 -0
  23. package/legacy/src/guardAggregates.cjs +32 -0
  24. package/legacy/src/guardAggregates.cjs.map +1 -0
  25. package/legacy/src/guardComplexObject.cjs +40 -0
  26. package/legacy/src/guardComplexObject.cjs.map +1 -0
  27. package/legacy/src/guardEmpty.cjs +25 -0
  28. package/legacy/src/guardEmpty.cjs.map +1 -0
  29. package/legacy/src/guardInstance.cjs +56 -0
  30. package/legacy/src/guardInstance.cjs.map +1 -0
  31. package/legacy/src/guardNull.cjs +26 -0
  32. package/legacy/src/guardNull.cjs.map +1 -0
  33. package/legacy/src/guardObjectKey.cjs +28 -0
  34. package/legacy/src/guardObjectKey.cjs.map +1 -0
  35. package/legacy/src/guardType.cjs +28 -0
  36. package/legacy/src/guardType.cjs.map +1 -0
  37. package/legacy/src/guardUndefined.cjs +26 -0
  38. package/legacy/src/guardUndefined.cjs.map +1 -0
  39. package/legacy/src/index.cjs +25 -0
  40. package/legacy/src/index.cjs.map +1 -0
  41. package/package.json +56 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # 1.0.0-beta.10
2
+
3
+ - updated source to typescript 5.9.3
4
+
5
+ # 1.0.0-beta.9
6
+
7
+ - updated deps
8
+
9
+ # 1.0.0-beta.8
10
+
11
+ - removed undefined and null checks from throwNotStringOrEmpty
12
+
13
+ # 1.0.0-beta.7
14
+
15
+ - fixed index.d.ts fn name for throwNotStringOrEmpty
16
+
17
+ # 1.0.0-beta.6
18
+
19
+ - added throwEmpty (for strings)
20
+
21
+ - added aggregate guards
22
+ - throwUndefinedOrNull
23
+ - throwNotSetOrEmpty
24
+
25
+ # 1.0.0-beta.5
26
+
27
+ - added cjs dist output
28
+
29
+ # 1.0.0-beta.3
30
+
31
+ - moved package to @esm-test npm org
32
+
33
+ # 1.0.0-beta.2
34
+
35
+ - Fixed package repo link
36
+
37
+ # 1.0.0-beta.1
38
+
39
+ - init commit extracted from [esm-test-parser](https://gitlab.com/esm-test-group/esm-test-parser)
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Esm test guards
2
+
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
+ [![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")
7
+
8
+ [![BuyMeACoffee](https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png)](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
+ ```
15
+
16
+ ## Usage
17
+
18
+ This library provides a set of utility functions to perform runtime checks and throw errors if the conditions are not met.
19
+
20
+ ### Type Guarding
21
+
22
+ ```typescript
23
+ import { throwNotType } from '@esm-test/guards';
24
+
25
+ const myVar: any = 123;
26
+ throwNotType('myVar', myVar, 'string'); // Throws Error: 'myVar' must be a type of 'string'
27
+ ```
28
+
29
+ ### Null and Undefined
30
+
31
+ ```typescript
32
+ import { throwUndefinedOrNull, throwNull, throwUndefined } from '@esm-test/guards';
33
+
34
+ throwNull('myVar', null); // Throws Error: myVar is null
35
+ throwUndefined('myVar', undefined); // Throws Error: myVar is not defined
36
+ throwUndefinedOrNull('myVar', null); // Throws Error: myVar is null
37
+ ```
38
+
39
+ ### Instances
40
+
41
+ ```typescript
42
+ import { throwNotInstance } from '@esm-test/guards';
43
+
44
+ class MyClass {}
45
+ const instance = new MyClass();
46
+
47
+ throwNotInstance('instance', {}, MyClass); // Throws Error: 'instance' must be an instance of 'MyClass'
48
+ ```
49
+
50
+ ### Complex Objects
51
+
52
+ Checks if a value is a plain object (not null, and constructor is `Object`).
53
+
54
+ ```typescript
55
+ import { throwNotComplexObject } from '@esm-test/guards';
56
+
57
+ throwNotComplexObject('config', []); // Throws Error: 'config' must be a complex object
58
+ ```
59
+
60
+ ### Strings
61
+
62
+ ```typescript
63
+ import { throwNotStringOrEmpty, throwEmpty } from '@esm-test/guards';
64
+
65
+ throwEmpty('name', ''); // Throws Error: name is empty
66
+ throwNotStringOrEmpty('name', 123); // Throws Error: 'name' must be a type of 'string'
67
+ ```
@@ -0,0 +1,2 @@
1
+ var p=t=>`${t} is empty`,s=(t,n)=>{if(n==="")throw new Error(p(t))};var a=t=>`${t} is null`,r=(t,n)=>{if(n!==null===!1)throw new Error(a(t))};var f=(t,n)=>`'${t}' must be a type of '${n}'`,i=(t,n,o)=>{if(typeof n===o===!1)throw new Error(f(t,o))};var y=t=>`${t} is not defined`,c=(t,n)=>{if(n!==void 0===!1)throw new Error(y(t))};var N=(t,n)=>{c(t,n),r(t,n)},O=(t,n)=>{i(t,n,"string"),s(t,n)};var m=t=>`'${t}' must be a complex object`,C=(t,n)=>{if(l(n)===!1)throw new Error(m(t))},l=t=>t!=null&&t.constructor&&t.constructor===Object;var x=(t,n)=>`'${t}' must be an instance of '${n.name}'`,D=(t,n,o)=>{if(n instanceof o===!1)throw new Error(x(t,o))},w=(t,...n)=>{let o=n.map(e=>e.name).join("|");return`'${t.constructor.name}' must be an instance of either '${o}'`},K=(t,...n)=>{for(let o=0;o<n.length;o++)if(t instanceof n[o])return;throw new Error(w(t,...n))};var g=(t,n)=>`'${t}' must be one of '${Object.keys(n).join(", ")}'`,U=(t,n,o)=>{if(Object.hasOwn(n,o)===!1)throw new Error(g(t,n))};export{p as emptyMessage,l as isComplexObject,w as notAnyInstanceMessage,m as notComplexObjectMessage,x as notInstanceMessage,g as notObjectKeyMessage,f as notTypeMessage,a as nullMessage,s as throwEmpty,K as throwNotAnyInstance,C as throwNotComplexObject,D as throwNotInstance,U as throwNotObjectKey,O as throwNotStringOrEmpty,i as throwNotType,r as throwNull,c as throwUndefined,N as throwUndefinedOrNull,y as undefinedMessage};
2
+ //# sourceMappingURL=index.min.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/guardEmpty.ts", "../src/guardNull.ts", "../src/guardType.ts", "../src/guardUndefined.ts", "../src/guardAggregates.ts", "../src/guardComplexObject.ts", "../src/guardInstance.ts", "../src/guardObjectKey.ts"],
4
+ "sourcesContent": ["/**\n * Generates an error message when a string is empty.\n * \n * @param guardName - The name of the variable being guarded.\n * @returns A formatted error message.\n */\nexport const emptyMessage = (guardName: string): string => `${guardName} is empty`;\n\n/**\n * Throws an error if the provided string is empty ('').\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The string to check for emptiness.\n * @throws {Error} Throws an error if `guard` is an empty string.\n */\nexport const throwEmpty = (guardName: string, guard: string): void => {\n const isEmpty = guard === '';\n if (isEmpty) throw new Error(emptyMessage(guardName));\n}", "/**\n * Generates an error message when a value is null.\n * \n * @param guardName - The name of the variable being guarded.\n * @returns A formatted error message.\n */\nexport const nullMessage = (guardName: string): string => `${guardName} is null`;\n\n/**\n * Throws an error if the provided value is null.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The value to check for null.\n * @throws {Error} Throws an error if `guard` is strictly equal to `null`.\n */\nexport const throwNull = (guardName: string, guard: any): void => {\n const isNull = guard !== null;\n if (isNull === false) {\n throw new Error(nullMessage(guardName));\n }\n}", "/**\n * Supported JavaScript types for type guarding.\n */\nexport type Types = \"number\" | \"string\" | \"boolean\" | \"undefined\" | \"function\" | \"object\" | \"bigint\" | \"symbol\";\n\n\n/**\n * Generates a standard error message when a value is not of the expected type.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guardType - The expected type.\n * @returns A formatted error message.\n */\nexport const notTypeMessage = (guardName: string, guardType: Types): string => (\n `'${guardName}' must be a type of '${guardType}'`\n)\n\n/**\n * Throws an error if the provided value is not of the specified type.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The value to check.\n * @param guardType - The expected type.\n * @throws {Error} Throws an error if `typeof guard` does not equal `guardType`.\n */\nexport const throwNotType = (guardName: string, guard: any, guardType: Types): void => {\n const isType = typeof guard === guardType;\n if (isType === false) {\n throw new Error(notTypeMessage(guardName, guardType));\n }\n}", "/**\n * Generates an error message when a value is undefined.\n * \n * @param guardName - The name of the variable being guarded.\n * @returns A formatted error message.\n */\nexport const undefinedMessage = (guardName: string): string => `${guardName} is not defined`;\n\n/**\n * Throws an error if the provided value is undefined.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The value to check for undefined.\n * @throws {Error} Throws an error if `guard` is strictly equal to `undefined`.\n */\nexport const throwUndefined = (guardName: string, guard: any): void => {\n const isDefined = guard !== undefined;\n if (isDefined === false) {\n throw new Error(undefinedMessage(guardName));\n }\n}", "import { throwEmpty } from \"./guardEmpty.js\";\nimport { throwNull } from \"./guardNull.js\";\nimport { throwNotType } from \"./guardType.js\";\nimport { throwUndefined } from \"./guardUndefined.js\";\n\n/**\n * Throws an error if the provided value is undefined or null.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The value to check.\n * @throws {Error} Throws an error if `guard` is `undefined` or `null`.\n */\nexport const throwUndefinedOrNull = (guardName: string, guard: any): void => {\n throwUndefined(guardName, guard);\n throwNull(guardName, guard);\n}\n\n/**\n * Throws an error if the provided value is not a string or is an empty string.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The value to check.\n * @throws {Error} Throws an error if `guard` is not a string or if it's empty ('').\n */\nexport const throwNotStringOrEmpty = (guardName: string, guard: any): void => {\n throwNotType(guardName, guard, 'string')\n throwEmpty(guardName, guard);\n}", "/**\n * Generates an error message when a value is not a complex object.\n * \n * @param guardName - The name of the variable being guarded.\n * @returns A formatted error message.\n */\nexport const notComplexObjectMessage = (guardName: string): string => (\n `'${guardName}' must be a complex object`\n)\n\n/**\n * Throws an error if the provided value is not a complex object.\n * \n * A complex object is defined as a non-null object that is not a primitive and whose constructor is `Object`.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The value to check.\n * @throws {Error} Throws an error if `isComplexObject(guard)` is false.\n */\nexport const throwNotComplexObject = (guardName: string, guard: any): void => {\n if (isComplexObject(guard) === false) {\n throw new Error(notComplexObjectMessage(guardName));\n }\n}\n\n/**\n * Determines if a value is a complex object.\n * \n * @param value - The value to test.\n * @returns `true` if the value is a defined, non-null object with a constructor matching `Object`.\n */\nexport const isComplexObject = (value: any): boolean => {\n const isDefined = value !== undefined && value !== null;\n return isDefined\n && value.constructor\n && value.constructor === Object;\n}", "/**\n * Represents a class constructor type.\n */\nexport type ClassInstance = new (...args: any[]) => void\n\n/**\n * Generates an error message when a value is not an instance of the specified class.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guardType - The expected class constructor.\n * @returns A formatted error message.\n */\nexport const notInstanceMessage = (guardName: string, guardType: ClassInstance): string => (\n `'${guardName}' must be an instance of '${guardType.name}'`\n)\n\n/**\n * Throws an error if the provided value is not an instance of the specified class.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The value to check.\n * @param guardType - The expected class constructor.\n * @throws {Error} Throws an error if `guard instanceof guardType` is false.\n */\nexport const throwNotInstance = (guardName: string, guard: any, guardType: ClassInstance): void => {\n const isInstance = guard instanceof guardType;\n if (isInstance === false) {\n throw new Error(notInstanceMessage(guardName, guardType));\n }\n}\n\n/**\n * Generates an error message when a value is not an instance of any of the specified classes.\n * \n * @param guardInstance - The value that failed the check.\n * @param guardTypes - The expected class constructors.\n * @returns A formatted error message.\n */\nexport const notAnyInstanceMessage = (guardInstance: any, ...guardTypes: ClassInstance[]): string => {\n const typeNames = guardTypes.map(t => t.name).join('|');\n return `'${guardInstance.constructor.name}' must be an instance of either '${typeNames}'`\n}\n\n/**\n * Throws an error if the provided value is not an instance of any of the specified classes.\n * \n * @param guardInstance - The value to check.\n * @param guardTypes - One or more expected class constructors.\n * @throws {Error} Throws an error if `guardInstance` is not an instance of any of the `guardTypes`.\n */\nexport const throwNotAnyInstance = (guardInstance: any, ...guardTypes: ClassInstance[]): void => {\n for (let i = 0; i < guardTypes.length; i++) {\n const isInstance = guardInstance instanceof guardTypes[i];\n if (isInstance) return;\n }\n throw new Error(notAnyInstanceMessage(guardInstance, ...guardTypes));\n}", "/**\n * Generates an error message when a value is not a key of the provided record.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The record containing valid keys.\n * @returns A formatted error message.\n */\nexport const notObjectKeyMessage = (guardName: string, guard: Record<any, any>): string => (\n `'${guardName}' must be one of '${Object.keys(guard).join(', ')}'`\n)\n\n/**\n * Throws an error if the provided key is not present in the given record.\n * \n * @param guardName - The name of the variable being guarded.\n * @param guard - The record to check against.\n * @param guardObjectKey - The key to check for existence in the record.\n * @throws {Error} Throws an error if `Object.hasOwn(guard, guardObjectKey)` is false.\n */\nexport const throwNotObjectKey = (guardName: string, guard: Record<any, any>, guardObjectKey: string): void => {\n const hasKey = Object.hasOwn(guard, guardObjectKey);\n if (hasKey === false) {\n throw new Error(notObjectKeyMessage(guardName, guard));\n }\n}"],
5
+ "mappings": "AAMO,IAAMA,EAAgBC,GAA8B,GAAGA,CAAS,YAS1DC,EAAa,CAACD,EAAmBE,IAAwB,CAEpE,GADgBA,IAAU,GACb,MAAM,IAAI,MAAMH,EAAaC,CAAS,CAAC,CACtD,ECZO,IAAMG,EAAeC,GAA8B,GAAGA,CAAS,WASzDC,EAAY,CAACD,EAAmBE,IAAqB,CAEhE,GADeA,IAAU,OACV,GACb,MAAM,IAAI,MAAMH,EAAYC,CAAS,CAAC,CAE1C,ECPO,IAAMG,EAAiB,CAACC,EAAmBC,IAChD,IAAID,CAAS,wBAAwBC,CAAS,IAWnCC,EAAe,CAACF,EAAmBG,EAAYF,IAA2B,CAErF,GADe,OAAOE,IAAUF,IACjB,GACb,MAAM,IAAI,MAAMF,EAAeC,EAAWC,CAAS,CAAC,CAExD,ECxBO,IAAMG,EAAoBC,GAA8B,GAAGA,CAAS,kBAS9DC,EAAiB,CAACD,EAAmBE,IAAqB,CAErE,GADkBA,IAAU,SACV,GAChB,MAAM,IAAI,MAAMH,EAAiBC,CAAS,CAAC,CAE/C,ECRO,IAAMG,EAAuB,CAACC,EAAmBC,IAAqB,CAC3EC,EAAeF,EAAWC,CAAK,EAC/BE,EAAUH,EAAWC,CAAK,CAC5B,EASaG,EAAwB,CAACJ,EAAmBC,IAAqB,CAC5EI,EAAaL,EAAWC,EAAO,QAAQ,EACvCK,EAAWN,EAAWC,CAAK,CAC7B,ECrBO,IAAMM,EAA2BC,GACtC,IAAIA,CAAS,6BAYFC,EAAwB,CAACD,EAAmBE,IAAqB,CAC5E,GAAIC,EAAgBD,CAAK,IAAM,GAC7B,MAAM,IAAI,MAAMH,EAAwBC,CAAS,CAAC,CAEtD,EAQaG,EAAmBC,GACWA,GAAU,MAE9CA,EAAM,aACNA,EAAM,cAAgB,OCvBtB,IAAMC,EAAqB,CAACC,EAAmBC,IACpD,IAAID,CAAS,6BAA6BC,EAAU,IAAI,IAW7CC,EAAmB,CAACF,EAAmBG,EAAYF,IAAmC,CAEjG,GADmBE,aAAiBF,IACjB,GACjB,MAAM,IAAI,MAAMF,EAAmBC,EAAWC,CAAS,CAAC,CAE5D,EASaG,EAAwB,CAACC,KAAuBC,IAAwC,CACnG,IAAMC,EAAYD,EAAW,IAAIE,GAAKA,EAAE,IAAI,EAAE,KAAK,GAAG,EACtD,MAAO,IAAIH,EAAc,YAAY,IAAI,oCAAoCE,CAAS,GACxF,EASaE,EAAsB,CAACJ,KAAuBC,IAAsC,CAC/F,QAASI,EAAI,EAAGA,EAAIJ,EAAW,OAAQI,IAErC,GADmBL,aAAyBC,EAAWI,CAAC,EACxC,OAElB,MAAM,IAAI,MAAMN,EAAsBC,EAAe,GAAGC,CAAU,CAAC,CACrE,ECjDO,IAAMK,EAAsB,CAACC,EAAmBC,IACrD,IAAID,CAAS,qBAAqB,OAAO,KAAKC,CAAK,EAAE,KAAK,IAAI,CAAC,IAWpDC,EAAoB,CAACF,EAAmBC,EAAyBE,IAAiC,CAE7G,GADe,OAAO,OAAOF,EAAOE,CAAc,IACnC,GACb,MAAM,IAAI,MAAMJ,EAAoBC,EAAWC,CAAK,CAAC,CAEzD",
6
+ "names": ["emptyMessage", "guardName", "throwEmpty", "guard", "nullMessage", "guardName", "throwNull", "guard", "notTypeMessage", "guardName", "guardType", "throwNotType", "guard", "undefinedMessage", "guardName", "throwUndefined", "guard", "throwUndefinedOrNull", "guardName", "guard", "throwUndefined", "throwNull", "throwNotStringOrEmpty", "throwNotType", "throwEmpty", "notComplexObjectMessage", "guardName", "throwNotComplexObject", "guard", "isComplexObject", "value", "notInstanceMessage", "guardName", "guardType", "throwNotInstance", "guard", "notAnyInstanceMessage", "guardInstance", "guardTypes", "typeNames", "t", "throwNotAnyInstance", "i", "notObjectKeyMessage", "guardName", "guard", "throwNotObjectKey", "guardObjectKey"]
7
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Throws an error if the provided value is undefined or null.
3
+ *
4
+ * @param guardName - The name of the variable being guarded.
5
+ * @param guard - The value to check.
6
+ * @throws {Error} Throws an error if `guard` is `undefined` or `null`.
7
+ */
8
+ export declare const throwUndefinedOrNull: (guardName: string, guard: any) => void;
9
+ /**
10
+ * Throws an error if the provided value is not a string or is an empty string.
11
+ *
12
+ * @param guardName - The name of the variable being guarded.
13
+ * @param guard - The value to check.
14
+ * @throws {Error} Throws an error if `guard` is not a string or if it's empty ('').
15
+ */
16
+ export declare const throwNotStringOrEmpty: (guardName: string, guard: any) => void;
17
+ //# sourceMappingURL=guardAggregates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardAggregates.d.ts","sourceRoot":"","sources":["../../../src/guardAggregates.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,WAAW,MAAM,EAAE,OAAO,GAAG,KAAG,IAGpE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,WAAW,MAAM,EAAE,OAAO,GAAG,KAAG,IAGrE,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Generates an error message when a value is not a complex object.
3
+ *
4
+ * @param guardName - The name of the variable being guarded.
5
+ * @returns A formatted error message.
6
+ */
7
+ export declare const notComplexObjectMessage: (guardName: string) => string;
8
+ /**
9
+ * Throws an error if the provided value is not a complex object.
10
+ *
11
+ * A complex object is defined as a non-null object that is not a primitive and whose constructor is `Object`.
12
+ *
13
+ * @param guardName - The name of the variable being guarded.
14
+ * @param guard - The value to check.
15
+ * @throws {Error} Throws an error if `isComplexObject(guard)` is false.
16
+ */
17
+ export declare const throwNotComplexObject: (guardName: string, guard: any) => void;
18
+ /**
19
+ * Determines if a value is a complex object.
20
+ *
21
+ * @param value - The value to test.
22
+ * @returns `true` if the value is a defined, non-null object with a constructor matching `Object`.
23
+ */
24
+ export declare const isComplexObject: (value: any) => boolean;
25
+ //# sourceMappingURL=guardComplexObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardComplexObject.d.ts","sourceRoot":"","sources":["../../../src/guardComplexObject.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAAI,WAAW,MAAM,KAAG,MAE3D,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,WAAW,MAAM,EAAE,OAAO,GAAG,KAAG,IAIrE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,GAAG,KAAG,OAK5C,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Generates an error message when a string is empty.
3
+ *
4
+ * @param guardName - The name of the variable being guarded.
5
+ * @returns A formatted error message.
6
+ */
7
+ export declare const emptyMessage: (guardName: string) => string;
8
+ /**
9
+ * Throws an error if the provided string is empty ('').
10
+ *
11
+ * @param guardName - The name of the variable being guarded.
12
+ * @param guard - The string to check for emptiness.
13
+ * @throws {Error} Throws an error if `guard` is an empty string.
14
+ */
15
+ export declare const throwEmpty: (guardName: string, guard: string) => void;
16
+ //# sourceMappingURL=guardEmpty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardEmpty.d.ts","sourceRoot":"","sources":["../../../src/guardEmpty.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,KAAG,MAAiC,CAAC;AAEnF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,WAAW,MAAM,EAAE,OAAO,MAAM,KAAG,IAG7D,CAAA"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Represents a class constructor type.
3
+ */
4
+ export type ClassInstance = new (...args: any[]) => void;
5
+ /**
6
+ * Generates an error message when a value is not an instance of the specified class.
7
+ *
8
+ * @param guardName - The name of the variable being guarded.
9
+ * @param guardType - The expected class constructor.
10
+ * @returns A formatted error message.
11
+ */
12
+ export declare const notInstanceMessage: (guardName: string, guardType: ClassInstance) => string;
13
+ /**
14
+ * Throws an error if the provided value is not an instance of the specified class.
15
+ *
16
+ * @param guardName - The name of the variable being guarded.
17
+ * @param guard - The value to check.
18
+ * @param guardType - The expected class constructor.
19
+ * @throws {Error} Throws an error if `guard instanceof guardType` is false.
20
+ */
21
+ export declare const throwNotInstance: (guardName: string, guard: any, guardType: ClassInstance) => void;
22
+ /**
23
+ * Generates an error message when a value is not an instance of any of the specified classes.
24
+ *
25
+ * @param guardInstance - The value that failed the check.
26
+ * @param guardTypes - The expected class constructors.
27
+ * @returns A formatted error message.
28
+ */
29
+ export declare const notAnyInstanceMessage: (guardInstance: any, ...guardTypes: ClassInstance[]) => string;
30
+ /**
31
+ * Throws an error if the provided value is not an instance of any of the specified classes.
32
+ *
33
+ * @param guardInstance - The value to check.
34
+ * @param guardTypes - One or more expected class constructors.
35
+ * @throws {Error} Throws an error if `guardInstance` is not an instance of any of the `guardTypes`.
36
+ */
37
+ export declare const throwNotAnyInstance: (guardInstance: any, ...guardTypes: ClassInstance[]) => void;
38
+ //# sourceMappingURL=guardInstance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardInstance.d.ts","sourceRoot":"","sources":["../../../src/guardInstance.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,WAAW,MAAM,EAAE,WAAW,aAAa,KAAG,MAEhF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,MAAM,EAAE,OAAO,GAAG,EAAE,WAAW,aAAa,KAAG,IAK1F,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,eAAe,GAAG,EAAE,GAAG,YAAY,aAAa,EAAE,KAAG,MAG1F,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,eAAe,GAAG,EAAE,GAAG,YAAY,aAAa,EAAE,KAAG,IAMxF,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Generates an error message when a value is null.
3
+ *
4
+ * @param guardName - The name of the variable being guarded.
5
+ * @returns A formatted error message.
6
+ */
7
+ export declare const nullMessage: (guardName: string) => string;
8
+ /**
9
+ * Throws an error if the provided value is null.
10
+ *
11
+ * @param guardName - The name of the variable being guarded.
12
+ * @param guard - The value to check for null.
13
+ * @throws {Error} Throws an error if `guard` is strictly equal to `null`.
14
+ */
15
+ export declare const throwNull: (guardName: string, guard: any) => void;
16
+ //# sourceMappingURL=guardNull.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardNull.d.ts","sourceRoot":"","sources":["../../../src/guardNull.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,KAAG,MAAgC,CAAC;AAEjF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,WAAW,MAAM,EAAE,OAAO,GAAG,KAAG,IAKzD,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Generates an error message when a value is not a key of the provided record.
3
+ *
4
+ * @param guardName - The name of the variable being guarded.
5
+ * @param guard - The record containing valid keys.
6
+ * @returns A formatted error message.
7
+ */
8
+ export declare const notObjectKeyMessage: (guardName: string, guard: Record<any, any>) => string;
9
+ /**
10
+ * Throws an error if the provided key is not present in the given record.
11
+ *
12
+ * @param guardName - The name of the variable being guarded.
13
+ * @param guard - The record to check against.
14
+ * @param guardObjectKey - The key to check for existence in the record.
15
+ * @throws {Error} Throws an error if `Object.hasOwn(guard, guardObjectKey)` is false.
16
+ */
17
+ export declare const throwNotObjectKey: (guardName: string, guard: Record<any, any>, guardObjectKey: string) => void;
18
+ //# sourceMappingURL=guardObjectKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardObjectKey.d.ts","sourceRoot":"","sources":["../../../src/guardObjectKey.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,MAAM,EAAE,OAAO,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,KAAG,MAEhF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,OAAO,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,gBAAgB,MAAM,KAAG,IAKtG,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Supported JavaScript types for type guarding.
3
+ */
4
+ export type Types = "number" | "string" | "boolean" | "undefined" | "function" | "object" | "bigint" | "symbol";
5
+ /**
6
+ * Generates a standard error message when a value is not of the expected type.
7
+ *
8
+ * @param guardName - The name of the variable being guarded.
9
+ * @param guardType - The expected type.
10
+ * @returns A formatted error message.
11
+ */
12
+ export declare const notTypeMessage: (guardName: string, guardType: Types) => string;
13
+ /**
14
+ * Throws an error if the provided value is not of the specified type.
15
+ *
16
+ * @param guardName - The name of the variable being guarded.
17
+ * @param guard - The value to check.
18
+ * @param guardType - The expected type.
19
+ * @throws {Error} Throws an error if `typeof guard` does not equal `guardType`.
20
+ */
21
+ export declare const throwNotType: (guardName: string, guard: any, guardType: Types) => void;
22
+ //# sourceMappingURL=guardType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardType.d.ts","sourceRoot":"","sources":["../../../src/guardType.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAGhH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,EAAE,WAAW,KAAK,KAAG,MAEpE,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,EAAE,OAAO,GAAG,EAAE,WAAW,KAAK,KAAG,IAK9E,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Generates an error message when a value is undefined.
3
+ *
4
+ * @param guardName - The name of the variable being guarded.
5
+ * @returns A formatted error message.
6
+ */
7
+ export declare const undefinedMessage: (guardName: string) => string;
8
+ /**
9
+ * Throws an error if the provided value is undefined.
10
+ *
11
+ * @param guardName - The name of the variable being guarded.
12
+ * @param guard - The value to check for undefined.
13
+ * @throws {Error} Throws an error if `guard` is strictly equal to `undefined`.
14
+ */
15
+ export declare const throwUndefined: (guardName: string, guard: any) => void;
16
+ //# sourceMappingURL=guardUndefined.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardUndefined.d.ts","sourceRoot":"","sources":["../../../src/guardUndefined.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,MAAM,KAAG,MAAuC,CAAC;AAE7F;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,EAAE,OAAO,GAAG,KAAG,IAK9D,CAAA"}
@@ -0,0 +1,9 @@
1
+ export * from './guardAggregates.js';
2
+ export * from './guardComplexObject.js';
3
+ export * from './guardEmpty.js';
4
+ export * from './guardInstance.js';
5
+ export * from './guardNull.js';
6
+ export * from './guardObjectKey.js';
7
+ export * from './guardType.js';
8
+ export * from './guardUndefined.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,32 @@
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
+ * Throws an error if the provided value is undefined or null.
10
+ *
11
+ * @param guardName - The name of the variable being guarded.
12
+ * @param guard - The value to check.
13
+ * @throws {Error} Throws an error if `guard` is `undefined` or `null`.
14
+ */
15
+ const throwUndefinedOrNull = (guardName, guard) => {
16
+ (0, guardUndefined_js_1.throwUndefined)(guardName, guard);
17
+ (0, guardNull_js_1.throwNull)(guardName, guard);
18
+ };
19
+ exports.throwUndefinedOrNull = throwUndefinedOrNull;
20
+ /**
21
+ * Throws an error if the provided value is not a string or is an empty string.
22
+ *
23
+ * @param guardName - The name of the variable being guarded.
24
+ * @param guard - The value to check.
25
+ * @throws {Error} Throws an error if `guard` is not a string or if it's empty ('').
26
+ */
27
+ const throwNotStringOrEmpty = (guardName, guard) => {
28
+ (0, guardType_js_1.throwNotType)(guardName, guard, 'string');
29
+ (0, guardEmpty_js_1.throwEmpty)(guardName, guard);
30
+ };
31
+ exports.throwNotStringOrEmpty = throwNotStringOrEmpty;
32
+ //# sourceMappingURL=guardAggregates.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardAggregates.cjs","sourceRoot":"","sources":["../../src/guardAggregates.ts"],"names":[],"mappings":";;;AAAA,mDAA6C;AAC7C,iDAA2C;AAC3C,iDAA8C;AAC9C,2DAAqD;AAErD;;;;;;GAMG;AACI,MAAM,oBAAoB,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAQ,EAAE;IAC1E,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;;;;;;GAMG;AACI,MAAM,qBAAqB,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAQ,EAAE;IAC3E,IAAA,2BAAY,EAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;IACxC,IAAA,0BAAU,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAA;AAHY,QAAA,qBAAqB,yBAGjC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isComplexObject = exports.throwNotComplexObject = exports.notComplexObjectMessage = void 0;
4
+ /**
5
+ * Generates an error message when a value is not a complex object.
6
+ *
7
+ * @param guardName - The name of the variable being guarded.
8
+ * @returns A formatted error message.
9
+ */
10
+ const notComplexObjectMessage = (guardName) => (`'${guardName}' must be a complex object`);
11
+ exports.notComplexObjectMessage = notComplexObjectMessage;
12
+ /**
13
+ * Throws an error if the provided value is not a complex object.
14
+ *
15
+ * A complex object is defined as a non-null object that is not a primitive and whose constructor is `Object`.
16
+ *
17
+ * @param guardName - The name of the variable being guarded.
18
+ * @param guard - The value to check.
19
+ * @throws {Error} Throws an error if `isComplexObject(guard)` is false.
20
+ */
21
+ const throwNotComplexObject = (guardName, guard) => {
22
+ if ((0, exports.isComplexObject)(guard) === false) {
23
+ throw new Error((0, exports.notComplexObjectMessage)(guardName));
24
+ }
25
+ };
26
+ exports.throwNotComplexObject = throwNotComplexObject;
27
+ /**
28
+ * Determines if a value is a complex object.
29
+ *
30
+ * @param value - The value to test.
31
+ * @returns `true` if the value is a defined, non-null object with a constructor matching `Object`.
32
+ */
33
+ const isComplexObject = (value) => {
34
+ const isDefined = value !== undefined && value !== null;
35
+ return isDefined
36
+ && value.constructor
37
+ && value.constructor === Object;
38
+ };
39
+ exports.isComplexObject = isComplexObject;
40
+ //# sourceMappingURL=guardComplexObject.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardComplexObject.cjs","sourceRoot":"","sources":["../../src/guardComplexObject.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,CACpE,IAAI,SAAS,4BAA4B,CAC1C,CAAA;AAFY,QAAA,uBAAuB,2BAEnC;AAED;;;;;;;;GAQG;AACI,MAAM,qBAAqB,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAQ,EAAE;IAC3E,IAAI,IAAA,uBAAe,EAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,IAAA,+BAAuB,EAAC,SAAS,CAAC,CAAC,CAAC;IACtD,CAAC;AACH,CAAC,CAAA;AAJY,QAAA,qBAAqB,yBAIjC;AAED;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAC,KAAU,EAAW,EAAE;IACrD,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,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwEmpty = exports.emptyMessage = void 0;
4
+ /**
5
+ * Generates an error message when a string is empty.
6
+ *
7
+ * @param guardName - The name of the variable being guarded.
8
+ * @returns A formatted error message.
9
+ */
10
+ const emptyMessage = (guardName) => `${guardName} is empty`;
11
+ exports.emptyMessage = emptyMessage;
12
+ /**
13
+ * Throws an error if the provided string is empty ('').
14
+ *
15
+ * @param guardName - The name of the variable being guarded.
16
+ * @param guard - The string to check for emptiness.
17
+ * @throws {Error} Throws an error if `guard` is an empty string.
18
+ */
19
+ const throwEmpty = (guardName, guard) => {
20
+ const isEmpty = guard === '';
21
+ if (isEmpty)
22
+ throw new Error((0, exports.emptyMessage)(guardName));
23
+ };
24
+ exports.throwEmpty = throwEmpty;
25
+ //# sourceMappingURL=guardEmpty.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardEmpty.cjs","sourceRoot":"","sources":["../../src/guardEmpty.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,GAAG,SAAS,WAAW,CAAC;AAAtE,QAAA,YAAY,gBAA0D;AAEnF;;;;;;GAMG;AACI,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAE,KAAa,EAAQ,EAAE;IACnE,MAAM,OAAO,GAAG,KAAK,KAAK,EAAE,CAAC;IAC7B,IAAI,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,IAAA,oBAAY,EAAC,SAAS,CAAC,CAAC,CAAC;AACxD,CAAC,CAAA;AAHY,QAAA,UAAU,cAGtB"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwNotAnyInstance = exports.notAnyInstanceMessage = exports.throwNotInstance = exports.notInstanceMessage = void 0;
4
+ /**
5
+ * Generates an error message when a value is not an instance of the specified class.
6
+ *
7
+ * @param guardName - The name of the variable being guarded.
8
+ * @param guardType - The expected class constructor.
9
+ * @returns A formatted error message.
10
+ */
11
+ const notInstanceMessage = (guardName, guardType) => (`'${guardName}' must be an instance of '${guardType.name}'`);
12
+ exports.notInstanceMessage = notInstanceMessage;
13
+ /**
14
+ * Throws an error if the provided value is not an instance of the specified class.
15
+ *
16
+ * @param guardName - The name of the variable being guarded.
17
+ * @param guard - The value to check.
18
+ * @param guardType - The expected class constructor.
19
+ * @throws {Error} Throws an error if `guard instanceof guardType` is false.
20
+ */
21
+ const throwNotInstance = (guardName, guard, guardType) => {
22
+ const isInstance = guard instanceof guardType;
23
+ if (isInstance === false) {
24
+ throw new Error((0, exports.notInstanceMessage)(guardName, guardType));
25
+ }
26
+ };
27
+ exports.throwNotInstance = throwNotInstance;
28
+ /**
29
+ * Generates an error message when a value is not an instance of any of the specified classes.
30
+ *
31
+ * @param guardInstance - The value that failed the check.
32
+ * @param guardTypes - The expected class constructors.
33
+ * @returns A formatted error message.
34
+ */
35
+ const notAnyInstanceMessage = (guardInstance, ...guardTypes) => {
36
+ const typeNames = guardTypes.map(t => t.name).join('|');
37
+ return `'${guardInstance.constructor.name}' must be an instance of either '${typeNames}'`;
38
+ };
39
+ exports.notAnyInstanceMessage = notAnyInstanceMessage;
40
+ /**
41
+ * Throws an error if the provided value is not an instance of any of the specified classes.
42
+ *
43
+ * @param guardInstance - The value to check.
44
+ * @param guardTypes - One or more expected class constructors.
45
+ * @throws {Error} Throws an error if `guardInstance` is not an instance of any of the `guardTypes`.
46
+ */
47
+ const throwNotAnyInstance = (guardInstance, ...guardTypes) => {
48
+ for (let i = 0; i < guardTypes.length; i++) {
49
+ const isInstance = guardInstance instanceof guardTypes[i];
50
+ if (isInstance)
51
+ return;
52
+ }
53
+ throw new Error((0, exports.notAnyInstanceMessage)(guardInstance, ...guardTypes));
54
+ };
55
+ exports.throwNotAnyInstance = throwNotAnyInstance;
56
+ //# sourceMappingURL=guardInstance.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardInstance.cjs","sourceRoot":"","sources":["../../src/guardInstance.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAAC,SAAiB,EAAE,SAAwB,EAAU,EAAE,CAAC,CACzF,IAAI,SAAS,6BAA6B,SAAS,CAAC,IAAI,GAAG,CAC5D,CAAA;AAFY,QAAA,kBAAkB,sBAE9B;AAED;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAE,SAAwB,EAAQ,EAAE;IAChG,MAAM,UAAU,GAAG,KAAK,YAAY,SAAS,CAAC;IAC9C,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,IAAA,0BAAkB,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC,CAAA;AALY,QAAA,gBAAgB,oBAK5B;AAED;;;;;;GAMG;AACI,MAAM,qBAAqB,GAAG,CAAC,aAAkB,EAAE,GAAG,UAA2B,EAAU,EAAE;IAClG,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;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CAAC,aAAkB,EAAE,GAAG,UAA2B,EAAQ,EAAE;IAC9F,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,UAAU,GAAG,aAAa,YAAY,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1D,IAAI,UAAU;YAAE,OAAO;IACzB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,IAAA,6BAAqB,EAAC,aAAa,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;AACvE,CAAC,CAAA;AANY,QAAA,mBAAmB,uBAM/B"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwNull = exports.nullMessage = void 0;
4
+ /**
5
+ * Generates an error message when a value is null.
6
+ *
7
+ * @param guardName - The name of the variable being guarded.
8
+ * @returns A formatted error message.
9
+ */
10
+ const nullMessage = (guardName) => `${guardName} is null`;
11
+ exports.nullMessage = nullMessage;
12
+ /**
13
+ * Throws an error if the provided value is null.
14
+ *
15
+ * @param guardName - The name of the variable being guarded.
16
+ * @param guard - The value to check for null.
17
+ * @throws {Error} Throws an error if `guard` is strictly equal to `null`.
18
+ */
19
+ const throwNull = (guardName, guard) => {
20
+ const isNull = guard !== null;
21
+ if (isNull === false) {
22
+ throw new Error((0, exports.nullMessage)(guardName));
23
+ }
24
+ };
25
+ exports.throwNull = throwNull;
26
+ //# sourceMappingURL=guardNull.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardNull.cjs","sourceRoot":"","sources":["../../src/guardNull.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,GAAG,SAAS,UAAU,CAAC;AAApE,QAAA,WAAW,eAAyD;AAEjF;;;;;;GAMG;AACI,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAQ,EAAE;IAC/D,MAAM,MAAM,GAAG,KAAK,KAAK,IAAI,CAAC;IAC9B,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,IAAA,mBAAW,EAAC,SAAS,CAAC,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC,CAAA;AALY,QAAA,SAAS,aAKrB"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwNotObjectKey = exports.notObjectKeyMessage = void 0;
4
+ /**
5
+ * Generates an error message when a value is not a key of the provided record.
6
+ *
7
+ * @param guardName - The name of the variable being guarded.
8
+ * @param guard - The record containing valid keys.
9
+ * @returns A formatted error message.
10
+ */
11
+ const notObjectKeyMessage = (guardName, guard) => (`'${guardName}' must be one of '${Object.keys(guard).join(', ')}'`);
12
+ exports.notObjectKeyMessage = notObjectKeyMessage;
13
+ /**
14
+ * Throws an error if the provided key is not present in the given record.
15
+ *
16
+ * @param guardName - The name of the variable being guarded.
17
+ * @param guard - The record to check against.
18
+ * @param guardObjectKey - The key to check for existence in the record.
19
+ * @throws {Error} Throws an error if `Object.hasOwn(guard, guardObjectKey)` is false.
20
+ */
21
+ const throwNotObjectKey = (guardName, guard, guardObjectKey) => {
22
+ const hasKey = Object.hasOwn(guard, guardObjectKey);
23
+ if (hasKey === false) {
24
+ throw new Error((0, exports.notObjectKeyMessage)(guardName, guard));
25
+ }
26
+ };
27
+ exports.throwNotObjectKey = throwNotObjectKey;
28
+ //# sourceMappingURL=guardObjectKey.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardObjectKey.cjs","sourceRoot":"","sources":["../../src/guardObjectKey.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CAAC,SAAiB,EAAE,KAAuB,EAAU,EAAE,CAAC,CACzF,IAAI,SAAS,qBAAqB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACnE,CAAA;AAFY,QAAA,mBAAmB,uBAE/B;AAED;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAE,KAAuB,EAAE,cAAsB,EAAQ,EAAE;IAC5G,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACpD,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,IAAA,2BAAmB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;AACH,CAAC,CAAA;AALY,QAAA,iBAAiB,qBAK7B"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwNotType = exports.notTypeMessage = void 0;
4
+ /**
5
+ * Generates a standard error message when a value is not of the expected type.
6
+ *
7
+ * @param guardName - The name of the variable being guarded.
8
+ * @param guardType - The expected type.
9
+ * @returns A formatted error message.
10
+ */
11
+ const notTypeMessage = (guardName, guardType) => (`'${guardName}' must be a type of '${guardType}'`);
12
+ exports.notTypeMessage = notTypeMessage;
13
+ /**
14
+ * Throws an error if the provided value is not of the specified type.
15
+ *
16
+ * @param guardName - The name of the variable being guarded.
17
+ * @param guard - The value to check.
18
+ * @param guardType - The expected type.
19
+ * @throws {Error} Throws an error if `typeof guard` does not equal `guardType`.
20
+ */
21
+ const throwNotType = (guardName, guard, guardType) => {
22
+ const isType = typeof guard === guardType;
23
+ if (isType === false) {
24
+ throw new Error((0, exports.notTypeMessage)(guardName, guardType));
25
+ }
26
+ };
27
+ exports.throwNotType = throwNotType;
28
+ //# sourceMappingURL=guardType.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardType.cjs","sourceRoot":"","sources":["../../src/guardType.ts"],"names":[],"mappings":";;;AAMA;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAE,SAAgB,EAAU,EAAE,CAAC,CAC7E,IAAI,SAAS,wBAAwB,SAAS,GAAG,CAClD,CAAA;AAFY,QAAA,cAAc,kBAE1B;AAED;;;;;;;GAOG;AACI,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAE,SAAgB,EAAQ,EAAE;IACpF,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,SAAS,CAAC;IAC1C,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,IAAA,sBAAc,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IACxD,CAAC;AACH,CAAC,CAAA;AALY,QAAA,YAAY,gBAKxB"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwUndefined = exports.undefinedMessage = void 0;
4
+ /**
5
+ * Generates an error message when a value is undefined.
6
+ *
7
+ * @param guardName - The name of the variable being guarded.
8
+ * @returns A formatted error message.
9
+ */
10
+ const undefinedMessage = (guardName) => `${guardName} is not defined`;
11
+ exports.undefinedMessage = undefinedMessage;
12
+ /**
13
+ * Throws an error if the provided value is undefined.
14
+ *
15
+ * @param guardName - The name of the variable being guarded.
16
+ * @param guard - The value to check for undefined.
17
+ * @throws {Error} Throws an error if `guard` is strictly equal to `undefined`.
18
+ */
19
+ const throwUndefined = (guardName, guard) => {
20
+ const isDefined = guard !== undefined;
21
+ if (isDefined === false) {
22
+ throw new Error((0, exports.undefinedMessage)(guardName));
23
+ }
24
+ };
25
+ exports.throwUndefined = throwUndefined;
26
+ //# sourceMappingURL=guardUndefined.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardUndefined.cjs","sourceRoot":"","sources":["../../src/guardUndefined.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,GAAG,SAAS,iBAAiB,CAAC;AAAhF,QAAA,gBAAgB,oBAAgE;AAE7F;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAQ,EAAE;IACpE,MAAM,SAAS,GAAG,KAAK,KAAK,SAAS,CAAC;IACtC,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,IAAA,wBAAgB,EAAC,SAAS,CAAC,CAAC,CAAC;IAC/C,CAAC;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.ts"],"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 ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@esm-test/guards",
3
+ "version": "1.0.0-beta.10",
4
+ "description": "A js utility library for guarding objects, instances and types",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "./dist/index.min.js",
10
+ "exports": {
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/index.min.js",
13
+ "require": "./legacy/src/index.cjs"
14
+ },
15
+ "imports": {
16
+ "#src/*": "./out/src/*",
17
+ "#test/*": "./out/test/*"
18
+ },
19
+ "devDependencies": {
20
+ "@types/mocha": "10.0.10",
21
+ "@types/node": "22.19.13",
22
+ "@types/source-map-support": "0.5.10",
23
+ "assert": "2.1.0",
24
+ "c8": "11.0.0",
25
+ "esbuild": "0.27.3",
26
+ "js-build-tasks": "1.0.0-rc.19",
27
+ "js-yaml": "4.1.1",
28
+ "mocha": "11.7.5",
29
+ "mocha-ui-esm": "1.0.0-beta.14",
30
+ "rimraf": "6.1.3",
31
+ "source-map-support": "0.5.21",
32
+ "typescript": "5.9.3"
33
+ },
34
+ "scripts": {
35
+ "clean": "task",
36
+ "compile": "task",
37
+ "coverage": "task",
38
+ "fresh": "task",
39
+ "generate:types": "task",
40
+ "test": "task",
41
+ "transform:legacy": "task",
42
+ "prepublishOnly": "task"
43
+ },
44
+ "author": "pflannery",
45
+ "license": "ISC",
46
+ "keywords": [
47
+ "npm",
48
+ "node",
49
+ "test",
50
+ "guards"
51
+ ],
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "https://gitlab.com/esm-test-group/esm-test-guards.git"
55
+ }
56
+ }