lodash.pad
Advanced tools
Comparing version 4.5.0 to 4.5.1
126
index.js
@@ -17,5 +17,3 @@ /** | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
symbolTag = '[object Symbol]'; | ||
var symbolTag = '[object Symbol]'; | ||
@@ -58,6 +56,6 @@ /** Used to match leading and trailing whitespace. */ | ||
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ | ||
var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); | ||
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 reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); | ||
var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); | ||
@@ -77,2 +75,46 @@ /** Built-in method references without a dependency on `root`. */ | ||
/** | ||
* Gets the size of an ASCII `string`. | ||
* | ||
* @private | ||
* @param {string} string The string inspect. | ||
* @returns {number} Returns the string size. | ||
*/ | ||
var asciiSize = baseProperty('length'); | ||
/** | ||
* 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(''); | ||
} | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
* | ||
* @private | ||
* @param {string} key The key of the property to get. | ||
* @returns {Function} Returns the new accessor function. | ||
*/ | ||
function baseProperty(key) { | ||
return function(object) { | ||
return object == null ? undefined : object[key]; | ||
}; | ||
} | ||
/** | ||
* 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); | ||
} | ||
/** | ||
* Gets the number of symbols in `string`. | ||
@@ -85,7 +127,30 @@ * | ||
function stringSize(string) { | ||
if (!(string && reHasComplexSymbol.test(string))) { | ||
return string.length; | ||
} | ||
var result = reComplexSymbol.lastIndex = 0; | ||
while (reComplexSymbol.test(string)) { | ||
return hasUnicode(string) | ||
? unicodeSize(string) | ||
: asciiSize(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); | ||
} | ||
/** | ||
* Gets the size of a Unicode `string`. | ||
* | ||
* @private | ||
* @param {string} string The string inspect. | ||
* @returns {number} Returns the string size. | ||
*/ | ||
function unicodeSize(string) { | ||
var result = reUnicode.lastIndex = 0; | ||
while (reUnicode.test(string)) { | ||
result++; | ||
@@ -97,3 +162,3 @@ } | ||
/** | ||
* Converts `string` to an array. | ||
* Converts a Unicode `string` to an array. | ||
* | ||
@@ -104,4 +169,4 @@ * @private | ||
*/ | ||
function stringToArray(string) { | ||
return string.match(reComplexSymbol); | ||
function unicodeToArray(string) { | ||
return string.match(reUnicode) || []; | ||
} | ||
@@ -114,3 +179,3 @@ | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
@@ -241,3 +306,3 @@ */ | ||
var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); | ||
return reHasComplexSymbol.test(chars) | ||
return hasUnicode(chars) | ||
? castSlice(stringToArray(result), 0, length).join('') | ||
@@ -248,29 +313,4 @@ : result.slice(0, length); | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a function, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array and weak map constructors, | ||
// and PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
} | ||
/** | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) | ||
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
@@ -392,3 +432,3 @@ * | ||
* **Note:** This method is loosely based on | ||
* [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). | ||
* [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). | ||
* | ||
@@ -453,3 +493,3 @@ * @static | ||
if (isObject(value)) { | ||
var other = isFunction(value.valueOf) ? value.valueOf() : value; | ||
var other = typeof value.valueOf == 'function' ? value.valueOf() : value; | ||
value = isObject(other) ? (other + '') : other; | ||
@@ -456,0 +496,0 @@ } |
{ | ||
"name": "lodash.pad", | ||
"version": "4.5.0", | ||
"version": "4.5.1", | ||
"description": "The lodash method `_.pad` exported as a module.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://lodash.com/", |
@@ -1,2 +0,2 @@ | ||
# lodash.pad v4.5.0 | ||
# lodash.pad v4.5.1 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.pad` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#pad) or [package source](https://github.com/lodash/lodash/blob/4.5.0-npm-packages/lodash.pad) for more details. | ||
See the [documentation](https://lodash.com/docs#pad) or [package source](https://github.com/lodash/lodash/blob/4.5.1-npm-packages/lodash.pad) for more details. |
17575
512