1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.filterFunctions = exports.isOf = exports.year = exports.second = exports.month = exports.minute = exports.hour = exports.day = exports.ceiling = exports.floor = exports.round = exports.concat = exports.trim = exports.toUpper = exports.toLower = exports.substring = exports.indexOf = exports.length = exports.startsWith = exports.endsWith = void 0;
|
4 | var filter_function_1 = require("./filter-function");
|
5 | /* String Functions */
|
6 | /**
|
7 | * Build a filter function to test whether a string ends with another. Evaluates to boolean.
|
8 | * @param str - The string to test. This can either be a string, a reference to a field or another filter function.
|
9 | * @param suffix - The suffix to test for. This can either be a string, a reference to a field or another filter function.
|
10 | *
|
11 | * @returns The newly created filter function
|
12 | */
|
13 | function endsWith(str, suffix) {
|
14 | return filter_function_1.filterFunction('endswith', 'boolean', str, suffix);
|
15 | }
|
16 | exports.endsWith = endsWith;
|
17 | /**
|
18 | * Build a filter function to test whether a string starts with another. Evaluates to boolean.
|
19 | * @param str - The string to test. This can either be a string, a reference to a field or another filter function.
|
20 | * @param prefix - The prefix to test for. This can either be a string, a reference to a field or another filter function.
|
21 | *
|
22 | * @returns The newly created filter function
|
23 | */
|
24 | function startsWith(str, prefix) {
|
25 | return filter_function_1.filterFunction('startswith', 'boolean', str, prefix);
|
26 | }
|
27 | exports.startsWith = startsWith;
|
28 | /**
|
29 | * Build a filter function to get the length of a string. Evaluates to int.
|
30 | * @param str - The string to compute the length for. This can either be a string, a reference to a field or another filter function.
|
31 | * @returns The newly created filter function
|
32 | */
|
33 | function length(str) {
|
34 | return filter_function_1.filterFunction('length', 'int', str);
|
35 | }
|
36 | exports.length = length;
|
37 | /**
|
38 | * Build a filter function to get the start index of a substring. Evaluates to int.
|
39 | * @param str - The string to get the index from. This can either be a string, a reference to a field or another filter function.
|
40 | * @param substr - The substring to get the index for. This can either be a string, a reference to a field or another filter function.
|
41 | *
|
42 | * @returns The newly created filter function
|
43 | */
|
44 | function indexOf(str, substr) {
|
45 | return filter_function_1.filterFunction('indexof', 'int', str, substr);
|
46 | }
|
47 | exports.indexOf = indexOf;
|
48 | /**
|
49 | * Build a filter function to get a substring starting from a designated position. Evaluates to string.
|
50 | * @param str - The string to get a substring from. This can either be a string, a reference to a field or another filter function.
|
51 | * @param pos - The starting position of the substring. This can be either a number, a reference to a field or another filter function.
|
52 | * @param len - The length of the substring. This can be either a number, a reference to a field or another filter function.
|
53 | * @returns The newly created filter function
|
54 | */
|
55 | function substring(str, pos, len) {
|
56 | return typeof len === 'undefined'
|
57 | ? filter_function_1.filterFunction('substring', 'string', str, pos)
|
58 | : filter_function_1.filterFunction('substring', 'string', str, pos, len);
|
59 | }
|
60 | exports.substring = substring;
|
61 | /**
|
62 | * Build a filter function to transform a string to lower case. Evaluates to string.
|
63 | * @param str - The string to transform. This can either be a string, a reference to a field or another filter function.
|
64 | * @returns The newly created filter function
|
65 | */
|
66 | function toLower(str) {
|
67 | return filter_function_1.filterFunction('tolower', 'string', str);
|
68 | }
|
69 | exports.toLower = toLower;
|
70 | /**
|
71 | * Build a filter function to transform a string to upper case. Evaluates to string.
|
72 | * @param str - The string to transform. This can either be a string, a reference to a field or another filter function.
|
73 | * @returns The newly created filter function
|
74 | */
|
75 | function toUpper(str) {
|
76 | return filter_function_1.filterFunction('toupper', 'string', str);
|
77 | }
|
78 | exports.toUpper = toUpper;
|
79 | /**
|
80 | * Build a filter function to trim whitespace from a string. Evaluates to string.
|
81 | * @param str - The string to trim whitespace from. This can either be a string, a reference to a field or another filter function.
|
82 | * @returns The newly created filter function
|
83 | */
|
84 | function trim(str) {
|
85 | return filter_function_1.filterFunction('trim', 'string', str);
|
86 | }
|
87 | exports.trim = trim;
|
88 | /**
|
89 | * Build a filter function to concatenate two strings. Evaluates to string.
|
90 | * @param str1 - The first string to concatenate. This can either be a string, a reference to a field or another filter function.
|
91 | * @param str2 - The second string to concatenate. This can either be a string, a reference to a field or another filter function.
|
92 | * @returns The newly created filter function
|
93 | */
|
94 | function concat(str1, str2) {
|
95 | return filter_function_1.filterFunction('concat', 'string', str1, str2);
|
96 | }
|
97 | exports.concat = concat;
|
98 | /* Math Functions */
|
99 | /**
|
100 | * Build a filter function to round a number. Evaluates to double or decimal, defaults to double.
|
101 | * @param num - The number to round. This can either be a number, a reference to a field or another filter function.
|
102 | * @param returnType - The return type to use.
|
103 | * @returns The newly created filter function
|
104 | */
|
105 | function round(num, returnType) {
|
106 | if (returnType === void 0) { returnType = 'double'; }
|
107 | return filter_function_1.filterFunction('round', returnType, num);
|
108 | }
|
109 | exports.round = round;
|
110 | /**
|
111 | * Build a filter function to floor a number. Evaluates to double or decimal, defaults to double.
|
112 | * @param num - The number to floor. This can either be a number, a reference to a field or another filter function.
|
113 | * @param returnType - The return type to use.
|
114 | * @returns The newly created filter function
|
115 | */
|
116 | function floor(num, returnType) {
|
117 | if (returnType === void 0) { returnType = 'double'; }
|
118 | return filter_function_1.filterFunction('floor', returnType, num);
|
119 | }
|
120 | exports.floor = floor;
|
121 | /**
|
122 | * Build a filter function to ceil a number. Evaluates to double or decimal, defaults to double.
|
123 | * @param num - The number to ceil. This can either be a number, a reference to a field or another filter function.
|
124 | * @param returnType - The return type to use.
|
125 | * @returns The newly created filter function
|
126 | */
|
127 | function ceiling(num, returnType) {
|
128 | if (returnType === void 0) { returnType = 'double'; }
|
129 | return filter_function_1.filterFunction('ceiling', returnType, num);
|
130 | }
|
131 | exports.ceiling = ceiling;
|
132 | /* Date Functions */
|
133 | /**
|
134 | * Build a filter function to get the day of a date. Evaluates to int.
|
135 | * @param date - The date to get the day for. This can either be a date (Moment) or a reference to a field.
|
136 | * @returns The newly created filter function
|
137 | */
|
138 | function day(date) {
|
139 | return filter_function_1.filterFunction('day', 'int', date);
|
140 | }
|
141 | exports.day = day;
|
142 | /**
|
143 | * Build a filter function to get the hour of a date. Evaluates to int.
|
144 | * @param date - The date to get the hour for. This can either be a date (Moment) or a reference to a field.
|
145 | * @returns The newly created filter function
|
146 | */
|
147 | function hour(date) {
|
148 | return filter_function_1.filterFunction('hour', 'int', date);
|
149 | }
|
150 | exports.hour = hour;
|
151 | /**
|
152 | * Build a filter function to get the minute of a date. Evaluates to int.
|
153 | * @param date - The date to get the minute for. This can either be a date (Moment) or a reference to a field.
|
154 | * @returns The newly created filter function
|
155 | */
|
156 | function minute(date) {
|
157 | return filter_function_1.filterFunction('minute', 'int', date);
|
158 | }
|
159 | exports.minute = minute;
|
160 | /**
|
161 | * Build a filter function to get the month of a date. Evaluates to int.
|
162 | * @param date - The date to get the month for. This can either be a date (Moment) or a reference to a field.
|
163 | * @returns The newly created filter function
|
164 | */
|
165 | function month(date) {
|
166 | return filter_function_1.filterFunction('month', 'int', date);
|
167 | }
|
168 | exports.month = month;
|
169 | /**
|
170 | * Build a filter function to get the second of a date. Evaluates to int.
|
171 | * @param date - The date to get the second for. This can either be a date (moment.Moment) or a reference to a field.
|
172 | * @returns The newly created filter function
|
173 | */
|
174 | function second(date) {
|
175 | return filter_function_1.filterFunction('second', 'int', date);
|
176 | }
|
177 | exports.second = second;
|
178 | /**
|
179 | * Build a filter function to get the year of a date. Evaluates to int.
|
180 | * @param date - The date to get the year for. This can either be a date (Moment) or a reference to a field.
|
181 | * @returns The newly created filter function
|
182 | */
|
183 | function year(date) {
|
184 | return filter_function_1.filterFunction('year', 'int', date);
|
185 | }
|
186 | exports.year = year;
|
187 | function isOf(expressionOrType, type) {
|
188 | return type
|
189 | ? filter_function_1.filterFunction('isof', 'boolean', expressionOrType, type)
|
190 | : filter_function_1.filterFunction('isof', 'boolean', expressionOrType);
|
191 | }
|
192 | exports.isOf = isOf;
|
193 | /**
|
194 | * Filter functions common to both OData v2 and OData v4. See below for version specific filter functions.
|
195 | * Filter functions are used to create more complex filtering expressions, e. g. when filtering by the first letter of a property:
|
196 | * ```
|
197 | * .filter(startsWith(BusinessPartner.FIRST_NAME, 'A').equals(true))
|
198 | * ```
|
199 | */
|
200 | exports.filterFunctions = {
|
201 | endsWith: endsWith,
|
202 | startsWith: startsWith,
|
203 | length: length,
|
204 | indexOf: indexOf,
|
205 | substring: substring,
|
206 | toLower: toLower,
|
207 | toUpper: toUpper,
|
208 | trim: trim,
|
209 | concat: concat,
|
210 | round: round,
|
211 | floor: floor,
|
212 | ceiling: ceiling,
|
213 | day: day,
|
214 | hour: hour,
|
215 | minute: minute,
|
216 | month: month,
|
217 | second: second,
|
218 | year: year,
|
219 | isOf: isOf
|
220 | };
|
221 | //# sourceMappingURL=filter-functions.js.map |
\ | No newline at end of file |