@ooneex/validation 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ooneex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @ooneex/validation
@@ -0,0 +1,68 @@
1
+ import * as A from "arktype";
2
+ type AssertType = A.Type;
3
+ interface IAssert {
4
+ getConstraint: () => AssertType;
5
+ getErrorMessage: () => string | null;
6
+ validate: (data: unknown, constraint?: AssertType) => ValidationResultType;
7
+ }
8
+ type ValidationResultType = {
9
+ isValid: boolean;
10
+ message?: string;
11
+ };
12
+ declare abstract class Validation implements IAssert {
13
+ abstract getConstraint(): AssertType;
14
+ abstract getErrorMessage(): string | null;
15
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
16
+ }
17
+ declare class AssertChatQuery extends Validation {
18
+ getConstraint(): AssertType;
19
+ getErrorMessage(): string | null;
20
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
21
+ }
22
+ declare class AssertCountryCode extends Validation {
23
+ getConstraint(): AssertType;
24
+ getErrorMessage(): string | null;
25
+ }
26
+ declare class AssertCurrency extends Validation {
27
+ getConstraint(): AssertType;
28
+ getErrorMessage(): string | null;
29
+ }
30
+ declare class AssertEmail extends Validation {
31
+ getConstraint(): AssertType;
32
+ getErrorMessage(): string | null;
33
+ }
34
+ declare class AssertFirstName extends Validation {
35
+ getConstraint(): AssertType;
36
+ getErrorMessage(): string | null;
37
+ }
38
+ declare class AssertHexaColor extends Validation {
39
+ getConstraint(): AssertType;
40
+ getErrorMessage(): string | null;
41
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
42
+ }
43
+ declare class AssertId extends Validation {
44
+ getConstraint(): AssertType;
45
+ getErrorMessage(): string | null;
46
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
47
+ }
48
+ declare class AssertLastName extends Validation {
49
+ getConstraint(): AssertType;
50
+ getErrorMessage(): string | null;
51
+ }
52
+ declare class AssertName extends Validation {
53
+ getConstraint(): AssertType;
54
+ getErrorMessage(): string | null;
55
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
56
+ }
57
+ declare class AssertUrl extends Validation {
58
+ getConstraint(): AssertType;
59
+ getErrorMessage(): string | null;
60
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
61
+ validateStrict(data: unknown): ValidationResultType;
62
+ }
63
+ declare class AssertYoutubeUrl extends Validation {
64
+ getConstraint(): AssertType;
65
+ getErrorMessage(): string | null;
66
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
67
+ }
68
+ export { AssertYoutubeUrl, AssertUrl, AssertName, AssertLastName, AssertId, AssertHexaColor, AssertFirstName, AssertEmail, AssertCurrency, AssertCountryCode, AssertChatQuery };
@@ -0,0 +1,3 @@
1
+ import*as p from"arktype";var o=p.type;import{type as V}from"arktype";class r{validate(t,i){i=i||this.getConstraint();let s=i(t);if(s instanceof V.errors)return{isValid:!1,message:this.getErrorMessage()||s.summary};return{isValid:!0}}}var h=1,E=2000,v=[/<script[^>]*>.*?<\/script>/gi,/<\/?[a-zA-Z][^>]*>/g,/javascript:/gi,/data:/gi,/vbscript:/gi];class l extends r{getConstraint(){return o(`${h} <= string <= ${E}`)}getErrorMessage(){return"Chat query must be between 1 and 2000 characters and cannot contain HTML tags, scripts, or unsafe protocols"}validate(t,i){let s=super.validate(t,i);if(!s.isValid)return s;let e=t;for(let n of v)if(n.lastIndex=0,n.test(e))return{isValid:!1,message:this.getErrorMessage()||"Invalid chat query"};return{isValid:!0}}}class u extends r{getConstraint(){return o("2 <= string <= 2 & /^[A-Z]{2}$/")}getErrorMessage(){return"Country code must be a 2-character uppercase ISO 3166-1 alpha-2 code"}}import{CURRENCIES as I}from"@ooneex/currencies";var R=I.map((t)=>t.code);class c extends r{getConstraint(){return o(`"${R.join('" | "')}" & /^[A-Z]{3}$/`)}getErrorMessage(){return"Currency code must be a valid ISO 4217 currency code (3 uppercase letters)"}}class m extends r{getConstraint(){return o("string.email")}getErrorMessage(){return"Must be a valid email address"}}class g extends r{getConstraint(){return o("1 <= string <= 50 & /^[a-zA-Z\\s'-]+$/")}getErrorMessage(){return"First name must be between 1 and 50 characters and contain only letters, spaces, hyphens, and apostrophes"}}var w=/^#[0-9A-Fa-f]{3}$/,_=/^#[0-9A-Fa-f]{6}$/;class y extends r{getConstraint(){return o("string")}getErrorMessage(){return"Value must be a valid hexadecimal color (e.g., #fff, #ffffff, #A1B2C3)"}validate(t,i){let s=super.validate(t,i);if(!s.isValid)return s;let e=t,n=w.test(e),a=_.test(e);if(!n&&!a)return{isValid:!1,message:this.getErrorMessage()||"Invalid hexadecimal color"};return{isValid:!0}}}var $=/^[0-9a-f]+$/,f=25;class A extends r{getConstraint(){return o(`${f} <= string <= ${f}`)}getErrorMessage(){return"ID must be exactly 25 characters long and contain only lowercase hexadecimal characters (0-9, a-f)"}validate(t,i){let s=super.validate(t,i);if(!s.isValid)return s;let e=t;if(!$.test(e))return{isValid:!1,message:this.getErrorMessage()||"Invalid ID format"};return{isValid:!0}}}class d extends r{getConstraint(){return o("1 <= string <= 50 & /^[a-zA-Z\\s'-]+$/")}getErrorMessage(){return"Last name must be between 1 and 50 characters and contain only letters, spaces, hyphens, and apostrophes"}}var D=1,M=50,U=/^[a-zA-ZÀ-ÿĀ-žА-я\u4e00-\u9fff\s\-'0-9.]+$/;class b extends r{getConstraint(){return o(`${D} <= string <= ${M}`)}getErrorMessage(){return"Name must be between 1 and 50 characters and contain only letters, numbers, spaces, hyphens, apostrophes, and periods"}validate(t,i){let s=super.validate(t,i);if(!s.isValid)return s;let e=t;if(e.trim()!==e)return{isValid:!1,message:this.getErrorMessage()||"Invalid name format"};if(!U.test(e))return{isValid:!1,message:this.getErrorMessage()||"Invalid name format"};if(e.includes(".")&&!e.match(/\.\s/))return{isValid:!1,message:this.getErrorMessage()||"Invalid name format"};return{isValid:!0}}}var T=2083,Y=/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .~-]*)*\/?(\?[&a-z\d%_.~+=-]*)?(#[-a-z\d_]*)?$/i,H=/^https?:\/\/(?:[-\w.])+(?::[0-9]+)?(?:\/(?:[\w/_.])*(?:\?(?:[\w&=%.])*)?(?:#(?:[\w.])*)?)?$/;class x extends r{getConstraint(){return o(`1 <= string <= ${T}`)}getErrorMessage(){return`URL must be between 1 and ${T} characters and follow a valid URL format (e.g., https://example.com, http://sub.domain.co.uk/path)`}validate(t,i){let s=super.validate(t,i);if(!s.isValid)return s;let e=t;if(e.match(/^(ftp|file|mailto|telnet|ssh|gopher):/i))return{isValid:!1,message:this.getErrorMessage()||"Invalid URL format"};if(e.includes("://")&&!e.match(/^https?:\/\//i))return{isValid:!1,message:this.getErrorMessage()||"Invalid URL format"};if(e.trim()!==e)return{isValid:!1,message:this.getErrorMessage()||"Invalid URL format"};if(e.includes("..")||e.startsWith(".")||e.includes("/.")||e.endsWith("."))return{isValid:!1,message:this.getErrorMessage()||"Invalid URL format"};if(!Y.test(e))return{isValid:!1,message:this.getErrorMessage()||"Invalid URL format"};return{isValid:!0}}validateStrict(t){let i=super.validate(t);if(!i.isValid)return i;let s=t;if(!H.test(s))return{isValid:!1,message:"URL must include protocol (http:// or https://) and follow strict URL format"};return{isValid:!0}}}var O=[/^https?:\/\/(www\.)?youtube\.com\/watch\?v=[A-Za-z0-9_-]+$/,/^https?:\/\/youtu\.be\/[A-Za-z0-9_-]+$/];class C extends r{getConstraint(){return o("string")}getErrorMessage(){return"Must be a valid YouTube URL (e.g., https://youtube.com/watch?v=dQw4w9WgXcQ or https://youtu.be/dQw4w9WgXcQ)"}validate(t,i){let s=super.validate(t,i);if(!s.isValid)return s;let e=t;if(!O.some((a)=>a.test(e)))return{isValid:!1,message:this.getErrorMessage()||"Invalid YouTube URL"};return{isValid:!0}}}export{C as AssertYoutubeUrl,x as AssertUrl,b as AssertName,d as AssertLastName,A as AssertId,y as AssertHexaColor,g as AssertFirstName,m as AssertEmail,c as AssertCurrency,u as AssertCountryCode,l as AssertChatQuery};export{o as a,r as b,l as c,u as d,c as e,m as f,g,y as h,A as i,d as j,b as k,x as l,C as m};
2
+
3
+ //# debugId=CE64EB4A82C25EE964756E2164756E21
@@ -0,0 +1,22 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/utils.ts", "src/Validation.ts", "src/constraints/AssertChatQuery.ts", "src/constraints/AssertCountryCode.ts", "src/constraints/AssertCurrency.ts", "src/constraints/AssertEmail.ts", "src/constraints/AssertFirstName.ts", "src/constraints/AssertHexaColor.ts", "src/constraints/AssertId.ts", "src/constraints/AssertLastName.ts", "src/constraints/AssertName.ts", "src/constraints/AssertUrl.ts", "src/constraints/AssertYoutubeUrl.ts"],
4
+ "sourcesContent": [
5
+ "import * as A from \"arktype\";\nimport type { TypeParser } from \"arktype/internal/type.ts\";\n\n// biome-ignore lint/complexity/noBannedTypes: trust me\nexport const Assert: TypeParser<{}> = A.type;\n",
6
+ "import { type } from \"arktype\";\nimport type { AssertType, IAssert, ValidationResultType } from \"./types\";\n\nexport abstract class Validation implements IAssert {\n public abstract getConstraint(): AssertType;\n public abstract getErrorMessage(): string | null;\n\n public validate(data: unknown, constraint?: AssertType): ValidationResultType {\n constraint = constraint || this.getConstraint();\n\n const out = constraint(data);\n\n if (out instanceof type.errors) {\n return {\n isValid: false,\n message: this.getErrorMessage() || out.summary,\n };\n }\n\n return {\n isValid: true,\n };\n }\n}\n",
7
+ "import type { AssertType, ValidationResultType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nconst CHAT_QUERY_MIN_LENGTH = 1;\nconst CHAT_QUERY_MAX_LENGTH = 2000;\nconst CHAT_QUERY_FORBIDDEN_PATTERNS = [\n /<script[^>]*>.*?<\\/script>/gi,\n /<\\/?[a-zA-Z][^>]*>/g,\n /javascript:/gi,\n /data:/gi,\n /vbscript:/gi,\n];\n\nexport class AssertChatQuery extends Validation {\n public getConstraint(): AssertType {\n return Assert(`${CHAT_QUERY_MIN_LENGTH} <= string <= ${CHAT_QUERY_MAX_LENGTH}`);\n }\n\n public getErrorMessage(): string | null {\n return \"Chat query must be between 1 and 2000 characters and cannot contain HTML tags, scripts, or unsafe protocols\";\n }\n\n public override validate(data: unknown, constraint?: AssertType): ValidationResultType {\n const basicValidation = super.validate(data, constraint);\n if (!basicValidation.isValid) {\n return basicValidation;\n }\n\n const query = data as string;\n\n for (const pattern of CHAT_QUERY_FORBIDDEN_PATTERNS) {\n pattern.lastIndex = 0;\n if (pattern.test(query)) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid chat query\",\n };\n }\n }\n\n return {\n isValid: true,\n };\n }\n}\n",
8
+ "import type { AssertType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nexport class AssertCountryCode extends Validation {\n public getConstraint(): AssertType {\n return Assert(\"2 <= string <= 2 & /^[A-Z]{2}$/\");\n }\n\n public getErrorMessage(): string | null {\n return \"Country code must be a 2-character uppercase ISO 3166-1 alpha-2 code\";\n }\n}\n",
9
+ "import { CURRENCIES } from \"@ooneex/currencies\";\nimport type { AssertType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nconst VALID_CURRENCY_CODES = CURRENCIES.map((currency) => currency.code);\n\nexport class AssertCurrency extends Validation {\n public getConstraint(): AssertType {\n return Assert(`\"${VALID_CURRENCY_CODES.join('\" | \"')}\" & /^[A-Z]{3}$/`);\n }\n\n public getErrorMessage(): string | null {\n return \"Currency code must be a valid ISO 4217 currency code (3 uppercase letters)\";\n }\n}\n",
10
+ "import type { AssertType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nexport class AssertEmail extends Validation {\n public getConstraint(): AssertType {\n return Assert(\"string.email\");\n }\n\n public getErrorMessage(): string | null {\n return \"Must be a valid email address\";\n }\n}\n",
11
+ "import type { AssertType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nexport class AssertFirstName extends Validation {\n public getConstraint(): AssertType {\n return Assert(\"1 <= string <= 50 & /^[a-zA-Z\\\\s'-]+$/\");\n }\n\n public getErrorMessage(): string | null {\n return \"First name must be between 1 and 50 characters and contain only letters, spaces, hyphens, and apostrophes\";\n }\n}\n",
12
+ "import type { AssertType, ValidationResultType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nconst HEXA_COLOR_3_DIGIT_REGEX = /^#[0-9A-Fa-f]{3}$/;\nconst HEXA_COLOR_6_DIGIT_REGEX = /^#[0-9A-Fa-f]{6}$/;\n\nexport class AssertHexaColor extends Validation {\n public getConstraint(): AssertType {\n return Assert(\"string\");\n }\n\n public getErrorMessage(): string | null {\n return \"Value must be a valid hexadecimal color (e.g., #fff, #ffffff, #A1B2C3)\";\n }\n\n public override validate(data: unknown, constraint?: AssertType): ValidationResultType {\n const basicValidation = super.validate(data, constraint);\n if (!basicValidation.isValid) {\n return basicValidation;\n }\n\n const color = data as string;\n\n const is3DigitHex = HEXA_COLOR_3_DIGIT_REGEX.test(color);\n const is6DigitHex = HEXA_COLOR_6_DIGIT_REGEX.test(color);\n\n if (!is3DigitHex && !is6DigitHex) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid hexadecimal color\",\n };\n }\n\n return {\n isValid: true,\n };\n }\n}\n",
13
+ "import type { AssertType, ValidationResultType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nconst ID_REGEX = /^[0-9a-f]+$/;\nconst DEFAULT_ID_LENGTH = 25;\n\nexport class AssertId extends Validation {\n public getConstraint(): AssertType {\n return Assert(`${DEFAULT_ID_LENGTH} <= string <= ${DEFAULT_ID_LENGTH}`);\n }\n\n public getErrorMessage(): string | null {\n return \"ID must be exactly 25 characters long and contain only lowercase hexadecimal characters (0-9, a-f)\";\n }\n\n public override validate(data: unknown, constraint?: AssertType): ValidationResultType {\n const basicValidation = super.validate(data, constraint);\n if (!basicValidation.isValid) {\n return basicValidation;\n }\n\n const id = data as string;\n\n if (!ID_REGEX.test(id)) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid ID format\",\n };\n }\n\n return {\n isValid: true,\n };\n }\n}\n",
14
+ "import type { AssertType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nexport class AssertLastName extends Validation {\n public getConstraint(): AssertType {\n return Assert(\"1 <= string <= 50 & /^[a-zA-Z\\\\s'-]+$/\");\n }\n\n public getErrorMessage(): string | null {\n return \"Last name must be between 1 and 50 characters and contain only letters, spaces, hyphens, and apostrophes\";\n }\n}\n",
15
+ "import type { AssertType, ValidationResultType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nconst NAME_MIN_LENGTH = 1;\nconst NAME_MAX_LENGTH = 50;\nconst NAME_REGEX = /^[a-zA-ZÀ-ÿĀ-žА-я\\u4e00-\\u9fff\\s\\-'0-9.]+$/;\n\nexport class AssertName extends Validation {\n public getConstraint(): AssertType {\n return Assert(`${NAME_MIN_LENGTH} <= string <= ${NAME_MAX_LENGTH}`);\n }\n\n public getErrorMessage(): string | null {\n return \"Name must be between 1 and 50 characters and contain only letters, numbers, spaces, hyphens, apostrophes, and periods\";\n }\n\n public override validate(data: unknown, constraint?: AssertType): ValidationResultType {\n const basicValidation = super.validate(data, constraint);\n if (!basicValidation.isValid) {\n return basicValidation;\n }\n\n const name = data as string;\n\n // Check for leading or trailing whitespace\n if (name.trim() !== name) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid name format\",\n };\n }\n\n if (!NAME_REGEX.test(name)) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid name format\",\n };\n }\n\n // Check for valid period usage (only allowed when followed by space like \"St. John\")\n if (name.includes(\".\") && !name.match(/\\.\\s/)) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid name format\",\n };\n }\n\n return {\n isValid: true,\n };\n }\n}\n",
16
+ "import type { AssertType, ValidationResultType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nconst URL_MAX_LENGTH = 2083;\nconst URL_REGEX = /^(https?:\\/\\/)?([\\da-z.-]+)\\.([a-z.]{2,6})([/\\w .~-]*)*\\/?(\\?[&a-z\\d%_.~+=-]*)?(#[-a-z\\d_]*)?$/i;\n\nconst STRICT_URL_REGEX = /^https?:\\/\\/(?:[-\\w.])+(?::[0-9]+)?(?:\\/(?:[\\w/_.])*(?:\\?(?:[\\w&=%.])*)?(?:#(?:[\\w.])*)?)?$/;\n\nexport class AssertUrl extends Validation {\n public getConstraint(): AssertType {\n return Assert(`1 <= string <= ${URL_MAX_LENGTH}`);\n }\n\n public getErrorMessage(): string | null {\n return `URL must be between 1 and ${URL_MAX_LENGTH} characters and follow a valid URL format (e.g., https://example.com, http://sub.domain.co.uk/path)`;\n }\n\n public override validate(data: unknown, constraint?: AssertType): ValidationResultType {\n const basicValidation = super.validate(data, constraint);\n if (!basicValidation.isValid) {\n return basicValidation;\n }\n\n const url = data as string;\n\n // Reject specific non-http/https protocols first\n if (url.match(/^(ftp|file|mailto|telnet|ssh|gopher):/i)) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid URL format\",\n };\n }\n\n // Reject malformed protocols\n if (url.includes(\"://\") && !url.match(/^https?:\\/\\//i)) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid URL format\",\n };\n }\n\n // Check for whitespace at start or end\n if (url.trim() !== url) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid URL format\",\n };\n }\n\n // Check for invalid domain patterns\n if (url.includes(\"..\") || url.startsWith(\".\") || url.includes(\"/.\") || url.endsWith(\".\")) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid URL format\",\n };\n }\n\n if (!URL_REGEX.test(url)) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid URL format\",\n };\n }\n\n return {\n isValid: true,\n };\n }\n\n public validateStrict(data: unknown): ValidationResultType {\n const basicValidation = super.validate(data);\n if (!basicValidation.isValid) {\n return basicValidation;\n }\n\n const url = data as string;\n\n if (!STRICT_URL_REGEX.test(url)) {\n return {\n isValid: false,\n message: \"URL must include protocol (http:// or https://) and follow strict URL format\",\n };\n }\n\n return {\n isValid: true,\n };\n }\n}\n",
17
+ "import type { AssertType, ValidationResultType } from \"../types\";\nimport { Assert } from \"../utils\";\nimport { Validation } from \"../Validation\";\n\nconst YOUTUBE_URL_PATTERNS = [\n /^https?:\\/\\/(www\\.)?youtube\\.com\\/watch\\?v=[A-Za-z0-9_-]+$/,\n /^https?:\\/\\/youtu\\.be\\/[A-Za-z0-9_-]+$/,\n];\n\nexport class AssertYoutubeUrl extends Validation {\n public getConstraint(): AssertType {\n return Assert(\"string\");\n }\n\n public getErrorMessage(): string | null {\n return \"Must be a valid YouTube URL (e.g., https://youtube.com/watch?v=dQw4w9WgXcQ or https://youtu.be/dQw4w9WgXcQ)\";\n }\n\n public override validate(data: unknown, constraint?: AssertType): ValidationResultType {\n const basicValidation = super.validate(data, constraint);\n if (!basicValidation.isValid) {\n return basicValidation;\n }\n\n const url = data as string;\n const isValidYouTubeUrl = YOUTUBE_URL_PATTERNS.some((pattern) => pattern.test(url));\n\n if (!isValidYouTubeUrl) {\n return {\n isValid: false,\n message: this.getErrorMessage() || \"Invalid YouTube URL\",\n };\n }\n\n return {\n isValid: true,\n };\n }\n}\n"
18
+ ],
19
+ "mappings": "AAAA,0BAIO,IAAM,EAA2B,OCJxC,eAAS,gBAGF,MAAe,CAA8B,CAI3C,QAAQ,CAAC,EAAe,EAA+C,CAC5E,EAAa,GAAc,KAAK,cAAc,EAE9C,IAAM,EAAM,EAAW,CAAI,EAE3B,GAAI,aAAe,EAAK,OACtB,MAAO,CACL,QAAS,GACT,QAAS,KAAK,gBAAgB,GAAK,EAAI,OACzC,EAGF,MAAO,CACL,QAAS,EACX,EAEJ,CCnBA,IAAM,EAAwB,EACxB,EAAwB,KACxB,EAAgC,CACpC,+BACA,sBACA,gBACA,UACA,aACF,EAEO,MAAM,UAAwB,CAAW,CACvC,aAAa,EAAe,CACjC,OAAO,EAAO,GAAG,kBAAsC,GAAuB,EAGzE,eAAe,EAAkB,CACtC,MAAO,8GAGO,QAAQ,CAAC,EAAe,EAA+C,CACrF,IAAM,EAAkB,MAAM,SAAS,EAAM,CAAU,EACvD,GAAI,CAAC,EAAgB,QACnB,OAAO,EAGT,IAAM,EAAQ,EAEd,QAAW,KAAW,EAEpB,GADA,EAAQ,UAAY,EAChB,EAAQ,KAAK,CAAK,EACpB,MAAO,CACL,QAAS,GACT,QAAS,KAAK,gBAAgB,GAAK,oBACrC,EAIJ,MAAO,CACL,QAAS,EACX,EAEJ,CCzCO,MAAM,UAA0B,CAAW,CACzC,aAAa,EAAe,CACjC,OAAO,EAAO,iCAAiC,EAG1C,eAAe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22
+ }
@@ -0,0 +1,72 @@
1
+ import * as A from "arktype";
2
+ type ValidationClassType = new (...args: any[]) => IAssert;
3
+ type AssertType = A.Type;
4
+ interface IAssert {
5
+ getConstraint: () => AssertType;
6
+ getErrorMessage: () => string | null;
7
+ validate: (data: unknown, constraint?: AssertType) => ValidationResultType;
8
+ }
9
+ type ValidationResultType = {
10
+ isValid: boolean;
11
+ message?: string;
12
+ };
13
+ declare abstract class Validation implements IAssert {
14
+ abstract getConstraint(): AssertType;
15
+ abstract getErrorMessage(): string | null;
16
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
17
+ }
18
+ declare class AssertChatQuery extends Validation {
19
+ getConstraint(): AssertType;
20
+ getErrorMessage(): string | null;
21
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
22
+ }
23
+ declare class AssertCountryCode extends Validation {
24
+ getConstraint(): AssertType;
25
+ getErrorMessage(): string | null;
26
+ }
27
+ declare class AssertCurrency extends Validation {
28
+ getConstraint(): AssertType;
29
+ getErrorMessage(): string | null;
30
+ }
31
+ declare class AssertEmail extends Validation {
32
+ getConstraint(): AssertType;
33
+ getErrorMessage(): string | null;
34
+ }
35
+ declare class AssertFirstName extends Validation {
36
+ getConstraint(): AssertType;
37
+ getErrorMessage(): string | null;
38
+ }
39
+ declare class AssertHexaColor extends Validation {
40
+ getConstraint(): AssertType;
41
+ getErrorMessage(): string | null;
42
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
43
+ }
44
+ declare class AssertId extends Validation {
45
+ getConstraint(): AssertType;
46
+ getErrorMessage(): string | null;
47
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
48
+ }
49
+ declare class AssertLastName extends Validation {
50
+ getConstraint(): AssertType;
51
+ getErrorMessage(): string | null;
52
+ }
53
+ declare class AssertName extends Validation {
54
+ getConstraint(): AssertType;
55
+ getErrorMessage(): string | null;
56
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
57
+ }
58
+ declare class AssertUrl extends Validation {
59
+ getConstraint(): AssertType;
60
+ getErrorMessage(): string | null;
61
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
62
+ validateStrict(data: unknown): ValidationResultType;
63
+ }
64
+ declare class AssertYoutubeUrl extends Validation {
65
+ getConstraint(): AssertType;
66
+ getErrorMessage(): string | null;
67
+ validate(data: unknown, constraint?: AssertType): ValidationResultType;
68
+ }
69
+ export * from "arktype";
70
+ import { TypeParser } from "arktype/internal/type.ts";
71
+ declare const Assert: TypeParser<{}>;
72
+ export { ValidationResultType, ValidationClassType, Validation, IAssert, AssertYoutubeUrl, AssertUrl, AssertType, AssertName, AssertLastName, AssertId, AssertHexaColor, AssertFirstName, AssertEmail, AssertCurrency, AssertCountryCode, AssertChatQuery, Assert };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import{a as e,b as r,c as t,d,e as V,f as h,g as j,h as k,i as q,j as v,k as w,l as z,m as B}from"./constraints/index.js";export*from"arktype";export{r as Validation,B as AssertYoutubeUrl,z as AssertUrl,w as AssertName,v as AssertLastName,q as AssertId,k as AssertHexaColor,j as AssertFirstName,h as AssertEmail,V as AssertCurrency,d as AssertCountryCode,t as AssertChatQuery,e as Assert};
2
+
3
+ //# debugId=E51C7CAFF4AB506864756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/index.ts"],
4
+ "sourcesContent": [
5
+ "export * from \"arktype\";\nexport * from \"./constraints\";\nexport * from \"./types\";\nexport * from \"./utils\";\nexport { Validation } from \"./Validation\";\n"
6
+ ],
7
+ "mappings": "0HAAA",
8
+ "debugId": "E51C7CAFF4AB506864756E2164756E21",
9
+ "names": []
10
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@ooneex/validation",
3
+ "description": "",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "LICENSE",
9
+ "README.md",
10
+ "package.json"
11
+ ],
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "./constraints": {
22
+ "import": {
23
+ "types": "./dist/constraints/index.d.ts",
24
+ "default": "./dist/constraints/index.js"
25
+ }
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "license": "MIT",
30
+ "scripts": {
31
+ "test": "bun test tests",
32
+ "build": "bunup",
33
+ "lint": "tsgo --noEmit && bunx biome lint",
34
+ "publish:prod": "bun publish --tolerate-republish --access public",
35
+ "publish:pack": "bun pm pack --destination ./dist",
36
+ "publish:dry": "bun publish --dry-run"
37
+ },
38
+ "devDependencies": {},
39
+ "peerDependencies": {},
40
+ "dependencies": {
41
+ "@ooneex/currencies": "0.0.1",
42
+ "arktype": "^2.1.27"
43
+ }
44
+ }