@spudlabs/guardis 0.4.0

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 (106) hide show
  1. package/README.md +901 -0
  2. package/esm/mod.d.ts +55 -0
  3. package/esm/mod.d.ts.map +1 -0
  4. package/esm/mod.js +43 -0
  5. package/esm/package.json +3 -0
  6. package/esm/specs/standard-schema-spec.v1.d.ts +56 -0
  7. package/esm/specs/standard-schema-spec.v1.d.ts.map +1 -0
  8. package/esm/specs/standard-schema-spec.v1.js +1 -0
  9. package/esm/src/batch.d.ts +23 -0
  10. package/esm/src/batch.d.ts.map +1 -0
  11. package/esm/src/batch.js +23 -0
  12. package/esm/src/brand.d.ts +62 -0
  13. package/esm/src/brand.d.ts.map +1 -0
  14. package/esm/src/brand.js +9 -0
  15. package/esm/src/context.d.ts +19 -0
  16. package/esm/src/context.d.ts.map +1 -0
  17. package/esm/src/context.js +41 -0
  18. package/esm/src/extend.d.ts +23 -0
  19. package/esm/src/extend.d.ts.map +1 -0
  20. package/esm/src/extend.js +9 -0
  21. package/esm/src/guard.d.ts +288 -0
  22. package/esm/src/guard.d.ts.map +1 -0
  23. package/esm/src/guard.js +631 -0
  24. package/esm/src/helpers/http.helpers.d.ts +3 -0
  25. package/esm/src/helpers/http.helpers.d.ts.map +1 -0
  26. package/esm/src/helpers/http.helpers.js +2 -0
  27. package/esm/src/helpers/strings.helpers.d.ts +18 -0
  28. package/esm/src/helpers/strings.helpers.d.ts.map +1 -0
  29. package/esm/src/helpers/strings.helpers.js +47 -0
  30. package/esm/src/introspect.d.ts +36 -0
  31. package/esm/src/introspect.d.ts.map +1 -0
  32. package/esm/src/introspect.js +25 -0
  33. package/esm/src/modules/async.d.ts +27 -0
  34. package/esm/src/modules/async.d.ts.map +1 -0
  35. package/esm/src/modules/async.js +38 -0
  36. package/esm/src/modules/http.branded.d.ts +42 -0
  37. package/esm/src/modules/http.branded.d.ts.map +1 -0
  38. package/esm/src/modules/http.branded.js +24 -0
  39. package/esm/src/modules/http.d.ts +46 -0
  40. package/esm/src/modules/http.d.ts.map +1 -0
  41. package/esm/src/modules/http.js +59 -0
  42. package/esm/src/modules/strings.branded.d.ts +185 -0
  43. package/esm/src/modules/strings.branded.d.ts.map +1 -0
  44. package/esm/src/modules/strings.branded.js +123 -0
  45. package/esm/src/modules/strings.d.ts +109 -0
  46. package/esm/src/modules/strings.d.ts.map +1 -0
  47. package/esm/src/modules/strings.js +147 -0
  48. package/esm/src/types.d.ts +318 -0
  49. package/esm/src/types.d.ts.map +1 -0
  50. package/esm/src/types.js +1 -0
  51. package/esm/src/utilities.d.ts +95 -0
  52. package/esm/src/utilities.d.ts.map +1 -0
  53. package/esm/src/utilities.js +196 -0
  54. package/package.json +40 -0
  55. package/script/mod.d.ts +55 -0
  56. package/script/mod.d.ts.map +1 -0
  57. package/script/mod.js +83 -0
  58. package/script/package.json +3 -0
  59. package/script/specs/standard-schema-spec.v1.d.ts +56 -0
  60. package/script/specs/standard-schema-spec.v1.d.ts.map +1 -0
  61. package/script/specs/standard-schema-spec.v1.js +2 -0
  62. package/script/src/batch.d.ts +23 -0
  63. package/script/src/batch.d.ts.map +1 -0
  64. package/script/src/batch.js +26 -0
  65. package/script/src/brand.d.ts +62 -0
  66. package/script/src/brand.d.ts.map +1 -0
  67. package/script/src/brand.js +12 -0
  68. package/script/src/context.d.ts +19 -0
  69. package/script/src/context.d.ts.map +1 -0
  70. package/script/src/context.js +45 -0
  71. package/script/src/extend.d.ts +23 -0
  72. package/script/src/extend.d.ts.map +1 -0
  73. package/script/src/extend.js +12 -0
  74. package/script/src/guard.d.ts +288 -0
  75. package/script/src/guard.d.ts.map +1 -0
  76. package/script/src/guard.js +640 -0
  77. package/script/src/helpers/http.helpers.d.ts +3 -0
  78. package/script/src/helpers/http.helpers.d.ts.map +1 -0
  79. package/script/src/helpers/http.helpers.js +5 -0
  80. package/script/src/helpers/strings.helpers.d.ts +18 -0
  81. package/script/src/helpers/strings.helpers.d.ts.map +1 -0
  82. package/script/src/helpers/strings.helpers.js +52 -0
  83. package/script/src/introspect.d.ts +36 -0
  84. package/script/src/introspect.d.ts.map +1 -0
  85. package/script/src/introspect.js +31 -0
  86. package/script/src/modules/async.d.ts +27 -0
  87. package/script/src/modules/async.d.ts.map +1 -0
  88. package/script/src/modules/async.js +41 -0
  89. package/script/src/modules/http.branded.d.ts +42 -0
  90. package/script/src/modules/http.branded.d.ts.map +1 -0
  91. package/script/src/modules/http.branded.js +30 -0
  92. package/script/src/modules/http.d.ts +46 -0
  93. package/script/src/modules/http.d.ts.map +1 -0
  94. package/script/src/modules/http.js +62 -0
  95. package/script/src/modules/strings.branded.d.ts +185 -0
  96. package/script/src/modules/strings.branded.d.ts.map +1 -0
  97. package/script/src/modules/strings.branded.js +126 -0
  98. package/script/src/modules/strings.d.ts +109 -0
  99. package/script/src/modules/strings.d.ts.map +1 -0
  100. package/script/src/modules/strings.js +150 -0
  101. package/script/src/types.d.ts +318 -0
  102. package/script/src/types.d.ts.map +1 -0
  103. package/script/src/types.js +2 -0
  104. package/script/src/utilities.d.ts +95 -0
  105. package/script/src/utilities.d.ts.map +1 -0
  106. package/script/src/utilities.js +207 -0
