@maroonedog/luq 0.1.0-alpha
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/LICENSE +9 -0
- package/README.md +879 -0
- package/dist/constants.d.ts +27 -0
- package/dist/core/async.experimental/async-context.d.ts +60 -0
- package/dist/core/builder/array-batch-optimizer.d.ts +66 -0
- package/dist/core/builder/context/field-context.d.ts +31 -0
- package/dist/core/builder/context/field-type-detector.d.ts +19 -0
- package/dist/core/builder/core/builder.d.ts +10 -0
- package/dist/core/builder/core/field-builder.d.ts +13 -0
- package/dist/core/builder/core/index.d.ts +17 -0
- package/dist/core/builder/index.d.ts +24 -0
- package/dist/core/builder/nested-array-processor.d.ts +52 -0
- package/dist/core/builder/plugins/composable-conditional-plugin.d.ts +32 -0
- package/dist/core/builder/plugins/composable-directly-plugin.d.ts +32 -0
- package/dist/core/builder/plugins/composable-plugin.d.ts +242 -0
- package/dist/core/builder/plugins/plugin-creator.d.ts +38 -0
- package/dist/core/builder/plugins/plugin-interfaces.d.ts +343 -0
- package/dist/core/builder/plugins/plugin-types.d.ts +441 -0
- package/dist/core/builder/raw-validator.d.ts +22 -0
- package/dist/core/builder/types/field-options.d.ts +46 -0
- package/dist/core/builder/types/types.d.ts +318 -0
- package/dist/core/builder/ultra-fast-validator.d.ts +30 -0
- package/dist/core/builder/validator-factory.d.ts +29 -0
- package/dist/core/global-config.d.ts +27 -0
- package/dist/core/index.d.ts +36 -0
- package/dist/core/optimization/array-batch-validator.d.ts +68 -0
- package/dist/core/optimization/core/field-utils.d.ts +103 -0
- package/dist/core/optimization/core/strategy-factory.d.ts +84 -0
- package/dist/core/optimization/core/validation-engine.d.ts +107 -0
- package/dist/core/optimization/execution-strategy-selector.d.ts +23 -0
- package/dist/core/optimization/unified-validator.d.ts +45 -0
- package/dist/core/plugin/__tests__/test-utils.d.ts +1 -0
- package/dist/core/plugin/arrayContains.d.ts +37 -0
- package/dist/core/plugin/arrayIncludes.d.ts +42 -0
- package/dist/core/plugin/arrayMaxLength.d.ts +43 -0
- package/dist/core/plugin/arrayMinLength.d.ts +43 -0
- package/dist/core/plugin/arrayUnique.d.ts +41 -0
- package/dist/core/plugin/booleanFalsy.d.ts +41 -0
- package/dist/core/plugin/booleanTruthy.d.ts +38 -0
- package/dist/core/plugin/compareField.d.ts +58 -0
- package/dist/core/plugin/conditionalSchema.d.ts +24 -0
- package/dist/core/plugin/custom.d.ts +60 -0
- package/dist/core/plugin/fromContext.d.ts +150 -0
- package/dist/core/plugin/index.d.ts +71 -0
- package/dist/core/plugin/jsonSchema/dsl-converter.d.ts +22 -0
- package/dist/core/plugin/jsonSchema/error-generation.d.ts +14 -0
- package/dist/core/plugin/jsonSchema/format-validators.d.ts +20 -0
- package/dist/core/plugin/jsonSchema/index.d.ts +11 -0
- package/dist/core/plugin/jsonSchema/plugin.d.ts +35 -0
- package/dist/core/plugin/jsonSchema/ref-resolver.d.ts +14 -0
- package/dist/core/plugin/jsonSchema/types.d.ts +69 -0
- package/dist/core/plugin/jsonSchema/validation-core.d.ts +29 -0
- package/dist/core/plugin/jsonSchemaFullFeature.d.ts +31 -0
- package/dist/core/plugin/literal.d.ts +40 -0
- package/dist/core/plugin/message-factories.d.ts +9 -0
- package/dist/core/plugin/nullable.d.ts +34 -0
- package/dist/core/plugin/numberFinite.d.ts +41 -0
- package/dist/core/plugin/numberInteger.d.ts +41 -0
- package/dist/core/plugin/numberMax.d.ts +49 -0
- package/dist/core/plugin/numberMin.d.ts +49 -0
- package/dist/core/plugin/numberMultipleOf.d.ts +42 -0
- package/dist/core/plugin/numberNegative.d.ts +41 -0
- package/dist/core/plugin/numberPositive.d.ts +41 -0
- package/dist/core/plugin/numberRange.d.ts +48 -0
- package/dist/core/plugin/object.d.ts +43 -0
- package/dist/core/plugin/objectAdditionalProperties.d.ts +51 -0
- package/dist/core/plugin/objectDependentRequired.d.ts +42 -0
- package/dist/core/plugin/objectDependentSchemas.d.ts +40 -0
- package/dist/core/plugin/objectMaxProperties.d.ts +42 -0
- package/dist/core/plugin/objectMinProperties.d.ts +42 -0
- package/dist/core/plugin/objectPatternProperties.d.ts +46 -0
- package/dist/core/plugin/objectPropertyNames.d.ts +36 -0
- package/dist/core/plugin/objectRecursively.d.ts +81 -0
- package/dist/core/plugin/oneOf.d.ts +44 -0
- package/dist/core/plugin/optional.d.ts +35 -0
- package/dist/core/plugin/optionalIf.d.ts +42 -0
- package/dist/core/plugin/orFail.d.ts +132 -0
- package/dist/core/plugin/readOnlyWriteOnly.d.ts +48 -0
- package/dist/core/plugin/required.d.ts +45 -0
- package/dist/core/plugin/requiredIf.d.ts +66 -0
- package/dist/core/plugin/shared-constants.d.ts +45 -0
- package/dist/core/plugin/shared.d.ts +3 -0
- package/dist/core/plugin/skip.d.ts +57 -0
- package/dist/core/plugin/stitch-typed.d.ts +15 -0
- package/dist/core/plugin/stitch.d.ts +1 -0
- package/dist/core/plugin/stitchSimple.d.ts +4 -0
- package/dist/core/plugin/stringAlphanumeric.d.ts +42 -0
- package/dist/core/plugin/stringBase64.d.ts +119 -0
- package/dist/core/plugin/stringContentEncoding.d.ts +43 -0
- package/dist/core/plugin/stringContentMediaType.d.ts +47 -0
- package/dist/core/plugin/stringDate.d.ts +48 -0
- package/dist/core/plugin/stringDatetime.d.ts +108 -0
- package/dist/core/plugin/stringDuration.d.ts +41 -0
- package/dist/core/plugin/stringEmail.d.ts +81 -0
- package/dist/core/plugin/stringEndsWith.d.ts +42 -0
- package/dist/core/plugin/stringExactLength.d.ts +46 -0
- package/dist/core/plugin/stringHostname.d.ts +104 -0
- package/dist/core/plugin/stringIpv4.d.ts +85 -0
- package/dist/core/plugin/stringIpv6.d.ts +104 -0
- package/dist/core/plugin/stringIri.d.ts +117 -0
- package/dist/core/plugin/stringIriReference.d.ts +43 -0
- package/dist/core/plugin/stringJsonPointer.d.ts +107 -0
- package/dist/core/plugin/stringMax.d.ts +43 -0
- package/dist/core/plugin/stringMin.d.ts +43 -0
- package/dist/core/plugin/stringPattern.d.ts +40 -0
- package/dist/core/plugin/stringRelativeJsonPointer.d.ts +42 -0
- package/dist/core/plugin/stringStartsWith.d.ts +42 -0
- package/dist/core/plugin/stringTime.d.ts +39 -0
- package/dist/core/plugin/stringUriTemplate.d.ts +43 -0
- package/dist/core/plugin/stringUrl.d.ts +97 -0
- package/dist/core/plugin/testUtils.d.ts +15 -0
- package/dist/core/plugin/transform-type-restrictions.d.ts +61 -0
- package/dist/core/plugin/transform.d.ts +35 -0
- package/dist/core/plugin/tupleBuilder.d.ts +66 -0
- package/dist/core/plugin/types.d.ts +143 -0
- package/dist/core/plugin/unionGuard.d.ts +50 -0
- package/dist/core/plugin/utils/field-accessor-optimized.d.ts +50 -0
- package/dist/core/plugin/utils/field-accessor.d.ts +107 -0
- package/dist/core/plugin/uuid.d.ts +95 -0
- package/dist/core/plugin/validateIf.d.ts +57 -0
- package/dist/core/registry/plugin-registry.d.ts +116 -0
- package/dist/core/registry.d.ts +6 -0
- package/dist/core/transform/index.d.ts +1 -0
- package/dist/core/transform/string/defaultValue.d.ts +6 -0
- package/dist/core/transform/string/index.d.ts +3 -0
- package/dist/core/transform/string/replace.d.ts +14 -0
- package/dist/core/transform/string/sanitize.d.ts +6 -0
- package/dist/core/utils/type-guards.d.ts +68 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +7 -0
- package/dist/plugins/arrayContains.d.ts +37 -0
- package/dist/plugins/arrayContains.js +1 -0
- package/dist/plugins/arrayContains.mjs +1 -0
- package/dist/plugins/arrayIncludes.d.ts +42 -0
- package/dist/plugins/arrayIncludes.js +1 -0
- package/dist/plugins/arrayIncludes.mjs +1 -0
- package/dist/plugins/arrayMaxLength.d.ts +43 -0
- package/dist/plugins/arrayMaxLength.js +1 -0
- package/dist/plugins/arrayMaxLength.mjs +1 -0
- package/dist/plugins/arrayMinLength.d.ts +43 -0
- package/dist/plugins/arrayMinLength.js +1 -0
- package/dist/plugins/arrayMinLength.mjs +1 -0
- package/dist/plugins/arrayUnique.d.ts +41 -0
- package/dist/plugins/arrayUnique.js +1 -0
- package/dist/plugins/arrayUnique.mjs +1 -0
- package/dist/plugins/booleanFalsy.d.ts +41 -0
- package/dist/plugins/booleanFalsy.js +1 -0
- package/dist/plugins/booleanFalsy.mjs +1 -0
- package/dist/plugins/booleanTruthy.d.ts +38 -0
- package/dist/plugins/booleanTruthy.js +1 -0
- package/dist/plugins/booleanTruthy.mjs +1 -0
- package/dist/plugins/compareField.d.ts +58 -0
- package/dist/plugins/compareField.js +1 -0
- package/dist/plugins/compareField.mjs +1 -0
- package/dist/plugins/custom.d.ts +60 -0
- package/dist/plugins/custom.js +1 -0
- package/dist/plugins/custom.mjs +1 -0
- package/dist/plugins/jsonSchema.d.ts +11 -0
- package/dist/plugins/jsonSchema.js +1 -0
- package/dist/plugins/jsonSchema.mjs +1 -0
- package/dist/plugins/jsonSchemaFullFeature.d.ts +31 -0
- package/dist/plugins/jsonSchemaFullFeature.js +1 -0
- package/dist/plugins/jsonSchemaFullFeature.mjs +1 -0
- package/dist/plugins/literal.d.ts +40 -0
- package/dist/plugins/literal.js +1 -0
- package/dist/plugins/literal.mjs +1 -0
- package/dist/plugins/nullable.d.ts +34 -0
- package/dist/plugins/nullable.js +1 -0
- package/dist/plugins/nullable.mjs +1 -0
- package/dist/plugins/numberInteger.d.ts +41 -0
- package/dist/plugins/numberInteger.js +1 -0
- package/dist/plugins/numberInteger.mjs +1 -0
- package/dist/plugins/numberMax.d.ts +49 -0
- package/dist/plugins/numberMax.js +1 -0
- package/dist/plugins/numberMax.mjs +1 -0
- package/dist/plugins/numberMin.d.ts +49 -0
- package/dist/plugins/numberMin.js +1 -0
- package/dist/plugins/numberMin.mjs +1 -0
- package/dist/plugins/numberMultipleOf.d.ts +42 -0
- package/dist/plugins/numberMultipleOf.js +1 -0
- package/dist/plugins/numberMultipleOf.mjs +1 -0
- package/dist/plugins/numberNegative.d.ts +41 -0
- package/dist/plugins/numberNegative.js +1 -0
- package/dist/plugins/numberNegative.mjs +1 -0
- package/dist/plugins/numberPositive.d.ts +41 -0
- package/dist/plugins/numberPositive.js +1 -0
- package/dist/plugins/numberPositive.mjs +1 -0
- package/dist/plugins/object.d.ts +43 -0
- package/dist/plugins/object.js +1 -0
- package/dist/plugins/object.mjs +1 -0
- package/dist/plugins/objectAdditionalProperties.d.ts +51 -0
- package/dist/plugins/objectAdditionalProperties.js +1 -0
- package/dist/plugins/objectAdditionalProperties.mjs +1 -0
- package/dist/plugins/objectDependentRequired.d.ts +42 -0
- package/dist/plugins/objectDependentRequired.js +1 -0
- package/dist/plugins/objectDependentRequired.mjs +1 -0
- package/dist/plugins/objectDependentSchemas.d.ts +40 -0
- package/dist/plugins/objectDependentSchemas.js +1 -0
- package/dist/plugins/objectDependentSchemas.mjs +1 -0
- package/dist/plugins/objectMaxProperties.d.ts +42 -0
- package/dist/plugins/objectMaxProperties.js +1 -0
- package/dist/plugins/objectMaxProperties.mjs +1 -0
- package/dist/plugins/objectMinProperties.d.ts +42 -0
- package/dist/plugins/objectMinProperties.js +1 -0
- package/dist/plugins/objectMinProperties.mjs +1 -0
- package/dist/plugins/objectPatternProperties.d.ts +46 -0
- package/dist/plugins/objectPatternProperties.js +1 -0
- package/dist/plugins/objectPatternProperties.mjs +1 -0
- package/dist/plugins/objectPropertyNames.d.ts +36 -0
- package/dist/plugins/objectPropertyNames.js +1 -0
- package/dist/plugins/objectPropertyNames.mjs +1 -0
- package/dist/plugins/oneOf.d.ts +44 -0
- package/dist/plugins/oneOf.js +1 -0
- package/dist/plugins/oneOf.mjs +1 -0
- package/dist/plugins/optional.d.ts +35 -0
- package/dist/plugins/optional.js +1 -0
- package/dist/plugins/optional.mjs +1 -0
- package/dist/plugins/readOnlyWriteOnly.d.ts +48 -0
- package/dist/plugins/readOnlyWriteOnly.js +1 -0
- package/dist/plugins/readOnlyWriteOnly.mjs +1 -0
- package/dist/plugins/required.d.ts +45 -0
- package/dist/plugins/required.js +1 -0
- package/dist/plugins/required.mjs +1 -0
- package/dist/plugins/requiredIf.d.ts +66 -0
- package/dist/plugins/requiredIf.js +1 -0
- package/dist/plugins/requiredIf.mjs +1 -0
- package/dist/plugins/skip.d.ts +57 -0
- package/dist/plugins/skip.js +1 -0
- package/dist/plugins/skip.mjs +1 -0
- package/dist/plugins/stringBase64.d.ts +119 -0
- package/dist/plugins/stringBase64.js +1 -0
- package/dist/plugins/stringBase64.mjs +1 -0
- package/dist/plugins/stringContentEncoding.d.ts +43 -0
- package/dist/plugins/stringContentEncoding.js +1 -0
- package/dist/plugins/stringContentEncoding.mjs +1 -0
- package/dist/plugins/stringContentMediaType.d.ts +47 -0
- package/dist/plugins/stringContentMediaType.js +1 -0
- package/dist/plugins/stringContentMediaType.mjs +1 -0
- package/dist/plugins/stringDate.d.ts +48 -0
- package/dist/plugins/stringDate.js +1 -0
- package/dist/plugins/stringDate.mjs +1 -0
- package/dist/plugins/stringDatetime.d.ts +108 -0
- package/dist/plugins/stringDatetime.js +1 -0
- package/dist/plugins/stringDatetime.mjs +1 -0
- package/dist/plugins/stringDuration.d.ts +41 -0
- package/dist/plugins/stringDuration.js +1 -0
- package/dist/plugins/stringDuration.mjs +1 -0
- package/dist/plugins/stringEmail.d.ts +81 -0
- package/dist/plugins/stringEmail.js +1 -0
- package/dist/plugins/stringEmail.mjs +1 -0
- package/dist/plugins/stringHostname.d.ts +104 -0
- package/dist/plugins/stringHostname.js +1 -0
- package/dist/plugins/stringHostname.mjs +1 -0
- package/dist/plugins/stringIpv4.d.ts +85 -0
- package/dist/plugins/stringIpv4.js +1 -0
- package/dist/plugins/stringIpv4.mjs +1 -0
- package/dist/plugins/stringIpv6.d.ts +104 -0
- package/dist/plugins/stringIpv6.js +1 -0
- package/dist/plugins/stringIpv6.mjs +1 -0
- package/dist/plugins/stringIri.d.ts +117 -0
- package/dist/plugins/stringIri.js +1 -0
- package/dist/plugins/stringIri.mjs +1 -0
- package/dist/plugins/stringIriReference.d.ts +43 -0
- package/dist/plugins/stringIriReference.js +1 -0
- package/dist/plugins/stringIriReference.mjs +1 -0
- package/dist/plugins/stringJsonPointer.d.ts +107 -0
- package/dist/plugins/stringJsonPointer.js +1 -0
- package/dist/plugins/stringJsonPointer.mjs +1 -0
- package/dist/plugins/stringMax.d.ts +43 -0
- package/dist/plugins/stringMax.js +1 -0
- package/dist/plugins/stringMax.mjs +1 -0
- package/dist/plugins/stringMin.d.ts +43 -0
- package/dist/plugins/stringMin.js +1 -0
- package/dist/plugins/stringMin.mjs +1 -0
- package/dist/plugins/stringPattern.d.ts +40 -0
- package/dist/plugins/stringPattern.js +1 -0
- package/dist/plugins/stringPattern.mjs +1 -0
- package/dist/plugins/stringRelativeJsonPointer.d.ts +42 -0
- package/dist/plugins/stringRelativeJsonPointer.js +1 -0
- package/dist/plugins/stringRelativeJsonPointer.mjs +1 -0
- package/dist/plugins/stringTime.d.ts +39 -0
- package/dist/plugins/stringTime.js +1 -0
- package/dist/plugins/stringTime.mjs +1 -0
- package/dist/plugins/stringUriTemplate.d.ts +43 -0
- package/dist/plugins/stringUriTemplate.js +1 -0
- package/dist/plugins/stringUriTemplate.mjs +1 -0
- package/dist/plugins/stringUrl.d.ts +97 -0
- package/dist/plugins/stringUrl.js +1 -0
- package/dist/plugins/stringUrl.mjs +1 -0
- package/dist/plugins/transform.d.ts +35 -0
- package/dist/plugins/transform.js +1 -0
- package/dist/plugins/transform.mjs +1 -0
- package/dist/plugins/tupleBuilder.d.ts +66 -0
- package/dist/plugins/tupleBuilder.js +1 -0
- package/dist/plugins/tupleBuilder.mjs +1 -0
- package/dist/plugins/uuid.d.ts +95 -0
- package/dist/plugins/uuid.js +1 -0
- package/dist/plugins/uuid.mjs +1 -0
- package/dist/plugins/validateIf.d.ts +57 -0
- package/dist/plugins/validateIf.js +1 -0
- package/dist/plugins/validateIf.mjs +1 -0
- package/dist/types/array-type-analysis.d.ts +115 -0
- package/dist/types/index.d.ts +74 -0
- package/dist/types/indexed-result.d.ts +44 -0
- package/dist/types/result.d.ts +159 -0
- package/dist/types/stitch-types.d.ts +118 -0
- package/dist/types/util.d.ts +19 -0
- package/dist/types/valitator.d.ts +10 -0
- package/package.json +353 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name stringContentEncoding
|
|
4
|
+
* @category string
|
|
5
|
+
* @description Validates string content encoding (base64, base32, binary, etc.)
|
|
6
|
+
* @allowedTypes ["string"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const validator = Builder()
|
|
10
|
+
* .use(stringContentEncodingPlugin)
|
|
11
|
+
* .for<{ data: string }>()
|
|
12
|
+
* .v("data", (b) => b.string.contentEncoding("base64"))
|
|
13
|
+
* .build();
|
|
14
|
+
*
|
|
15
|
+
* // Valid for base64: SGVsbG8gV29ybGQ=
|
|
16
|
+
* // Valid for base32: JBSWY3DPEBLW64TMMQ======
|
|
17
|
+
* // Valid for binary: 01001000 01100101
|
|
18
|
+
* ```
|
|
19
|
+
* @params
|
|
20
|
+
* - encoding: "base64" | "base32" | "binary" | "7bit" | "8bit" | "quoted-printable"
|
|
21
|
+
* - options?: { messageFactory?: (context: MessageContext) => string }
|
|
22
|
+
* @returns Validation function that checks content encoding
|
|
23
|
+
* @customError
|
|
24
|
+
* ```typescript
|
|
25
|
+
* .contentEncoding("base64", {
|
|
26
|
+
* messageFactory: ({ path, value }) =>
|
|
27
|
+
* `${path} must be valid base64 encoded content (received: ${value.substring(0, 20)}...)`
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
* @since 0.1.0-alpha
|
|
31
|
+
*/
|
|
32
|
+
import type { MessageContext } from "../core/plugin/types";
|
|
33
|
+
export declare const stringContentEncodingPlugin: import("../index").TypedPlugin<"stringContentEncoding", "contentEncoding", (encoding: "base64" | "base32" | "binary" | "7bit" | "8bit" | "quoted-printable" | string, options?: {
|
|
34
|
+
messageFactory?: (context: MessageContext) => string;
|
|
35
|
+
}) => {
|
|
36
|
+
check: (value: string) => boolean;
|
|
37
|
+
code: string;
|
|
38
|
+
getErrorMessage: (value: string, path: string) => string;
|
|
39
|
+
messageFactory: (context: MessageContext) => string;
|
|
40
|
+
params: (string | {
|
|
41
|
+
messageFactory?: (context: MessageContext) => string;
|
|
42
|
+
})[];
|
|
43
|
+
}, readonly ["string"], "validator", "standard">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(e,n)=>{for(var r in n)l(e,r,{get:n[r],enumerable:!0})},c=(e,n,r,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of T(n))!p.call(e,t)&&t!==r&&l(e,t,{get:()=>n[t],enumerable:!(a=g(n,t))||a.enumerable});return e};var y=e=>c(l({},"__esModule",{value:!0}),e);var w={};d(w,{stringContentEncodingPlugin:()=>E});module.exports=y(w);var f=(e,n,r,a)=>{let o=(s=>(...i)=>{let m=s(...i);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:a}:m})(r);switch(e){case"conditional":return(s,...i)=>o(s,...i);case"fieldReference":return(s,...i)=>o(s,...i);case"multiFieldReference":return o;case"transform":return s=>o(s);case"arrayElement":return(s,...i)=>o(s,...i);case"context":return s=>o(s);default:return o}};function u(e){let{name:n,methodName:r,allowedTypes:a,category:t,impl:o}=e;return{name:n,methodName:r,allowedTypes:a,category:t,create:()=>f(t,r,o,n)}}var N=/^[A-Za-z0-9+/]*={0,2}$/,h=/^[A-Z2-7]*={0,6}$/,x=/^[01\s]*$/;function I(e){for(let n=0;n<e.length;n++)if(e.charCodeAt(n)>127)return!1;return!0}function P(e){return!0}function C(e){let n=e.split(/\r?\n/);for(let r of n){if(r.length>76)return!1;let a=0;for(;a<r.length;)if(r[a]==="="){if(a===r.length-1)break;if(a+2<r.length){let t=r.substring(a+1,a+3);if(!/^[0-9A-Fa-f]{2}$/.test(t))return!1;a+=3}else return!1}else a++}return!0}function b(e,n){switch(n.toLowerCase()){case"base64":return e===""?!0:e.length%4!==0?!1:N.test(e);case"base32":return e===""?!0:e.length%8!==0?!1:h.test(e);case"binary":return x.test(e);case"7bit":return I(e);case"8bit":return P(e);case"quoted-printable":return C(e);default:return!0}}var E=u({name:"stringContentEncoding",methodName:"contentEncoding",allowedTypes:["string"],category:"standard",impl:(e,n)=>({check:t=>typeof t!="string"?!1:b(t,e),code:"CONTENT_ENCODING",getErrorMessage:(t,o)=>{let s={path:o,value:t,code:"CONTENT_ENCODING"};return n?.messageFactory?.(s)||`${o} must be valid ${e} encoded content`},messageFactory:t=>n?.messageFactory?.(t)||`${t.path} must be valid ${e} encoded content`,params:[e,n]})});0&&(module.exports={stringContentEncodingPlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u=(e,n,s,t)=>{let o=(a=>(...i)=>{let m=a(...i);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:t}:m})(s);switch(e){case"conditional":return(a,...i)=>o(a,...i);case"fieldReference":return(a,...i)=>o(a,...i);case"multiFieldReference":return o;case"transform":return a=>o(a);case"arrayElement":return(a,...i)=>o(a,...i);case"context":return a=>o(a);default:return o}};function l(e){let{name:n,methodName:s,allowedTypes:t,category:r,impl:o}=e;return{name:n,methodName:s,allowedTypes:t,category:r,create:()=>u(r,s,o,n)}}var g=/^[A-Za-z0-9+/]*={0,2}$/,T=/^[A-Z2-7]*={0,6}$/,p=/^[01\s]*$/;function d(e){for(let n=0;n<e.length;n++)if(e.charCodeAt(n)>127)return!1;return!0}function c(e){return!0}function y(e){let n=e.split(/\r?\n/);for(let s of n){if(s.length>76)return!1;let t=0;for(;t<s.length;)if(s[t]==="="){if(t===s.length-1)break;if(t+2<s.length){let r=s.substring(t+1,t+3);if(!/^[0-9A-Fa-f]{2}$/.test(r))return!1;t+=3}else return!1}else t++}return!0}function f(e,n){switch(n.toLowerCase()){case"base64":return e===""?!0:e.length%4!==0?!1:g.test(e);case"base32":return e===""?!0:e.length%8!==0?!1:T.test(e);case"binary":return p.test(e);case"7bit":return d(e);case"8bit":return c(e);case"quoted-printable":return y(e);default:return!0}}var x=l({name:"stringContentEncoding",methodName:"contentEncoding",allowedTypes:["string"],category:"standard",impl:(e,n)=>({check:r=>typeof r!="string"?!1:f(r,e),code:"CONTENT_ENCODING",getErrorMessage:(r,o)=>{let a={path:o,value:r,code:"CONTENT_ENCODING"};return n?.messageFactory?.(a)||`${o} must be valid ${e} encoded content`},messageFactory:r=>n?.messageFactory?.(r)||`${r.path} must be valid ${e} encoded content`,params:[e,n]})});export{x as stringContentEncodingPlugin};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name stringContentMediaType
|
|
4
|
+
* @category string
|
|
5
|
+
* @description Validates that a string's decoded content matches the specified media type
|
|
6
|
+
* @allowedTypes ["string"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const validator = Builder()
|
|
10
|
+
* .use(stringContentMediaTypePlugin)
|
|
11
|
+
* .for<{ data: string }>()
|
|
12
|
+
* .v("data", (b) => b.string.contentMediaType("application/json"))
|
|
13
|
+
* .build();
|
|
14
|
+
*
|
|
15
|
+
* // Valid: base64-encoded JSON
|
|
16
|
+
* validator.validate({ data: "eyJrZXkiOiJ2YWx1ZSJ9" }); // {"key":"value"}
|
|
17
|
+
*
|
|
18
|
+
* // Invalid: not valid JSON when decoded
|
|
19
|
+
* validator.validate({ data: "aGVsbG8gd29ybGQ=" }); // "hello world"
|
|
20
|
+
* ```
|
|
21
|
+
* @params
|
|
22
|
+
* - mediaType: string - The expected media type
|
|
23
|
+
* - options?: { encoding?: string; messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
24
|
+
* @returns Validation function that checks content media type
|
|
25
|
+
* @customError
|
|
26
|
+
* ```typescript
|
|
27
|
+
* .contentMediaType("application/json", {
|
|
28
|
+
* messageFactory: ({ path, value }) =>
|
|
29
|
+
* `${path} must contain valid JSON content (received: ${value.substring(0, 20)}...)`
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
* @since 0.1.0-alpha
|
|
33
|
+
*/
|
|
34
|
+
import type { MessageContext } from "../core/plugin/types";
|
|
35
|
+
export declare const stringContentMediaTypePlugin: import("../index").TypedPlugin<"stringContentMediaType", "contentMediaType", (mediaType: string, options?: {
|
|
36
|
+
encoding?: string;
|
|
37
|
+
messageFactory?: (context: MessageContext) => string;
|
|
38
|
+
}) => {
|
|
39
|
+
check: (value: string) => boolean;
|
|
40
|
+
code: string;
|
|
41
|
+
getErrorMessage: (value: string, path: string) => string;
|
|
42
|
+
messageFactory: (context: MessageContext) => string;
|
|
43
|
+
params: (string | {
|
|
44
|
+
encoding?: string;
|
|
45
|
+
messageFactory?: (context: MessageContext) => string;
|
|
46
|
+
})[];
|
|
47
|
+
}, readonly ["string"], "validator", "standard">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var c=(e,t)=>{for(var r in t)u(e,r,{get:t[r],enumerable:!0})},f=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!T.call(e,n)&&n!==r&&u(e,n,{get:()=>t[n],enumerable:!(s=p(t,n))||s.enumerable});return e};var y=e=>f(u({},"__esModule",{value:!0}),e);var C={};c(C,{stringContentMediaTypePlugin:()=>I});module.exports=y(C);var x=(e,t,r,s)=>{let i=(a=>(...o)=>{let m=a(...o);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:s}:m})(r);switch(e){case"conditional":return(a,...o)=>i(a,...o);case"fieldReference":return(a,...o)=>i(a,...o);case"multiFieldReference":return i;case"transform":return a=>i(a);case"arrayElement":return(a,...o)=>i(a,...o);case"context":return a=>i(a);default:return i}};function g(e){let{name:t,methodName:r,allowedTypes:s,category:n,impl:i}=e;return{name:t,methodName:r,allowedTypes:s,category:n,create:()=>x(n,r,i,t)}}function h(e,t){try{if(t==="base64"){if(typeof Buffer<"u")return Buffer.from(e,"base64").toString("utf-8");if(typeof atob<"u")return atob(e)}return e}catch{return null}}var l={"application/json":e=>{try{return JSON.parse(e),!0}catch{return!1}},"text/html":e=>/<\/?[a-z][\s\S]*>/i.test(e),"text/xml":e=>/^<\?xml[^>]*\?>|^<[a-zA-Z][\s\S]*>[\s\S]*<\/[a-zA-Z][\s\S]*>$/m.test(e.trim()),"text/plain":()=>!0,"text/css":e=>/[a-zA-Z-]+\s*:\s*[^;]+;?|\.[a-zA-Z-]+\s*\{|#[a-zA-Z-]+\s*\{|[a-zA-Z]+\s*\{/.test(e),"text/javascript":e=>/function\s+\w+\s*\(|const\s+\w+|let\s+\w+|var\s+\w+|=>\s*{|class\s+\w+/.test(e),"application/xml":e=>l["text/xml"](e),"application/pdf":e=>e.startsWith("%PDF"),"image/png":e=>{if(typeof Buffer<"u"){let t=Buffer.from(e,"binary");return t.length>=8&&t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71}return e.charCodeAt(0)===137&&e.charCodeAt(1)===80&&e.charCodeAt(2)===78&&e.charCodeAt(3)===71},"image/jpeg":e=>{if(typeof Buffer<"u"){let t=Buffer.from(e,"binary");return t.length>=3&&t[0]===255&&t[1]===216&&t[2]===255}return e.charCodeAt(0)===255&&e.charCodeAt(1)===216&&e.charCodeAt(2)===255},"image/gif":e=>e.startsWith("GIF87a")||e.startsWith("GIF89a"),"image/svg+xml":e=>/<svg[^>]*>[\s\S]*<\/svg>/i.test(e)};function N(e,t,r){let s=r?h(e,r):e;if(s===null)return!1;let n=l[t.toLowerCase()];return n?n(s):t.startsWith("text/")?!0:t.startsWith("application/")&&t.includes("json")?l["application/json"](s):t.startsWith("application/")&&t.includes("xml")?l["application/xml"](s):!0}var I=g({name:"stringContentMediaType",methodName:"contentMediaType",allowedTypes:["string"],category:"standard",impl:(e,t)=>({check:n=>typeof n!="string"?!1:N(n,e,t?.encoding),code:"CONTENT_MEDIA_TYPE",getErrorMessage:(n,i)=>{let a={path:i,value:n,code:"CONTENT_MEDIA_TYPE"};return t?.messageFactory?.(a)||`${i} must be valid ${e} content${t?.encoding?` (${t.encoding} encoded)`:""}`},messageFactory:n=>t?.messageFactory?.(n)||`${n.path} must be valid ${e} content${t?.encoding?` (${t.encoding} encoded)`:""}`,params:[e,t]})});0&&(module.exports={stringContentMediaTypePlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=(e,t,i,s)=>{let a=(r=>(...o)=>{let m=r(...o);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:s}:m})(i);switch(e){case"conditional":return(r,...o)=>a(r,...o);case"fieldReference":return(r,...o)=>a(r,...o);case"multiFieldReference":return a;case"transform":return r=>a(r);case"arrayElement":return(r,...o)=>a(r,...o);case"context":return r=>a(r);default:return a}};function u(e){let{name:t,methodName:i,allowedTypes:s,category:n,impl:a}=e;return{name:t,methodName:i,allowedTypes:s,category:n,create:()=>g(n,i,a,t)}}function p(e,t){try{if(t==="base64"){if(typeof Buffer<"u")return Buffer.from(e,"base64").toString("utf-8");if(typeof atob<"u")return atob(e)}return e}catch{return null}}var l={"application/json":e=>{try{return JSON.parse(e),!0}catch{return!1}},"text/html":e=>/<\/?[a-z][\s\S]*>/i.test(e),"text/xml":e=>/^<\?xml[^>]*\?>|^<[a-zA-Z][\s\S]*>[\s\S]*<\/[a-zA-Z][\s\S]*>$/m.test(e.trim()),"text/plain":()=>!0,"text/css":e=>/[a-zA-Z-]+\s*:\s*[^;]+;?|\.[a-zA-Z-]+\s*\{|#[a-zA-Z-]+\s*\{|[a-zA-Z]+\s*\{/.test(e),"text/javascript":e=>/function\s+\w+\s*\(|const\s+\w+|let\s+\w+|var\s+\w+|=>\s*{|class\s+\w+/.test(e),"application/xml":e=>l["text/xml"](e),"application/pdf":e=>e.startsWith("%PDF"),"image/png":e=>{if(typeof Buffer<"u"){let t=Buffer.from(e,"binary");return t.length>=8&&t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71}return e.charCodeAt(0)===137&&e.charCodeAt(1)===80&&e.charCodeAt(2)===78&&e.charCodeAt(3)===71},"image/jpeg":e=>{if(typeof Buffer<"u"){let t=Buffer.from(e,"binary");return t.length>=3&&t[0]===255&&t[1]===216&&t[2]===255}return e.charCodeAt(0)===255&&e.charCodeAt(1)===216&&e.charCodeAt(2)===255},"image/gif":e=>e.startsWith("GIF87a")||e.startsWith("GIF89a"),"image/svg+xml":e=>/<svg[^>]*>[\s\S]*<\/svg>/i.test(e)};function d(e,t,i){let s=i?p(e,i):e;if(s===null)return!1;let n=l[t.toLowerCase()];return n?n(s):t.startsWith("text/")?!0:t.startsWith("application/")&&t.includes("json")?l["application/json"](s):t.startsWith("application/")&&t.includes("xml")?l["application/xml"](s):!0}var f=u({name:"stringContentMediaType",methodName:"contentMediaType",allowedTypes:["string"],category:"standard",impl:(e,t)=>({check:n=>typeof n!="string"?!1:d(n,e,t?.encoding),code:"CONTENT_MEDIA_TYPE",getErrorMessage:(n,a)=>{let r={path:a,value:n,code:"CONTENT_MEDIA_TYPE"};return t?.messageFactory?.(r)||`${a} must be valid ${e} content${t?.encoding?` (${t.encoding} encoded)`:""}`},messageFactory:n=>t?.messageFactory?.(n)||`${n.path} must be valid ${e} content${t?.encoding?` (${t.encoding} encoded)`:""}`,params:[e,t]})});export{f as stringContentMediaTypePlugin};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name stringDate
|
|
4
|
+
* @category string
|
|
5
|
+
* @description Validates ISO 8601 date format (YYYY-MM-DD)
|
|
6
|
+
* @allowedTypes ["string"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const validator = Builder()
|
|
10
|
+
* .use(stringDatePlugin)
|
|
11
|
+
* .for<{ birthDate: string }>()
|
|
12
|
+
* .v("birthDate", (b) => b.string.date())
|
|
13
|
+
* .build();
|
|
14
|
+
*
|
|
15
|
+
* // Valid formats:
|
|
16
|
+
* // 2024-01-15
|
|
17
|
+
* // 2024-12-31
|
|
18
|
+
* // 2000-02-29 (leap year)
|
|
19
|
+
*
|
|
20
|
+
* // Invalid:
|
|
21
|
+
* // 2024-13-01 (invalid month)
|
|
22
|
+
* // 2024-02-30 (invalid day)
|
|
23
|
+
* // 2024-1-1 (must be zero-padded)
|
|
24
|
+
* ```
|
|
25
|
+
* @params
|
|
26
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
27
|
+
* @returns Validation function that checks ISO 8601 date format
|
|
28
|
+
* @customError
|
|
29
|
+
* ```typescript
|
|
30
|
+
* .date({
|
|
31
|
+
* messageFactory: ({ path, value }) =>
|
|
32
|
+
* `${path} must be a valid ISO 8601 date format (received: ${value})`
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
* @since 0.1.0-alpha
|
|
36
|
+
*/
|
|
37
|
+
import type { MessageContext } from "../core/plugin/types";
|
|
38
|
+
export declare const stringDatePlugin: import("../index").TypedPlugin<"stringDate", "date", (options?: {
|
|
39
|
+
messageFactory?: (context: MessageContext) => string;
|
|
40
|
+
}) => {
|
|
41
|
+
check: (value: string) => boolean;
|
|
42
|
+
code: string;
|
|
43
|
+
getErrorMessage: (value: string, path: string) => string;
|
|
44
|
+
messageFactory: (context: MessageContext) => string;
|
|
45
|
+
params: {
|
|
46
|
+
messageFactory?: (context: MessageContext) => string;
|
|
47
|
+
}[];
|
|
48
|
+
}, readonly ["string"], "validator", "standard">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var y=(e,n)=>{for(var o in n)l(e,o,{get:n[o],enumerable:!0})},c=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of d(n))!g.call(e,s)&&s!==o&&l(e,s,{get:()=>n[s],enumerable:!(t=u(n,s))||t.enumerable});return e};var f=e=>c(l({},"__esModule",{value:!0}),e);var P={};y(P,{stringDatePlugin:()=>x});module.exports=f(P);var N=(e,n,o,t)=>{let a=(r=>(...i)=>{let m=r(...i);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:t}:m})(o);switch(e){case"conditional":return(r,...i)=>a(r,...i);case"fieldReference":return(r,...i)=>a(r,...i);case"multiFieldReference":return a;case"transform":return r=>a(r);case"arrayElement":return(r,...i)=>a(r,...i);case"context":return r=>a(r);default:return a}};function p(e){let{name:n,methodName:o,allowedTypes:t,category:s,impl:a}=e;return{name:n,methodName:o,allowedTypes:t,category:s,create:()=>N(s,o,a,n)}}var h=/^(\d{4})-(\d{2})-(\d{2})$/;function I(e){let n=e.match(h);if(!n)return!1;let[,o,t,s]=n,a=parseInt(o,10),r=parseInt(t,10),i=parseInt(s,10);if(r<1||r>12||i<1||i>31)return!1;let m=[31,28,31,30,31,30,31,31,30,31,30,31];if((a%4===0&&a%100!==0||a%400===0)&&(m[1]=29),i>m[r-1])return!1;let T=new Date(`${e}T12:00:00Z`);return isNaN(T.getTime())?!1:T.toISOString().split("T")[0]===e}var x=p({name:"stringDate",methodName:"date",allowedTypes:["string"],category:"standard",impl:e=>({check:t=>typeof t!="string"?!1:I(t),code:"FORMAT_DATE",getErrorMessage:(t,s)=>{let a={path:s,value:t,code:"FORMAT_DATE"};return e?.messageFactory?.(a)||`${s} must be a valid ISO 8601 date (YYYY-MM-DD)`},messageFactory:t=>e?.messageFactory?.(t)||`${t.path} must be a valid ISO 8601 date (YYYY-MM-DD)`,params:[e]})});0&&(module.exports={stringDatePlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=(a,i,m,t)=>{let e=(n=>(...r)=>{let o=n(...r);return o&&typeof o=="object"&&"check"in o?{...o,pluginName:t}:o})(m);switch(a){case"conditional":return(n,...r)=>e(n,...r);case"fieldReference":return(n,...r)=>e(n,...r);case"multiFieldReference":return e;case"transform":return n=>e(n);case"arrayElement":return(n,...r)=>e(n,...r);case"context":return n=>e(n);default:return e}};function T(a){let{name:i,methodName:m,allowedTypes:t,category:s,impl:e}=a;return{name:i,methodName:m,allowedTypes:t,category:s,create:()=>p(s,m,e,i)}}var u=/^(\d{4})-(\d{2})-(\d{2})$/;function d(a){let i=a.match(u);if(!i)return!1;let[,m,t,s]=i,e=parseInt(m,10),n=parseInt(t,10),r=parseInt(s,10);if(n<1||n>12||r<1||r>31)return!1;let o=[31,28,31,30,31,30,31,31,30,31,30,31];if((e%4===0&&e%100!==0||e%400===0)&&(o[1]=29),r>o[n-1])return!1;let l=new Date(`${a}T12:00:00Z`);return isNaN(l.getTime())?!1:l.toISOString().split("T")[0]===a}var N=T({name:"stringDate",methodName:"date",allowedTypes:["string"],category:"standard",impl:a=>({check:t=>typeof t!="string"?!1:d(t),code:"FORMAT_DATE",getErrorMessage:(t,s)=>{let e={path:s,value:t,code:"FORMAT_DATE"};return a?.messageFactory?.(e)||`${s} must be a valid ISO 8601 date (YYYY-MM-DD)`},messageFactory:t=>a?.messageFactory?.(t)||`${t.path} must be a valid ISO 8601 date (YYYY-MM-DD)`,params:[a]})});export{N as stringDatePlugin};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { MessageContext } from "../core/plugin/types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name stringDatetime
|
|
5
|
+
* @category string
|
|
6
|
+
* @description Validates ISO 8601 datetime format with optional timezone support
|
|
7
|
+
* @allowedTypes ["string"]
|
|
8
|
+
* @see https://tools.ietf.org/html/rfc3339 - RFC 3339: Date and Time on the Internet: Timestamps
|
|
9
|
+
* @see https://en.wikipedia.org/wiki/ISO_8601 - ISO 8601 Date and Time Format
|
|
10
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date - MDN Date Object
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Basic usage - validates ISO 8601 datetime format (RFC 3339 compliant)
|
|
14
|
+
* const validator = Builder()
|
|
15
|
+
* .use(stringDatetimePlugin)
|
|
16
|
+
* .for<{ timestamp: string }>()
|
|
17
|
+
* .v("timestamp", (b) => b.string.datetime())
|
|
18
|
+
* .build();
|
|
19
|
+
*
|
|
20
|
+
* // Strict mode - requires timezone
|
|
21
|
+
* const strictValidator = Builder()
|
|
22
|
+
* .use(stringDatetimePlugin)
|
|
23
|
+
* .for<{ timestamp: string }>()
|
|
24
|
+
* .v("timestamp", (b) => b.string.datetime({ strict: true }))
|
|
25
|
+
* .build();
|
|
26
|
+
*
|
|
27
|
+
* // ✅ VALID datetime formats (RFC 3339 / ISO 8601)
|
|
28
|
+
* // UTC timezone
|
|
29
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00Z" }); // UTC with Z
|
|
30
|
+
* validator.parse({ timestamp: "2024-12-31T23:59:59Z" }); // End of year
|
|
31
|
+
* validator.parse({ timestamp: "2000-01-01T00:00:00Z" }); // Y2K date
|
|
32
|
+
*
|
|
33
|
+
* // With timezone offsets
|
|
34
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00+09:00" }); // Japan timezone
|
|
35
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00-05:00" }); // EST timezone
|
|
36
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00+00:00" }); // UTC with offset
|
|
37
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00-12:00" }); // Far west timezone
|
|
38
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00+14:00" }); // Far east timezone
|
|
39
|
+
*
|
|
40
|
+
* // With milliseconds
|
|
41
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00.123Z" }); // 3-digit milliseconds
|
|
42
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00.1Z" }); // 1-digit milliseconds
|
|
43
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00.12Z" }); // 2-digit milliseconds
|
|
44
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00.999+09:00" }); // Max milliseconds with offset
|
|
45
|
+
*
|
|
46
|
+
* // Leap year dates
|
|
47
|
+
* validator.parse({ timestamp: "2024-02-29T12:00:00Z" }); // Valid leap day 2024
|
|
48
|
+
* validator.parse({ timestamp: "2000-02-29T12:00:00Z" }); // Valid leap day 2000
|
|
49
|
+
*
|
|
50
|
+
* // Edge cases
|
|
51
|
+
* validator.parse({ timestamp: "2024-01-01T00:00:00Z" }); // Start of year
|
|
52
|
+
* validator.parse({ timestamp: "2024-12-31T23:59:59.999Z" }); // End of year with ms
|
|
53
|
+
* validator.parse({ timestamp: "1970-01-01T00:00:00Z" }); // Unix epoch
|
|
54
|
+
* validator.parse({ timestamp: "9999-12-31T23:59:59Z" }); // Far future
|
|
55
|
+
*
|
|
56
|
+
* // Without timezone (lenient mode only)
|
|
57
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00" }); // Local time (strict: false)
|
|
58
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00.123" }); // Local time with ms
|
|
59
|
+
*
|
|
60
|
+
* // ❌ INVALID datetime formats
|
|
61
|
+
* validator.parse({ timestamp: "invalid-datetime" }); // Plain text
|
|
62
|
+
* validator.parse({ timestamp: "2024-13-15T10:30:00Z" }); // Invalid month (13)
|
|
63
|
+
* validator.parse({ timestamp: "2024-00-15T10:30:00Z" }); // Invalid month (0)
|
|
64
|
+
* validator.parse({ timestamp: "2024-01-32T10:30:00Z" }); // Invalid day (32)
|
|
65
|
+
* validator.parse({ timestamp: "2024-01-00T10:30:00Z" }); // Invalid day (0)
|
|
66
|
+
* validator.parse({ timestamp: "2024-01-15T25:30:00Z" }); // Invalid hour (25)
|
|
67
|
+
* validator.parse({ timestamp: "2024-01-15T10:60:00Z" }); // Invalid minute (60)
|
|
68
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:61Z" }); // Invalid second (61)
|
|
69
|
+
* validator.parse({ timestamp: "2024-02-30T10:30:00Z" }); // Invalid day for February
|
|
70
|
+
* validator.parse({ timestamp: "2023-02-29T10:30:00Z" }); // Not a leap year
|
|
71
|
+
* validator.parse({ timestamp: "2024-04-31T10:30:00Z" }); // Invalid day for April
|
|
72
|
+
* validator.parse({ timestamp: "2024-01-15 10:30:00Z" }); // Space instead of T
|
|
73
|
+
* validator.parse({ timestamp: "2024/01/15T10:30:00Z" }); // Wrong date separator
|
|
74
|
+
* validator.parse({ timestamp: "24-01-15T10:30:00Z" }); // 2-digit year
|
|
75
|
+
* validator.parse({ timestamp: "2024-1-15T10:30:00Z" }); // Single-digit month
|
|
76
|
+
* validator.parse({ timestamp: "2024-01-5T10:30:00Z" }); // Single-digit day
|
|
77
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00" }); // Missing timezone (strict: true)
|
|
78
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00+25:00" }); // Invalid timezone offset
|
|
79
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00.1234Z" }); // Too many milliseconds digits
|
|
80
|
+
* validator.parse({ timestamp: "" }); // Empty string
|
|
81
|
+
* validator.parse({ timestamp: "2024-01-15T10:30:00Z " }); // Trailing space
|
|
82
|
+
* validator.parse({ timestamp: " 2024-01-15T10:30:00Z" }); // Leading space
|
|
83
|
+
* ```
|
|
84
|
+
* @params
|
|
85
|
+
* - options?: { messageFactory?: (context: MessageContext) => string; strict?: boolean } - Optional configuration
|
|
86
|
+
* @returns Validation function that checks ISO 8601 datetime format
|
|
87
|
+
* @customError
|
|
88
|
+
* ```typescript
|
|
89
|
+
* .datetime({
|
|
90
|
+
* messageFactory: ({ path, value }) =>
|
|
91
|
+
* `${path} must be a valid ISO 8601 datetime (received: ${value})`
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
* @since 0.1.0-alpha
|
|
95
|
+
*/
|
|
96
|
+
export declare const stringDatetimePlugin: import("../index").TypedPlugin<"stringDatetime", "datetime", (options?: {
|
|
97
|
+
messageFactory?: (context: MessageContext) => string;
|
|
98
|
+
strict?: boolean;
|
|
99
|
+
}) => {
|
|
100
|
+
check: (value: string) => boolean;
|
|
101
|
+
code: string;
|
|
102
|
+
getErrorMessage: (value: string, path: string) => string;
|
|
103
|
+
messageFactory: (context: MessageContext) => string;
|
|
104
|
+
params: {
|
|
105
|
+
messageFactory?: (context: MessageContext) => string;
|
|
106
|
+
strict?: boolean;
|
|
107
|
+
}[];
|
|
108
|
+
}, readonly ["string"], "validator", "standard">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var o in t)u(e,o,{get:t[o],enumerable:!0})},C=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of x(t))!P.call(e,a)&&a!==o&&u(e,a,{get:()=>t[a],enumerable:!(n=h(t,a))||n.enumerable});return e};var E=e=>C(u({},"__esModule",{value:!0}),e);var k={};M(k,{stringDatetimePlugin:()=>W});module.exports=E(k);var w=(e,t,o,n)=>{let r=(s=>(...i)=>{let m=s(...i);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:n}:m})(o);switch(e){case"conditional":return(s,...i)=>r(s,...i);case"fieldReference":return(s,...i)=>r(s,...i);case"multiFieldReference":return r;case"transform":return s=>r(s);case"arrayElement":return(s,...i)=>r(s,...i);case"context":return s=>r(s);default:return r}};function f(e){let{name:t,methodName:o,allowedTypes:n,category:a,impl:r}=e;return{name:t,methodName:o,allowedTypes:n,category:a,create:()=>w(a,o,r,t)}}var S=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})$/,b=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?$/;function O(e,t=!1){let o=t?S:b,n=e.match(o);if(!n)return!1;let[,a,r,s,i,m,I]=n,l=parseInt(a,10),T=parseInt(r,10),d=parseInt(s,10),p=parseInt(i,10),g=parseInt(m,10),c=parseInt(I,10);if(T<1||T>12||d<1||d>31||p<0||p>23||g<0||g>59||c<0||c>60)return!1;let y=[31,28,31,30,31,30,31,31,30,31,30,31];if((l%4===0&&l%100!==0||l%400===0)&&(y[1]=29),d>y[T-1])return!1;let N=new Date(e);return!isNaN(N.getTime())}var W=f({name:"stringDatetime",methodName:"datetime",allowedTypes:["string"],category:"standard",impl:e=>({check:n=>typeof n!="string"?!1:O(n,e?.strict),code:"FORMAT_DATETIME",getErrorMessage:(n,a)=>{let r={path:a,value:n,code:"FORMAT_DATETIME"};return e?.messageFactory?.(r)||`${a} must be a valid ISO 8601 datetime`},messageFactory:n=>e?.messageFactory?.(n)||`${n.path} must be a valid ISO 8601 datetime`,params:[e]})});0&&(module.exports={stringDatetimePlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var N=(a,m,o,e)=>{let n=(t=>(...r)=>{let i=t(...r);return i&&typeof i=="object"&&"check"in i?{...i,pluginName:e}:i})(o);switch(a){case"conditional":return(t,...r)=>n(t,...r);case"fieldReference":return(t,...r)=>n(t,...r);case"multiFieldReference":return n;case"transform":return t=>n(t);case"arrayElement":return(t,...r)=>n(t,...r);case"context":return t=>n(t);default:return n}};function y(a){let{name:m,methodName:o,allowedTypes:e,category:s,impl:n}=a;return{name:m,methodName:o,allowedTypes:e,category:s,create:()=>N(s,o,n,m)}}var h=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})$/,x=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?$/;function P(a,m=!1){let o=m?h:x,e=a.match(o);if(!e)return!1;let[,s,n,t,r,i,f]=e,l=parseInt(s,10),T=parseInt(n,10),d=parseInt(t,10),u=parseInt(r,10),p=parseInt(i,10),g=parseInt(f,10);if(T<1||T>12||d<1||d>31||u<0||u>23||p<0||p>59||g<0||g>60)return!1;let c=[31,28,31,30,31,30,31,31,30,31,30,31];if((l%4===0&&l%100!==0||l%400===0)&&(c[1]=29),d>c[T-1])return!1;let I=new Date(a);return!isNaN(I.getTime())}var w=y({name:"stringDatetime",methodName:"datetime",allowedTypes:["string"],category:"standard",impl:a=>({check:e=>typeof e!="string"?!1:P(e,a?.strict),code:"FORMAT_DATETIME",getErrorMessage:(e,s)=>{let n={path:s,value:e,code:"FORMAT_DATETIME"};return a?.messageFactory?.(n)||`${s} must be a valid ISO 8601 datetime`},messageFactory:e=>a?.messageFactory?.(e)||`${e.path} must be a valid ISO 8601 datetime`,params:[a]})});export{w as stringDatetimePlugin};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name stringDuration
|
|
4
|
+
* @category string
|
|
5
|
+
* @description Validates ISO 8601 duration format
|
|
6
|
+
* @allowedTypes ["string"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const validator = Builder()
|
|
10
|
+
* .use(stringDurationPlugin)
|
|
11
|
+
* .for<{ duration: string }>()
|
|
12
|
+
* .v("duration", (b) => b.string.duration())
|
|
13
|
+
* .build();
|
|
14
|
+
*
|
|
15
|
+
* // Valid: P3Y6M4DT12H30M5S (3 years, 6 months, 4 days, 12 hours, 30 minutes, 5 seconds)
|
|
16
|
+
* // Valid: PT1H30M (1 hour, 30 minutes)
|
|
17
|
+
* // Valid: P7D (7 days)
|
|
18
|
+
* ```
|
|
19
|
+
* @params
|
|
20
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional custom error message factory
|
|
21
|
+
* @returns Validation function that checks ISO 8601 duration format
|
|
22
|
+
* @customError
|
|
23
|
+
* ```typescript
|
|
24
|
+
* .duration({
|
|
25
|
+
* messageFactory: ({ path, value }) =>
|
|
26
|
+
* `${path} must be valid ISO 8601 duration format, received: ${value}`
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
* @since 0.1.0-alpha
|
|
30
|
+
*/
|
|
31
|
+
import type { MessageContext } from "../core/plugin/types";
|
|
32
|
+
export declare const stringDurationPlugin: import("../index").TypedPlugin<"stringDuration", "duration", (options?: {
|
|
33
|
+
messageFactory?: (context: MessageContext) => string;
|
|
34
|
+
}) => {
|
|
35
|
+
check: (value: string) => boolean;
|
|
36
|
+
code: string;
|
|
37
|
+
getErrorMessage: (value: string, path: string) => string;
|
|
38
|
+
params: {
|
|
39
|
+
messageFactory?: (context: MessageContext) => string;
|
|
40
|
+
}[];
|
|
41
|
+
}, readonly ["string"], "validator", "standard">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var g=(n,e)=>{for(var a in e)l(n,a,{get:e[a],enumerable:!0})},y=(n,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!d.call(n,r)&&r!==a&&l(n,r,{get:()=>e[r],enumerable:!(t=p(e,r))||t.enumerable});return n};var c=n=>y(l({},"__esModule",{value:!0}),n);var I={};g(I,{stringDurationPlugin:()=>x});module.exports=c(I);var f=(n,e,a,t)=>{let s=(o=>(...i)=>{let m=o(...i);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:t}:m})(a);switch(n){case"conditional":return(o,...i)=>s(o,...i);case"fieldReference":return(o,...i)=>s(o,...i);case"multiFieldReference":return s;case"transform":return o=>s(o);case"arrayElement":return(o,...i)=>s(o,...i);case"context":return o=>s(o);default:return s}};function T(n){let{name:e,methodName:a,allowedTypes:t,category:r,impl:s}=n;return{name:e,methodName:a,allowedTypes:t,category:r,create:()=>f(r,a,s,e)}}var N=/^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+(\.\d+)?S)?)?$/,x=T({name:"stringDuration",methodName:"duration",allowedTypes:["string"],category:"standard",impl:n=>{let e=()=>"must be a valid ISO 8601 duration",a=n?.messageFactory||(t=>`${t.path} ${e()}`);return{check:t=>typeof t!="string"?!1:N.test(t),code:"FORMAT_DURATION",getErrorMessage:(t,r)=>a({path:r,value:t,code:"FORMAT_DURATION"}),params:[n]}}});0&&(module.exports={stringDurationPlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var T=(r,s,o,n)=>{let t=(e=>(...a)=>{let m=e(...a);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:n}:m})(o);switch(r){case"conditional":return(e,...a)=>t(e,...a);case"fieldReference":return(e,...a)=>t(e,...a);case"multiFieldReference":return t;case"transform":return e=>t(e);case"arrayElement":return(e,...a)=>t(e,...a);case"context":return e=>t(e);default:return t}};function l(r){let{name:s,methodName:o,allowedTypes:n,category:i,impl:t}=r;return{name:s,methodName:o,allowedTypes:n,category:i,create:()=>T(i,o,t,s)}}var p=/^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+(\.\d+)?S)?)?$/,g=l({name:"stringDuration",methodName:"duration",allowedTypes:["string"],category:"standard",impl:r=>{let s=()=>"must be a valid ISO 8601 duration",o=r?.messageFactory||(n=>`${n.path} ${s()}`);return{check:n=>typeof n!="string"?!1:p.test(n),code:"FORMAT_DURATION",getErrorMessage:(n,i)=>o({path:i,value:n,code:"FORMAT_DURATION"}),params:[r]}}});export{g as stringDurationPlugin};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ValidationOptions } from "../core/plugin/types";
|
|
2
|
+
interface EmailValidationOptions extends ValidationOptions {
|
|
3
|
+
allowedDomains?: string[];
|
|
4
|
+
customRegex?: RegExp;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @luq-plugin
|
|
8
|
+
* @name stringEmail
|
|
9
|
+
* @category standard
|
|
10
|
+
* @description Simple and fast email validation with domain restriction and custom regex support (RFC 5322 compliant)
|
|
11
|
+
* @allowedTypes ["string"]
|
|
12
|
+
* @see https://tools.ietf.org/html/rfc5322 - RFC 5322: Internet Message Format
|
|
13
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email - MDN Email Input Validation
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Basic usage - validates email format (RFC 5322 compliant)
|
|
17
|
+
* const validator = Builder()
|
|
18
|
+
* .use(stringEmailPlugin)
|
|
19
|
+
* .for<UserProfile>()
|
|
20
|
+
* .v("email", (b) => b.string.email())
|
|
21
|
+
* .v("contactEmail", (b) => b.string.required().email())
|
|
22
|
+
* .build();
|
|
23
|
+
*
|
|
24
|
+
* // Domain restriction (practical: corporate email only)
|
|
25
|
+
* builder.v("workEmail", b => b.string.required().email({
|
|
26
|
+
* allowedDomains: ["company.com", "subsidiary.co.jp"]
|
|
27
|
+
* }))
|
|
28
|
+
*
|
|
29
|
+
* // Custom regex for specific format requirements
|
|
30
|
+
* builder.v("strictEmail", b => b.string.email({
|
|
31
|
+
* customRegex: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
|
|
32
|
+
* }))
|
|
33
|
+
*
|
|
34
|
+
* // For length limits, use existing string plugins:
|
|
35
|
+
* builder.v("email", b => b.string.required().max(100).email())
|
|
36
|
+
*
|
|
37
|
+
* // ✅ VALID email formats (RFC 5322)
|
|
38
|
+
* validator.parse({ email: "user@example.com" }); // Standard format
|
|
39
|
+
* validator.parse({ email: "test.email+tag@domain.co.uk" }); // With plus and dots
|
|
40
|
+
* validator.parse({ email: "user123@test-server.com" }); // Numbers and hyphens
|
|
41
|
+
* validator.parse({ email: "firstname.lastname@example.org" }); // Multiple dots
|
|
42
|
+
* validator.parse({ email: "user+filter@gmail.com" }); // Plus addressing
|
|
43
|
+
* validator.parse({ email: "a@b.co" }); // Minimal valid
|
|
44
|
+
* validator.parse({ email: "test_email@domain-name.com" }); // Underscores and hyphens
|
|
45
|
+
*
|
|
46
|
+
* // ❌ INVALID email formats
|
|
47
|
+
* validator.parse({ email: "plainaddress" }); // No @ symbol
|
|
48
|
+
* validator.parse({ email: "@missingdomain.com" }); // Missing local part
|
|
49
|
+
* validator.parse({ email: "missing.domain@" }); // Missing domain
|
|
50
|
+
* validator.parse({ email: "spaces @domain.com" }); // Spaces not allowed
|
|
51
|
+
* validator.parse({ email: "user@.com" }); // Invalid domain start
|
|
52
|
+
* validator.parse({ email: "user@domain" }); // Missing TLD
|
|
53
|
+
* validator.parse({ email: "user@@domain.com" }); // Double @ symbol
|
|
54
|
+
* validator.parse({ email: "user@domain..com" }); // Double dots in domain
|
|
55
|
+
* validator.parse({ email: ".user@domain.com" }); // Leading dot
|
|
56
|
+
* validator.parse({ email: "user.@domain.com" }); // Trailing dot
|
|
57
|
+
* ```
|
|
58
|
+
* @params
|
|
59
|
+
* - options?: EmailValidationOptions - Simple email validation configuration
|
|
60
|
+
* - allowedDomains?: string[] - Only allow emails from these domains (practical for corporate restrictions)
|
|
61
|
+
* - customRegex?: RegExp - Custom regex to override basic validation (practical escape hatch)
|
|
62
|
+
* - messageFactory?: (context: MessageContext) => string - Custom error message factory
|
|
63
|
+
* @returns Validation function optimized for performance - regex validation with optional domain filtering or custom regex
|
|
64
|
+
* @customError
|
|
65
|
+
* ```typescript
|
|
66
|
+
* .email({
|
|
67
|
+
* allowedDomains: ["company.com"],
|
|
68
|
+
* messageFactory: ({ path, value }) =>
|
|
69
|
+
* `${path} must be a company email address (received: ${value})`
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
* @since 0.1.0-alpha
|
|
73
|
+
*/
|
|
74
|
+
export declare const stringEmailPlugin: import("../index").TypedPlugin<"stringEmail", "email", (options?: EmailValidationOptions) => {
|
|
75
|
+
check: (value: any) => boolean;
|
|
76
|
+
code: string;
|
|
77
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
78
|
+
params: EmailValidationOptions[];
|
|
79
|
+
validationOptions: EmailValidationOptions;
|
|
80
|
+
}, readonly ["string"], "validator", "standard">;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var c=(n,t)=>{for(var o in t)l(n,o,{get:t[o],enumerable:!0})},f=(n,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!y.call(n,s)&&s!==o&&l(n,s,{get:()=>t[s],enumerable:!(i=u(t,s))||i.enumerable});return n};var x=n=>f(l({},"__esModule",{value:!0}),n);var E={};c(E,{stringEmailPlugin:()=>w});module.exports=x(E);var N=(n,t,o,i)=>{let e=(a=>(...r)=>{let m=a(...r);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:i}:m})(o);switch(n){case"conditional":return(a,...r)=>e(a,...r);case"fieldReference":return(a,...r)=>e(a,...r);case"multiFieldReference":return e;case"transform":return a=>e(a);case"arrayElement":return(a,...r)=>e(a,...r);case"context":return a=>e(a);default:return e}};function d(n){let{name:t,methodName:o,allowedTypes:i,category:s,impl:e}=n;return{name:t,methodName:o,allowedTypes:i,category:s,create:()=>N(s,o,e,t)}}var I=["string"],h=/^[a-zA-Z0-9]([a-zA-Z0-9._%+-]*[a-zA-Z0-9])?@[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/,P="stringEmail",w=d({name:"stringEmail",methodName:"email",allowedTypes:I,category:"standard",impl:n=>{let t=n?.code||P,o=n?.messageFactory||(e=>e.reason?`Invalid email: ${e.reason}`:"Invalid email address"),i=n?.allowedDomains?new Set(n.allowedDomains.map(e=>e.toLowerCase())):null,s=n?.customRegex||h;return{check:e=>{if(typeof e!="string")return!0;if(!s.test(e))return!1;if(i){let a=e.lastIndexOf("@");if(a===-1)return!1;let r=e.substring(a+1).toLowerCase();return i.has(r)}return!0},code:t,getErrorMessage:(e,a)=>{if(typeof e!="string")return o({path:a,value:e,code:t});let r="";if(!s.test(e))r="invalid format";else if(i){let T=e.lastIndexOf("@");if(T!==-1){let p=e.substring(T+1).toLowerCase();i.has(p)||(r=`domain not allowed (allowed: ${Array.from(i).join(", ")})`)}}return o({path:a,value:e,code:t,reason:r})},params:n?[n]:[],validationOptions:n}}});0&&(module.exports={stringEmailPlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=(a,o,i,r)=>{let e=(n=>(...t)=>{let m=n(...t);return m&&typeof m=="object"&&"check"in m?{...m,pluginName:r}:m})(i);switch(a){case"conditional":return(n,...t)=>e(n,...t);case"fieldReference":return(n,...t)=>e(n,...t);case"multiFieldReference":return e;case"transform":return n=>e(n);case"arrayElement":return(n,...t)=>e(n,...t);case"context":return n=>e(n);default:return e}};function T(a){let{name:o,methodName:i,allowedTypes:r,category:s,impl:e}=a;return{name:o,methodName:i,allowedTypes:r,category:s,create:()=>p(s,i,e,o)}}var u=["string"],g=/^[a-zA-Z0-9]([a-zA-Z0-9._%+-]*[a-zA-Z0-9])?@[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/,y="stringEmail",x=T({name:"stringEmail",methodName:"email",allowedTypes:u,category:"standard",impl:a=>{let o=a?.code||y,i=a?.messageFactory||(e=>e.reason?`Invalid email: ${e.reason}`:"Invalid email address"),r=a?.allowedDomains?new Set(a.allowedDomains.map(e=>e.toLowerCase())):null,s=a?.customRegex||g;return{check:e=>{if(typeof e!="string")return!0;if(!s.test(e))return!1;if(r){let n=e.lastIndexOf("@");if(n===-1)return!1;let t=e.substring(n+1).toLowerCase();return r.has(t)}return!0},code:o,getErrorMessage:(e,n)=>{if(typeof e!="string")return i({path:n,value:e,code:o});let t="";if(!s.test(e))t="invalid format";else if(r){let l=e.lastIndexOf("@");if(l!==-1){let d=e.substring(l+1).toLowerCase();r.has(d)||(t=`domain not allowed (allowed: ${Array.from(r).join(", ")})`)}}return i({path:n,value:e,code:o,reason:t})},params:a?[a]:[],validationOptions:a}}});export{x as stringEmailPlugin};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name stringHostname
|
|
4
|
+
* @category string
|
|
5
|
+
* @description Validates hostname format (RFC 1123)
|
|
6
|
+
* @allowedTypes ["string"]
|
|
7
|
+
* @see https://tools.ietf.org/html/rfc1123 - RFC 1123: Requirements for Internet Hosts - Application and Support
|
|
8
|
+
* @see https://tools.ietf.org/html/rfc952 - RFC 952: DoD Internet Host Table Specification
|
|
9
|
+
* @see https://en.wikipedia.org/wiki/Hostname - Hostname Format Reference
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Basic usage - validates hostname format (RFC 1123 compliant)
|
|
13
|
+
* const validator = Builder()
|
|
14
|
+
* .use(stringHostnamePlugin)
|
|
15
|
+
* .for<{ hostname: string }>()
|
|
16
|
+
* .v("hostname", (b) => b.string.hostname())
|
|
17
|
+
* .build();
|
|
18
|
+
*
|
|
19
|
+
* // ✅ VALID hostnames (RFC 1123)
|
|
20
|
+
* validator.parse({ hostname: "example.com" }); // Standard domain
|
|
21
|
+
* validator.parse({ hostname: "www.example.com" }); // Subdomain
|
|
22
|
+
* validator.parse({ hostname: "mail-server.company.org" }); // With hyphens
|
|
23
|
+
* validator.parse({ hostname: "a.b.c" }); // Short labels
|
|
24
|
+
* validator.parse({ hostname: "host123.domain.co.uk" }); // With numbers
|
|
25
|
+
* validator.parse({ hostname: "localhost" }); // Single label
|
|
26
|
+
* validator.parse({ hostname: "api-v2.service.internal" }); // Multiple hyphens
|
|
27
|
+
* validator.parse({ hostname: "test" }); // Single word
|
|
28
|
+
* validator.parse({ hostname: "1a.2b.3c" }); // Starting with numbers
|
|
29
|
+
* validator.parse({ hostname: "x" }); // Single character
|
|
30
|
+
* validator.parse({ hostname: "sub.domain.example.com" }); // Multiple levels
|
|
31
|
+
* validator.parse({ hostname: "ftp.files.company-name.org" }); // Complex structure
|
|
32
|
+
* validator.parse({ hostname: "db1.cluster.production" }); // Database naming
|
|
33
|
+
* validator.parse({ hostname: "web01.dmz.corp" }); // Network zones
|
|
34
|
+
* validator.parse({ hostname: "backup-server.it.department" }); // Organizational
|
|
35
|
+
*
|
|
36
|
+
* // Edge cases
|
|
37
|
+
* validator.parse({ hostname: "a".repeat(63) }); // Max label length (63 chars)
|
|
38
|
+
* validator.parse({ hostname: "a".repeat(63) + "." + "b".repeat(63) }); // Multiple max labels
|
|
39
|
+
* validator.parse({ hostname: "0" }); // Single digit
|
|
40
|
+
* validator.parse({ hostname: "9a" }); // Number followed by letter
|
|
41
|
+
*
|
|
42
|
+
* // ❌ INVALID hostnames
|
|
43
|
+
* validator.parse({ hostname: "-example.com" }); // Starting with hyphen
|
|
44
|
+
* validator.parse({ hostname: "example-.com" }); // Label ending with hyphen
|
|
45
|
+
* validator.parse({ hostname: "example.com-" }); // Hostname ending with hyphen
|
|
46
|
+
* validator.parse({ hostname: ".example.com" }); // Starting with dot
|
|
47
|
+
* validator.parse({ hostname: "example..com" }); // Double dot (empty label)
|
|
48
|
+
* validator.parse({ hostname: "example.com." }); // Trailing dot
|
|
49
|
+
* validator.parse({ hostname: "" }); // Empty string
|
|
50
|
+
* validator.parse({ hostname: "example .com" }); // Space in hostname
|
|
51
|
+
* validator.parse({ hostname: "example_com" }); // Underscore not allowed
|
|
52
|
+
* validator.parse({ hostname: "EXAMPLE.COM" }); // All caps (valid but not recommended)
|
|
53
|
+
* validator.parse({ hostname: "example.com/path" }); // With path
|
|
54
|
+
* validator.parse({ hostname: "example.com:8080" }); // With port
|
|
55
|
+
* validator.parse({ hostname: "user@example.com" }); // With user
|
|
56
|
+
* validator.parse({ hostname: "http://example.com" }); // Full URL
|
|
57
|
+
* validator.parse({ hostname: "192.168.1.1" }); // IP address (not hostname)
|
|
58
|
+
* validator.parse({ hostname: "[::1]" }); // IPv6 address
|
|
59
|
+
*
|
|
60
|
+
* // Label too long (> 63 characters)
|
|
61
|
+
* validator.parse({ hostname: "a".repeat(64) + ".com" }); // Single label > 63 chars
|
|
62
|
+
*
|
|
63
|
+
* // Hostname too long (> 253 characters total)
|
|
64
|
+
* const longLabel = "a".repeat(50);
|
|
65
|
+
* const longHostname = Array(10).fill(longLabel).join(".") + ".com"; // > 253 chars total
|
|
66
|
+
* validator.parse({ hostname: longHostname });
|
|
67
|
+
*
|
|
68
|
+
* // Special characters not allowed
|
|
69
|
+
* validator.parse({ hostname: "exam@ple.com" }); // @ symbol
|
|
70
|
+
* validator.parse({ hostname: "exam#ple.com" }); // # symbol
|
|
71
|
+
* validator.parse({ hostname: "exam$ple.com" }); // $ symbol
|
|
72
|
+
* validator.parse({ hostname: "exam%ple.com" }); // % symbol
|
|
73
|
+
* validator.parse({ hostname: "exam&ple.com" }); // & symbol
|
|
74
|
+
* validator.parse({ hostname: "example.com!" }); // Exclamation mark
|
|
75
|
+
* validator.parse({ hostname: "example.com?" }); // Question mark
|
|
76
|
+
*
|
|
77
|
+
* // Unicode/international domain names (IDN not supported in basic hostname)
|
|
78
|
+
* validator.parse({ hostname: "ドメイン.com" }); // Japanese characters
|
|
79
|
+
* validator.parse({ hostname: "münchen.de" }); // German umlaut
|
|
80
|
+
* validator.parse({ hostname: "café.fr" }); // French accent
|
|
81
|
+
* ```
|
|
82
|
+
* @params
|
|
83
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional custom error message factory
|
|
84
|
+
* @returns Validation function that checks hostname format
|
|
85
|
+
* @customError
|
|
86
|
+
* ```typescript
|
|
87
|
+
* .hostname({
|
|
88
|
+
* messageFactory: ({ path, value }) =>
|
|
89
|
+
* `${path} must be valid hostname format, received: ${value}`
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
* @since 0.1.0-alpha
|
|
93
|
+
*/
|
|
94
|
+
import type { MessageContext } from "../core/plugin/types";
|
|
95
|
+
export declare const stringHostnamePlugin: import("../index").TypedPlugin<"stringHostname", "hostname", (options?: {
|
|
96
|
+
messageFactory?: (context: MessageContext) => string;
|
|
97
|
+
}) => {
|
|
98
|
+
check: (value: string) => boolean;
|
|
99
|
+
code: string;
|
|
100
|
+
getErrorMessage: (value: string, path: string) => string;
|
|
101
|
+
params: {
|
|
102
|
+
messageFactory?: (context: MessageContext) => string;
|
|
103
|
+
}[];
|
|
104
|
+
}, readonly ["string"], "validator", "standard">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var d=(n,e)=>{for(var a in e)l(n,a,{get:e[a],enumerable:!0})},y=(n,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!g.call(n,r)&&r!==a&&l(n,r,{get:()=>e[r],enumerable:!(t=p(e,r))||t.enumerable});return n};var c=n=>y(l({},"__esModule",{value:!0}),n);var x={};d(x,{stringHostnamePlugin:()=>h});module.exports=c(x);var f=(n,e,a,t)=>{let s=(o=>(...m)=>{let i=o(...m);return i&&typeof i=="object"&&"check"in i?{...i,pluginName:t}:i})(a);switch(n){case"conditional":return(o,...m)=>s(o,...m);case"fieldReference":return(o,...m)=>s(o,...m);case"multiFieldReference":return s;case"transform":return o=>s(o);case"arrayElement":return(o,...m)=>s(o,...m);case"context":return o=>s(o);default:return s}};function T(n){let{name:e,methodName:a,allowedTypes:t,category:r,impl:s}=n;return{name:e,methodName:a,allowedTypes:t,category:r,create:()=>f(r,a,s,e)}}var N=/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/,h=T({name:"stringHostname",methodName:"hostname",allowedTypes:["string"],category:"standard",impl:n=>{let e=()=>"must be a valid hostname",a=n?.messageFactory||(t=>`${t.path} ${e()}`);return{check:t=>typeof t!="string"||t.length>253?!1:N.test(t),code:"FORMAT_HOSTNAME",getErrorMessage:(t,r)=>a({path:r,value:t,code:"FORMAT_HOSTNAME"}),params:[n]}}});0&&(module.exports={stringHostnamePlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var T=(r,s,o,e)=>{let t=(n=>(...a)=>{let i=n(...a);return i&&typeof i=="object"&&"check"in i?{...i,pluginName:e}:i})(o);switch(r){case"conditional":return(n,...a)=>t(n,...a);case"fieldReference":return(n,...a)=>t(n,...a);case"multiFieldReference":return t;case"transform":return n=>t(n);case"arrayElement":return(n,...a)=>t(n,...a);case"context":return n=>t(n);default:return t}};function l(r){let{name:s,methodName:o,allowedTypes:e,category:m,impl:t}=r;return{name:s,methodName:o,allowedTypes:e,category:m,create:()=>T(m,o,t,s)}}var p=/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/,d=l({name:"stringHostname",methodName:"hostname",allowedTypes:["string"],category:"standard",impl:r=>{let s=()=>"must be a valid hostname",o=r?.messageFactory||(e=>`${e.path} ${s()}`);return{check:e=>typeof e!="string"||e.length>253?!1:p.test(e),code:"FORMAT_HOSTNAME",getErrorMessage:(e,m)=>o({path:m,value:e,code:"FORMAT_HOSTNAME"}),params:[r]}}});export{d as stringHostnamePlugin};
|