58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
/**
|
|
* @file This method removes whitespace from the left end of a string.
|
|
* @version 3.0.0
|
|
* @author Xotic750 <Xotic750@gmail.com>
|
|
* @copyright Xotic750
|
|
* @license {@link <https://opensource.org/licenses/MIT> MIT}
|
|
* @module trim-left-x
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var requireCoercibleToString = require('require-coercible-to-string-x');
|
|
var Rx = require('cached-constructors-x').RegExp;
|
|
var reLeft2016 = new Rx('^[' + require('white-space-x').string2016 + ']+');
|
|
var reLeft2018 = new Rx('^[' + require('white-space-x').string2018 + ']+');
|
|
var replace = ''.replace;
|
|
|
|
var $trimLeft2016 = function trimLeft2016(string) {
|
|
return replace.call(requireCoercibleToString(string), reLeft2016, '');
|
|
};
|
|
|
|
var $trimLeft2018 = function trimLeft2018(string) {
|
|
return replace.call(requireCoercibleToString(string), reLeft2018, '');
|
|
};
|
|
|
|
module.exports = {
|
|
/**
|
|
* A reference to leftTrim2018.
|
|
*/
|
|
trimLeft: $trimLeft2018,
|
|
|
|
/**
|
|
* This method removes whitespace from the left end of a string. (ES2016)
|
|
*
|
|
* @param {string} string - The string to trim the left end whitespace from.
|
|
* @throws {TypeError} If string is null or undefined or not coercible.
|
|
* @returns {string} The left trimmed string.
|
|
* @example
|
|
* var trimLeft = require('trim-left-x').trimLeft2016;
|
|
*
|
|
* trimLeft(' \t\na \t\n') === 'a \t\n'; // true
|
|
*/
|
|
trimLeft2016: $trimLeft2016,
|
|
|
|
/**
|
|
* This method removes whitespace from the left end of a string. (ES2018)
|
|
*
|
|
* @param {string} string - The string to trim the left end whitespace from.
|
|
* @throws {TypeError} If string is null or undefined or not coercible.
|
|
* @returns {string} The left trimmed string.
|
|
* @example
|
|
* var trimLeft = require('trim-left-x').trimLeft2018;
|
|
*
|
|
* trimLeft(' \t\na \t\n') === 'a \t\n'; // true
|
|
*/
|
|
trimLeft2018: $trimLeft2018
|
|
};
|