-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ends-with.ts
47 lines (45 loc) · 1.82 KB
/
ends-with.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
/**
* @packageDocumentation
* @module string
*/
import { Observable, OperatorFunction } from 'rxjs';
import { map } from 'rxjs/operators';
/**
* The `endsWith` operator can be used with an [Observable](https://rxjs-dev.firebaseapp.com/guide/observable) string
* value and returns a boolean value if the string of length ends with the passed character using
* [String.prototype.endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
*
* * If you need to get the string value instead of value use [[filterEndsWith]]
*
* @param character The character to check the string ends with
*
* @example
* ```ts
* fromString(['test', 'testing'])
* .pipe(endsWith('g'))
* .subscribe(console.log) // [false, true]
* ```
*
* @returns Boolean that passes the equality check of [String.prototype.endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
* @category RxJS String Query
*/
function endsWith(character: string): OperatorFunction<string, boolean>;
/**
* @param character The character to check the string ends with
* @param length Optional length of the string to check
*
* @example
* ```ts
* fromString(['test', 'testing'])
* .pipe(endsWith('t', 4))
* .subscribe(console.log) // [true, true]
* ```
*
* @returns Boolean that passes the equality check of [String.prototype.endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
* @category RxJS String Query
*/
function endsWith(character: string, length: number): OperatorFunction<string, boolean>;
function endsWith(character: string, length?: number): OperatorFunction<string, boolean> {
return (source: Observable<string>) => source.pipe(map((value) => value.endsWith(character, length)));
}
export { endsWith };