-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrAfter.ts
35 lines (29 loc) · 1 KB
/
strAfter.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
import strPortion from './strPortion.js';
/**
* Return the remainder of a string after the first occurrence of a given value.
* The entire string will be returned if the value does not exist within the string.
*
* @param {string} subject - The string being searched on, otherwise known as the haystack
* @param {string} search - The value being searched for, otherwise known as the needle
* @returns {string}
*
* @example
* ```js
* strAfter('This is the way', 'This is'); // ' the way'
* strAfter('This is the way', 'nope'); // 'This is the way'
* ```
*/
export default function strAfter(subject: string, search: string): string {
return strPortion(subject, search, false, true);
}
// Alternative way !
// export default function strAfter(subject: string, search: string): string {
// if (search === '') {
// return subject;
// }
// const parts = subject.split(search);
// if (parts.length < 2) {
// return subject;
// }
// return parts.splice(1).join(search);
// }