@allgemein/schema-api 1.5.3 → 1.5.4
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.
|
@@ -17,6 +17,9 @@ function Regex(regex, options) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
if (options) {
|
|
20
|
+
if (!opts.validateOptions) {
|
|
21
|
+
opts.validateOptions = { regex: {} };
|
|
22
|
+
}
|
|
20
23
|
(0, lodash_1.assign)(opts.validateOptions.regex, options);
|
|
21
24
|
}
|
|
22
25
|
AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/decorators/validate/Regex.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/decorators/validate/Regex.ts"],"names":[],"mappings":";;;AAAA,mCAAiD;AAEjD,mEAA8D;AAC9D,4EAAuE;AASvE,SAAgB,KAAK,CAAC,KAAsB,EAAE,OAAuB;IACnE,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,MAAM,IAAI,GAAQ;YAChB,OAAO,EAAE,IAAA,iBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;SAChD,CAAC;QACF,IAAI,CAAC,IAAA,iBAAQ,EAAC,KAAK,CAAC,IAAI,CAAC,IAAA,gBAAO,EAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC7C,IAAI,CAAC,eAAe,GAAG;gBACrB,KAAK,EAAE;oBACL,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB;aACF,CAAC;SACH;QACD,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;gBACzB,IAAI,CAAC,eAAe,GAAG,EAAC,KAAK,EAAE,EAAE,EAAC,CAAC;aACpC;YACD,IAAA,eAAM,EAAC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SAC7C;QAED,qCAAiB,CAAC,aAAa,CAC7B,MAAM,CAAC,WAAW,EAClB,YAAY,EACZ,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA1BD,sBA0BC;AAED,mCAAgB,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO;IACb,EAAE,EAAE,CAAC,KAAa,EAAE,OAAsB,EAAE,QAAc,EAAE,EAAE;QAC5D,6CAA6C;QAC7C,iBAAiB;QACjB,IAAI;QACJ,IAAI,IAAA,iBAAQ,EAAC,KAAK,CAAC,EAAE;YACnB,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACrD,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBACjB,OAAO,IAAI,CAAC;aACb;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc,EAAE;QACd,OAAO,EAAE,6FAA6F;KACvG;IACD,kBAAkB,EAAE,SAAS;CAC9B,CACF,CAAC","file":"Regex.js","sourcesContent":["import {assign, isEmpty, isString} from 'lodash';\n\nimport {AnnotationsHelper} from '../../lib/AnnotationsHelper';\nimport {DefaultValidator} from '../../lib/validation/DefaultValidator';\nimport {IValidateOptions} from '../../lib/validation/IValidateOptions';\n\nexport interface IRegexOptions extends IValidateOptions {\n pattern?: string;\n message?: string;\n flags?: string;\n}\n\nexport function Regex(regex: string | RegExp, options?: IRegexOptions) {\n return function (source: any, propertyName: string) {\n const opts: any = {\n pattern: isString(regex) ? regex : regex.source,\n };\n if (!isString(regex) && !isEmpty(regex.flags)) {\n opts.validateOptions = {\n regex: {\n flags: regex.flags,\n }\n };\n }\n if (options) {\n if (!opts.validateOptions) {\n opts.validateOptions = {regex: {}};\n }\n assign(opts.validateOptions.regex, options);\n }\n\n AnnotationsHelper.forPropertyOn(\n source.constructor,\n propertyName,\n opts,\n 'merge'\n );\n };\n}\n\nDefaultValidator.define({\n name: 'regex',\n fn: (value: string, options: IRegexOptions, instance?: any) => {\n // if (isUndefined(value) || isNull(value)) {\n // return true;\n // }\n if (isString(value)) {\n const r = new RegExp(options.pattern, options.flags);\n if (r.test(value)) {\n return true;\n }\n }\n return false;\n },\n defaultOptions: {\n message: 'Value of property \"%propertyName\" doesn\\'t match the regular expression \"%options.pattern\".'\n },\n involveOnOptionKey: 'pattern'\n }\n);\n"],"sourceRoot":"../.."}
|