@simplism/core
Advanced tools
Comparing version 10.3.62 to 10.3.63
@@ -16,20 +16,18 @@ import "./ArrayExt"; | ||
validate(value: any, def: ValidateDef): IValidateResult | undefined; | ||
validates(source: any, defs: ((item: any) => { | ||
[key: string]: IValidateDef; | ||
}), throwNotUse?: boolean): IValidateResult[]; | ||
validates(source: any, defs: { | ||
[key: string]: ValidateDef; | ||
}): IValidateResult[]; | ||
}, throwNotUse?: boolean): IValidateResult[]; | ||
validatesArray<T, K extends keyof T>(arr: T[], displayName: string, def: ((item: T) => { | ||
[P in K]: IArrayValidateDef; | ||
[P in K]: IValidateDef; | ||
})): void; | ||
validatesArray<T, K extends keyof T>(arr: T[], displayName: string, def: { | ||
[P in K]: IArrayValidateDef; | ||
[P in K]: IValidateDef; | ||
}): void; | ||
} | ||
} | ||
export interface IArrayValidateDef { | ||
displayName: string; | ||
type?: Type<any> | Type<any>[]; | ||
notnull?: boolean; | ||
validator?(value: any): boolean; | ||
} | ||
export interface IValidateDef { | ||
displayName?: string; | ||
type?: Type<any> | Type<any>[]; | ||
@@ -36,0 +34,0 @@ notnull?: boolean; |
{ | ||
"name": "@simplism/core", | ||
"version": "10.3.62", | ||
"version": "10.3.63", | ||
"description": "Simplism Core Package", | ||
@@ -5,0 +5,0 @@ "repository": "github:kslhunter/simplism", |
@@ -17,18 +17,14 @@ import "./ArrayExt"; | ||
validates(source: any, defs: { [key: string]: ValidateDef }): IValidateResult[]; | ||
validates(source: any, defs: ((item: any) => { [key: string]: IValidateDef }), throwNotUse?: boolean): IValidateResult[]; | ||
validatesArray<T, K extends keyof T>(arr: T[], displayName: string, def: ((item: T) => { [P in K]: IArrayValidateDef })): void; | ||
validatesArray<T, K extends keyof T>(arr: T[], displayName: string, def: { [P in K]: IArrayValidateDef }): void; | ||
} | ||
} | ||
validates(source: any, defs: { [key: string]: ValidateDef }, throwNotUse?: boolean): IValidateResult[]; | ||
export interface IArrayValidateDef { | ||
displayName: string; | ||
type?: Type<any> | Type<any>[]; | ||
notnull?: boolean; | ||
validatesArray<T, K extends keyof T>(arr: T[], displayName: string, def: ((item: T) => { [P in K]: IValidateDef })): void; | ||
validator?(value: any): boolean; | ||
validatesArray<T, K extends keyof T>(arr: T[], displayName: string, def: { [P in K]: IValidateDef }): void; | ||
} | ||
} | ||
export interface IValidateDef { | ||
displayName?: string; | ||
type?: Type<any> | Type<any>[]; | ||
@@ -181,6 +177,7 @@ notnull?: boolean; | ||
Object.validates = function (source: any, defs: { [propertyKey: string]: ValidateDef }): IValidateResult[] { | ||
Object.validates = function (source: any, defs: { [propertyKey: string]: ValidateDef } | ((item: any) => { [propertyKey: string]: ValidateDef }), throwNotUse?: boolean): IValidateResult[] { | ||
const result: IValidateResult[] = []; | ||
for (const propertyKey of Object.keys(defs)) { | ||
const validateResult = this.validate(source[propertyKey], defs[propertyKey]); | ||
const defsObj = typeof defs === "function" ? defs(source) : defs; | ||
for (const propertyKey of Object.keys(defsObj)) { | ||
const validateResult = this.validate(source[propertyKey], defsObj[propertyKey]); | ||
if (validateResult) { | ||
@@ -194,11 +191,17 @@ result.push({ | ||
if (result.length > 0 && !throwNotUse) { | ||
const propertyDisplayNames = result.map(item1 => defsObj[item1.propertyKey!]["displayName"]); | ||
throw new Error(`ė ë Ĩę°ė´ ėëĒģëėėĩëë¤.\r\n - ${propertyDisplayNames.join("', '")}'`); | ||
} | ||
return result; | ||
}; | ||
Object.validatesArray = function (arr: any[], displayName: string, def: { [propertyKey: string]: ValidateDef } | ((item: any) => { [propertyKey: string]: IArrayValidateDef })): void { | ||
Object.validatesArray = function (arr: any[], displayName: string, def: { [propertyKey: string]: ValidateDef } | ((item: any) => { [propertyKey: string]: ValidateDef })): void { | ||
const errorMessages = []; | ||
for (const item of arr) { | ||
const result = Object.validates(item, typeof def === "function" ? def(item) : def); | ||
const defObj = typeof def === "function" ? def(item) : def; | ||
const result = Object.validates(item, defObj, true); | ||
if (result.length > 0) { | ||
const propertyDisplayNames = result.map(item1 => def[item1.propertyKey!]["displayName"]); | ||
const propertyDisplayNames = result.map(item1 => defObj[item1.propertyKey!]["displayName"]); | ||
errorMessages.push(`- '${displayName}'ė ${arr.indexOf(item) + 1}ë˛ė§¸ íëĒŠė¤ '${propertyDisplayNames.join("', '")}'`); | ||
@@ -210,2 +213,2 @@ } | ||
} | ||
}; | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235416
3329