rename startsWith to hasPrefix
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -61,7 +61,7 @@ export type FilterPredicateValue =
|
||||
$contains: FilterPredicate;
|
||||
}
|
||||
| {
|
||||
$startsWith: string;
|
||||
$hasPrefix: string;
|
||||
}
|
||||
| UnknownFilterPredicateValueMatcher;
|
||||
|
||||
@@ -102,6 +102,6 @@ export type UnknownFilterPredicateOperator = {
|
||||
export type UnknownFilterPredicateValueMatcher = {
|
||||
[KMatcher in `$${string}`]: JsonValue;
|
||||
} & {
|
||||
[KMatcher in '$exists' | '$in' | '$contains' | '$startsWith']: never;
|
||||
[KMatcher in '$exists' | '$in' | '$contains' | '$hasPrefix']: never;
|
||||
};
|
||||
```
|
||||
|
||||
@@ -237,7 +237,7 @@ describe('evaluate', () => {
|
||||
'metadata.annotations.github.com/repo': { $exists: true },
|
||||
},
|
||||
],
|
||||
['a', { 'spec.type': { $startsWith: 'g' } }],
|
||||
['a', { 'spec.type': { $hasPrefix: 'g' } }],
|
||||
])('filter entry %#', (expected, filter) => {
|
||||
it('filterPredicateToFilterFunction', () => {
|
||||
const filtered = entities.filter(entity =>
|
||||
|
||||
@@ -104,13 +104,13 @@ function evaluateFilterPredicateValue(
|
||||
}
|
||||
return value === undefined;
|
||||
}
|
||||
if ('$startsWith' in filter) {
|
||||
if ('$hasPrefix' in filter) {
|
||||
if (typeof value !== 'string') {
|
||||
return false;
|
||||
}
|
||||
return value
|
||||
.toLocaleUpperCase('en-US')
|
||||
.startsWith(filter.$startsWith.toLocaleUpperCase('en-US'));
|
||||
.startsWith(filter.$hasPrefix.toLocaleUpperCase('en-US'));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -153,7 +153,7 @@ export type FilterPredicateExpression = {
|
||||
export type UnknownFilterPredicateValueMatcher = {
|
||||
[KMatcher in `$${string}`]: JsonValue;
|
||||
} & {
|
||||
[KMatcher in '$exists' | '$in' | '$contains' | '$startsWith']: never;
|
||||
[KMatcher in '$exists' | '$in' | '$contains' | '$hasPrefix']: never;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -188,7 +188,7 @@ export type FilterPredicateValue =
|
||||
/**
|
||||
* Asserts that the property value is string, and that it starts with the given string.
|
||||
*/
|
||||
$startsWith: string;
|
||||
$hasPrefix: string;
|
||||
}
|
||||
| UnknownFilterPredicateValueMatcher;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user