/** * @file This method removes whitespace from the right end of a string. * @version 3.0.0 * @author Xotic750 * @copyright Xotic750 * @license {@link MIT} * @module trim-right-x */ 'use strict'; var requireCoercibleToString = require('require-coercible-to-string-x'); var Rx = require('cached-constructors-x').RegExp; var reRight2016 = new Rx('[' + require('white-space-x').string2016 + ']+$'); var reRight2018 = new Rx('[' + require('white-space-x').string2018 + ']+$'); var replace = ''.replace; var $trimRight2016 = function trimRight2016(string) { return replace.call(requireCoercibleToString(string), reRight2016, ''); }; var $trimRight2018 = function trimRight2018(string) { return replace.call(requireCoercibleToString(string), reRight2018, ''); }; module.exports = { /** * A reference to trimRight2018. */ trimRight: $trimRight2018, /** * This method removes whitespace from the right end of a string. (ES2016) * * @param {string} string - The string to trim the right end whitespace from. * @throws {TypeError} If string is null or undefined or not coercible. * @returns {string} The right trimmed string. * @example * var trimRight = require('trim-right-x'); * * trimRight(' \t\na \t\n') === ' \t\na'; // true */ trimRight2016: $trimRight2016, /** * This method removes whitespace from the right end of a string. (ES2018) * * @param {string} string - The string to trim the right end whitespace from. * @throws {TypeError} If string is null or undefined or not coercible. * @returns {string} The right trimmed string. * @example * var trimRight = require('trim-right-x'); * * trimRight(' \t\na \t\n') === ' \t\na'; // true */ trimRight2018: $trimRight2018 };