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