-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
_.gpIndexOfNonStrict
and _.gpIncludesNonStrict
- Loading branch information
1 parent
106e560
commit 5b65cd9
Showing
3 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(function() { | ||
|
||
_.mixin({gpIndexOfNonStrict: gpIndexOfNonStrict}); | ||
|
||
/** | ||
* Same as `_.indexOf` except that non-strict equality operator is used for comparison | ||
* | ||
* @see {@link _.indexOf} | ||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality_()} | ||
* | ||
* @example | ||
* | ||
* _.indexOf([1, 2, 1, 2], '2'); | ||
* // => 1 | ||
*/ | ||
function gpIndexOfNonStrict(array, value, fromIndex) { | ||
|
||
var length = array ? array.length : 0; | ||
|
||
if (!length) { | ||
return -1; | ||
} | ||
|
||
fromIndex = _.toInteger(fromIndex); | ||
|
||
if (fromIndex < 0) { | ||
fromIndex = _.max(length + fromIndex, 0); | ||
} | ||
|
||
var index = fromIndex - 1; | ||
|
||
while (++index < length) { | ||
|
||
if (array[index] == value) { | ||
return index; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(function() { | ||
|
||
_.mixin({gpIncludesNonStrict: gpIncludesNonStrict}); | ||
|
||
/** | ||
* Same as `_.includes` except that | ||
* non-strict equality comparison operator is used for comparison | ||
* | ||
* @see {@link _.includes} | ||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality_()} | ||
* | ||
* @example | ||
* | ||
* _.includes([1, 2, 3], '1'); | ||
* // => true | ||
* | ||
* _.includes({ 'user': 'fred', 'age': '40' }, 40); | ||
* // => true | ||
* | ||
* _.includes([undefined], null); | ||
* // => true | ||
* | ||
* _.includes([1], true); | ||
* // => true | ||
* | ||
* _.includes('', false); | ||
* // => true | ||
*/ | ||
function gpIncludesNonStrict(collection, value, fromIndex, guard) { | ||
|
||
collection = _.isArrayLike(collection) ? collection : _.values(collection); | ||
fromIndex = (fromIndex && !guard) ? _.toInteger(fromIndex) : 0; | ||
|
||
var length = collection.length; | ||
if (fromIndex < 0) { | ||
fromIndex = _.max(length + fromIndex, 0); | ||
} | ||
|
||
if (_.isString(collection) && collection) { | ||
return (fromIndex <= length && collection.indexOf(value, fromIndex) > -1); | ||
} else if (_.isArray()) { | ||
return (!!length && baseIndexOf(collection, value, fromIndex) > -1); | ||
} else { | ||
return collection == value; | ||
} | ||
} | ||
|
||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"name": "@goldenplanet/lodash", | ||
"description": "Lodash mixins for OpenBizBox", | ||
"version": "1.0.1", | ||
"version": "1.0.3", | ||
"authors": [ | ||
"Steven Pribilinskiy <[email protected]>" | ||
], | ||
"homepage": "https://github.com/goldenplanetdk/lodash-mixins", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"lodash": "~3.10.1" | ||
"lodash": "4.5.0" | ||
} | ||
} |