joi: add support for array.unique(comparator) (#16200)

Add an optional extended description…
This commit is contained in:
Pasi Eronen
2017-04-28 20:56:46 +03:00
committed by Sheetal Nandi
parent cb42760188
commit 0aa77fc2b3
2 changed files with 4 additions and 1 deletions

View File

@@ -567,7 +567,8 @@ export interface ArraySchema extends AnySchema<ArraySchema> {
* Be aware that a deep equality is performed on elements of the array having a type of object,
* a performance penalty is to be expected for this kind of operation.
*/
unique(): ArraySchema;
unique(comparator?: (a: any, b: any) => boolean): ArraySchema;
unique(comparator?: string): ArraySchema;
}
export interface ObjectSchema extends AnySchema<ObjectSchema> {

View File

@@ -261,6 +261,8 @@ arrSchema = arrSchema.min(num);
arrSchema = arrSchema.max(num);
arrSchema = arrSchema.length(num);
arrSchema = arrSchema.unique();
arrSchema = arrSchema.unique((a, b) => a.test === b.test);
arrSchema = arrSchema.unique('customer.id');
arrSchema = arrSchema.items(numSchema);