@newdash/newdash
Version:
javascript/typescript utility library
44 lines (43 loc) • 1.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.trimEnd = void 0;
const baseToString_1 = __importDefault(require("./.internal/baseToString"));
const castSlice_1 = __importDefault(require("./.internal/castSlice"));
const charsEndIndex_1 = __importDefault(require("./.internal/charsEndIndex"));
const stringToArray_1 = __importDefault(require("./.internal/stringToArray"));
const toString_1 = __importDefault(require("./toString"));
/**
* Removes trailing whitespace or specified characters from `string`.
*
* @since 5.6.0
* @category String
* @param str The string to trim.
* @param chars The characters to trim.
* @returns Returns the trimmed string.
* @see [[trim]],[[trimStart]]
* @example
*
* ```js
* trimEnd(' abc ')
* // => ' abc'
*
* trimEnd('-_-abc-_-', '_-')
* // => '-_-abc'
* ```
*/
function trimEnd(str, chars, guard) {
const string = (0, toString_1.default)(str);
if (string && (guard || chars === undefined)) {
return string.trimEnd();
}
if (!string || !(chars = (0, baseToString_1.default)(chars))) {
return string;
}
const strSymbols = (0, stringToArray_1.default)(string), end = (0, charsEndIndex_1.default)(strSymbols, (0, stringToArray_1.default)(chars)) + 1;
return (0, castSlice_1.default)(strSymbols, 0, end).join("");
}
exports.trimEnd = trimEnd;
exports.default = trimEnd;