UNPKG

@modern-kit/utils

Version:
19 lines (16 loc) 543 B
import { flatMap } from '../../array/flatMap/index.mjs'; import { isNil } from '../../validator/isNil/index.mjs'; import '../../array/flatten/index.mjs'; function trimEnd(str, chars) { if (isNil(chars)) { return str.trimEnd(); } const charsToUse = Array.isArray(chars) ? flatMap(chars, (char) => char.split("")) : chars; let endIndex = str.length; while (endIndex > 0 && charsToUse.includes(str[endIndex - 1])) { endIndex--; } return str.substring(0, endIndex); } export { trimEnd }; //# sourceMappingURL=index.mjs.map