unverified $regex implmentation

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-10-01 12:44:57 +02:00
parent be4e3a8cb5
commit d41af86109
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0

View File

@ -43,6 +43,18 @@ const predicates: Record<string, PredicateFactory> = {
} }
return result return result
} }
},
$regex: (o: { $regex: string, $options: string }, propertyKey: string): Predicate => {
const re = new RegExp(o.$regex, o.$options)
return (docs: Doc[]): Doc[] => {
const result: Doc[] = []
for (const doc of docs) {
const value = (doc as any)[propertyKey] as string
if (value.match(re) !== null) result.push(doc)
}
return result
}
} }
} }