-
Notifications
You must be signed in to change notification settings - Fork 41
/
filter-functions.ts
58 lines (52 loc) · 2.37 KB
/
filter-functions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. */
import { Field, StringFilterFunction, BooleanFilterFunction } from '../common';
import { filterFunction } from '../common/filter/filter-function';
import { filterFunctions as filterFunctionsCommon } from '../common/filter/filter-functions';
import { Entity } from './entity';
/* String Functions */
/**
* Build a filter function to test whether a string is a substring of the other. Evaluates to boolean.
* @param substr - The substring to test for. This can either be a string, a reference to a field or another filter function.
* @param str - The string to test. This can either be a string, a reference to a field or another filter function.
*
* @returns The newly created filter function
*/
export function substringOf<EntityT extends Entity>(
substr: string | Field<EntityT> | StringFilterFunction<EntityT>,
str: string | Field<EntityT> | StringFilterFunction<EntityT>
): BooleanFilterFunction<EntityT> {
return filterFunction('substringof', 'boolean', substr, str);
}
/**
* Build a filter function to replace the occurence of a search string with another string. Evaluates to string.
* @param str - The string to get the index from. This can either be a string, a reference to a field or another filter function.
* @param searchStr - The substring to get the index for. This can either be a string, a reference to a field or another filter function.
* @param replaceStr - The substring to get the index for. This can either be a string, a reference to a field or another filter function.
*
* @returns The newly created filter function
*/
export function replace<EntityT extends Entity>(
str: string | Field<EntityT> | StringFilterFunction<EntityT>,
searchStr: string | Field<EntityT> | StringFilterFunction<EntityT>,
replaceStr: string | Field<EntityT> | StringFilterFunction<EntityT>
): StringFilterFunction<EntityT> {
return filterFunction('replace', 'string', str, searchStr, replaceStr);
}
/**
* @hidden
* Export length filter function for backwards compatibility.
*/
export const length = filterFunctionsCommon.length;
/**
* @hidden
* Export substring filter function for backwards compatibility.
*/
export const substring = filterFunctionsCommon.substring;
/**
* OData v2 specific filter functions
*/
export const filterFunctions = {
...filterFunctionsCommon,
substringOf,
replace
};