@@ -0,0 +1,47 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // MIT License
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ // The above copyright notice and this permission notice shall be included in all
10
+ // copies or substantial portions of the Software.
11
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
+ // SOFTWARE.
18
+ const CAPITALIZED_WORD_REGEXP = /\p{Lu}\p{Ll}+/u; // e.g. Apple
19
+ const ACRONYM_REGEXP = /\p{Lu}+(?=(\p{Lu}\p{Ll})|\P{L}|\b)/u; // e.g. ID, URL, handles an acronym followed by a capitalized word e.g. HTMLElement
20
+ const LOWERCASED_WORD_REGEXP = /(\p{Ll}+)/u; // e.g. apple
21
+ const ANY_LETTERS = /\p{L}+/u; // will match any sequence of letters, including in languages without a concept of upper/lower case
22
+ const DIGITS_REGEXP = /\p{N}+/u; // e.g. 123
23
+ const WORD_OR_NUMBER_REGEXP = new RegExp(`${CAPITALIZED_WORD_REGEXP.source}|${ACRONYM_REGEXP.source}|${LOWERCASED_WORD_REGEXP.source}|${ANY_LETTERS.source}|${DIGITS_REGEXP.source}`, "gu");
24
+ export function splitToWords(input) {
25
+ return input.match(WORD_OR_NUMBER_REGEXP) ?? [];
26
+ }
27
+ export function capitalizeWord(word) {
28
+ return word ? word[0].toUpperCase() + word.slice(1).toLowerCase() : word;
29
+ }
30
+ /**
31
+ * Converts a string into PascalCase.
32
+ *
33
+ * @example Usage
34
+ * ```ts
35
+ * import { toPascalCase } from "@std/text/to-pascal-case";
36
+ * import { assertEquals } from "@std/assert";
37
+ *
38
+ * assertEquals(toPascalCase("deno is awesome"), "DenoIsAwesome");
39
+ * ```
40
+ *
41
+ * @param input The string that is going to be converted into PascalCase
42
+ * @returns The string as PascalCase
43
+ */
44
+ export function toPascalCase(input) {
45
+ input = input.trim();
46
+ return splitToWords(input).map(capitalizeWord).join("");
47
+ }
@@ -0,0 +1,36 @@
1
+ import type { StandardSchemaV1 } from "../specs/standard-schema-spec.v1.js";
2
+ import type { Context, Parser, Predicate, TypeGuard } from "./types.js";
3
+ /** Base internal metadata attached to type guards */
4
+ export type GuardMeta<T> = {
5
+ _: {
6
+ name: string | undefined;
7
+ parser: Parser<T>;
8
+ };
9
+ };
10
+ /** Extended metadata for guards with context-aware validation */
11
+ export type GuardWithContext<T> = GuardMeta<T> & {
12
+ _: {
13
+ context: (value: unknown, ctx?: Context) => StandardSchemaV1.Result<T>;
14
+ };
15
+ };
16
+ /**
17
+ * Type guard that checks if a given guard object contains meta information.
18
+ *
19
+ * Specifically, it verifies that the guard has an underscore (`_`) property,
20
+ * which is an object containing a `name` (string or undefined) and a `parser` function.
21
+ */
22
+ export declare const hasMeta: <T1>(guard: Predicate<T1> | TypeGuard<T1>) => guard is typeof guard & GuardMeta<T1>;
23
+ /**
24
+ * Checks if a guard has a defined name for error messaging.
25
+ * Returns true only if the guard has meta and a truthy name string.
26
+ */
27
+ export declare const hasName: <T1>(guard: Predicate<T1> | TypeGuard<T1>) => guard is typeof guard & GuardMeta<T1> & {
28
+ _: {
29
+ name: string;
30
+ };
31
+ };
32
+ /**
33
+ * Checks if a guard has context-aware validation support for path tracking.
34
+ */
35
+ export declare const hasContext: <T1>(guard: Predicate<T1> | TypeGuard<T1>) => guard is typeof guard & GuardWithContext<T1>;
36
+ //# sourceMappingURL=introspect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspect.d.ts","sourceRoot":"","sources":["../../src/src/introspect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAExE,qDAAqD;AACrD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,CAAC,EAAE;QACD,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG;IAC/C,CAAC,EAAE;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KACxE,CAAC;CACH,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,EAAE,EACxB,OAAO,SAAS,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,KACnC,KAAK,IAAI,OAAO,KAAK,GAAG,SAAS,CAAC,EAAE,CAItC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,EAAE,EACxB,OAAO,SAAS,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,KACnC,KAAK,IAAI,OAAO,KAAK,GAAG,SAAS,CAAC,EAAE,CAAC,GAAG;IAAE,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAE/D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,EAAE,EAC3B,OAAO,SAAS,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,KACnC,KAAK,IAAI,OAAO,KAAK,GAAG,gBAAgB,CAAC,EAAE,CAG7C,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Type guard that checks if a given guard object contains meta information.
3
+ *
4
+ * Specifically, it verifies that the guard has an underscore (`_`) property,
5
+ * which is an object containing a `name` (string or undefined) and a `parser` function.
6
+ */
7
+ export const hasMeta = (guard) => {
8
+ return "_" in guard && !!guard._ &&
9
+ typeof guard._ === "object" && "parser" in guard._ &&
10
+ typeof guard._.parser === "function";
11
+ };
12
+ /**
13
+ * Checks if a guard has a defined name for error messaging.
14
+ * Returns true only if the guard has meta and a truthy name string.
15
+ */
16
+ export const hasName = (guard) => {
17
+ return hasMeta(guard) && typeof guard._.name === "string" && guard._.name.length > 0;
18
+ };
19
+ /**
20
+ * Checks if a guard has context-aware validation support for path tracking.
21
+ */
22
+ export const hasContext = (guard) => {
23
+ return hasMeta(guard) && "context" in guard._ &&
24
+ typeof guard._.context === "function";
25
+ };
@@ -0,0 +1,27 @@
1
+ import type { TypeGuard } from "../types.js";
2
+ /**
3
+ * Returns true if input is an async function.
4
+ * @param {unknown} t
5
+ * @return {boolean}
6
+ */
7
+ export declare const isAsyncFunction: TypeGuard<(...args: unknown[]) => Promise<unknown>>;
8
+ /**
9
+ * Returns true if input is a Promise.
10
+ * @param {unknown} t
11
+ * @return {boolean}
12
+ */
13
+ export declare const isPromise: TypeGuard<Promise<unknown>>;
14
+ /**
15
+ * Returns true if input is Promise-like (i.e. has a `then` method).
16
+ * @param {unknown} t
17
+ * @return {boolean}
18
+ */
19
+ export declare const isPromiseLike: TypeGuard<PromiseLike<unknown>>;
20
+ /**
21
+ * Returns true if input is thenable (i.e. has a `then` method).
22
+ * Alias for isPromiseLike.
23
+ * @param {unknown} t
24
+ * @return {boolean}
25
+ */
26
+ export declare const isThenable: TypeGuard<PromiseLike<unknown>>;
27
+ //# sourceMappingURL=async.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../../src/src/modules/async.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAS/E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAGjD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAazD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,iCAAgB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { createTypeGuard } from "../guard.js";
2
+ /**
3
+ * Returns true if input is an async function.
4
+ * @param {unknown} t
5
+ * @return {boolean}
6
+ */
7
+ export const isAsyncFunction = createTypeGuard("async function", (t) => {
8
+ return typeof t === "function" && t.constructor.name === "AsyncFunction"
9
+ ? t
10
+ : null;
11
+ });
12
+ /**
13
+ * Returns true if input is a Promise.
14
+ * @param {unknown} t
15
+ * @return {boolean}
16
+ */
17
+ export const isPromise = createTypeGuard("Promise", (t) => (t instanceof Promise ? t : null));
18
+ /**
19
+ * Returns true if input is Promise-like (i.e. has a `then` method).
20
+ * @param {unknown} t
21
+ * @return {boolean}
22
+ */
23
+ export const isPromiseLike = createTypeGuard("PromiseLike", (t) => {
24
+ if (t &&
25
+ typeof t === "object" &&
26
+ "then" in t &&
27
+ typeof t.then === "function") {
28
+ return t;
29
+ }
30
+ return null;
31
+ });
32
+ /**
33
+ * Returns true if input is thenable (i.e. has a `then` method).
34
+ * Alias for isPromiseLike.
35
+ * @param {unknown} t
36
+ * @return {boolean}
37
+ */
38
+ export const isThenable = isPromiseLike; // alias
@@ -0,0 +1,42 @@
1
+ import type { Brand } from "../brand.js";
2
+ import type { TypeGuard } from "../types.js";
3
+ /**
4
+ * Represents a branded type for an IPv4 address.
5
+ * This type ensures that a string is explicitly marked as an "IPv4"
6
+ * to provide additional type safety and clarity in the codebase.
7
+ */
8
+ export type IPv4 = Brand<string, "IPv4">;
9
+ /**
10
+ * Determines if a given string is a valid IPv4 address.
11
+ *
12
+ * This function extends the `isString` validator to include additional checks
13
+ * for IPv4 addresses. It ensures that the input string:
14
+ * - Matches the `ipv4Regex` pattern.
15
+ * - Each octet is between 0 and 255.
16
+ */
17
+ export declare const isIpv4: TypeGuard<IPv4>;
18
+ /**
19
+ * Represents a branded type for an IPv6 address.
20
+ * This type ensures that a string is explicitly marked as an "IPv6"
21
+ */
22
+ export type IPv6 = Brand<string, "IPv6">;
23
+ /**
24
+ * Determines if a given string is a valid IPv6 address.
25
+ *
26
+ * This function extends the `isString` validator to include additional checks
27
+ * for IPv6 addresses. It ensures that the input string:
28
+ * - Has a length of 45 characters or less.
29
+ * - Matches the `ipv6Regex` pattern.
30
+ */
31
+ export declare const isIpv6: TypeGuard<IPv6>;
32
+ /**
33
+ * Represents a branded type for an IP address, which can be either
34
+ * an IPv4 or IPv6 address.
35
+ */
36
+ export type IPAddress = IPv4 | IPv6;
37
+ /**
38
+ * Type guard that checks if a value is either a valid IPv4 or IPv6 address.
39
+ */
40
+ export declare const isIpAddress: TypeGuard<IPAddress>;
41
+ export { isNativeURL, isRequest, isResponse } from "./http.js";
42
+ //# sourceMappingURL=http.branded.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.branded.d.ts","sourceRoot":"","sources":["../../../src/src/modules/http.branded.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,EAAc,SAAS,CAAC,IAAI,CAAC,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,EAAc,SAAS,CAAC,IAAI,CAAC,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,SAAS,CAAqB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { isIpv4 as _isIpv4, isIpv6 as _isIpv6 } from "./http.js";
2
+ /**
3
+ * Determines if a given string is a valid IPv4 address.
4
+ *
5
+ * This function extends the `isString` validator to include additional checks
6
+ * for IPv4 addresses. It ensures that the input string:
7
+ * - Matches the `ipv4Regex` pattern.
8
+ * - Each octet is between 0 and 255.
9
+ */
10
+ export const isIpv4 = _isIpv4;
11
+ /**
12
+ * Determines if a given string is a valid IPv6 address.
13
+ *
14
+ * This function extends the `isString` validator to include additional checks
15
+ * for IPv6 addresses. It ensures that the input string:
16
+ * - Has a length of 45 characters or less.
17
+ * - Matches the `ipv6Regex` pattern.
18
+ */
19
+ export const isIpv6 = _isIpv6;
20
+ /**
21
+ * Type guard that checks if a value is either a valid IPv4 or IPv6 address.
22
+ */
23
+ export const isIpAddress = isIpv4.or(isIpv6);
24
+ export { isNativeURL, isRequest, isResponse } from "./http.js";
@@ -0,0 +1,46 @@
1
+ import type { TypeGuard } from "../types.js";
2
+ /**
3
+ * Returns true if input is an instance of the native URL
4
+ * class.
5
+ * @param {unknown} t
6
+ * @return {boolean}
7
+ */
8
+ export declare const isNativeURL: TypeGuard<URL>;
9
+ /**
10
+ * Returns true if input is an instance of the native Request
11
+ * class.
12
+ * @param {unknown} t
13
+ * @return {boolean}
14
+ */
15
+ export declare const isRequest: TypeGuard<Request>;
16
+ /**
17
+ * Returns true if input is an instance of the native Response
18
+ * class.
19
+ * @param {unknown} t
20
+ * @return {boolean}
21
+ */
22
+ export declare const isResponse: TypeGuard<Response>;
23
+ /**
24
+ * Determines if a given string is a valid IPv4 address.
25
+ *
26
+ * This function extends the `isString` validator to include additional checks
27
+ * for IPv4 addresses. It ensures that the input string:
28
+ * - Matches the `ipv4Regex` pattern.
29
+ * - Each octet is between 0 and 255.
30
+ */
31
+ export declare const isIpv4: TypeGuard<string>;
32
+ /**
33
+ * Determines if a given string is a valid IPv6 address.
34
+ *
35
+ * This function extends the `isString` validator to include additional checks
36
+ * for IPv6 addresses. It ensures that the input string:
37
+ * - Has a length of 45 characters or less.
38
+ * - Matches the `ipv6Regex` pattern.
39
+ */
40
+ export declare const isIpv6: TypeGuard<string>;
41
+ /**
42
+ * Type guard that checks if a given string is either a valid IPv4 or IPv6 address.
43
+ * Combines the `isIpv4` and `isIpv6` type guards using a logical OR operation.
44
+ */
45
+ export declare const isIpAddress: TypeGuard<string>;
46
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/src/modules/http.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,GAAG,CAGtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,OAAO,CAGxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,CAAC,QAAQ,CAG1C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,MAAM,CAiBpC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,MAAM,CAKpC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,MAAM,CAAqB,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { createTypeGuard } from "../guard.js";
2
+ import { IPV4_REGEX, IPV6_REGEX } from "../helpers/http.helpers.js";
3
+ /**
4
+ * Returns true if input is an instance of the native URL
5
+ * class.
6
+ * @param {unknown} t
7
+ * @return {boolean}
8
+ */
9
+ export const isNativeURL = createTypeGuard("URL", (t) => t instanceof URL ? t : null);
10
+ /**
11
+ * Returns true if input is an instance of the native Request
12
+ * class.
13
+ * @param {unknown} t
14
+ * @return {boolean}
15
+ */
16
+ export const isRequest = createTypeGuard("Request", (t) => t instanceof Request ? t : null);
17
+ /**
18
+ * Returns true if input is an instance of the native Response
19
+ * class.
20
+ * @param {unknown} t
21
+ * @return {boolean}
22
+ */
23
+ export const isResponse = createTypeGuard("Response", (t) => t instanceof Response ? t : null);
24
+ /**
25
+ * Determines if a given string is a valid IPv4 address.
26
+ *
27
+ * This function extends the `isString` validator to include additional checks
28
+ * for IPv4 addresses. It ensures that the input string:
29
+ * - Matches the `ipv4Regex` pattern.
30
+ * - Each octet is between 0 and 255.
31
+ */
32
+ export const isIpv4 = createTypeGuard("IPv4", (v) => {
33
+ if (typeof v !== "string" || v.length > 15)
34
+ return null; // Max IPv4 length is 15 characters
35
+ const match = v.match(IPV4_REGEX);
36
+ if (match && match.slice(1).every((octet) => {
37
+ const num = parseInt(octet, 10);
38
+ return num >= 0 && num <= 255 && octet === num.toString();
39
+ })) {
40
+ return v;
41
+ }
42
+ return null;
43
+ });
44
+ /**
45
+ * Determines if a given string is a valid IPv6 address.
46
+ *
47
+ * This function extends the `isString` validator to include additional checks
48
+ * for IPv6 addresses. It ensures that the input string:
49
+ * - Has a length of 45 characters or less.
50
+ * - Matches the `ipv6Regex` pattern.
51
+ */
52
+ export const isIpv6 = createTypeGuard("IPv6", (v) => {
53
+ return typeof v === "string" && v.length <= 45 && IPV6_REGEX.test(v) ? v : null;
54
+ });
55
+ /**
56
+ * Type guard that checks if a given string is either a valid IPv4 or IPv6 address.
57
+ * Combines the `isIpv4` and `isIpv6` type guards using a logical OR operation.
58
+ */
59
+ export const isIpAddress = isIpv4.or(isIpv6);
@@ -0,0 +1,185 @@
1
+ /**
2
+ * This module provides type guards for common string patterns.
3
+ */
4
+ import type { Brand } from "../brand.js";
5
+ import type { TypeGuard } from "../types.js";
6
+ /**
7
+ * Represents a branded type for an email address.
8
+ * This type ensures that a string is explicitly marked as an "Email"
9
+ * to provide additional type safety and clarity in the codebase.
10
+ */
11
+ export type Email = Brand<string, "Email">;
12
+ /**
13
+ * Type guard for validating whether a given value is a valid email string. Uses a
14
+ * branded type to ensure type safety and distinguish it from other strings.
15
+ *
16
+ * Uses the `EMAIL_REGEX` to test if the input is a string that matches the email format.
17
+ *
18
+ * @param t - The value to test for email validity.
19
+ * @returns Boolean indicating whether the input is a valid email.
20
+ */
21
+ export declare const isEmail: TypeGuard<Email>;
22
+ /**
23
+ * Represents a branded type for an International Phone number.
24
+ * This type ensures that a string is explicitly marked as an "InternationalPhone"
25
+ * to provide additional type safety and clarity in the codebase.
26
+ */
27
+ export type InternationalPhone = Brand<string, "InternationalPhone">;
28
+ /**
29
+ * Type guard for validating whether a given value is a valid international phone number string.
30
+ * Uses a branded type to ensure type safety and distinguish it from other strings.
31
+ *
32
+ * Uses the `INT_PHONE_REGEX` to test if the input is a string that matches the international phone number format.
33
+ *
34
+ * @param t - The value to test for international phone number validity.
35
+ * @returns Boolean indicating whether the input is a valid international phone number.
36
+ */
37
+ export declare const isInternationalPhone: TypeGuard<InternationalPhone>;
38
+ /**
39
+ * Represents a branded type for a US Phone number.
40
+ * This type ensures that a string is explicitly marked as a "USPhone"
41
+ * to provide additional type safety and clarity in the codebase.
42
+ */
43
+ export type USPhone = Brand<string, "USPhone">;
44
+ /**
45
+ * Type guard for validating whether a given value is a valid US phone number string.
46
+ * Uses a branded type to ensure type safety and distinguish it from other strings.
47
+ *
48
+ * Uses the `US_PHONE_REGEX` to test if the input is a string that matches the US phone number format.
49
+ *
50
+ * @param t - The value to test for US phone number validity.
51
+ * @returns Boolean indicating whether the input is a valid US phone number.
52
+ */
53
+ export declare const isUSPhone: TypeGuard<USPhone>;
54
+ /**
55
+ * Represents a branded type for a phone number.
56
+ * This type ensures that a string is explicitly marked as a "PhoneNumber"
57
+ * to provide additional type safety and clarity in the codebase.
58
+ */
59
+ export type PhoneNumber = USPhone | InternationalPhone;
60
+ /**
61
+ * Type guard for validating whether a given value is a valid phone number string,
62
+ * either in international or US format. Uses a branded type to ensure type safety
63
+ * and distinguish it from other strings.
64
+ *
65
+ * Uses both `INT_PHONE_REGEX` and `US_PHONE_REGEX` to test if the input is a string
66
+ * that matches either format.
67
+ *
68
+ * @param t - The value to test for phone number validity.
69
+ * @returns Boolean indicating whether the input is a valid phone number.
70
+ */
71
+ export declare const isPhoneNumber: TypeGuard<PhoneNumber>;
72
+ /**
73
+ * Represents a branded type for a UUIDv4.
74
+ * This type ensures that a string is explicitly marked as a "UUIDv4"
75
+ * to provide additional type safety and clarity in the codebase.
76
+ */
77
+ export type UUIDv4 = Brand<string, "UUIDv4">;
78
+ /**
79
+ * Type guard for validating whether a given value is a valid UUIDv4 string.
80
+ * Uses a branded type to ensure type safety and distinguish it from other strings.
81
+ *
82
+ * Uses a regex pattern to test if the input is a string that matches the UUIDv4 format.
83
+ *
84
+ * @param t - The value to test for UUIDv4 validity.
85
+ * @returns Boolean indicating whether the input is a valid UUIDv4.
86
+ */
87
+ export declare const isUUIDv4: TypeGuard<UUIDv4>;
88
+ /**
89
+ * Represents a branded type for a UUIDv7.
90
+ * This type ensures that a string is explicitly marked as a "UUIDv7"
91
+ * to provide additional type safety and clarity in the codebase.
92
+ */
93
+ export type UUIDv7 = Brand<string, "UUIDv7">;
94
+ /**
95
+ * Type guard for validating whether a given value is a valid UUIDv7 string.
96
+ * Uses a branded type to ensure type safety and distinguish it from other strings.
97
+ *
98
+ * Uses a regex pattern to test if the input is a string that matches the UUIDv7 format.
99
+ *
100
+ * @param t - The value to test for UUIDv7 validity.
101
+ * @returns Boolean indicating whether the input is a valid UUIDv7.
102
+ */
103
+ export declare const isUUIDv7: TypeGuard<UUIDv7>;
104
+ /**
105
+ * Represents a branded type for a comma-delimited string.
106
+ * This type ensures that a string is explicitly marked as a "CommaDelimitedString"
107
+ * to provide additional type safety and clarity in the codebase.
108
+ */
109
+ export type CommaDelimitedString = Brand<string, "CommaDelimitedString">;
110
+ /**
111
+ * Type guard for validating whether a given value is a valid comma-delimited string.
112
+ * Uses a branded type to ensure type safety and distinguish it from other strings.
113
+ *
114
+ * Uses a regex pattern to test if the input is a string that matches the comma-delimited format.
115
+ *
116
+ * @param t - The value to test for comma-delimited string validity.
117
+ * @returns Boolean indicating whether the input is a valid comma-delimited string.
118
+ */
119
+ export declare const isCommaDelimited: TypeGuard<CommaDelimitedString>;
120
+ /**
121
+ * Represents a branded type for a period-delimited string.
122
+ * This type ensures that a string is explicitly marked as a "PeriodDelimitedString"
123
+ * to provide additional type safety and clarity in the codebase.
124
+ */
125
+ export type PeriodDelimitedString = Brand<string, "PeriodDelimitedString">;
126
+ /**
127
+ * Type guard for validating whether a given value is a valid period-delimited string.
128
+ * Uses a branded type to ensure type safety and distinguish it from other strings.
129
+ *
130
+ * Uses a regex pattern to test if the input is a string that matches the period-delimited format.
131
+ *
132
+ * @param t - The value to test for period-delimited string validity.
133
+ * @returns Boolean indicating whether the input is a valid period-delimited string.
134
+ */
135
+ export declare const isPeriodDelimited: TypeGuard<PeriodDelimitedString>;
136
+ /**
137
+ * Represents a branded type for a comma-delimited string of integers.
138
+ * This type ensures that a string is explicitly marked as a "CommaDelimitedIntegers"
139
+ * to provide additional type safety and clarity in the codebase.
140
+ */
141
+ export type CommaDelimitedIntegers = Brand<string, "CommaDelimitedIntegers">;
142
+ /**
143
+ * A type guard function that checks if a given string matches the pattern of a comma-delimited
144
+ * string of integers.
145
+ *
146
+ * - Matches one or more integers (positive or negative) separated by commas.
147
+ * - Does not allow empty values between commas.
148
+ * - Does not allow any whitespace (between digits or after commas).
149
+ * - Does not match empty strings.
150
+ *
151
+ * @param t - The value to test for comma-delimited integers validity.
152
+ * @returns Boolean indicating whether the input is a valid comma-delimited string of integers.
153
+ *
154
+ * @example
155
+ * - Valid: "1,2,3", "123,456,789", "-1,2,-3"
156
+ * - Invalid: "1,,3", "1, 2, 3", "1 2,3", "", "1.5,2"
157
+ */
158
+ export declare const isCommaDelimitedIntegers: TypeGuard<CommaDelimitedIntegers>;
159
+ /**
160
+ * Represents a branded type for a comma-delimited string of numbers.
161
+ * This type ensures that a string is explicitly marked as a "CommaDelimitedNumbers"
162
+ * to provide additional type safety and clarity in the codebase.
163
+ */
164
+ export type CommaDelimitedNumbers = Brand<string, "CommaDelimitedNumbers">;
165
+ /**
166
+ * A type guard function that checks if a given string matches the pattern of a comma-delimited
167
+ * string of numbers.
168
+ *
169
+ * - Matches one or more numbers (integers, floats, decimals, or percentages) separated by commas.
170
+ * - Supports positive and negative numbers.
171
+ * - Supports decimal values (e.g., "1.5", "3.14159").
172
+ * - Supports percentage values (e.g., "50%", "12.5%").
173
+ * - Does not allow empty values between commas.
174
+ * - Does not allow any whitespace (between digits or after commas).
175
+ * - Does not match empty strings.
176
+ *
177
+ * @param t - The value to test for comma-delimited numbers validity.
178
+ * @returns Boolean indicating whether the input is a valid comma-delimited string of numbers.
179
+ *
180
+ * @example
181
+ * - Valid: "1,2,3", "1.5,2.5,3.5", "-1.5,2,3.14", "50%,75%,100%", "1.5%,2,3%"
182
+ * - Invalid: "1,,3", "1, 2, 3", "1 2,3", "", "1..5,2", "1.5.5,2"
183
+ */
184
+ export declare const isCommaDelimitedNumbers: TypeGuard<CommaDelimitedNumbers>;
185
+ //# sourceMappingURL=strings.branded.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strings.branded.d.ts","sourceRoot":"","sources":["../../../src/src/modules/strings.branded.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAc7C;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,EAAe,SAAS,CAAC,KAAK,CAAC,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAErE;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAA4B,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAE3F;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE/C;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,EAAiB,SAAS,CAAC,OAAO,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,kBAAkB,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EAAqB,SAAS,CAAC,WAAW,CAAC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,EAAgB,SAAS,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,EAAgB,SAAS,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAEzE;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,EAAwB,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAErF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAE3E;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,EAAyB,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAExF;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;AAE7E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,EAAgC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAEvG;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,uBAAuB,EAA+B,SAAS,CAAC,qBAAqB,CAAC,CAAC"}