You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
304 lines
8.1 KiB
304 lines
8.1 KiB
1 year ago
|
/**
|
||
|
* lodash (Custom Build) <https://lodash.com/>
|
||
|
* Build: `lodash modularize exports="npm" -o ./`
|
||
|
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
||
|
* Released under MIT license <https://lodash.com/license>
|
||
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
||
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||
|
*/
|
||
|
|
||
|
/** Used as references for various `Number` constants. */
|
||
|
var INFINITY = 1 / 0;
|
||
|
|
||
|
/** `Object#toString` result references. */
|
||
|
var symbolTag = '[object Symbol]';
|
||
|
|
||
|
/** Used to compose unicode character classes. */
|
||
|
var rsAstralRange = '\\ud800-\\udfff',
|
||
|
rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
|
||
|
rsComboSymbolsRange = '\\u20d0-\\u20f0',
|
||
|
rsVarRange = '\\ufe0e\\ufe0f';
|
||
|
|
||
|
/** Used to compose unicode capture groups. */
|
||
|
var rsAstral = '[' + rsAstralRange + ']',
|
||
|
rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
|
||
|
rsFitz = '\\ud83c[\\udffb-\\udfff]',
|
||
|
rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
|
||
|
rsNonAstral = '[^' + rsAstralRange + ']',
|
||
|
rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
|
||
|
rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
|
||
|
rsZWJ = '\\u200d';
|
||
|
|
||
|
/** Used to compose unicode regexes. */
|
||
|
var reOptMod = rsModifier + '?',
|
||
|
rsOptVar = '[' + rsVarRange + ']?',
|
||
|
rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
|
||
|
rsSeq = rsOptVar + reOptMod + rsOptJoin,
|
||
|
rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
|
||
|
|
||
|
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
|
||
|
var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
|
||
|
|
||
|
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
|
||
|
var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
|
||
|
|
||
|
/** Detect free variable `global` from Node.js. */
|
||
|
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
||
|
|
||
|
/** Detect free variable `self`. */
|
||
|
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
||
|
|
||
|
/** Used as a reference to the global object. */
|
||
|
var root = freeGlobal || freeSelf || Function('return this')();
|
||
|
|
||
|
/**
|
||
|
* Converts an ASCII `string` to an array.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} string The string to convert.
|
||
|
* @returns {Array} Returns the converted array.
|
||
|
*/
|
||
|
function asciiToArray(string) {
|
||
|
return string.split('');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Checks if `string` contains Unicode symbols.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} string The string to inspect.
|
||
|
* @returns {boolean} Returns `true` if a symbol is found, else `false`.
|
||
|
*/
|
||
|
function hasUnicode(string) {
|
||
|
return reHasUnicode.test(string);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Converts `string` to an array.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} string The string to convert.
|
||
|
* @returns {Array} Returns the converted array.
|
||
|
*/
|
||
|
function stringToArray(string) {
|
||
|
return hasUnicode(string)
|
||
|
? unicodeToArray(string)
|
||
|
: asciiToArray(string);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Converts a Unicode `string` to an array.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} string The string to convert.
|
||
|
* @returns {Array} Returns the converted array.
|
||
|
*/
|
||
|
function unicodeToArray(string) {
|
||
|
return string.match(reUnicode) || [];
|
||
|
}
|
||
|
|
||
|
/** Used for built-in method references. */
|
||
|
var objectProto = Object.prototype;
|
||
|
|
||
|
/**
|
||
|
* Used to resolve the
|
||
|
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
||
|
* of values.
|
||
|
*/
|
||
|
var objectToString = objectProto.toString;
|
||
|
|
||
|
/** Built-in value references. */
|
||
|
var Symbol = root.Symbol;
|
||
|
|
||
|
/** Used to convert symbols to primitives and strings. */
|
||
|
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
||
|
symbolToString = symbolProto ? symbolProto.toString : undefined;
|
||
|
|
||
|
/**
|
||
|
* The base implementation of `_.slice` without an iteratee call guard.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {Array} array The array to slice.
|
||
|
* @param {number} [start=0] The start position.
|
||
|
* @param {number} [end=array.length] The end position.
|
||
|
* @returns {Array} Returns the slice of `array`.
|
||
|
*/
|
||
|
function baseSlice(array, start, end) {
|
||
|
var index = -1,
|
||
|
length = array.length;
|
||
|
|
||
|
if (start < 0) {
|
||
|
start = -start > length ? 0 : (length + start);
|
||
|
}
|
||
|
end = end > length ? length : end;
|
||
|
if (end < 0) {
|
||
|
end += length;
|
||
|
}
|
||
|
length = start > end ? 0 : ((end - start) >>> 0);
|
||
|
start >>>= 0;
|
||
|
|
||
|
var result = Array(length);
|
||
|
while (++index < length) {
|
||
|
result[index] = array[index + start];
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* The base implementation of `_.toString` which doesn't convert nullish
|
||
|
* values to empty strings.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {*} value The value to process.
|
||
|
* @returns {string} Returns the string.
|
||
|
*/
|
||
|
function baseToString(value) {
|
||
|
// Exit early for strings to avoid a performance hit in some environments.
|
||
|
if (typeof value == 'string') {
|
||
|
return value;
|
||
|
}
|
||
|
if (isSymbol(value)) {
|
||
|
return symbolToString ? symbolToString.call(value) : '';
|
||
|
}
|
||
|
var result = (value + '');
|
||
|
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Casts `array` to a slice if it's needed.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {Array} array The array to inspect.
|
||
|
* @param {number} start The start position.
|
||
|
* @param {number} [end=array.length] The end position.
|
||
|
* @returns {Array} Returns the cast slice.
|
||
|
*/
|
||
|
function castSlice(array, start, end) {
|
||
|
var length = array.length;
|
||
|
end = end === undefined ? length : end;
|
||
|
return (!start && end >= length) ? array : baseSlice(array, start, end);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates a function like `_.lowerFirst`.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} methodName The name of the `String` case method to use.
|
||
|
* @returns {Function} Returns the new case function.
|
||
|
*/
|
||
|
function createCaseFirst(methodName) {
|
||
|
return function(string) {
|
||
|
string = toString(string);
|
||
|
|
||
|
var strSymbols = hasUnicode(string)
|
||
|
? stringToArray(string)
|
||
|
: undefined;
|
||
|
|
||
|
var chr = strSymbols
|
||
|
? strSymbols[0]
|
||
|
: string.charAt(0);
|
||
|
|
||
|
var trailing = strSymbols
|
||
|
? castSlice(strSymbols, 1).join('')
|
||
|
: string.slice(1);
|
||
|
|
||
|
return chr[methodName]() + trailing;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
||
|
* and has a `typeof` result of "object".
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 4.0.0
|
||
|
* @category Lang
|
||
|
* @param {*} value The value to check.
|
||
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
||
|
* @example
|
||
|
*
|
||
|
* _.isObjectLike({});
|
||
|
* // => true
|
||
|
*
|
||
|
* _.isObjectLike([1, 2, 3]);
|
||
|
* // => true
|
||
|
*
|
||
|
* _.isObjectLike(_.noop);
|
||
|
* // => false
|
||
|
*
|
||
|
* _.isObjectLike(null);
|
||
|
* // => false
|
||
|
*/
|
||
|
function isObjectLike(value) {
|
||
|
return !!value && typeof value == 'object';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Checks if `value` is classified as a `Symbol` primitive or object.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 4.0.0
|
||
|
* @category Lang
|
||
|
* @param {*} value The value to check.
|
||
|
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
||
|
* @example
|
||
|
*
|
||
|
* _.isSymbol(Symbol.iterator);
|
||
|
* // => true
|
||
|
*
|
||
|
* _.isSymbol('abc');
|
||
|
* // => false
|
||
|
*/
|
||
|
function isSymbol(value) {
|
||
|
return typeof value == 'symbol' ||
|
||
|
(isObjectLike(value) && objectToString.call(value) == symbolTag);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Converts `value` to a string. An empty string is returned for `null`
|
||
|
* and `undefined` values. The sign of `-0` is preserved.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 4.0.0
|
||
|
* @category Lang
|
||
|
* @param {*} value The value to process.
|
||
|
* @returns {string} Returns the string.
|
||
|
* @example
|
||
|
*
|
||
|
* _.toString(null);
|
||
|
* // => ''
|
||
|
*
|
||
|
* _.toString(-0);
|
||
|
* // => '-0'
|
||
|
*
|
||
|
* _.toString([1, 2, 3]);
|
||
|
* // => '1,2,3'
|
||
|
*/
|
||
|
function toString(value) {
|
||
|
return value == null ? '' : baseToString(value);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Converts the first character of `string` to upper case.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 4.0.0
|
||
|
* @category String
|
||
|
* @param {string} [string=''] The string to convert.
|
||
|
* @returns {string} Returns the converted string.
|
||
|
* @example
|
||
|
*
|
||
|
* _.upperFirst('fred');
|
||
|
* // => 'Fred'
|
||
|
*
|
||
|
* _.upperFirst('FRED');
|
||
|
* // => 'FRED'
|
||
|
*/
|
||
|
var upperFirst = createCaseFirst('toUpperCase');
|
||
|
|
||
|
module.exports = upperFirst;
|