mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
@@ -23,9 +23,7 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
}
|
||||
|
||||
/**
|
||||
* @class Collection
|
||||
* @property length
|
||||
* @memberOf {kit}
|
||||
* @memberOf kit
|
||||
*/
|
||||
var Collection = function (data = []) {
|
||||
var self = this;
|
||||
@@ -79,6 +77,10 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
}
|
||||
return lastIndex;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {{}|*[]}
|
||||
*/
|
||||
Collection.prototype.all = function () {
|
||||
if(this.__type === 'array' || this.__type === 'arrayObject') {
|
||||
return this.toArray();
|
||||
@@ -114,7 +116,7 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
/**
|
||||
* @param key
|
||||
* @param value
|
||||
* @return {Collection}
|
||||
* @return this
|
||||
*/
|
||||
Collection.prototype.add = Collection.prototype.set = Collection.prototype.put = function (key, value) {
|
||||
var index = -1;
|
||||
@@ -128,7 +130,7 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
};
|
||||
/**
|
||||
* @param value
|
||||
* @return {Collection}
|
||||
* @return this
|
||||
*/
|
||||
Collection.prototype.push = function (value) {
|
||||
this.set(this.__getLastIndex() + 1, value);
|
||||
@@ -193,7 +195,7 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
};
|
||||
/**
|
||||
* @param callback
|
||||
* @return {Collection}
|
||||
* @return this
|
||||
*/
|
||||
Collection.prototype.filter = function (callback = filter) {
|
||||
var res = getSimilarInstance(this.__type);
|
||||
@@ -208,7 +210,7 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
/**
|
||||
* Метод возвращает все элементы коллекции, кроме тех у кого ключи соответствуют заданным
|
||||
* @param keys
|
||||
* @return {Collection}
|
||||
* @return this
|
||||
*/
|
||||
Collection.prototype.except = function (keys) {
|
||||
var __keys = [], iKey;
|
||||
@@ -410,11 +412,8 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
}
|
||||
var n = fromIndex | 0;
|
||||
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
||||
function sameValueZero(x, y) {
|
||||
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
|
||||
}
|
||||
while (k < len) {
|
||||
if (sameValueZero(this.__values[k], searchElement)) {
|
||||
if (support.isEqualArrayValues(this.__values[k], searchElement, true)) {
|
||||
return true;
|
||||
}
|
||||
k++;
|
||||
@@ -422,17 +421,58 @@ __PluginManager__.register('Collection', function(require, exports, module, glob
|
||||
return false;
|
||||
};
|
||||
|
||||
Collection.prototype.contains = function(value, strict = false) {
|
||||
var len = this.__keys.length, k = 0;
|
||||
if (len === 0) {
|
||||
return false;
|
||||
}
|
||||
if (support.isFunction(value)) {
|
||||
return this.filter(value).count() > 0;
|
||||
}
|
||||
while (k < len) {
|
||||
if (support.isEqualArrayValues(this.__values[k], value, strict)) {
|
||||
return true;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Collection.prototype.hasAnyValue = function(valueList, strict = false) {
|
||||
var valueCollection = new Collection(valueList);
|
||||
var res = false;
|
||||
this.each(function(v, k, arr){
|
||||
if (valueCollection.contains(v, strict)) {
|
||||
res = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return res;
|
||||
};
|
||||
|
||||
Collection.prototype.hasAnyKey = function(keyList) {
|
||||
var keyCollection = new Collection(valueList);
|
||||
var res = false;
|
||||
this.each(function(v, k, arr){
|
||||
if (keyCollection.contains(k, false)) {
|
||||
res = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return res;
|
||||
};
|
||||
|
||||
|
||||
Collection.prototype.search = function(searchElement) {
|
||||
var len = this.__keys.length;
|
||||
if (len === 0) {
|
||||
return false;
|
||||
}
|
||||
var k = 0;
|
||||
function sameValueZero(x, y) {
|
||||
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
|
||||
}
|
||||
while (k < len) {
|
||||
if (sameValueZero(this.__values[k], searchElement)) {
|
||||
if (support.isEqualArrayValues(this.__values[k], searchElement, true)) {
|
||||
return this.__keys[k];
|
||||
}
|
||||
k++;
|
||||
|
||||
Reference in New Issue
Block a user