mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add stringToArray helper.
This commit is contained in:
28
lodash.js
28
lodash.js
@@ -1192,10 +1192,21 @@
|
|||||||
*/
|
*/
|
||||||
function stringSize(string) {
|
function stringSize(string) {
|
||||||
return (string && reStrSurrogate.test(string))
|
return (string && reStrSurrogate.test(string))
|
||||||
? string.match(reStrSymbol).length
|
? stringToArray(string).length
|
||||||
: string.length;
|
: string.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts `string` to an array.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} string The string to convert.
|
||||||
|
* @returns {Array} Returns the converted array.
|
||||||
|
*/
|
||||||
|
function stringToArray(string) {
|
||||||
|
return string ? string.match(reStrSymbol) : [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
|
* Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
|
||||||
* character of `string`.
|
* character of `string`.
|
||||||
@@ -3619,7 +3630,7 @@
|
|||||||
|
|
||||||
var result = repeat(chars, nativeCeil(padLength / stringSize(chars)));
|
var result = repeat(chars, nativeCeil(padLength / stringSize(chars)));
|
||||||
return reStrSurrogate.test(chars)
|
return reStrSurrogate.test(chars)
|
||||||
? result.match(reStrSymbol).slice(0, padLength).join('')
|
? stringToArray(result).slice(0, padLength).join('')
|
||||||
: result.slice(0, padLength);
|
: result.slice(0, padLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8976,13 +8987,7 @@
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (isArrayLike(value)) {
|
if (isArrayLike(value)) {
|
||||||
if (!value.length) {
|
return (!isArray(value) && isString(value)) ? stringToArray(value) : copyArray(value);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (!isArray(value) && isString(value)) {
|
|
||||||
return reStrSurrogate.test(value) ? value.match(reStrSymbol) : value.split('');
|
|
||||||
}
|
|
||||||
return copyArray(value);
|
|
||||||
}
|
}
|
||||||
if (iteratorSymbol && value[iteratorSymbol]) {
|
if (iteratorSymbol && value[iteratorSymbol]) {
|
||||||
return iteratorToArray(value[iteratorSymbol]());
|
return iteratorToArray(value[iteratorSymbol]());
|
||||||
@@ -11028,7 +11033,10 @@
|
|||||||
if (end < 1) {
|
if (end < 1) {
|
||||||
return omission;
|
return omission;
|
||||||
}
|
}
|
||||||
var result = string.slice(0, end);
|
var result = reStrSurrogate.test(string)
|
||||||
|
? stringToArray(string).slice(0, end).join('')
|
||||||
|
: string.slice(0, end);
|
||||||
|
|
||||||
if (separator === undefined) {
|
if (separator === undefined) {
|
||||||
return result + omission;
|
return result + omission;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user