mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Bump to v3.0.0.
This commit is contained in:
44
lodash.trimright/index.js
Normal file
44
lodash.trimright/index.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* lodash 3.0.0 (Custom Build) <https://lodash.com/>
|
||||
* Build: `lodash modern modularize exports="npm" -o ./`
|
||||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
||||
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
|
||||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
* Available under MIT license <https://lodash.com/license>
|
||||
*/
|
||||
var baseToString = require('lodash._basetostring'),
|
||||
charsRightIndex = require('lodash._charsrightindex'),
|
||||
isIterateeCall = require('lodash._isiterateecall'),
|
||||
trimmedRightIndex = require('lodash._trimmedrightindex');
|
||||
|
||||
/**
|
||||
* Removes trailing whitespace or specified characters from `string`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category String
|
||||
* @param {string} [string=''] The string to trim.
|
||||
* @param {string} [chars=whitespace] The characters to trim.
|
||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
||||
* @returns {string} Returns the trimmed string.
|
||||
* @example
|
||||
*
|
||||
* _.trimRight(' abc ');
|
||||
* // => ' abc'
|
||||
*
|
||||
* _.trimRight('-_-abc-_-', '_-');
|
||||
* // => '-_-abc'
|
||||
*/
|
||||
function trimRight(string, chars, guard) {
|
||||
var value = string;
|
||||
string = baseToString(string);
|
||||
if (!string) {
|
||||
return string;
|
||||
}
|
||||
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
|
||||
return string.slice(0, trimmedRightIndex(string) + 1)
|
||||
}
|
||||
return string.slice(0, charsRightIndex(string, baseToString(chars)) + 1);
|
||||
}
|
||||
|
||||
module.exports = trimRight;
|
||||
Reference in New Issue
Block a user