|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
683 bytes
|
| Line | |
|---|
| 1 | function trimEnd(str, chars) {
|
|---|
| 2 | if (chars === undefined) {
|
|---|
| 3 | return str.trimEnd();
|
|---|
| 4 | }
|
|---|
| 5 | let endIndex = str.length;
|
|---|
| 6 | switch (typeof chars) {
|
|---|
| 7 | case 'string': {
|
|---|
| 8 | if (chars.length !== 1) {
|
|---|
| 9 | throw new Error(`The 'chars' parameter should be a single character string.`);
|
|---|
| 10 | }
|
|---|
| 11 | while (endIndex > 0 && str[endIndex - 1] === chars) {
|
|---|
| 12 | endIndex--;
|
|---|
| 13 | }
|
|---|
| 14 | break;
|
|---|
| 15 | }
|
|---|
| 16 | case 'object': {
|
|---|
| 17 | while (endIndex > 0 && chars.includes(str[endIndex - 1])) {
|
|---|
| 18 | endIndex--;
|
|---|
| 19 | }
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | return str.substring(0, endIndex);
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | export { trimEnd };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.