lodash.padstart
Advanced tools
Comparing version 4.2.0 to 4.3.0
147
index.js
/** | ||
* lodash 4.2.0 (Custom Build) <https://lodash.com/> | ||
* lodash 4.3.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | ||
* 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 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
*/ | ||
var repeat = require('lodash.repeat'), | ||
toString = require('lodash.tostring'); | ||
var toString = require('lodash.tostring'); | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY = 1 / 0, | ||
MAX_SAFE_INTEGER = 9007199254740991, | ||
MAX_INTEGER = 1.7976931348623157e+308, | ||
@@ -19,3 +19,4 @@ NAN = 0 / 0; | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
genTag = '[object GeneratorFunction]', | ||
symbolTag = '[object Symbol]'; | ||
@@ -105,5 +106,34 @@ /** Used to match leading and trailing whitespace. */ | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeCeil = Math.ceil; | ||
var nativeCeil = Math.ceil, | ||
nativeFloor = Math.floor; | ||
/** | ||
* The base implementation of `_.repeat` which doesn't coerce arguments. | ||
* | ||
* @private | ||
* @param {string} string The string to repeat. | ||
* @param {number} n The number of times to repeat the string. | ||
* @returns {string} Returns the repeated string. | ||
*/ | ||
function baseRepeat(string, n) { | ||
var result = ''; | ||
if (!string || n < 1 || n > MAX_SAFE_INTEGER) { | ||
return result; | ||
} | ||
// Leverage the exponentiation by squaring algorithm for a faster repeat. | ||
// See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. | ||
do { | ||
if (n % 2) { | ||
result += string; | ||
} | ||
n = nativeFloor(n / 2); | ||
if (n) { | ||
string += string; | ||
} | ||
} while (n); | ||
return result; | ||
} | ||
/** | ||
* Creates the padding for `string` based on `length`. The `chars` string | ||
@@ -113,21 +143,17 @@ * is truncated if the number of characters exceeds `length`. | ||
* @private | ||
* @param {string} string The string to create padding for. | ||
* @param {number} [length=0] The padding length. | ||
* @param {number} length The padding length. | ||
* @param {string} [chars=' '] The string used as padding. | ||
* @returns {string} Returns the padding for `string`. | ||
*/ | ||
function createPadding(string, length, chars) { | ||
length = toInteger(length); | ||
function createPadding(length, chars) { | ||
chars = chars === undefined ? ' ' : (chars + ''); | ||
var strLength = stringSize(string); | ||
if (!length || strLength >= length) { | ||
return ''; | ||
var charsLength = chars.length; | ||
if (charsLength < 2) { | ||
return charsLength ? baseRepeat(chars, length) : chars; | ||
} | ||
var padLength = length - strLength; | ||
chars = chars === undefined ? ' ' : (chars + ''); | ||
var result = repeat(chars, nativeCeil(padLength / stringSize(chars))); | ||
var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); | ||
return reHasComplexSymbol.test(chars) | ||
? stringToArray(result).slice(0, padLength).join('') | ||
: result.slice(0, padLength); | ||
? stringToArray(result).slice(0, length).join('') | ||
: result.slice(0, length); | ||
} | ||
@@ -140,5 +166,7 @@ | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, | ||
* else `false`. | ||
* @example | ||
@@ -154,4 +182,4 @@ * | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array constructors, and | ||
// PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
// 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) : ''; | ||
@@ -167,2 +195,3 @@ return tag == funcTag || tag == genTag; | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
@@ -191,8 +220,61 @@ * @param {*} value The value to check. | ||
/** | ||
* 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 correctly classified, | ||
* 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 an integer. | ||
* | ||
* **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). | ||
* **Note:** This function is loosely based on | ||
* [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
@@ -233,2 +315,3 @@ * @param {*} value The value to convert. | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
@@ -252,2 +335,8 @@ * @param {*} value The value to process. | ||
function toNumber(value) { | ||
if (typeof value == 'number') { | ||
return value; | ||
} | ||
if (isSymbol(value)) { | ||
return NAN; | ||
} | ||
if (isObject(value)) { | ||
@@ -273,2 +362,3 @@ var other = isFunction(value.valueOf) ? value.valueOf() : value; | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category String | ||
@@ -292,5 +382,10 @@ * @param {string} [string=''] The string to pad. | ||
string = toString(string); | ||
return createPadding(string, length, chars) + string; | ||
length = toInteger(length); | ||
var strLength = length ? stringSize(string) : 0; | ||
return (length && strLength < length) | ||
? (createPadding(length - strLength, chars) + string) | ||
: string; | ||
} | ||
module.exports = padStart; |
{ | ||
"name": "lodash.padstart", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "The lodash method `_.padStart` exported as a module.", | ||
@@ -12,3 +12,3 @@ "homepage": "https://lodash.com/", | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (https://github.com/phated)", | ||
"Blaine Bublitz <blaine.bublitz@gmail.com> (https://github.com/phated)", | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
@@ -19,5 +19,4 @@ ], | ||
"dependencies": { | ||
"lodash.repeat": "^4.0.0", | ||
"lodash.tostring": "^4.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash.padstart v4.2.0 | ||
# lodash.padstart v4.3.0 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.padStart` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#padStart) or [package source](https://github.com/lodash/lodash/blob/4.2.0-npm-packages/lodash.padstart) for more details. | ||
See the [documentation](https://lodash.com/docs#padStart) or [package source](https://github.com/lodash/lodash/blob/4.3.0-npm-packages/lodash.padstart) for more details. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13530
1
350
1
- Removedlodash.repeat@^4.0.0
- Removedlodash.repeat@4.1.0(transitive)