@epilot/validators
Advanced tools
+9
-0
@@ -5,2 +5,11 @@ # Changelog | ||
| ### [0.0.13](https://gitlab.com/e-pilot/product/frontend/base/validators/compare/v0.0.12...v0.0.13) (2021-06-30) | ||
| ### [0.0.12](https://gitlab.com/e-pilot/product/frontend/base/validators/compare/v0.0.11...v0.0.12) (2021-06-30) | ||
| ### Features | ||
| * date range validator ([0bd0367](https://gitlab.com/e-pilot/product/frontend/base/validators/commit/0bd03671432751e1eedc76bba375c049a78bcdf7)) | ||
| ### [0.0.11](https://gitlab.com/e-pilot/product/frontend/base/validators/compare/v0.0.10...v0.0.11) (2021-05-21) | ||
@@ -7,0 +16,0 @@ |
@@ -170,2 +170,11 @@ 'use strict'; | ||
| }, { | ||
| keyword: 'rangeDateDE', | ||
| callback: function callback(schema, data) { | ||
| return schema && Array.isArray(schema) && schema.length === 2 ? parseDateDE(data).getTime() >= new Date().getTime() + schema[0] * 24 * 60 * 60 * 1000 && parseDateDE(data).getTime() <= new Date().getTime() + schema[1] * 24 * 60 * 60 * 1000 : false; | ||
| }, | ||
| errorMessage: { | ||
| en: 'Date must be between {minDate} and {maxDate}.', | ||
| de: 'Datum muss zwischen {minDate} und {maxDate} liegen.' | ||
| } | ||
| }, { | ||
| keyword: 'birthdateDE', | ||
@@ -180,2 +189,15 @@ callback: function callback(schema, data) { | ||
| }]; | ||
| function convertDate(date, separator) { | ||
| if (separator === void 0) { | ||
| separator = '.'; | ||
| } | ||
| function pad(s) { | ||
| return s < 10 ? '0' + s : s; | ||
| } | ||
| return [pad(date.getDate()), pad(date.getMonth() + 1), date.getFullYear()].join(separator); | ||
| } | ||
| function validateSchemaKeyword(schemaKeyword, locale) { | ||
@@ -187,9 +209,32 @@ var keyword = schemaKeyword.keyword, | ||
| var validate = function validate(schema, data) { | ||
| validate.errors = [{ | ||
| keyword: keyword, | ||
| message: errorMessage ? errorMessage[locale || 'de'].replace('{schema}', schema) : locale === 'en' ? 'The entered format is invalid.' : 'Das eingegebene Format ist ungültig.', | ||
| params: { | ||
| keyword: keyword | ||
| } | ||
| }]; | ||
| switch (keyword) { | ||
| case 'rangeDateDE': | ||
| { | ||
| var minDays = schema[0], | ||
| maxDays = schema[1]; | ||
| var minDate = new Date(); | ||
| minDate.setDate(minDate.getDate() + minDays); | ||
| var maxDate = new Date(); | ||
| maxDate.setDate(maxDate.getDate() + maxDays); | ||
| validate.errors = [{ | ||
| keyword: keyword, | ||
| message: errorMessage[locale || 'de'].replace('{minDate}', convertDate(minDate)).replace('{maxDate}', convertDate(maxDate)), | ||
| params: { | ||
| keyword: keyword | ||
| } | ||
| }]; | ||
| break; | ||
| } | ||
| default: | ||
| validate.errors = [{ | ||
| keyword: keyword, | ||
| message: errorMessage ? errorMessage[locale || 'de'].replace('{schema}', schema) : locale === 'en' ? 'The entered format is invalid.' : 'Das eingegebene Format ist ungültig.', | ||
| params: { | ||
| keyword: keyword | ||
| } | ||
| }]; | ||
| break; | ||
| } | ||
| return callback(schema, data); | ||
@@ -196,0 +241,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"validators.cjs.development.js","sources":["../src/utils/reg_exps.ts","../src/utils/validators.ts","../src/utils/schema_keywords.ts"],"sourcesContent":["type RegExpStatment = {\n [key: string]: {\n name: string\n regex: RegExp\n description: string\n }\n}\n\nconst regExpStatments: RegExpStatment = {\n email: {\n name: 'email',\n regex: /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n description: 'this pattern is used to check if the email is valid'\n },\n\n lettersMinimum_3: {\n name: 'lettersMinimum_3',\n regex: /^[a-zA-Z]{3,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 3 letter'\n },\n\n numbersMinimum_6: {\n name: 'numbersMinimum_6',\n regex: /^[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers'\n },\n\n numbersTelephone_6: {\n name: 'numbersTelephone_6',\n regex: /^[+]*[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign'\n },\n\n numbersExact_11: {\n name: 'numbersExact_11',\n regex: /^[0-9]{11,11}$/,\n description:\n 'this pattern is used to validate that the input length exactly 12 numbers'\n },\n\n numbersMaximum_11: {\n name: 'numbersMaximum_11',\n regex: /^[0-9]{1,11}$/,\n description:\n 'this pattern is used to validate that the input length is maximum 11 numbers'\n },\n\n date_de: {\n name: 'date_de',\n regex: /^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,\n description:\n 'this pattern is used to validate that the input is valid german date DD.MM.YYYY'\n }\n}\n\nexport default regExpStatments\n","import regExpStatments from './reg_exps'\nimport IBAN from 'iban'\n\n/**\n * Validate date in german format is in the past\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateBirthDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format and the date in the past\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() < new Date().getTime()) {\n return true\n }\n }\n\n return false\n}\n\n\n/**\n * Validate date is 14 days in the future\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateFutureDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() > new Date().getTime()+(14*24*60*60*1000)) {\n return true\n }\n }\n\n return false\n}\n\nexport function parseDateDE(dateStr: string): Date {\n const dateArray = dateStr.split('.')\n const date = new Date()\n\n date.setFullYear(+dateArray[2], +dateArray[1] - 1, +dateArray[0])\n\n return date\n}\n\ntype FunctionalValidators = {\n [key: string]: {\n name: string\n callback: (data: string) => boolean\n description: string\n }\n}\n\n/**\n * Validate iban and validate its syntax\n * @param data iban string\n * @returns boolean\n */\nexport function validateIBAN(data: string): boolean {\n return IBAN.isValid(data)\n}\n\nexport const functionalValidators: FunctionalValidators = {\n iban: {\n name: 'iban',\n callback: validateIBAN,\n description:\n 'this validation function will validate the syntax of the provided iban'\n },\n birth_date: {\n name: 'birth_date',\n callback: validateBirthDate,\n description:\n 'this function will validate that the date is in the past'\n },\n future_date_14: {\n name: 'future_date_14',\n callback: validateFutureDate,\n description:\n 'this function will validate that the date is in the future with 14 days at least'\n }\n}\n\nexport const IBAN_Specifications = IBAN.countries","import regExpStatments from './reg_exps'\nimport { ErrorObject } from 'ajv'\nimport { parseDateDE } from './validators'\n\ntype SchemaValidateFunction = {\n (schema: any, data: any):\n | boolean\n | Promise<any>\n errors?: Partial<ErrorObject>[]\n}\n\ntype SchemaKeyword = {\n keyword: string\n callback: (schema: any, data: any) => boolean\n errorMessage: {\n [locale: string]: string\n }\n}\n\nexport const schemaKeywords: SchemaKeyword[] = [\n {\n keyword: 'email',\n callback: (schema: boolean, data: string) =>\n schema ? regExpStatments.email.regex.test(data) : false,\n errorMessage: {\n en: 'Please enter a valid email address.',\n de: 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'\n }\n },\n {\n keyword: 'onlyLetters',\n callback: (schema: boolean, data: string) =>\n schema ? /^[a-zA-Z]+$/.test(data) : false,\n errorMessage: {\n en: 'Only letters allowed.',\n de: 'Nur Buchstaben erlaubt.'\n }\n },\n {\n keyword: 'onlyNumbers',\n callback: (schema: boolean, data: string) =>\n schema ? /^[0-9]+$/.test(data) : false,\n errorMessage: {\n en: 'Only numbers allowed.',\n de: 'Nur Zahlen erlaubt.'\n }\n },\n {\n keyword: 'dateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? regExpStatments.date_de.regex.test(data)\n : false,\n errorMessage: {\n en: 'Date should have the format DD.MM.YYYY.',\n de: 'Das Datum sollte das Format TT.MM.JJJJ haben.'\n }\n },\n {\n keyword: 'minNumbersTelephone',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? new RegExp(`^[+]*[0-9]{${schema},}$`).test(data)\n : false,\n errorMessage: {\n en: 'Please enter a valid telephone number.',\n de: 'Bitte geben Sie eine gültige Telefonnummer ein.'\n }\n },\n {\n keyword: 'futureDateDE',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? parseDateDE(data).getTime() > new Date().getTime()+(schema*24*60*60*1000)\n : false,\n errorMessage: {\n en: 'The date must be at least {schema} days in the future.',\n de: 'Das Datum muss mind. {schema} Tage in der Zukunft liegen.'\n }\n },\n {\n keyword: 'birthdateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? parseDateDE(data).getTime() < new Date().getTime()\n : false,\n errorMessage: {\n en: 'Please enter a valid date of birth.',\n de: 'Bitte geben Sie ein gültiges Geburtsdatum ein.'\n }\n }\n]\n\nexport function validateSchemaKeyword(\n schemaKeyword: SchemaKeyword,\n locale?: string\n): SchemaValidateFunction {\n const { keyword, callback, errorMessage } = schemaKeyword\n\n const validate: SchemaValidateFunction = (schema: any, data: any) => {\n validate.errors = [\n {\n keyword,\n message: errorMessage\n ? errorMessage[locale || 'de'].replace('{schema}', schema)\n : locale === 'en'\n ? 'The entered format is invalid.'\n : 'Das eingegebene Format ist ungültig.',\n params: { keyword }\n }\n ]\n\n return callback(schema, data)\n }\n\n return validate\n}\n"],"names":["regExpStatments","email","name","regex","description","lettersMinimum_3","numbersMinimum_6","numbersTelephone_6","numbersExact_11","numbersMaximum_11","date_de","validateBirthDate","data","de_date","test","parseDateDE","getTime","Date","validateFutureDate","dateStr","dateArray","split","date","setFullYear","validateIBAN","IBAN","isValid","functionalValidators","iban","callback","birth_date","future_date_14","IBAN_Specifications","countries","schemaKeywords","keyword","schema","errorMessage","en","de","RegExp","validateSchemaKeyword","schemaKeyword","locale","validate","errors","message","replace","params"],"mappings":";;;;;;;;AAQA,IAAMA,eAAe,GAAmB;AACtCC,EAAAA,KAAK,EAAE;AACLC,IAAAA,IAAI,EAAE,OADD;AAELC,IAAAA,KAAK,EAAE,uJAFF;AAGLC,IAAAA,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E3B,MAAMO,QAAQ,GAA2B,SAAnCA,QAAmC,CAACR,MAAD,EAAcxB,IAAd;AACvCgC,IAAAA,QAAQ,CAACC,MAAT,GAAkB,CAChB;AACEV,MAAAA,OAAO,EAAPA,OADF;AAEEW,MAAAA,OAAO,EAAET,YAAY,GACjBA,YAAY,CAACM,MAAM,IAAI,IAAX,CAAZ,CAA6BI,OAA7B,CAAqC,UAArC,EAAiDX,MAAjD,CADiB,GAEjBO,MAAM,KAAK,IAAX,GACA,gCADA,GAEA,sCANN;AAOEK,MAAAA,MAAM,EAAE;AAAEb,QAAAA,OAAO,EAAPA;AAAF;AAPV,KADgB,CAAlB;AAYA,WAAON,QAAQ,CAACO,MAAD,EAASxB,IAAT,CAAf;AACD,GAdD;;AAgBA,SAAOgC,QAAP;AACD;;;;;;;;;;;;"} | ||
| {"version":3,"file":"validators.cjs.development.js","sources":["../src/utils/reg_exps.ts","../src/utils/validators.ts","../src/utils/schema_keywords.ts"],"sourcesContent":["type RegExpStatment = {\n [key: string]: {\n name: string\n regex: RegExp\n description: string\n }\n}\n\nconst regExpStatments: RegExpStatment = {\n email: {\n name: 'email',\n regex: /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n description: 'this pattern is used to check if the email is valid'\n },\n\n lettersMinimum_3: {\n name: 'lettersMinimum_3',\n regex: /^[a-zA-Z]{3,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 3 letter'\n },\n\n numbersMinimum_6: {\n name: 'numbersMinimum_6',\n regex: /^[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers'\n },\n\n numbersTelephone_6: {\n name: 'numbersTelephone_6',\n regex: /^[+]*[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign'\n },\n\n numbersExact_11: {\n name: 'numbersExact_11',\n regex: /^[0-9]{11,11}$/,\n description:\n 'this pattern is used to validate that the input length exactly 12 numbers'\n },\n\n numbersMaximum_11: {\n name: 'numbersMaximum_11',\n regex: /^[0-9]{1,11}$/,\n description:\n 'this pattern is used to validate that the input length is maximum 11 numbers'\n },\n\n date_de: {\n name: 'date_de',\n regex: /^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,\n description:\n 'this pattern is used to validate that the input is valid german date DD.MM.YYYY'\n }\n}\n\nexport default regExpStatments\n","import regExpStatments from './reg_exps'\nimport IBAN from 'iban'\n\n/**\n * Validate date in german format is in the past\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateBirthDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format and the date in the past\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() < new Date().getTime()) {\n return true\n }\n }\n\n return false\n}\n\n\n/**\n * Validate date is 14 days in the future\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateFutureDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() > new Date().getTime()+(14*24*60*60*1000)) {\n return true\n }\n }\n\n return false\n}\n\nexport function parseDateDE(dateStr: string): Date {\n const dateArray = dateStr.split('.')\n const date = new Date()\n\n date.setFullYear(+dateArray[2], +dateArray[1] - 1, +dateArray[0])\n\n return date\n}\n\ntype FunctionalValidators = {\n [key: string]: {\n name: string\n callback: (data: string) => boolean\n description: string\n }\n}\n\n/**\n * Validate iban and validate its syntax\n * @param data iban string\n * @returns boolean\n */\nexport function validateIBAN(data: string): boolean {\n return IBAN.isValid(data)\n}\n\nexport const functionalValidators: FunctionalValidators = {\n iban: {\n name: 'iban',\n callback: validateIBAN,\n description:\n 'this validation function will validate the syntax of the provided iban'\n },\n birth_date: {\n name: 'birth_date',\n callback: validateBirthDate,\n description:\n 'this function will validate that the date is in the past'\n },\n future_date_14: {\n name: 'future_date_14',\n callback: validateFutureDate,\n description:\n 'this function will validate that the date is in the future with 14 days at least'\n }\n}\n\nexport const IBAN_Specifications = IBAN.countries","import regExpStatments from './reg_exps'\nimport { ErrorObject } from 'ajv'\nimport { parseDateDE } from './validators'\n\ntype SchemaValidateFunction = {\n (schema: any, data: any):\n | boolean\n | Promise<any>\n errors?: Partial<ErrorObject>[]\n}\n\ntype SchemaKeyword = {\n keyword: string\n callback: (schema: any, data: any) => boolean\n errorMessage: {\n [locale: string]: string\n }\n}\n\nexport const schemaKeywords: SchemaKeyword[] = [\n {\n keyword: 'email',\n callback: (schema: boolean, data: string) =>\n schema ? regExpStatments.email.regex.test(data) : false,\n errorMessage: {\n en: 'Please enter a valid email address.',\n de: 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'\n }\n },\n {\n keyword: 'onlyLetters',\n callback: (schema: boolean, data: string) =>\n schema ? /^[a-zA-Z]+$/.test(data) : false,\n errorMessage: {\n en: 'Only letters allowed.',\n de: 'Nur Buchstaben erlaubt.'\n }\n },\n {\n keyword: 'onlyNumbers',\n callback: (schema: boolean, data: string) =>\n schema ? /^[0-9]+$/.test(data) : false,\n errorMessage: {\n en: 'Only numbers allowed.',\n de: 'Nur Zahlen erlaubt.'\n }\n },\n {\n keyword: 'dateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? regExpStatments.date_de.regex.test(data)\n : false,\n errorMessage: {\n en: 'Date should have the format DD.MM.YYYY.',\n de: 'Das Datum sollte das Format TT.MM.JJJJ haben.'\n }\n },\n {\n keyword: 'minNumbersTelephone',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? new RegExp(`^[+]*[0-9]{${schema},}$`).test(data)\n : false,\n errorMessage: {\n en: 'Please enter a valid telephone number.',\n de: 'Bitte geben Sie eine gültige Telefonnummer ein.'\n }\n },\n {\n keyword: 'futureDateDE',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? parseDateDE(data).getTime() > new Date().getTime()+(schema*24*60*60*1000)\n : false,\n errorMessage: {\n en: 'The date must be at least {schema} days in the future.',\n de: 'Das Datum muss mind. {schema} Tage in der Zukunft liegen.'\n }\n },\n {\n keyword: 'rangeDateDE',\n callback: (schema: number[], data: string) => {\n return schema && Array.isArray(schema) && schema.length === 2\n ? parseDateDE(data).getTime() >= new Date().getTime()+(schema[0]*24*60*60*1000) && parseDateDE(data).getTime() <= new Date().getTime()+(schema[1]*24*60*60*1000)\n : false\n },\n errorMessage: {\n en: 'Date must be between {minDate} and {maxDate}.',\n de: 'Datum muss zwischen {minDate} und {maxDate} liegen.'\n }\n },\n {\n keyword: 'birthdateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? parseDateDE(data).getTime() < new Date().getTime()\n : false,\n errorMessage: {\n en: 'Please enter a valid date of birth.',\n de: 'Bitte geben Sie ein gültiges Geburtsdatum ein.'\n }\n }\n]\n\nfunction convertDate(date: Date, separator = '.') {\n function pad(s: number) { return (s < 10) ? '0' + s : s; }\n return [pad(date.getDate()), pad(date.getMonth()+1), date.getFullYear()].join(separator)\n}\n\nexport function validateSchemaKeyword(\n schemaKeyword: SchemaKeyword,\n locale?: string\n): SchemaValidateFunction {\n const { keyword, callback, errorMessage } = schemaKeyword\n\n const validate: SchemaValidateFunction = (schema: any, data: any) => {\n switch(keyword) {\n case 'rangeDateDE': {\n const [minDays, maxDays] = schema\n const minDate = new Date()\n minDate.setDate(minDate.getDate() + minDays)\n const maxDate = new Date()\n maxDate.setDate(maxDate.getDate() + maxDays)\n\n validate.errors = [\n {\n keyword,\n message: errorMessage[locale || 'de'].replace('{minDate}', convertDate(minDate)).replace('{maxDate}', convertDate(maxDate)),\n params: { keyword }\n }\n ]\n break\n }\n default:\n validate.errors = [\n {\n keyword,\n message: errorMessage\n ? errorMessage[locale || 'de'].replace('{schema}', schema)\n : locale === 'en'\n ? 'The entered format is invalid.'\n : 'Das eingegebene Format ist ungültig.',\n params: { keyword }\n }\n ]\n break\n }\n\n return callback(schema, data)\n }\n\n return validate\n}\n"],"names":["regExpStatments","email","name","regex","description","lettersMinimum_3","numbersMinimum_6","numbersTelephone_6","numbersExact_11","numbersMaximum_11","date_de","validateBirthDate","data","de_date","test","parseDateDE","getTime","Date","validateFutureDate","dateStr","dateArray","split","date","setFullYear","validateIBAN","IBAN","isValid","functionalValidators","iban","callback","birth_date","future_date_14","IBAN_Specifications","countries","schemaKeywords","keyword","schema","errorMessage","en","de","RegExp","Array","isArray","length","convertDate","separator","pad","s","getDate","getMonth","getFullYear","join","validateSchemaKeyword","schemaKeyword","locale","validate","minDays","maxDays","minDate","setDate","maxDate","errors","message","replace","params"],"mappings":";;;;;;;;AAQA,IAAMA,eAAe,GAAmB;AACtCC,EAAAA,KAAK,EAAE;AACLC,IAAAA,IAAI,EAAE,OADD;AAELC,IAAAA,KAAK,EAAE,uJAFF;AAGLC,IAAAA,WAAW,EAAE;AAHR,GAD+B;AAOtCC,EAAAA,gBAAgB,EAAE;AAChBH,IAAAA,IAAI,EAAE,kBADU;AAEhBC,IAAAA,KAAK,EAAE,gBAFS;AAGhBC,IAAAA,WAAW,EACT;AAJc,GAPoB;AActCE,EAAAA,gBAAgB,EAAE;AAChBJ,IAAAA,IAAI,EAAE,kBADU;AAEhBC,IAAAA,KAAK,EAAE,aAFS;AAGhBC,IAAAA,WAAW,EACT;AAJc,GAdoB;AAqBtCG,EAAAA,kBAAkB,EAAE;AAClBL,IAAAA,IAAI,EAAE,oBADY;AAElBC,IAAAA,KAAK,EAAE,iBAFW;AAGlBC,IAAAA,WAAW,EACT;AAJgB,GArBkB;AA4BtCI,EAAAA,eAAe,EAAE;AACfN,IAAAA,IAAI,EAAE,iBADS;AAEfC,IAAAA,KAAK,EAAE,gBAFQ;AAGfC,IAAAA,WAAW,EACT;AAJa,GA5BqB;AAmCtCK,EAAAA,iBAAiB,EAAE;AACjBP,IAAAA,IAAI,EAAE,mBADW;AAEjBC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D;;AACD;AACEoB,QAAAA,QAAQ,CAACM,MAAT,GAAkB,CAChB;AACE1B,UAAAA,OAAO,EAAPA,OADF;AAEE2B,UAAAA,OAAO,EAAEzB,YAAY,GACjBA,YAAY,CAACiB,MAAM,IAAI,IAAX,CAAZ,CAA6BS,OAA7B,CAAqC,UAArC,EAAiD3B,MAAjD,CADiB,GAEjBkB,MAAM,KAAK,IAAX,GACA,gCADA,GAEA,sCANN;AAOEU,UAAAA,MAAM,EAAE;AAAE7B,YAAAA,OAAO,EAAPA;AAAF;AAPV,SADgB,CAAlB;AAWA;AA7BJ;;AAgCA,WAAON,QAAQ,CAACO,MAAD,EAASxB,IAAT,CAAf;AACD,GAlCD;;AAoCA,SAAO2C,QAAP;AACD;;;;;;;;;;;;"} |
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("iban"))&&"object"==typeof e&&"default"in e?e.default:e,a={email:{name:"email",regex:/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,description:"this pattern is used to check if the email is valid"},lettersMinimum_3:{name:"lettersMinimum_3",regex:/^[a-zA-Z]{3,}$/,description:"this pattern is used to validate that the input length is at least 3 letter"},numbersMinimum_6:{name:"numbersMinimum_6",regex:/^[0-9]{6,}$/,description:"this pattern is used to validate that the input length is at least 6 numbers"},numbersTelephone_6:{name:"numbersTelephone_6",regex:/^[+]*[0-9]{6,}$/,description:"this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign"},numbersExact_11:{name:"numbersExact_11",regex:/^[0-9]{11,11}$/,description:"this pattern is used to validate that the input length exactly 12 numbers"},numbersMaximum_11:{name:"numbersMaximum_11",regex:/^[0-9]{1,11}$/,description:"this pattern is used to validate that the input length is maximum 11 numbers"},date_de:{name:"date_de",regex:/^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,description:"this pattern is used to validate that the input is valid german date DD.MM.YYYY"}};function r(e){return!!(a.date_de.regex.test(e)&&n(e).getTime()<(new Date).getTime())}function i(e){return!!(a.date_de.regex.test(e)&&n(e).getTime()>(new Date).getTime()+12096e5)}function n(e){var t=e.split("."),a=new Date;return a.setFullYear(+t[2],+t[1]-1,+t[0]),a}function s(e){return t.isValid(e)}var l={iban:{name:"iban",callback:s,description:"this validation function will validate the syntax of the provided iban"},birth_date:{name:"birth_date",callback:r,description:"this function will validate that the date is in the past"},future_date_14:{name:"future_date_14",callback:i,description:"this function will validate that the date is in the future with 14 days at least"}},u=[{keyword:"email",callback:function(e,t){return!!e&&a.email.regex.test(t)},errorMessage:{en:"Please enter a valid email address.",de:"Bitte geben Sie eine gültige E-Mail-Adresse ein."}},{keyword:"onlyLetters",callback:function(e,t){return!!e&&/^[a-zA-Z]+$/.test(t)},errorMessage:{en:"Only letters allowed.",de:"Nur Buchstaben erlaubt."}},{keyword:"onlyNumbers",callback:function(e,t){return!!e&&/^[0-9]+$/.test(t)},errorMessage:{en:"Only numbers allowed.",de:"Nur Zahlen erlaubt."}},{keyword:"dateDE",callback:function(e,t){return!!e&&a.date_de.regex.test(t)},errorMessage:{en:"Date should have the format DD.MM.YYYY.",de:"Das Datum sollte das Format TT.MM.JJJJ haben."}},{keyword:"minNumbersTelephone",callback:function(e,t){return!(!e||"number"!=typeof e)&&new RegExp("^[+]*[0-9]{"+e+",}$").test(t)},errorMessage:{en:"Please enter a valid telephone number.",de:"Bitte geben Sie eine gültige Telefonnummer ein."}},{keyword:"futureDateDE",callback:function(e,t){return!(!e||"number"!=typeof e)&&n(t).getTime()>(new Date).getTime()+24*e*60*60*1e3},errorMessage:{en:"The date must be at least {schema} days in the future.",de:"Das Datum muss mind. {schema} Tage in der Zukunft liegen."}},{keyword:"birthdateDE",callback:function(e,t){return!!e&&n(t).getTime()<(new Date).getTime()},errorMessage:{en:"Please enter a valid date of birth.",de:"Bitte geben Sie ein gültiges Geburtsdatum ein."}}];exports.IBAN_Specifications=t.countries,exports.functionalValidators=l,exports.parseDateDE=n,exports.regExpStatments=a,exports.schemaKeywords=u,exports.validateBirthDate=r,exports.validateFutureDate=i,exports.validateIBAN=s,exports.validateSchemaKeyword=function(e,t){var a=e.keyword,r=e.callback,i=e.errorMessage;return function e(n,s){return e.errors=[{keyword:a,message:i?i[t||"de"].replace("{schema}",n):"en"===t?"The entered format is invalid.":"Das eingegebene Format ist ungültig.",params:{keyword:a}}],r(n,s)}}; | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("iban"))&&"object"==typeof e&&"default"in e?e.default:e,a={email:{name:"email",regex:/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,description:"this pattern is used to check if the email is valid"},lettersMinimum_3:{name:"lettersMinimum_3",regex:/^[a-zA-Z]{3,}$/,description:"this pattern is used to validate that the input length is at least 3 letter"},numbersMinimum_6:{name:"numbersMinimum_6",regex:/^[0-9]{6,}$/,description:"this pattern is used to validate that the input length is at least 6 numbers"},numbersTelephone_6:{name:"numbersTelephone_6",regex:/^[+]*[0-9]{6,}$/,description:"this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign"},numbersExact_11:{name:"numbersExact_11",regex:/^[0-9]{11,11}$/,description:"this pattern is used to validate that the input length exactly 12 numbers"},numbersMaximum_11:{name:"numbersMaximum_11",regex:/^[0-9]{1,11}$/,description:"this pattern is used to validate that the input length is maximum 11 numbers"},date_de:{name:"date_de",regex:/^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,description:"this pattern is used to validate that the input is valid german date DD.MM.YYYY"}};function r(e){return!!(a.date_de.regex.test(e)&&i(e).getTime()<(new Date).getTime())}function n(e){return!!(a.date_de.regex.test(e)&&i(e).getTime()>(new Date).getTime()+12096e5)}function i(e){var t=e.split("."),a=new Date;return a.setFullYear(+t[2],+t[1]-1,+t[0]),a}function s(e){return t.isValid(e)}var l={iban:{name:"iban",callback:s,description:"this validation function will validate the syntax of the provided iban"},birth_date:{name:"birth_date",callback:r,description:"this function will validate that the date is in the past"},future_date_14:{name:"future_date_14",callback:n,description:"this function will validate that the date is in the future with 14 days at least"}},u=[{keyword:"email",callback:function(e,t){return!!e&&a.email.regex.test(t)},errorMessage:{en:"Please enter a valid email address.",de:"Bitte geben Sie eine gültige E-Mail-Adresse ein."}},{keyword:"onlyLetters",callback:function(e,t){return!!e&&/^[a-zA-Z]+$/.test(t)},errorMessage:{en:"Only letters allowed.",de:"Nur Buchstaben erlaubt."}},{keyword:"onlyNumbers",callback:function(e,t){return!!e&&/^[0-9]+$/.test(t)},errorMessage:{en:"Only numbers allowed.",de:"Nur Zahlen erlaubt."}},{keyword:"dateDE",callback:function(e,t){return!!e&&a.date_de.regex.test(t)},errorMessage:{en:"Date should have the format DD.MM.YYYY.",de:"Das Datum sollte das Format TT.MM.JJJJ haben."}},{keyword:"minNumbersTelephone",callback:function(e,t){return!(!e||"number"!=typeof e)&&new RegExp("^[+]*[0-9]{"+e+",}$").test(t)},errorMessage:{en:"Please enter a valid telephone number.",de:"Bitte geben Sie eine gültige Telefonnummer ein."}},{keyword:"futureDateDE",callback:function(e,t){return!(!e||"number"!=typeof e)&&i(t).getTime()>(new Date).getTime()+24*e*60*60*1e3},errorMessage:{en:"The date must be at least {schema} days in the future.",de:"Das Datum muss mind. {schema} Tage in der Zukunft liegen."}},{keyword:"rangeDateDE",callback:function(e,t){return!(!e||!Array.isArray(e)||2!==e.length)&&i(t).getTime()>=(new Date).getTime()+24*e[0]*60*60*1e3&&i(t).getTime()<=(new Date).getTime()+24*e[1]*60*60*1e3},errorMessage:{en:"Date must be between {minDate} and {maxDate}.",de:"Datum muss zwischen {minDate} und {maxDate} liegen."}},{keyword:"birthdateDE",callback:function(e,t){return!!e&&i(t).getTime()<(new Date).getTime()},errorMessage:{en:"Please enter a valid date of birth.",de:"Bitte geben Sie ein gültiges Geburtsdatum ein."}}];function d(e,t){function a(e){return e<10?"0"+e:e}return void 0===t&&(t="."),[a(e.getDate()),a(e.getMonth()+1),e.getFullYear()].join(t)}exports.IBAN_Specifications=t.countries,exports.functionalValidators=l,exports.parseDateDE=i,exports.regExpStatments=a,exports.schemaKeywords=u,exports.validateBirthDate=r,exports.validateFutureDate=n,exports.validateIBAN=s,exports.validateSchemaKeyword=function(e,t){var a=e.keyword,r=e.callback,n=e.errorMessage;return function e(i,s){switch(a){case"rangeDateDE":var l=i[0],u=i[1],o=new Date;o.setDate(o.getDate()+l);var m=new Date;m.setDate(m.getDate()+u),e.errors=[{keyword:a,message:n[t||"de"].replace("{minDate}",d(o)).replace("{maxDate}",d(m)),params:{keyword:a}}];break;default:e.errors=[{keyword:a,message:n?n[t||"de"].replace("{schema}",i):"en"===t?"The entered format is invalid.":"Das eingegebene Format ist ungültig.",params:{keyword:a}}]}return r(i,s)}}; | ||
| //# sourceMappingURL=validators.cjs.production.min.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"validators.cjs.production.min.js","sources":["../src/utils/reg_exps.ts","../src/utils/validators.ts","../src/utils/schema_keywords.ts"],"sourcesContent":["type RegExpStatment = {\n [key: string]: {\n name: string\n regex: RegExp\n description: string\n }\n}\n\nconst regExpStatments: RegExpStatment = {\n email: {\n name: 'email',\n regex: /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n description: 'this pattern is used to check if the email is valid'\n },\n\n lettersMinimum_3: {\n name: 'lettersMinimum_3',\n regex: /^[a-zA-Z]{3,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 3 letter'\n },\n\n numbersMinimum_6: {\n name: 'numbersMinimum_6',\n regex: /^[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers'\n },\n\n numbersTelephone_6: {\n name: 'numbersTelephone_6',\n regex: /^[+]*[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign'\n },\n\n numbersExact_11: {\n name: 'numbersExact_11',\n regex: /^[0-9]{11,11}$/,\n description:\n 'this pattern is used to validate that the input length exactly 12 numbers'\n },\n\n numbersMaximum_11: {\n name: 'numbersMaximum_11',\n regex: /^[0-9]{1,11}$/,\n description:\n 'this pattern is used to validate that the input length is maximum 11 numbers'\n },\n\n date_de: {\n name: 'date_de',\n regex: /^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,\n description:\n 'this pattern is used to validate that the input is valid german date DD.MM.YYYY'\n }\n}\n\nexport default regExpStatments\n","import regExpStatments from './reg_exps'\nimport IBAN from 'iban'\n\n/**\n * Validate date in german format is in the past\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateBirthDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format and the date in the past\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() < new Date().getTime()) {\n return true\n }\n }\n\n return false\n}\n\n\n/**\n * Validate date is 14 days in the future\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateFutureDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() > new Date().getTime()+(14*24*60*60*1000)) {\n return true\n }\n }\n\n return false\n}\n\nexport function parseDateDE(dateStr: string): Date {\n const dateArray = dateStr.split('.')\n const date = new Date()\n\n date.setFullYear(+dateArray[2], +dateArray[1] - 1, +dateArray[0])\n\n return date\n}\n\ntype FunctionalValidators = {\n [key: string]: {\n name: string\n callback: (data: string) => boolean\n description: string\n }\n}\n\n/**\n * Validate iban and validate its syntax\n * @param data iban string\n * @returns boolean\n */\nexport function validateIBAN(data: string): boolean {\n return IBAN.isValid(data)\n}\n\nexport const functionalValidators: FunctionalValidators = {\n iban: {\n name: 'iban',\n callback: validateIBAN,\n description:\n 'this validation function will validate the syntax of the provided iban'\n },\n birth_date: {\n name: 'birth_date',\n callback: validateBirthDate,\n description:\n 'this function will validate that the date is in the past'\n },\n future_date_14: {\n name: 'future_date_14',\n callback: validateFutureDate,\n description:\n 'this function will validate that the date is in the future with 14 days at least'\n }\n}\n\nexport const IBAN_Specifications = IBAN.countries","import regExpStatments from './reg_exps'\nimport { ErrorObject } from 'ajv'\nimport { parseDateDE } from './validators'\n\ntype SchemaValidateFunction = {\n (schema: any, data: any):\n | boolean\n | Promise<any>\n errors?: Partial<ErrorObject>[]\n}\n\ntype SchemaKeyword = {\n keyword: string\n callback: (schema: any, data: any) => boolean\n errorMessage: {\n [locale: string]: string\n }\n}\n\nexport const schemaKeywords: SchemaKeyword[] = [\n {\n keyword: 'email',\n callback: (schema: boolean, data: string) =>\n schema ? regExpStatments.email.regex.test(data) : false,\n errorMessage: {\n en: 'Please enter a valid email address.',\n de: 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'\n }\n },\n {\n keyword: 'onlyLetters',\n callback: (schema: boolean, data: string) =>\n schema ? /^[a-zA-Z]+$/.test(data) : false,\n errorMessage: {\n en: 'Only letters allowed.',\n de: 'Nur Buchstaben erlaubt.'\n }\n },\n {\n keyword: 'onlyNumbers',\n callback: (schema: boolean, data: string) =>\n schema ? /^[0-9]+$/.test(data) : false,\n errorMessage: {\n en: 'Only numbers allowed.',\n de: 'Nur Zahlen erlaubt.'\n }\n },\n {\n keyword: 'dateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? regExpStatments.date_de.regex.test(data)\n : false,\n errorMessage: {\n en: 'Date should have the format DD.MM.YYYY.',\n de: 'Das Datum sollte das Format TT.MM.JJJJ haben.'\n }\n },\n {\n keyword: 'minNumbersTelephone',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? new RegExp(`^[+]*[0-9]{${schema},}$`).test(data)\n : false,\n errorMessage: {\n en: 'Please enter a valid telephone number.',\n de: 'Bitte geben Sie eine gültige Telefonnummer ein.'\n }\n },\n {\n keyword: 'futureDateDE',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? parseDateDE(data).getTime() > new Date().getTime()+(schema*24*60*60*1000)\n : false,\n errorMessage: {\n en: 'The date must be at least {schema} days in the future.',\n de: 'Das Datum muss mind. {schema} Tage in der Zukunft liegen.'\n }\n },\n {\n keyword: 'birthdateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? parseDateDE(data).getTime() < new Date().getTime()\n : false,\n errorMessage: {\n en: 'Please enter a valid date of birth.',\n de: 'Bitte geben Sie ein gültiges Geburtsdatum ein.'\n }\n }\n]\n\nexport function validateSchemaKeyword(\n schemaKeyword: SchemaKeyword,\n locale?: string\n): SchemaValidateFunction {\n const { keyword, callback, errorMessage } = schemaKeyword\n\n const validate: SchemaValidateFunction = (schema: any, data: any) => {\n validate.errors = [\n {\n keyword,\n message: errorMessage\n ? errorMessage[locale || 'de'].replace('{schema}', schema)\n : locale === 'en'\n ? 'The entered format is invalid.'\n : 'Das eingegebene Format ist ungültig.',\n params: { keyword }\n }\n ]\n\n return callback(schema, data)\n }\n\n return validate\n}\n"],"names":["regExpStatments","email","name","regex","description","lettersMinimum_3","numbersMinimum_6","numbersTelephone_6","numbersExact_11","numbersMaximum_11","date_de","validateBirthDate","data","test","parseDateDE","getTime","Date","validateFutureDate","dateStr","dateArray","split","date","setFullYear","validateIBAN","IBAN","isValid","functionalValidators","iban","callback","birth_date","future_date_14","schemaKeywords","keyword","schema","errorMessage","en","de","RegExp","countries","schemaKeyword","locale","validate","errors","message","replace","params"],"mappings":"+IAQMA,EAAkC,CACtCC,MAAO,CACLC,KAAM,QACNC,MAAO,wJACPC,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S,WAAWpB,KAAKD,IAC3BsB,aAAc,CACZC,GAAI,wBACJC,GAAI,wBAGR,CACEJ,QAAS,SACTJ,SAAU,SAACK,EAAiBrB,WAC1BqB,GACIjC,EAAgBU,QAAQP,MAAMU,KAAKD,IAEzCsB,aAAc,CACZC,GAAI,0CACJC,GAAI,kDAGR,CACEJ,QAAS,sBACTJ,SAAU,SAACK,EAAgBrB,YAC3BqB,GAA4B,iBAAXA,IACX,IAAII,qBAAqBJ,SAAapB,KAAKD,IAEjDsB,aAAc,CACZC,GAAI,yCACJC,GAAI,oDAGR,CACEJ,QAAS,eACTJ,SAAU,SAACK,EAAgBrB,YACzBqB,GAA4B,iBAAXA,IACbnB,EAAYF,GAAMG,WAAY,IAAIC,MAAOD,UAAkB,GAAPkB,EAAU,GAAG,GAAG,KAE1EC,aAAc,CACZC,GAAI,yDACJC,GAAI,8DAGR,CACEJ,QAAS,cACTJ,SAAU,SAACK,EAAiBrB,WAC1BqB,GACInB,EAAYF,GAAMG,WAAY,IAAIC,MAAOD,WAE/CmB,aAAc,CACZC,GAAI,sCACJC,GAAI,gFDDyBZ,EAAKc,yOCOtCC,EACAC,OAEQR,EAAoCO,EAApCP,QAASJ,EAA2BW,EAA3BX,SAAUM,EAAiBK,EAAjBL,oBAEc,SAAnCO,EAAoCR,EAAarB,UACrD6B,EAASC,OAAS,CAChB,CACEV,QAAAA,EACAW,QAAST,EACLA,EAAaM,GAAU,MAAMI,QAAQ,WAAYX,GACtC,OAAXO,EACA,iCACA,uCACJK,OAAQ,CAAEb,QAAAA,KAIPJ,EAASK,EAAQrB"} | ||
| {"version":3,"file":"validators.cjs.production.min.js","sources":["../src/utils/reg_exps.ts","../src/utils/validators.ts","../src/utils/schema_keywords.ts"],"sourcesContent":["type RegExpStatment = {\n [key: string]: {\n name: string\n regex: RegExp\n description: string\n }\n}\n\nconst regExpStatments: RegExpStatment = {\n email: {\n name: 'email',\n regex: /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n description: 'this pattern is used to check if the email is valid'\n },\n\n lettersMinimum_3: {\n name: 'lettersMinimum_3',\n regex: /^[a-zA-Z]{3,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 3 letter'\n },\n\n numbersMinimum_6: {\n name: 'numbersMinimum_6',\n regex: /^[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers'\n },\n\n numbersTelephone_6: {\n name: 'numbersTelephone_6',\n regex: /^[+]*[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign'\n },\n\n numbersExact_11: {\n name: 'numbersExact_11',\n regex: /^[0-9]{11,11}$/,\n description:\n 'this pattern is used to validate that the input length exactly 12 numbers'\n },\n\n numbersMaximum_11: {\n name: 'numbersMaximum_11',\n regex: /^[0-9]{1,11}$/,\n description:\n 'this pattern is used to validate that the input length is maximum 11 numbers'\n },\n\n date_de: {\n name: 'date_de',\n regex: /^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,\n description:\n 'this pattern is used to validate that the input is valid german date DD.MM.YYYY'\n }\n}\n\nexport default regExpStatments\n","import regExpStatments from './reg_exps'\nimport IBAN from 'iban'\n\n/**\n * Validate date in german format is in the past\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateBirthDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format and the date in the past\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() < new Date().getTime()) {\n return true\n }\n }\n\n return false\n}\n\n\n/**\n * Validate date is 14 days in the future\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateFutureDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() > new Date().getTime()+(14*24*60*60*1000)) {\n return true\n }\n }\n\n return false\n}\n\nexport function parseDateDE(dateStr: string): Date {\n const dateArray = dateStr.split('.')\n const date = new Date()\n\n date.setFullYear(+dateArray[2], +dateArray[1] - 1, +dateArray[0])\n\n return date\n}\n\ntype FunctionalValidators = {\n [key: string]: {\n name: string\n callback: (data: string) => boolean\n description: string\n }\n}\n\n/**\n * Validate iban and validate its syntax\n * @param data iban string\n * @returns boolean\n */\nexport function validateIBAN(data: string): boolean {\n return IBAN.isValid(data)\n}\n\nexport const functionalValidators: FunctionalValidators = {\n iban: {\n name: 'iban',\n callback: validateIBAN,\n description:\n 'this validation function will validate the syntax of the provided iban'\n },\n birth_date: {\n name: 'birth_date',\n callback: validateBirthDate,\n description:\n 'this function will validate that the date is in the past'\n },\n future_date_14: {\n name: 'future_date_14',\n callback: validateFutureDate,\n description:\n 'this function will validate that the date is in the future with 14 days at least'\n }\n}\n\nexport const IBAN_Specifications = IBAN.countries","import regExpStatments from './reg_exps'\nimport { ErrorObject } from 'ajv'\nimport { parseDateDE } from './validators'\n\ntype SchemaValidateFunction = {\n (schema: any, data: any):\n | boolean\n | Promise<any>\n errors?: Partial<ErrorObject>[]\n}\n\ntype SchemaKeyword = {\n keyword: string\n callback: (schema: any, data: any) => boolean\n errorMessage: {\n [locale: string]: string\n }\n}\n\nexport const schemaKeywords: SchemaKeyword[] = [\n {\n keyword: 'email',\n callback: (schema: boolean, data: string) =>\n schema ? regExpStatments.email.regex.test(data) : false,\n errorMessage: {\n en: 'Please enter a valid email address.',\n de: 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'\n }\n },\n {\n keyword: 'onlyLetters',\n callback: (schema: boolean, data: string) =>\n schema ? /^[a-zA-Z]+$/.test(data) : false,\n errorMessage: {\n en: 'Only letters allowed.',\n de: 'Nur Buchstaben erlaubt.'\n }\n },\n {\n keyword: 'onlyNumbers',\n callback: (schema: boolean, data: string) =>\n schema ? /^[0-9]+$/.test(data) : false,\n errorMessage: {\n en: 'Only numbers allowed.',\n de: 'Nur Zahlen erlaubt.'\n }\n },\n {\n keyword: 'dateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? regExpStatments.date_de.regex.test(data)\n : false,\n errorMessage: {\n en: 'Date should have the format DD.MM.YYYY.',\n de: 'Das Datum sollte das Format TT.MM.JJJJ haben.'\n }\n },\n {\n keyword: 'minNumbersTelephone',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? new RegExp(`^[+]*[0-9]{${schema},}$`).test(data)\n : false,\n errorMessage: {\n en: 'Please enter a valid telephone number.',\n de: 'Bitte geben Sie eine gültige Telefonnummer ein.'\n }\n },\n {\n keyword: 'futureDateDE',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? parseDateDE(data).getTime() > new Date().getTime()+(schema*24*60*60*1000)\n : false,\n errorMessage: {\n en: 'The date must be at least {schema} days in the future.',\n de: 'Das Datum muss mind. {schema} Tage in der Zukunft liegen.'\n }\n },\n {\n keyword: 'rangeDateDE',\n callback: (schema: number[], data: string) => {\n return schema && Array.isArray(schema) && schema.length === 2\n ? parseDateDE(data).getTime() >= new Date().getTime()+(schema[0]*24*60*60*1000) && parseDateDE(data).getTime() <= new Date().getTime()+(schema[1]*24*60*60*1000)\n : false\n },\n errorMessage: {\n en: 'Date must be between {minDate} and {maxDate}.',\n de: 'Datum muss zwischen {minDate} und {maxDate} liegen.'\n }\n },\n {\n keyword: 'birthdateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? parseDateDE(data).getTime() < new Date().getTime()\n : false,\n errorMessage: {\n en: 'Please enter a valid date of birth.',\n de: 'Bitte geben Sie ein gültiges Geburtsdatum ein.'\n }\n }\n]\n\nfunction convertDate(date: Date, separator = '.') {\n function pad(s: number) { return (s < 10) ? '0' + s : s; }\n return [pad(date.getDate()), pad(date.getMonth()+1), date.getFullYear()].join(separator)\n}\n\nexport function validateSchemaKeyword(\n schemaKeyword: SchemaKeyword,\n locale?: string\n): SchemaValidateFunction {\n const { keyword, callback, errorMessage } = schemaKeyword\n\n const validate: SchemaValidateFunction = (schema: any, data: any) => {\n switch(keyword) {\n case 'rangeDateDE': {\n const [minDays, maxDays] = schema\n const minDate = new Date()\n minDate.setDate(minDate.getDate() + minDays)\n const maxDate = new Date()\n maxDate.setDate(maxDate.getDate() + maxDays)\n\n validate.errors = [\n {\n keyword,\n message: errorMessage[locale || 'de'].replace('{minDate}', convertDate(minDate)).replace('{maxDate}', convertDate(maxDate)),\n params: { keyword }\n }\n ]\n break\n }\n default:\n validate.errors = [\n {\n keyword,\n message: errorMessage\n ? errorMessage[locale || 'de'].replace('{schema}', schema)\n : locale === 'en'\n ? 'The entered format is invalid.'\n : 'Das eingegebene Format ist ungültig.',\n params: { keyword }\n }\n ]\n break\n }\n\n return callback(schema, data)\n }\n\n return validate\n}\n"],"names":["regExpStatments","email","name","regex","description","lettersMinimum_3","numbersMinimum_6","numbersTelephone_6","numbersExact_11","numbersMaximum_11","date_de","validateBirthDate","data","test","parseDateDE","getTime","Date","validateFutureDate","dateStr","dateArray","split","date","setFullYear","validateIBAN","IBAN","isValid","functionalValidators","iban","callback","birth_date","future_date_14","schemaKeywords","keyword","schema","errorMessage","en","de","RegExp","Array","isArray","length","convertDate","separator","pad","s","getDate","getMonth","getFullYear","join","countries","schemaKeyword","locale","validate","minDays","maxDays","minDate","setDate","maxDate","errors","message","replace","params"],"mappings":"+IAQMA,EAAkC,CACtCC,MAAO,CACLC,KAAM,QACNC,MAAO,wJACPC,YAAa,uDAGfC,iBAAkB,CAChBH,KAAM,mBACNC,MAAO,iBACPC,YACE,+EAGJE,iBAAkB,CAChBJ,KAAM,mBACNC,MAAO,cACPC,YACE,gFAGJG,mBAAoB,CAClBL,KAAM,qBACNC,MAAO,kBACPC,YACE,+GAGJI,gBAAiB,CACfN,KAAM,kBACNC,MAAO,iBACPC,YACE,6EAGJK,kBAAmB,CACjBP,KAAM,oBACNC,MAAO,gB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,EAASM,OAAS,CAChB,CACE1B,QAAAA,EACA2B,QAASzB,EAAaiB,GAAU,MAAMS,QAAQ,YAAanB,EAAYc,IAAUK,QAAQ,YAAanB,EAAYgB,IAClHI,OAAQ,CAAE7B,QAAAA,mBAMdoB,EAASM,OAAS,CAChB,CACE1B,QAAAA,EACA2B,QAASzB,EACLA,EAAaiB,GAAU,MAAMS,QAAQ,WAAY3B,GACtC,OAAXkB,EACA,iCACA,uCACJU,OAAQ,CAAE7B,QAAAA,YAMXJ,EAASK,EAAQrB"} |
@@ -164,2 +164,11 @@ import IBAN from 'iban'; | ||
| }, { | ||
| keyword: 'rangeDateDE', | ||
| callback: function callback(schema, data) { | ||
| return schema && Array.isArray(schema) && schema.length === 2 ? parseDateDE(data).getTime() >= new Date().getTime() + schema[0] * 24 * 60 * 60 * 1000 && parseDateDE(data).getTime() <= new Date().getTime() + schema[1] * 24 * 60 * 60 * 1000 : false; | ||
| }, | ||
| errorMessage: { | ||
| en: 'Date must be between {minDate} and {maxDate}.', | ||
| de: 'Datum muss zwischen {minDate} und {maxDate} liegen.' | ||
| } | ||
| }, { | ||
| keyword: 'birthdateDE', | ||
@@ -174,2 +183,15 @@ callback: function callback(schema, data) { | ||
| }]; | ||
| function convertDate(date, separator) { | ||
| if (separator === void 0) { | ||
| separator = '.'; | ||
| } | ||
| function pad(s) { | ||
| return s < 10 ? '0' + s : s; | ||
| } | ||
| return [pad(date.getDate()), pad(date.getMonth() + 1), date.getFullYear()].join(separator); | ||
| } | ||
| function validateSchemaKeyword(schemaKeyword, locale) { | ||
@@ -181,9 +203,32 @@ var keyword = schemaKeyword.keyword, | ||
| var validate = function validate(schema, data) { | ||
| validate.errors = [{ | ||
| keyword: keyword, | ||
| message: errorMessage ? errorMessage[locale || 'de'].replace('{schema}', schema) : locale === 'en' ? 'The entered format is invalid.' : 'Das eingegebene Format ist ungültig.', | ||
| params: { | ||
| keyword: keyword | ||
| } | ||
| }]; | ||
| switch (keyword) { | ||
| case 'rangeDateDE': | ||
| { | ||
| var minDays = schema[0], | ||
| maxDays = schema[1]; | ||
| var minDate = new Date(); | ||
| minDate.setDate(minDate.getDate() + minDays); | ||
| var maxDate = new Date(); | ||
| maxDate.setDate(maxDate.getDate() + maxDays); | ||
| validate.errors = [{ | ||
| keyword: keyword, | ||
| message: errorMessage[locale || 'de'].replace('{minDate}', convertDate(minDate)).replace('{maxDate}', convertDate(maxDate)), | ||
| params: { | ||
| keyword: keyword | ||
| } | ||
| }]; | ||
| break; | ||
| } | ||
| default: | ||
| validate.errors = [{ | ||
| keyword: keyword, | ||
| message: errorMessage ? errorMessage[locale || 'de'].replace('{schema}', schema) : locale === 'en' ? 'The entered format is invalid.' : 'Das eingegebene Format ist ungültig.', | ||
| params: { | ||
| keyword: keyword | ||
| } | ||
| }]; | ||
| break; | ||
| } | ||
| return callback(schema, data); | ||
@@ -190,0 +235,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"validators.esm.js","sources":["../src/utils/reg_exps.ts","../src/utils/validators.ts","../src/utils/schema_keywords.ts"],"sourcesContent":["type RegExpStatment = {\n [key: string]: {\n name: string\n regex: RegExp\n description: string\n }\n}\n\nconst regExpStatments: RegExpStatment = {\n email: {\n name: 'email',\n regex: /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n description: 'this pattern is used to check if the email is valid'\n },\n\n lettersMinimum_3: {\n name: 'lettersMinimum_3',\n regex: /^[a-zA-Z]{3,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 3 letter'\n },\n\n numbersMinimum_6: {\n name: 'numbersMinimum_6',\n regex: /^[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers'\n },\n\n numbersTelephone_6: {\n name: 'numbersTelephone_6',\n regex: /^[+]*[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign'\n },\n\n numbersExact_11: {\n name: 'numbersExact_11',\n regex: /^[0-9]{11,11}$/,\n description:\n 'this pattern is used to validate that the input length exactly 12 numbers'\n },\n\n numbersMaximum_11: {\n name: 'numbersMaximum_11',\n regex: /^[0-9]{1,11}$/,\n description:\n 'this pattern is used to validate that the input length is maximum 11 numbers'\n },\n\n date_de: {\n name: 'date_de',\n regex: /^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,\n description:\n 'this pattern is used to validate that the input is valid german date DD.MM.YYYY'\n }\n}\n\nexport default regExpStatments\n","import regExpStatments from './reg_exps'\nimport IBAN from 'iban'\n\n/**\n * Validate date in german format is in the past\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateBirthDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format and the date in the past\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() < new Date().getTime()) {\n return true\n }\n }\n\n return false\n}\n\n\n/**\n * Validate date is 14 days in the future\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateFutureDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() > new Date().getTime()+(14*24*60*60*1000)) {\n return true\n }\n }\n\n return false\n}\n\nexport function parseDateDE(dateStr: string): Date {\n const dateArray = dateStr.split('.')\n const date = new Date()\n\n date.setFullYear(+dateArray[2], +dateArray[1] - 1, +dateArray[0])\n\n return date\n}\n\ntype FunctionalValidators = {\n [key: string]: {\n name: string\n callback: (data: string) => boolean\n description: string\n }\n}\n\n/**\n * Validate iban and validate its syntax\n * @param data iban string\n * @returns boolean\n */\nexport function validateIBAN(data: string): boolean {\n return IBAN.isValid(data)\n}\n\nexport const functionalValidators: FunctionalValidators = {\n iban: {\n name: 'iban',\n callback: validateIBAN,\n description:\n 'this validation function will validate the syntax of the provided iban'\n },\n birth_date: {\n name: 'birth_date',\n callback: validateBirthDate,\n description:\n 'this function will validate that the date is in the past'\n },\n future_date_14: {\n name: 'future_date_14',\n callback: validateFutureDate,\n description:\n 'this function will validate that the date is in the future with 14 days at least'\n }\n}\n\nexport const IBAN_Specifications = IBAN.countries","import regExpStatments from './reg_exps'\nimport { ErrorObject } from 'ajv'\nimport { parseDateDE } from './validators'\n\ntype SchemaValidateFunction = {\n (schema: any, data: any):\n | boolean\n | Promise<any>\n errors?: Partial<ErrorObject>[]\n}\n\ntype SchemaKeyword = {\n keyword: string\n callback: (schema: any, data: any) => boolean\n errorMessage: {\n [locale: string]: string\n }\n}\n\nexport const schemaKeywords: SchemaKeyword[] = [\n {\n keyword: 'email',\n callback: (schema: boolean, data: string) =>\n schema ? regExpStatments.email.regex.test(data) : false,\n errorMessage: {\n en: 'Please enter a valid email address.',\n de: 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'\n }\n },\n {\n keyword: 'onlyLetters',\n callback: (schema: boolean, data: string) =>\n schema ? /^[a-zA-Z]+$/.test(data) : false,\n errorMessage: {\n en: 'Only letters allowed.',\n de: 'Nur Buchstaben erlaubt.'\n }\n },\n {\n keyword: 'onlyNumbers',\n callback: (schema: boolean, data: string) =>\n schema ? /^[0-9]+$/.test(data) : false,\n errorMessage: {\n en: 'Only numbers allowed.',\n de: 'Nur Zahlen erlaubt.'\n }\n },\n {\n keyword: 'dateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? regExpStatments.date_de.regex.test(data)\n : false,\n errorMessage: {\n en: 'Date should have the format DD.MM.YYYY.',\n de: 'Das Datum sollte das Format TT.MM.JJJJ haben.'\n }\n },\n {\n keyword: 'minNumbersTelephone',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? new RegExp(`^[+]*[0-9]{${schema},}$`).test(data)\n : false,\n errorMessage: {\n en: 'Please enter a valid telephone number.',\n de: 'Bitte geben Sie eine gültige Telefonnummer ein.'\n }\n },\n {\n keyword: 'futureDateDE',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? parseDateDE(data).getTime() > new Date().getTime()+(schema*24*60*60*1000)\n : false,\n errorMessage: {\n en: 'The date must be at least {schema} days in the future.',\n de: 'Das Datum muss mind. {schema} Tage in der Zukunft liegen.'\n }\n },\n {\n keyword: 'birthdateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? parseDateDE(data).getTime() < new Date().getTime()\n : false,\n errorMessage: {\n en: 'Please enter a valid date of birth.',\n de: 'Bitte geben Sie ein gültiges Geburtsdatum ein.'\n }\n }\n]\n\nexport function validateSchemaKeyword(\n schemaKeyword: SchemaKeyword,\n locale?: string\n): SchemaValidateFunction {\n const { keyword, callback, errorMessage } = schemaKeyword\n\n const validate: SchemaValidateFunction = (schema: any, data: any) => {\n validate.errors = [\n {\n keyword,\n message: errorMessage\n ? errorMessage[locale || 'de'].replace('{schema}', schema)\n : locale === 'en'\n ? 'The entered format is invalid.'\n : 'Das eingegebene Format ist ungültig.',\n params: { keyword }\n }\n ]\n\n return callback(schema, data)\n }\n\n return validate\n}\n"],"names":["regExpStatments","email","name","regex","description","lettersMinimum_3","numbersMinimum_6","numbersTelephone_6","numbersExact_11","numbersMaximum_11","date_de","validateBirthDate","data","de_date","test","parseDateDE","getTime","Date","validateFutureDate","dateStr","dateArray","split","date","setFullYear","validateIBAN","IBAN","isValid","functionalValidators","iban","callback","birth_date","future_date_14","IBAN_Specifications","countries","schemaKeywords","keyword","schema","errorMessage","en","de","RegExp","validateSchemaKeyword","schemaKeyword","locale","validate","errors","message","replace","params"],"mappings":";;AAQA,IAAMA,eAAe,GAAmB;AACtCC,EAAAA,KAAK,EAAE;AACLC,IAAAA,IAAI,EAAE,OADD;AAELC,IAAAA,KAAK,EAAE,uJAFF;AAGLC,IAAAA,WAAW,EAAE;AAHR,GAD+B;AAOtCC,EAAAA,gBAAgB,EAAE;AAChBH,IAAAA,IAAI,EAAE,k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,QAAQ,CAACC,MAAT,GAAkB,CAChB;AACEV,MAAAA,OAAO,EAAPA,OADF;AAEEW,MAAAA,OAAO,EAAET,YAAY,GACjBA,YAAY,CAACM,MAAM,IAAI,IAAX,CAAZ,CAA6BI,OAA7B,CAAqC,UAArC,EAAiDX,MAAjD,CADiB,GAEjBO,MAAM,KAAK,IAAX,GACA,gCADA,GAEA,sCANN;AAOEK,MAAAA,MAAM,EAAE;AAAEb,QAAAA,OAAO,EAAPA;AAAF;AAPV,KADgB,CAAlB;AAYA,WAAON,QAAQ,CAACO,MAAD,EAASxB,IAAT,CAAf;AACD,GAdD;;AAgBA,SAAOgC,QAAP;AACD;;;;"} | ||
| {"version":3,"file":"validators.esm.js","sources":["../src/utils/reg_exps.ts","../src/utils/validators.ts","../src/utils/schema_keywords.ts"],"sourcesContent":["type RegExpStatment = {\n [key: string]: {\n name: string\n regex: RegExp\n description: string\n }\n}\n\nconst regExpStatments: RegExpStatment = {\n email: {\n name: 'email',\n regex: /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n description: 'this pattern is used to check if the email is valid'\n },\n\n lettersMinimum_3: {\n name: 'lettersMinimum_3',\n regex: /^[a-zA-Z]{3,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 3 letter'\n },\n\n numbersMinimum_6: {\n name: 'numbersMinimum_6',\n regex: /^[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers'\n },\n\n numbersTelephone_6: {\n name: 'numbersTelephone_6',\n regex: /^[+]*[0-9]{6,}$/,\n description:\n 'this pattern is used to validate that the input length is at least 6 numbers and it could start with + sign'\n },\n\n numbersExact_11: {\n name: 'numbersExact_11',\n regex: /^[0-9]{11,11}$/,\n description:\n 'this pattern is used to validate that the input length exactly 12 numbers'\n },\n\n numbersMaximum_11: {\n name: 'numbersMaximum_11',\n regex: /^[0-9]{1,11}$/,\n description:\n 'this pattern is used to validate that the input length is maximum 11 numbers'\n },\n\n date_de: {\n name: 'date_de',\n regex: /^[0-3][0-9][.][0-1][0-9][.][1|2][0-9]{3}$/,\n description:\n 'this pattern is used to validate that the input is valid german date DD.MM.YYYY'\n }\n}\n\nexport default regExpStatments\n","import regExpStatments from './reg_exps'\nimport IBAN from 'iban'\n\n/**\n * Validate date in german format is in the past\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateBirthDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format and the date in the past\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() < new Date().getTime()) {\n return true\n }\n }\n\n return false\n}\n\n\n/**\n * Validate date is 14 days in the future\n * @param data date as string DD.MM.YYY\n * @returns boolean\n */\nexport function validateFutureDate(data: string): boolean {\n const de_date = regExpStatments.date_de.regex\n // check if the data format matches the de format\n\n if (de_date.test(data)) {\n if (parseDateDE(data).getTime() > new Date().getTime()+(14*24*60*60*1000)) {\n return true\n }\n }\n\n return false\n}\n\nexport function parseDateDE(dateStr: string): Date {\n const dateArray = dateStr.split('.')\n const date = new Date()\n\n date.setFullYear(+dateArray[2], +dateArray[1] - 1, +dateArray[0])\n\n return date\n}\n\ntype FunctionalValidators = {\n [key: string]: {\n name: string\n callback: (data: string) => boolean\n description: string\n }\n}\n\n/**\n * Validate iban and validate its syntax\n * @param data iban string\n * @returns boolean\n */\nexport function validateIBAN(data: string): boolean {\n return IBAN.isValid(data)\n}\n\nexport const functionalValidators: FunctionalValidators = {\n iban: {\n name: 'iban',\n callback: validateIBAN,\n description:\n 'this validation function will validate the syntax of the provided iban'\n },\n birth_date: {\n name: 'birth_date',\n callback: validateBirthDate,\n description:\n 'this function will validate that the date is in the past'\n },\n future_date_14: {\n name: 'future_date_14',\n callback: validateFutureDate,\n description:\n 'this function will validate that the date is in the future with 14 days at least'\n }\n}\n\nexport const IBAN_Specifications = IBAN.countries","import regExpStatments from './reg_exps'\nimport { ErrorObject } from 'ajv'\nimport { parseDateDE } from './validators'\n\ntype SchemaValidateFunction = {\n (schema: any, data: any):\n | boolean\n | Promise<any>\n errors?: Partial<ErrorObject>[]\n}\n\ntype SchemaKeyword = {\n keyword: string\n callback: (schema: any, data: any) => boolean\n errorMessage: {\n [locale: string]: string\n }\n}\n\nexport const schemaKeywords: SchemaKeyword[] = [\n {\n keyword: 'email',\n callback: (schema: boolean, data: string) =>\n schema ? regExpStatments.email.regex.test(data) : false,\n errorMessage: {\n en: 'Please enter a valid email address.',\n de: 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'\n }\n },\n {\n keyword: 'onlyLetters',\n callback: (schema: boolean, data: string) =>\n schema ? /^[a-zA-Z]+$/.test(data) : false,\n errorMessage: {\n en: 'Only letters allowed.',\n de: 'Nur Buchstaben erlaubt.'\n }\n },\n {\n keyword: 'onlyNumbers',\n callback: (schema: boolean, data: string) =>\n schema ? /^[0-9]+$/.test(data) : false,\n errorMessage: {\n en: 'Only numbers allowed.',\n de: 'Nur Zahlen erlaubt.'\n }\n },\n {\n keyword: 'dateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? regExpStatments.date_de.regex.test(data)\n : false,\n errorMessage: {\n en: 'Date should have the format DD.MM.YYYY.',\n de: 'Das Datum sollte das Format TT.MM.JJJJ haben.'\n }\n },\n {\n keyword: 'minNumbersTelephone',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? new RegExp(`^[+]*[0-9]{${schema},}$`).test(data)\n : false,\n errorMessage: {\n en: 'Please enter a valid telephone number.',\n de: 'Bitte geben Sie eine gültige Telefonnummer ein.'\n }\n },\n {\n keyword: 'futureDateDE',\n callback: (schema: number, data: string) =>\n schema && typeof schema === 'number'\n ? parseDateDE(data).getTime() > new Date().getTime()+(schema*24*60*60*1000)\n : false,\n errorMessage: {\n en: 'The date must be at least {schema} days in the future.',\n de: 'Das Datum muss mind. {schema} Tage in der Zukunft liegen.'\n }\n },\n {\n keyword: 'rangeDateDE',\n callback: (schema: number[], data: string) => {\n return schema && Array.isArray(schema) && schema.length === 2\n ? parseDateDE(data).getTime() >= new Date().getTime()+(schema[0]*24*60*60*1000) && parseDateDE(data).getTime() <= new Date().getTime()+(schema[1]*24*60*60*1000)\n : false\n },\n errorMessage: {\n en: 'Date must be between {minDate} and {maxDate}.',\n de: 'Datum muss zwischen {minDate} und {maxDate} liegen.'\n }\n },\n {\n keyword: 'birthdateDE',\n callback: (schema: boolean, data: string) =>\n schema\n ? parseDateDE(data).getTime() < new Date().getTime()\n : false,\n errorMessage: {\n en: 'Please enter a valid date of birth.',\n de: 'Bitte geben Sie ein gültiges Geburtsdatum ein.'\n }\n }\n]\n\nfunction convertDate(date: Date, separator = '.') {\n function pad(s: number) { return (s < 10) ? '0' + s : s; }\n return [pad(date.getDate()), pad(date.getMonth()+1), date.getFullYear()].join(separator)\n}\n\nexport function validateSchemaKeyword(\n schemaKeyword: SchemaKeyword,\n locale?: string\n): SchemaValidateFunction {\n const { keyword, callback, errorMessage } = schemaKeyword\n\n const validate: SchemaValidateFunction = (schema: any, data: any) => {\n switch(keyword) {\n case 'rangeDateDE': {\n const [minDays, maxDays] = schema\n const minDate = new Date()\n minDate.setDate(minDate.getDate() + minDays)\n const maxDate = new Date()\n maxDate.setDate(maxDate.getDate() + maxDays)\n\n validate.errors = [\n {\n keyword,\n message: errorMessage[locale || 'de'].replace('{minDate}', convertDate(minDate)).replace('{maxDate}', convertDate(maxDate)),\n params: { keyword }\n }\n ]\n break\n }\n default:\n validate.errors = [\n {\n keyword,\n message: errorMessage\n ? errorMessage[locale || 'de'].replace('{schema}', schema)\n : locale === 'en'\n ? 'The entered format is invalid.'\n : 'Das eingegebene Format ist ungültig.',\n params: { keyword }\n }\n ]\n break\n }\n\n return callback(schema, data)\n }\n\n return validate\n}\n"],"names":["regExpStatments","email","name","regex","description","lettersMinimum_3","numbersMinimum_6","numbersTelephone_6","numbersExact_11","numbersMaximum_11","date_de","validateBirthDate","data","de_date","test","parseDateDE","getTime","Date","validateFutureDate","dateStr","dateArray","split","date","setFullYear","validateIBAN","IBAN","isValid","functionalValidators","iban","callback","birth_date","future_date_14","IBAN_Specifications","countries","schemaKeywords","keyword","schema","errorMessage","en","de","RegExp","Array","isArray","length","convertDate","separator","pad","s","getDate","getMonth","getFullYear","join","validateSchemaKeyword","schemaKeyword","locale","validate","minDays","maxDays","minDate","setDate","maxDate","errors","message","replace","params"],"mappings":";;AAQA,IAAMA,eAAe,GAAmB;AACtCC,EAAAA,KAAK,EAAE;AACLC,IAAAA,IAAI,EAAE,OADD;AAELC,IAAAA,KAAK,EAAE,uJAFF;AAGLC,IAAAA,WAAW,EAAE;AAHR,GAD+B;AAOtCC,EAAAA,gBAAgB,EAAE;AAChBH,IAAAA,IAAI,EAAE,kBADU;AAEhBC,IAAAA,KAAK,EAAE,gBAFS;AAGhBC,IAAAA,WAAW,EACT;AAJc,GAPoB;AActCE,EAAAA,gBAAgB,EAAE;AAChBJ,IAAAA,IAAI,EAAE,kBADU;AAEhBC,IAAAA,KAAK,EAAE,aAFS;AAGhBC,IAAAA,WAAW,EACT;AAJc,GAdoB;AAqBtCG,EAAAA,kBAAkB,EAAE;AAClBL,IAAAA,IAAI,EAAE,oBADY;AAElBC,IAAAA,KAAK,EAAE,iBAFW;AAGlBC,IAAAA,WAAW,EACT;AAJgB,GArBkB;AA4BtCI,EAAAA,eAAe,EAAE;AACfN,IAAAA,IAAI,EAAE,iBADS;AAEfC,IAAAA,KAAK,EAAE,gBAFQ;AAGfC,IAAAA,WAAW,EACT;AAJa,GA5BqB;AAmCtCK,EAAAA,iBAAiB,EAAE;AACjBP,IAAAA,IAAI,EAAE,mBADW;AAEjBC,IAAAA,KAAK,EAAE,eAFU;AAGjBC,IAAAA,WAAW,EACT;AAJe,GAnCmB;AA0CtCM,EAAAA,OAAO,EAAE;AACPR,I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OAAO,EAAEzB,YAAY,GACjBA,YAAY,CAACiB,MAAM,IAAI,IAAX,CAAZ,CAA6BS,OAA7B,CAAqC,UAArC,EAAiD3B,MAAjD,CADiB,GAEjBkB,MAAM,KAAK,IAAX,GACA,gCADA,GAEA,sCANN;AAOEU,UAAAA,MAAM,EAAE;AAAE7B,YAAAA,OAAO,EAAPA;AAAF;AAPV,SADgB,CAAlB;AAWA;AA7BJ;;AAgCA,WAAON,QAAQ,CAACO,MAAD,EAASxB,IAAT,CAAf;AACD,GAlCD;;AAoCA,SAAO2C,QAAP;AACD;;;;"} |
+1
-1
| { | ||
| "name": "@epilot/validators", | ||
| "version": "0.0.11", | ||
| "version": "0.0.13", | ||
| "author": { | ||
@@ -5,0 +5,0 @@ "name": "epilot GmbH", |
@@ -82,2 +82,14 @@ import regExpStatments from './reg_exps' | ||
| { | ||
| keyword: 'rangeDateDE', | ||
| callback: (schema: number[], data: string) => { | ||
| return schema && Array.isArray(schema) && schema.length === 2 | ||
| ? parseDateDE(data).getTime() >= new Date().getTime()+(schema[0]*24*60*60*1000) && parseDateDE(data).getTime() <= new Date().getTime()+(schema[1]*24*60*60*1000) | ||
| : false | ||
| }, | ||
| errorMessage: { | ||
| en: 'Date must be between {minDate} and {maxDate}.', | ||
| de: 'Datum muss zwischen {minDate} und {maxDate} liegen.' | ||
| } | ||
| }, | ||
| { | ||
| keyword: 'birthdateDE', | ||
@@ -95,2 +107,7 @@ callback: (schema: boolean, data: string) => | ||
| function convertDate(date: Date, separator = '.') { | ||
| function pad(s: number) { return (s < 10) ? '0' + s : s; } | ||
| return [pad(date.getDate()), pad(date.getMonth()+1), date.getFullYear()].join(separator) | ||
| } | ||
| export function validateSchemaKeyword( | ||
@@ -103,13 +120,33 @@ schemaKeyword: SchemaKeyword, | ||
| const validate: SchemaValidateFunction = (schema: any, data: any) => { | ||
| validate.errors = [ | ||
| { | ||
| keyword, | ||
| message: errorMessage | ||
| ? errorMessage[locale || 'de'].replace('{schema}', schema) | ||
| : locale === 'en' | ||
| ? 'The entered format is invalid.' | ||
| : 'Das eingegebene Format ist ungültig.', | ||
| params: { keyword } | ||
| switch(keyword) { | ||
| case 'rangeDateDE': { | ||
| const [minDays, maxDays] = schema | ||
| const minDate = new Date() | ||
| minDate.setDate(minDate.getDate() + minDays) | ||
| const maxDate = new Date() | ||
| maxDate.setDate(maxDate.getDate() + maxDays) | ||
| validate.errors = [ | ||
| { | ||
| keyword, | ||
| message: errorMessage[locale || 'de'].replace('{minDate}', convertDate(minDate)).replace('{maxDate}', convertDate(maxDate)), | ||
| params: { keyword } | ||
| } | ||
| ] | ||
| break | ||
| } | ||
| ] | ||
| default: | ||
| validate.errors = [ | ||
| { | ||
| keyword, | ||
| message: errorMessage | ||
| ? errorMessage[locale || 'de'].replace('{schema}', schema) | ||
| : locale === 'en' | ||
| ? 'The entered format is invalid.' | ||
| : 'Das eingegebene Format ist ungültig.', | ||
| params: { keyword } | ||
| } | ||
| ] | ||
| break | ||
| } | ||
@@ -116,0 +153,0 @@ return callback(schema, data) |
77906
21.29%806
16.81%