mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Make _.contains work with strings similar ES6 draft String#contains.
Former-commit-id: 3cfffdcddec3e1e8175da95043ec86ac3c6a85fe
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post-process a given minified JavaScript `source`, preparing it for
|
* Post-process a given minified Lo-Dash `source`, preparing it for
|
||||||
* deployment.
|
* deployment.
|
||||||
*
|
*
|
||||||
* @param {String} source The source to process.
|
* @param {String} source The source to process.
|
||||||
|
|||||||
@@ -198,7 +198,7 @@
|
|||||||
/**
|
/**
|
||||||
* Pre-process a given Lo-Dash source, preparing it for minification.
|
* Pre-process a given Lo-Dash source, preparing it for minification.
|
||||||
*
|
*
|
||||||
* @param {String} source The Lo-Dash source to process.
|
* @param {String} source The source to process.
|
||||||
* @returns {String} Returns the processed source.
|
* @returns {String} Returns the processed source.
|
||||||
*/
|
*/
|
||||||
function preprocess(source) {
|
function preprocess(source) {
|
||||||
@@ -218,6 +218,9 @@
|
|||||||
// remove brackets from `_.escape()` in `_.template`
|
// remove brackets from `_.escape()` in `_.template`
|
||||||
source = source.replace(/__e *= *_\['escape']/, '__e=_.escape');
|
source = source.replace(/__e *= *_\['escape']/, '__e=_.escape');
|
||||||
|
|
||||||
|
// remove brackets from `collection.indexOf` in `_.contains`
|
||||||
|
source = source.replace("collection['indexOf'](target)", 'collection.indexOf(target)');
|
||||||
|
|
||||||
// remove brackets from `result[length].value` in `_.sortBy`
|
// remove brackets from `result[length].value` in `_.sortBy`
|
||||||
source = source.replace("result[length]['value']", 'result[length].value');
|
source = source.replace("result[length]['value']", 'result[length].value');
|
||||||
|
|
||||||
|
|||||||
19
lodash.js
19
lodash.js
@@ -514,10 +514,12 @@
|
|||||||
data.firstArg = firstArg;
|
data.firstArg = firstArg;
|
||||||
data.hasDontEnumBug = hasDontEnumBug;
|
data.hasDontEnumBug = hasDontEnumBug;
|
||||||
data.isKeysFast = isKeysFast;
|
data.isKeysFast = isKeysFast;
|
||||||
data.noCharByIndex = noCharByIndex;
|
|
||||||
data.shadowed = shadowed;
|
data.shadowed = shadowed;
|
||||||
data.useHas = data.useHas !== false;
|
data.useHas = data.useHas !== false;
|
||||||
|
|
||||||
|
if (!('noCharByIndex' in data)) {
|
||||||
|
data.noCharByIndex = noCharByIndex;
|
||||||
|
}
|
||||||
if (!data.exit) {
|
if (!data.exit) {
|
||||||
data.exit = 'if (!' + firstArg + ') return result';
|
data.exit = 'if (!' + firstArg + ') return result';
|
||||||
}
|
}
|
||||||
@@ -711,11 +713,21 @@
|
|||||||
*
|
*
|
||||||
* _.contains([1, 2, 3], 3);
|
* _.contains([1, 2, 3], 3);
|
||||||
* // => true
|
* // => true
|
||||||
|
*
|
||||||
|
* _.contains({ 'name': 'moe', 'age': 40 }, 'moe');
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* _.contains('curly', 'ur');
|
||||||
|
* // => true
|
||||||
*/
|
*/
|
||||||
var contains = createIterator({
|
var contains = createIterator({
|
||||||
'args': 'collection, target',
|
'args': 'collection, target',
|
||||||
'init': 'false',
|
'init': 'false',
|
||||||
'inLoop': 'if (iteratee[index] === target) return true'
|
'noCharByIndex': false,
|
||||||
|
'beforeLoop': {
|
||||||
|
'array': 'if (toString.call(iteratee) == stringClass) return collection.indexOf(target) > -1'
|
||||||
|
},
|
||||||
|
'inLoop': 'if (iteratee[index] === target) return true',
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2636,6 +2648,9 @@
|
|||||||
*
|
*
|
||||||
* _.isEmpty({});
|
* _.isEmpty({});
|
||||||
* // => true
|
* // => true
|
||||||
|
*
|
||||||
|
* _.isEmpty('');
|
||||||
|
* // => true
|
||||||
*/
|
*/
|
||||||
var isEmpty = createIterator({
|
var isEmpty = createIterator({
|
||||||
'args': 'value',
|
'args': 'value',
|
||||||
|
|||||||
17
test/test.js
17
test/test.js
@@ -132,6 +132,23 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('lodash.contains');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
_.each([
|
||||||
|
{ 'kind': 'literal', 'value': 'abc' },
|
||||||
|
{ 'kind': 'object', 'value': Object('abc') }
|
||||||
|
],
|
||||||
|
function(data) {
|
||||||
|
test('should work with a string ' + data.kind + ' for `collection`', function() {
|
||||||
|
equal(_.contains(data.value, 'bc'), true);
|
||||||
|
equal(_.contains(data.value, 'd'), false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('lodash.debounce');
|
QUnit.module('lodash.debounce');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user