scrivito_sdk 0.42.1 → 0.50.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/views/scrivito/ui/index.html.erb +0 -1
- data/config/ca-bundle.crt +1 -1
- data/config/routes.rb +8 -5
- data/lib/assets/javascripts/scrivito_ui.js +406 -286
- data/lib/assets/stylesheets/scrivito_sdk.css +1 -1
- data/lib/assets/stylesheets/scrivito_ui.css +1 -1
- data/lib/generators/scrivito/install/templates/app/models/page.rb +1 -1
- data/lib/generators/scrivito/migration/templates/migration.erb +1 -1
- data/lib/generators/scrivito/page/templates/migration.erb +1 -1
- data/lib/generators/scrivito/widget/templates/migration.erb +1 -1
- data/lib/scrivito/attribute_definition_migrator.rb +110 -0
- data/lib/scrivito/client_config.rb +1 -1
- data/lib/scrivito/configuration.rb +16 -0
- data/lib/scrivito/test_request.rb +10 -5
- data/lib/scrivito/user.rb +37 -5
- data/lib/scrivito/user_definition.rb +50 -16
- data/lib/tasks/migrate_attribute_definitions.rake +6 -0
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70cfbded7c08170b69bac4f46a7bafd3c37c8539
|
4
|
+
data.tar.gz: 4f684ad24b4cba99c43412e03949e802a4e3c707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f379ba2c03ff06267648b8d1504e9dba89de52636b714612466a69a48d05618052a2721c7ac1d068d2c6e0f069d7e0ce01f2264584df29c1e386b21f231d45f4
|
7
|
+
data.tar.gz: 0a4f892d6809b97c9fb4cf4d3ca518d44d03950e8ceae94c18025452eef3421f0d53d6c578bd100d00da75ab85318b9024616eeaf64c635503347a1082022ded
|
data/config/ca-bundle.crt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
2
|
## Bundle of CA Root Certificates
|
3
3
|
##
|
4
|
-
## Certificate data from Mozilla as of:
|
4
|
+
## Certificate data from Mozilla as of: Fri Mar 6 09:58:49 2015
|
5
5
|
##
|
6
6
|
## This is a bundle of X.509 certificates of public Certificate Authorities
|
7
7
|
## (CA). These were automatically extracted from Mozilla's root certificates
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
resources :objs, controller: 'scrivito/objs', path: '__scrivito/objs',
|
3
|
-
only: [:create, :update, :destroy] do
|
3
|
+
only: [:create, :update, :destroy], defaults: {format: :json} do
|
4
4
|
collection do
|
5
5
|
get :page_class_selection
|
6
6
|
get :search
|
@@ -23,14 +23,17 @@ Rails.application.routes.draw do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
resources :tasks, controller: 'scrivito/tasks', path: '__scrivito/tasks', only: [:show]
|
26
|
+
resources :tasks, controller: 'scrivito/tasks', path: '__scrivito/tasks', only: [:show],
|
27
|
+
defaults: {format: :json}
|
27
28
|
|
28
|
-
get '__scrivito/blobs/upload_permission' => 'scrivito/blobs#upload_permission'
|
29
|
+
get '__scrivito/blobs/upload_permission' => 'scrivito/blobs#upload_permission',
|
30
|
+
defaults: {format: :json}
|
29
31
|
|
30
32
|
resources :workspaces,
|
31
33
|
controller: 'scrivito/workspaces',
|
32
34
|
path: '__scrivito/workspaces',
|
33
|
-
only: [:index, :show, :create, :update, :destroy]
|
35
|
+
only: [:index, :show, :create, :update, :destroy],
|
36
|
+
defaults: {format: :json} do
|
34
37
|
member do
|
35
38
|
put :rebase
|
36
39
|
put :publish
|
@@ -38,7 +41,7 @@ Rails.application.routes.draw do
|
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
|
-
get '__scrivito/users/suggest' => 'scrivito/users#suggest'
|
44
|
+
get '__scrivito/users/suggest' => 'scrivito/users#suggest', defaults: {format: :json}
|
42
45
|
|
43
46
|
get 'scrivito', to: 'scrivito/ui#index', as: 'scrivito_ui'
|
44
47
|
get 'scrivito/*application_path', to: 'scrivito/ui#index', format: false
|
@@ -15712,9 +15712,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15712
15712
|
}
|
15713
15713
|
|
15714
15714
|
;
|
15715
|
-
// Underscore.js 1.
|
15715
|
+
// Underscore.js 1.8.2
|
15716
15716
|
// http://underscorejs.org
|
15717
|
-
// (c) 2009-
|
15717
|
+
// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
15718
15718
|
// Underscore may be freely distributed under the MIT license.
|
15719
15719
|
|
15720
15720
|
(function() {
|
@@ -15735,7 +15735,6 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15735
15735
|
var
|
15736
15736
|
push = ArrayProto.push,
|
15737
15737
|
slice = ArrayProto.slice,
|
15738
|
-
concat = ArrayProto.concat,
|
15739
15738
|
toString = ObjProto.toString,
|
15740
15739
|
hasOwnProperty = ObjProto.hasOwnProperty;
|
15741
15740
|
|
@@ -15744,7 +15743,11 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15744
15743
|
var
|
15745
15744
|
nativeIsArray = Array.isArray,
|
15746
15745
|
nativeKeys = Object.keys,
|
15747
|
-
nativeBind = FuncProto.bind
|
15746
|
+
nativeBind = FuncProto.bind,
|
15747
|
+
nativeCreate = Object.create;
|
15748
|
+
|
15749
|
+
// Naked function reference for surrogate-prototype-swapping.
|
15750
|
+
var Ctor = function(){};
|
15748
15751
|
|
15749
15752
|
// Create a safe reference to the Underscore object for use below.
|
15750
15753
|
var _ = function(obj) {
|
@@ -15766,12 +15769,12 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15766
15769
|
}
|
15767
15770
|
|
15768
15771
|
// Current version.
|
15769
|
-
_.VERSION = '1.
|
15772
|
+
_.VERSION = '1.8.2';
|
15770
15773
|
|
15771
15774
|
// Internal function that returns an efficient (for current engines) version
|
15772
15775
|
// of the passed-in callback, to be repeatedly applied in other Underscore
|
15773
15776
|
// functions.
|
15774
|
-
var
|
15777
|
+
var optimizeCb = function(func, context, argCount) {
|
15775
15778
|
if (context === void 0) return func;
|
15776
15779
|
switch (argCount == null ? 3 : argCount) {
|
15777
15780
|
case 1: return function(value) {
|
@@ -15795,12 +15798,52 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15795
15798
|
// A mostly-internal function to generate callbacks that can be applied
|
15796
15799
|
// to each element in a collection, returning the desired result — either
|
15797
15800
|
// identity, an arbitrary callback, a property matcher, or a property accessor.
|
15798
|
-
|
15801
|
+
var cb = function(value, context, argCount) {
|
15799
15802
|
if (value == null) return _.identity;
|
15800
|
-
if (_.isFunction(value)) return
|
15801
|
-
if (_.isObject(value)) return _.
|
15803
|
+
if (_.isFunction(value)) return optimizeCb(value, context, argCount);
|
15804
|
+
if (_.isObject(value)) return _.matcher(value);
|
15802
15805
|
return _.property(value);
|
15803
15806
|
};
|
15807
|
+
_.iteratee = function(value, context) {
|
15808
|
+
return cb(value, context, Infinity);
|
15809
|
+
};
|
15810
|
+
|
15811
|
+
// An internal function for creating assigner functions.
|
15812
|
+
var createAssigner = function(keysFunc, undefinedOnly) {
|
15813
|
+
return function(obj) {
|
15814
|
+
var length = arguments.length;
|
15815
|
+
if (length < 2 || obj == null) return obj;
|
15816
|
+
for (var index = 1; index < length; index++) {
|
15817
|
+
var source = arguments[index],
|
15818
|
+
keys = keysFunc(source),
|
15819
|
+
l = keys.length;
|
15820
|
+
for (var i = 0; i < l; i++) {
|
15821
|
+
var key = keys[i];
|
15822
|
+
if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key];
|
15823
|
+
}
|
15824
|
+
}
|
15825
|
+
return obj;
|
15826
|
+
};
|
15827
|
+
};
|
15828
|
+
|
15829
|
+
// An internal function for creating a new object that inherits from another.
|
15830
|
+
var baseCreate = function(prototype) {
|
15831
|
+
if (!_.isObject(prototype)) return {};
|
15832
|
+
if (nativeCreate) return nativeCreate(prototype);
|
15833
|
+
Ctor.prototype = prototype;
|
15834
|
+
var result = new Ctor;
|
15835
|
+
Ctor.prototype = null;
|
15836
|
+
return result;
|
15837
|
+
};
|
15838
|
+
|
15839
|
+
// Helper for collection methods to determine whether a collection
|
15840
|
+
// should be iterated as an array or as an object
|
15841
|
+
// Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
|
15842
|
+
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
|
15843
|
+
var isArrayLike = function(collection) {
|
15844
|
+
var length = collection && collection.length;
|
15845
|
+
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
|
15846
|
+
};
|
15804
15847
|
|
15805
15848
|
// Collection Functions
|
15806
15849
|
// --------------------
|
@@ -15809,11 +15852,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15809
15852
|
// Handles raw objects in addition to array-likes. Treats all
|
15810
15853
|
// sparse array-likes as if they were dense.
|
15811
15854
|
_.each = _.forEach = function(obj, iteratee, context) {
|
15812
|
-
|
15813
|
-
|
15814
|
-
|
15815
|
-
|
15816
|
-
for (i = 0; i < length; i++) {
|
15855
|
+
iteratee = optimizeCb(iteratee, context);
|
15856
|
+
var i, length;
|
15857
|
+
if (isArrayLike(obj)) {
|
15858
|
+
for (i = 0, length = obj.length; i < length; i++) {
|
15817
15859
|
iteratee(obj[i], i, obj);
|
15818
15860
|
}
|
15819
15861
|
} else {
|
@@ -15827,77 +15869,66 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15827
15869
|
|
15828
15870
|
// Return the results of applying the iteratee to each element.
|
15829
15871
|
_.map = _.collect = function(obj, iteratee, context) {
|
15830
|
-
|
15831
|
-
|
15832
|
-
var keys = obj.length !== +obj.length && _.keys(obj),
|
15872
|
+
iteratee = cb(iteratee, context);
|
15873
|
+
var keys = !isArrayLike(obj) && _.keys(obj),
|
15833
15874
|
length = (keys || obj).length,
|
15834
|
-
results = Array(length)
|
15835
|
-
currentKey;
|
15875
|
+
results = Array(length);
|
15836
15876
|
for (var index = 0; index < length; index++) {
|
15837
|
-
currentKey = keys ? keys[index] : index;
|
15877
|
+
var currentKey = keys ? keys[index] : index;
|
15838
15878
|
results[index] = iteratee(obj[currentKey], currentKey, obj);
|
15839
15879
|
}
|
15840
15880
|
return results;
|
15841
15881
|
};
|
15842
15882
|
|
15843
|
-
|
15883
|
+
// Create a reducing function iterating left or right.
|
15884
|
+
function createReduce(dir) {
|
15885
|
+
// Optimized iterator function as using arguments.length
|
15886
|
+
// in the main function will deoptimize the, see #1991.
|
15887
|
+
function iterator(obj, iteratee, memo, keys, index, length) {
|
15888
|
+
for (; index >= 0 && index < length; index += dir) {
|
15889
|
+
var currentKey = keys ? keys[index] : index;
|
15890
|
+
memo = iteratee(memo, obj[currentKey], currentKey, obj);
|
15891
|
+
}
|
15892
|
+
return memo;
|
15893
|
+
}
|
15894
|
+
|
15895
|
+
return function(obj, iteratee, memo, context) {
|
15896
|
+
iteratee = optimizeCb(iteratee, context, 4);
|
15897
|
+
var keys = !isArrayLike(obj) && _.keys(obj),
|
15898
|
+
length = (keys || obj).length,
|
15899
|
+
index = dir > 0 ? 0 : length - 1;
|
15900
|
+
// Determine the initial value if none is provided.
|
15901
|
+
if (arguments.length < 3) {
|
15902
|
+
memo = obj[keys ? keys[index] : index];
|
15903
|
+
index += dir;
|
15904
|
+
}
|
15905
|
+
return iterator(obj, iteratee, memo, keys, index, length);
|
15906
|
+
};
|
15907
|
+
}
|
15844
15908
|
|
15845
15909
|
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
15846
15910
|
// or `foldl`.
|
15847
|
-
_.reduce = _.foldl = _.inject =
|
15848
|
-
if (obj == null) obj = [];
|
15849
|
-
iteratee = createCallback(iteratee, context, 4);
|
15850
|
-
var keys = obj.length !== +obj.length && _.keys(obj),
|
15851
|
-
length = (keys || obj).length,
|
15852
|
-
index = 0, currentKey;
|
15853
|
-
if (arguments.length < 3) {
|
15854
|
-
if (!length) throw new TypeError(reduceError);
|
15855
|
-
memo = obj[keys ? keys[index++] : index++];
|
15856
|
-
}
|
15857
|
-
for (; index < length; index++) {
|
15858
|
-
currentKey = keys ? keys[index] : index;
|
15859
|
-
memo = iteratee(memo, obj[currentKey], currentKey, obj);
|
15860
|
-
}
|
15861
|
-
return memo;
|
15862
|
-
};
|
15911
|
+
_.reduce = _.foldl = _.inject = createReduce(1);
|
15863
15912
|
|
15864
15913
|
// The right-associative version of reduce, also known as `foldr`.
|
15865
|
-
_.reduceRight = _.foldr =
|
15866
|
-
if (obj == null) obj = [];
|
15867
|
-
iteratee = createCallback(iteratee, context, 4);
|
15868
|
-
var keys = obj.length !== + obj.length && _.keys(obj),
|
15869
|
-
index = (keys || obj).length,
|
15870
|
-
currentKey;
|
15871
|
-
if (arguments.length < 3) {
|
15872
|
-
if (!index) throw new TypeError(reduceError);
|
15873
|
-
memo = obj[keys ? keys[--index] : --index];
|
15874
|
-
}
|
15875
|
-
while (index--) {
|
15876
|
-
currentKey = keys ? keys[index] : index;
|
15877
|
-
memo = iteratee(memo, obj[currentKey], currentKey, obj);
|
15878
|
-
}
|
15879
|
-
return memo;
|
15880
|
-
};
|
15914
|
+
_.reduceRight = _.foldr = createReduce(-1);
|
15881
15915
|
|
15882
15916
|
// Return the first value which passes a truth test. Aliased as `detect`.
|
15883
15917
|
_.find = _.detect = function(obj, predicate, context) {
|
15884
|
-
var
|
15885
|
-
|
15886
|
-
|
15887
|
-
|
15888
|
-
|
15889
|
-
|
15890
|
-
|
15891
|
-
});
|
15892
|
-
return result;
|
15918
|
+
var key;
|
15919
|
+
if (isArrayLike(obj)) {
|
15920
|
+
key = _.findIndex(obj, predicate, context);
|
15921
|
+
} else {
|
15922
|
+
key = _.findKey(obj, predicate, context);
|
15923
|
+
}
|
15924
|
+
if (key !== void 0 && key !== -1) return obj[key];
|
15893
15925
|
};
|
15894
15926
|
|
15895
15927
|
// Return all the elements that pass a truth test.
|
15896
15928
|
// Aliased as `select`.
|
15897
15929
|
_.filter = _.select = function(obj, predicate, context) {
|
15898
15930
|
var results = [];
|
15899
|
-
|
15900
|
-
predicate = _.iteratee(predicate, context);
|
15931
|
+
predicate = cb(predicate, context);
|
15901
15932
|
_.each(obj, function(value, index, list) {
|
15902
15933
|
if (predicate(value, index, list)) results.push(value);
|
15903
15934
|
});
|
@@ -15906,19 +15937,17 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15906
15937
|
|
15907
15938
|
// Return all the elements for which a truth test fails.
|
15908
15939
|
_.reject = function(obj, predicate, context) {
|
15909
|
-
return _.filter(obj, _.negate(
|
15940
|
+
return _.filter(obj, _.negate(cb(predicate)), context);
|
15910
15941
|
};
|
15911
15942
|
|
15912
15943
|
// Determine whether all of the elements match a truth test.
|
15913
15944
|
// Aliased as `all`.
|
15914
15945
|
_.every = _.all = function(obj, predicate, context) {
|
15915
|
-
|
15916
|
-
|
15917
|
-
|
15918
|
-
|
15919
|
-
|
15920
|
-
for (index = 0; index < length; index++) {
|
15921
|
-
currentKey = keys ? keys[index] : index;
|
15946
|
+
predicate = cb(predicate, context);
|
15947
|
+
var keys = !isArrayLike(obj) && _.keys(obj),
|
15948
|
+
length = (keys || obj).length;
|
15949
|
+
for (var index = 0; index < length; index++) {
|
15950
|
+
var currentKey = keys ? keys[index] : index;
|
15922
15951
|
if (!predicate(obj[currentKey], currentKey, obj)) return false;
|
15923
15952
|
}
|
15924
15953
|
return true;
|
@@ -15927,24 +15956,21 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15927
15956
|
// Determine if at least one element in the object matches a truth test.
|
15928
15957
|
// Aliased as `any`.
|
15929
15958
|
_.some = _.any = function(obj, predicate, context) {
|
15930
|
-
|
15931
|
-
|
15932
|
-
|
15933
|
-
|
15934
|
-
|
15935
|
-
for (index = 0; index < length; index++) {
|
15936
|
-
currentKey = keys ? keys[index] : index;
|
15959
|
+
predicate = cb(predicate, context);
|
15960
|
+
var keys = !isArrayLike(obj) && _.keys(obj),
|
15961
|
+
length = (keys || obj).length;
|
15962
|
+
for (var index = 0; index < length; index++) {
|
15963
|
+
var currentKey = keys ? keys[index] : index;
|
15937
15964
|
if (predicate(obj[currentKey], currentKey, obj)) return true;
|
15938
15965
|
}
|
15939
15966
|
return false;
|
15940
15967
|
};
|
15941
15968
|
|
15942
15969
|
// Determine if the array or object contains a given value (using `===`).
|
15943
|
-
// Aliased as `include`.
|
15944
|
-
_.contains = _.include = function(obj, target) {
|
15945
|
-
if (obj
|
15946
|
-
|
15947
|
-
return _.indexOf(obj, target) >= 0;
|
15970
|
+
// Aliased as `includes` and `include`.
|
15971
|
+
_.contains = _.includes = _.include = function(obj, target, fromIndex) {
|
15972
|
+
if (!isArrayLike(obj)) obj = _.values(obj);
|
15973
|
+
return _.indexOf(obj, target, typeof fromIndex == 'number' && fromIndex) >= 0;
|
15948
15974
|
};
|
15949
15975
|
|
15950
15976
|
// Invoke a method (with arguments) on every item in a collection.
|
@@ -15952,7 +15978,8 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15952
15978
|
var args = slice.call(arguments, 2);
|
15953
15979
|
var isFunc = _.isFunction(method);
|
15954
15980
|
return _.map(obj, function(value) {
|
15955
|
-
|
15981
|
+
var func = isFunc ? method : value[method];
|
15982
|
+
return func == null ? func : func.apply(value, args);
|
15956
15983
|
});
|
15957
15984
|
};
|
15958
15985
|
|
@@ -15964,13 +15991,13 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15964
15991
|
// Convenience version of a common use case of `filter`: selecting only objects
|
15965
15992
|
// containing specific `key:value` pairs.
|
15966
15993
|
_.where = function(obj, attrs) {
|
15967
|
-
return _.filter(obj, _.
|
15994
|
+
return _.filter(obj, _.matcher(attrs));
|
15968
15995
|
};
|
15969
15996
|
|
15970
15997
|
// Convenience version of a common use case of `find`: getting the first object
|
15971
15998
|
// containing specific `key:value` pairs.
|
15972
15999
|
_.findWhere = function(obj, attrs) {
|
15973
|
-
return _.find(obj, _.
|
16000
|
+
return _.find(obj, _.matcher(attrs));
|
15974
16001
|
};
|
15975
16002
|
|
15976
16003
|
// Return the maximum element (or element-based computation).
|
@@ -15978,7 +16005,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15978
16005
|
var result = -Infinity, lastComputed = -Infinity,
|
15979
16006
|
value, computed;
|
15980
16007
|
if (iteratee == null && obj != null) {
|
15981
|
-
obj = obj
|
16008
|
+
obj = isArrayLike(obj) ? obj : _.values(obj);
|
15982
16009
|
for (var i = 0, length = obj.length; i < length; i++) {
|
15983
16010
|
value = obj[i];
|
15984
16011
|
if (value > result) {
|
@@ -15986,7 +16013,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
15986
16013
|
}
|
15987
16014
|
}
|
15988
16015
|
} else {
|
15989
|
-
iteratee =
|
16016
|
+
iteratee = cb(iteratee, context);
|
15990
16017
|
_.each(obj, function(value, index, list) {
|
15991
16018
|
computed = iteratee(value, index, list);
|
15992
16019
|
if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
|
@@ -16003,7 +16030,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16003
16030
|
var result = Infinity, lastComputed = Infinity,
|
16004
16031
|
value, computed;
|
16005
16032
|
if (iteratee == null && obj != null) {
|
16006
|
-
obj = obj
|
16033
|
+
obj = isArrayLike(obj) ? obj : _.values(obj);
|
16007
16034
|
for (var i = 0, length = obj.length; i < length; i++) {
|
16008
16035
|
value = obj[i];
|
16009
16036
|
if (value < result) {
|
@@ -16011,7 +16038,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16011
16038
|
}
|
16012
16039
|
}
|
16013
16040
|
} else {
|
16014
|
-
iteratee =
|
16041
|
+
iteratee = cb(iteratee, context);
|
16015
16042
|
_.each(obj, function(value, index, list) {
|
16016
16043
|
computed = iteratee(value, index, list);
|
16017
16044
|
if (computed < lastComputed || computed === Infinity && result === Infinity) {
|
@@ -16026,7 +16053,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16026
16053
|
// Shuffle a collection, using the modern version of the
|
16027
16054
|
// [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
|
16028
16055
|
_.shuffle = function(obj) {
|
16029
|
-
var set = obj
|
16056
|
+
var set = isArrayLike(obj) ? obj : _.values(obj);
|
16030
16057
|
var length = set.length;
|
16031
16058
|
var shuffled = Array(length);
|
16032
16059
|
for (var index = 0, rand; index < length; index++) {
|
@@ -16042,7 +16069,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16042
16069
|
// The internal `guard` argument allows it to work with `map`.
|
16043
16070
|
_.sample = function(obj, n, guard) {
|
16044
16071
|
if (n == null || guard) {
|
16045
|
-
if (obj
|
16072
|
+
if (!isArrayLike(obj)) obj = _.values(obj);
|
16046
16073
|
return obj[_.random(obj.length - 1)];
|
16047
16074
|
}
|
16048
16075
|
return _.shuffle(obj).slice(0, Math.max(0, n));
|
@@ -16050,7 +16077,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16050
16077
|
|
16051
16078
|
// Sort the object's values by a criterion produced by an iteratee.
|
16052
16079
|
_.sortBy = function(obj, iteratee, context) {
|
16053
|
-
iteratee =
|
16080
|
+
iteratee = cb(iteratee, context);
|
16054
16081
|
return _.pluck(_.map(obj, function(value, index, list) {
|
16055
16082
|
return {
|
16056
16083
|
value: value,
|
@@ -16072,7 +16099,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16072
16099
|
var group = function(behavior) {
|
16073
16100
|
return function(obj, iteratee, context) {
|
16074
16101
|
var result = {};
|
16075
|
-
iteratee =
|
16102
|
+
iteratee = cb(iteratee, context);
|
16076
16103
|
_.each(obj, function(value, index) {
|
16077
16104
|
var key = iteratee(value, index, obj);
|
16078
16105
|
behavior(result, value, key);
|
@@ -16100,37 +16127,24 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16100
16127
|
if (_.has(result, key)) result[key]++; else result[key] = 1;
|
16101
16128
|
});
|
16102
16129
|
|
16103
|
-
// Use a comparator function to figure out the smallest index at which
|
16104
|
-
// an object should be inserted so as to maintain order. Uses binary search.
|
16105
|
-
_.sortedIndex = function(array, obj, iteratee, context) {
|
16106
|
-
iteratee = _.iteratee(iteratee, context, 1);
|
16107
|
-
var value = iteratee(obj);
|
16108
|
-
var low = 0, high = array.length;
|
16109
|
-
while (low < high) {
|
16110
|
-
var mid = low + high >>> 1;
|
16111
|
-
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
|
16112
|
-
}
|
16113
|
-
return low;
|
16114
|
-
};
|
16115
|
-
|
16116
16130
|
// Safely create a real, live array from anything iterable.
|
16117
16131
|
_.toArray = function(obj) {
|
16118
16132
|
if (!obj) return [];
|
16119
16133
|
if (_.isArray(obj)) return slice.call(obj);
|
16120
|
-
if (obj
|
16134
|
+
if (isArrayLike(obj)) return _.map(obj, _.identity);
|
16121
16135
|
return _.values(obj);
|
16122
16136
|
};
|
16123
16137
|
|
16124
16138
|
// Return the number of elements in an object.
|
16125
16139
|
_.size = function(obj) {
|
16126
16140
|
if (obj == null) return 0;
|
16127
|
-
return obj
|
16141
|
+
return isArrayLike(obj) ? obj.length : _.keys(obj).length;
|
16128
16142
|
};
|
16129
16143
|
|
16130
16144
|
// Split a collection into two arrays: one whose elements all satisfy the given
|
16131
16145
|
// predicate, and one whose elements all do not satisfy the predicate.
|
16132
16146
|
_.partition = function(obj, predicate, context) {
|
16133
|
-
predicate =
|
16147
|
+
predicate = cb(predicate, context);
|
16134
16148
|
var pass = [], fail = [];
|
16135
16149
|
_.each(obj, function(value, key, obj) {
|
16136
16150
|
(predicate(value, key, obj) ? pass : fail).push(value);
|
@@ -16147,30 +16161,27 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16147
16161
|
_.first = _.head = _.take = function(array, n, guard) {
|
16148
16162
|
if (array == null) return void 0;
|
16149
16163
|
if (n == null || guard) return array[0];
|
16150
|
-
|
16151
|
-
return slice.call(array, 0, n);
|
16164
|
+
return _.initial(array, array.length - n);
|
16152
16165
|
};
|
16153
16166
|
|
16154
16167
|
// Returns everything but the last entry of the array. Especially useful on
|
16155
16168
|
// the arguments object. Passing **n** will return all the values in
|
16156
|
-
// the array, excluding the last N.
|
16157
|
-
// `_.map`.
|
16169
|
+
// the array, excluding the last N.
|
16158
16170
|
_.initial = function(array, n, guard) {
|
16159
16171
|
return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
|
16160
16172
|
};
|
16161
16173
|
|
16162
16174
|
// Get the last element of an array. Passing **n** will return the last N
|
16163
|
-
// values in the array.
|
16175
|
+
// values in the array.
|
16164
16176
|
_.last = function(array, n, guard) {
|
16165
16177
|
if (array == null) return void 0;
|
16166
16178
|
if (n == null || guard) return array[array.length - 1];
|
16167
|
-
return
|
16179
|
+
return _.rest(array, Math.max(0, array.length - n));
|
16168
16180
|
};
|
16169
16181
|
|
16170
16182
|
// Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
|
16171
16183
|
// Especially useful on the arguments object. Passing an **n** will return
|
16172
|
-
// the rest N values in the array.
|
16173
|
-
// check allows it to work with `_.map`.
|
16184
|
+
// the rest N values in the array.
|
16174
16185
|
_.rest = _.tail = _.drop = function(array, n, guard) {
|
16175
16186
|
return slice.call(array, n == null || guard ? 1 : n);
|
16176
16187
|
};
|
@@ -16181,18 +16192,20 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16181
16192
|
};
|
16182
16193
|
|
16183
16194
|
// Internal implementation of a recursive `flatten` function.
|
16184
|
-
var flatten = function(input, shallow, strict,
|
16185
|
-
|
16186
|
-
|
16187
|
-
}
|
16188
|
-
for (var i = 0, length = input.length; i < length; i++) {
|
16195
|
+
var flatten = function(input, shallow, strict, startIndex) {
|
16196
|
+
var output = [], idx = 0;
|
16197
|
+
for (var i = startIndex || 0, length = input && input.length; i < length; i++) {
|
16189
16198
|
var value = input[i];
|
16190
|
-
if (
|
16191
|
-
|
16192
|
-
|
16193
|
-
|
16194
|
-
|
16195
|
-
|
16199
|
+
if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
|
16200
|
+
//flatten current level of array or arguments object
|
16201
|
+
if (!shallow) value = flatten(value, shallow, strict);
|
16202
|
+
var j = 0, len = value.length;
|
16203
|
+
output.length += len;
|
16204
|
+
while (j < len) {
|
16205
|
+
output[idx++] = value[j++];
|
16206
|
+
}
|
16207
|
+
} else if (!strict) {
|
16208
|
+
output[idx++] = value;
|
16196
16209
|
}
|
16197
16210
|
}
|
16198
16211
|
return output;
|
@@ -16200,7 +16213,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16200
16213
|
|
16201
16214
|
// Flatten out an array, either recursively (by default), or just one level.
|
16202
16215
|
_.flatten = function(array, shallow) {
|
16203
|
-
return flatten(array, shallow, false
|
16216
|
+
return flatten(array, shallow, false);
|
16204
16217
|
};
|
16205
16218
|
|
16206
16219
|
// Return a version of the array that does not contain the specified value(s).
|
@@ -16218,21 +16231,21 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16218
16231
|
iteratee = isSorted;
|
16219
16232
|
isSorted = false;
|
16220
16233
|
}
|
16221
|
-
if (iteratee != null) iteratee =
|
16234
|
+
if (iteratee != null) iteratee = cb(iteratee, context);
|
16222
16235
|
var result = [];
|
16223
16236
|
var seen = [];
|
16224
16237
|
for (var i = 0, length = array.length; i < length; i++) {
|
16225
|
-
var value = array[i]
|
16238
|
+
var value = array[i],
|
16239
|
+
computed = iteratee ? iteratee(value, i, array) : value;
|
16226
16240
|
if (isSorted) {
|
16227
|
-
if (!i || seen !==
|
16228
|
-
seen =
|
16241
|
+
if (!i || seen !== computed) result.push(value);
|
16242
|
+
seen = computed;
|
16229
16243
|
} else if (iteratee) {
|
16230
|
-
|
16231
|
-
if (_.indexOf(seen, computed) < 0) {
|
16244
|
+
if (!_.contains(seen, computed)) {
|
16232
16245
|
seen.push(computed);
|
16233
16246
|
result.push(value);
|
16234
16247
|
}
|
16235
|
-
} else if (_.
|
16248
|
+
} else if (!_.contains(result, value)) {
|
16236
16249
|
result.push(value);
|
16237
16250
|
}
|
16238
16251
|
}
|
@@ -16242,7 +16255,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16242
16255
|
// Produce an array that contains the union: each distinct element from all of
|
16243
16256
|
// the passed-in arrays.
|
16244
16257
|
_.union = function() {
|
16245
|
-
return _.uniq(flatten(arguments, true, true
|
16258
|
+
return _.uniq(flatten(arguments, true, true));
|
16246
16259
|
};
|
16247
16260
|
|
16248
16261
|
// Produce an array that contains every item shared between all the
|
@@ -16265,7 +16278,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16265
16278
|
// Take the difference between one array and a number of other arrays.
|
16266
16279
|
// Only the elements present in just the first array will remain.
|
16267
16280
|
_.difference = function(array) {
|
16268
|
-
var rest = flatten(
|
16281
|
+
var rest = flatten(arguments, true, true, 1);
|
16269
16282
|
return _.filter(array, function(value){
|
16270
16283
|
return !_.contains(rest, value);
|
16271
16284
|
});
|
@@ -16273,23 +16286,28 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16273
16286
|
|
16274
16287
|
// Zip together multiple lists into a single array -- elements that share
|
16275
16288
|
// an index go together.
|
16276
|
-
_.zip = function(
|
16277
|
-
|
16278
|
-
|
16279
|
-
|
16280
|
-
|
16281
|
-
|
16289
|
+
_.zip = function() {
|
16290
|
+
return _.unzip(arguments);
|
16291
|
+
};
|
16292
|
+
|
16293
|
+
// Complement of _.zip. Unzip accepts an array of arrays and groups
|
16294
|
+
// each array's elements on shared indices
|
16295
|
+
_.unzip = function(array) {
|
16296
|
+
var length = array && _.max(array, 'length').length || 0;
|
16297
|
+
var result = Array(length);
|
16298
|
+
|
16299
|
+
for (var index = 0; index < length; index++) {
|
16300
|
+
result[index] = _.pluck(array, index);
|
16282
16301
|
}
|
16283
|
-
return
|
16302
|
+
return result;
|
16284
16303
|
};
|
16285
16304
|
|
16286
16305
|
// Converts lists into objects. Pass either a single array of `[key, value]`
|
16287
16306
|
// pairs, or two parallel arrays of the same length -- one of keys, and one of
|
16288
16307
|
// the corresponding values.
|
16289
16308
|
_.object = function(list, values) {
|
16290
|
-
if (list == null) return {};
|
16291
16309
|
var result = {};
|
16292
|
-
for (var i = 0, length = list.length; i < length; i++) {
|
16310
|
+
for (var i = 0, length = list && list.length; i < length; i++) {
|
16293
16311
|
if (values) {
|
16294
16312
|
result[list[i]] = values[i];
|
16295
16313
|
} else {
|
@@ -16304,30 +16322,63 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16304
16322
|
// If the array is large and already in sort order, pass `true`
|
16305
16323
|
// for **isSorted** to use binary search.
|
16306
16324
|
_.indexOf = function(array, item, isSorted) {
|
16307
|
-
|
16308
|
-
|
16309
|
-
|
16310
|
-
|
16311
|
-
|
16312
|
-
|
16313
|
-
|
16314
|
-
|
16315
|
-
|
16325
|
+
var i = 0, length = array && array.length;
|
16326
|
+
if (typeof isSorted == 'number') {
|
16327
|
+
i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
|
16328
|
+
} else if (isSorted && length) {
|
16329
|
+
i = _.sortedIndex(array, item);
|
16330
|
+
return array[i] === item ? i : -1;
|
16331
|
+
}
|
16332
|
+
if (item !== item) {
|
16333
|
+
return _.findIndex(slice.call(array, i), _.isNaN);
|
16316
16334
|
}
|
16317
16335
|
for (; i < length; i++) if (array[i] === item) return i;
|
16318
16336
|
return -1;
|
16319
16337
|
};
|
16320
16338
|
|
16321
16339
|
_.lastIndexOf = function(array, item, from) {
|
16322
|
-
|
16323
|
-
var idx = array.length;
|
16340
|
+
var idx = array ? array.length : 0;
|
16324
16341
|
if (typeof from == 'number') {
|
16325
16342
|
idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
|
16326
16343
|
}
|
16344
|
+
if (item !== item) {
|
16345
|
+
return _.findLastIndex(slice.call(array, 0, idx), _.isNaN);
|
16346
|
+
}
|
16327
16347
|
while (--idx >= 0) if (array[idx] === item) return idx;
|
16328
16348
|
return -1;
|
16329
16349
|
};
|
16330
16350
|
|
16351
|
+
// Generator function to create the findIndex and findLastIndex functions
|
16352
|
+
function createIndexFinder(dir) {
|
16353
|
+
return function(array, predicate, context) {
|
16354
|
+
predicate = cb(predicate, context);
|
16355
|
+
var length = array != null && array.length;
|
16356
|
+
var index = dir > 0 ? 0 : length - 1;
|
16357
|
+
for (; index >= 0 && index < length; index += dir) {
|
16358
|
+
if (predicate(array[index], index, array)) return index;
|
16359
|
+
}
|
16360
|
+
return -1;
|
16361
|
+
};
|
16362
|
+
}
|
16363
|
+
|
16364
|
+
// Returns the first index on an array-like that passes a predicate test
|
16365
|
+
_.findIndex = createIndexFinder(1);
|
16366
|
+
|
16367
|
+
_.findLastIndex = createIndexFinder(-1);
|
16368
|
+
|
16369
|
+
// Use a comparator function to figure out the smallest index at which
|
16370
|
+
// an object should be inserted so as to maintain order. Uses binary search.
|
16371
|
+
_.sortedIndex = function(array, obj, iteratee, context) {
|
16372
|
+
iteratee = cb(iteratee, context, 1);
|
16373
|
+
var value = iteratee(obj);
|
16374
|
+
var low = 0, high = array.length;
|
16375
|
+
while (low < high) {
|
16376
|
+
var mid = Math.floor((low + high) / 2);
|
16377
|
+
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
|
16378
|
+
}
|
16379
|
+
return low;
|
16380
|
+
};
|
16381
|
+
|
16331
16382
|
// Generate an integer Array containing an arithmetic progression. A port of
|
16332
16383
|
// the native Python `range()` function. See
|
16333
16384
|
// [the Python documentation](http://docs.python.org/library/functions.html#range).
|
@@ -16351,25 +16402,25 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16351
16402
|
// Function (ahem) Functions
|
16352
16403
|
// ------------------
|
16353
16404
|
|
16354
|
-
//
|
16355
|
-
|
16405
|
+
// Determines whether to execute a function as a constructor
|
16406
|
+
// or a normal function with the provided arguments
|
16407
|
+
var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
|
16408
|
+
if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
|
16409
|
+
var self = baseCreate(sourceFunc.prototype);
|
16410
|
+
var result = sourceFunc.apply(self, args);
|
16411
|
+
if (_.isObject(result)) return result;
|
16412
|
+
return self;
|
16413
|
+
};
|
16356
16414
|
|
16357
16415
|
// Create a function bound to a given object (assigning `this`, and arguments,
|
16358
16416
|
// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
|
16359
16417
|
// available.
|
16360
16418
|
_.bind = function(func, context) {
|
16361
|
-
var args, bound;
|
16362
16419
|
if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
|
16363
16420
|
if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
|
16364
|
-
args = slice.call(arguments, 2);
|
16365
|
-
bound = function() {
|
16366
|
-
|
16367
|
-
Ctor.prototype = func.prototype;
|
16368
|
-
var self = new Ctor;
|
16369
|
-
Ctor.prototype = null;
|
16370
|
-
var result = func.apply(self, args.concat(slice.call(arguments)));
|
16371
|
-
if (_.isObject(result)) return result;
|
16372
|
-
return self;
|
16421
|
+
var args = slice.call(arguments, 2);
|
16422
|
+
var bound = function() {
|
16423
|
+
return executeBound(func, bound, context, this, args.concat(slice.call(arguments)));
|
16373
16424
|
};
|
16374
16425
|
return bound;
|
16375
16426
|
};
|
@@ -16379,15 +16430,16 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16379
16430
|
// as a placeholder, allowing any combination of arguments to be pre-filled.
|
16380
16431
|
_.partial = function(func) {
|
16381
16432
|
var boundArgs = slice.call(arguments, 1);
|
16382
|
-
|
16383
|
-
var position = 0;
|
16384
|
-
var args =
|
16385
|
-
for (var i = 0
|
16386
|
-
|
16433
|
+
var bound = function() {
|
16434
|
+
var position = 0, length = boundArgs.length;
|
16435
|
+
var args = Array(length);
|
16436
|
+
for (var i = 0; i < length; i++) {
|
16437
|
+
args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i];
|
16387
16438
|
}
|
16388
16439
|
while (position < arguments.length) args.push(arguments[position++]);
|
16389
|
-
return func
|
16440
|
+
return executeBound(func, bound, this, this, args);
|
16390
16441
|
};
|
16442
|
+
return bound;
|
16391
16443
|
};
|
16392
16444
|
|
16393
16445
|
// Bind a number of an object's methods to that object. Remaining arguments
|
@@ -16407,7 +16459,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16407
16459
|
_.memoize = function(func, hasher) {
|
16408
16460
|
var memoize = function(key) {
|
16409
16461
|
var cache = memoize.cache;
|
16410
|
-
var address = hasher ? hasher.apply(this, arguments) : key;
|
16462
|
+
var address = '' + (hasher ? hasher.apply(this, arguments) : key);
|
16411
16463
|
if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
|
16412
16464
|
return cache[address];
|
16413
16465
|
};
|
@@ -16426,9 +16478,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16426
16478
|
|
16427
16479
|
// Defers a function, scheduling it to run after the current call stack has
|
16428
16480
|
// cleared.
|
16429
|
-
_.defer =
|
16430
|
-
return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
|
16431
|
-
};
|
16481
|
+
_.defer = _.partial(_.delay, _, 1);
|
16432
16482
|
|
16433
16483
|
// Returns a function, that, when invoked, will only be triggered at most once
|
16434
16484
|
// during a given window of time. Normally, the throttled function will run
|
@@ -16453,8 +16503,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16453
16503
|
context = this;
|
16454
16504
|
args = arguments;
|
16455
16505
|
if (remaining <= 0 || remaining > wait) {
|
16456
|
-
|
16457
|
-
|
16506
|
+
if (timeout) {
|
16507
|
+
clearTimeout(timeout);
|
16508
|
+
timeout = null;
|
16509
|
+
}
|
16458
16510
|
previous = now;
|
16459
16511
|
result = func.apply(context, args);
|
16460
16512
|
if (!timeout) context = args = null;
|
@@ -16475,7 +16527,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16475
16527
|
var later = function() {
|
16476
16528
|
var last = _.now() - timestamp;
|
16477
16529
|
|
16478
|
-
if (last < wait && last
|
16530
|
+
if (last < wait && last >= 0) {
|
16479
16531
|
timeout = setTimeout(later, wait - last);
|
16480
16532
|
} else {
|
16481
16533
|
timeout = null;
|
@@ -16528,7 +16580,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16528
16580
|
};
|
16529
16581
|
};
|
16530
16582
|
|
16531
|
-
// Returns a function that will only be executed after
|
16583
|
+
// Returns a function that will only be executed on and after the Nth call.
|
16532
16584
|
_.after = function(times, func) {
|
16533
16585
|
return function() {
|
16534
16586
|
if (--times < 1) {
|
@@ -16537,15 +16589,14 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16537
16589
|
};
|
16538
16590
|
};
|
16539
16591
|
|
16540
|
-
// Returns a function that will only be executed
|
16592
|
+
// Returns a function that will only be executed up to (but not including) the Nth call.
|
16541
16593
|
_.before = function(times, func) {
|
16542
16594
|
var memo;
|
16543
16595
|
return function() {
|
16544
16596
|
if (--times > 0) {
|
16545
16597
|
memo = func.apply(this, arguments);
|
16546
|
-
} else {
|
16547
|
-
func = null;
|
16548
16598
|
}
|
16599
|
+
if (times <= 1) func = null;
|
16549
16600
|
return memo;
|
16550
16601
|
};
|
16551
16602
|
};
|
@@ -16557,13 +16608,47 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16557
16608
|
// Object Functions
|
16558
16609
|
// ----------------
|
16559
16610
|
|
16560
|
-
//
|
16611
|
+
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
|
16612
|
+
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
|
16613
|
+
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
|
16614
|
+
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
|
16615
|
+
|
16616
|
+
function collectNonEnumProps(obj, keys) {
|
16617
|
+
var nonEnumIdx = nonEnumerableProps.length;
|
16618
|
+
var constructor = obj.constructor;
|
16619
|
+
var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
|
16620
|
+
|
16621
|
+
// Constructor is a special case.
|
16622
|
+
var prop = 'constructor';
|
16623
|
+
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
|
16624
|
+
|
16625
|
+
while (nonEnumIdx--) {
|
16626
|
+
prop = nonEnumerableProps[nonEnumIdx];
|
16627
|
+
if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
|
16628
|
+
keys.push(prop);
|
16629
|
+
}
|
16630
|
+
}
|
16631
|
+
}
|
16632
|
+
|
16633
|
+
// Retrieve the names of an object's own properties.
|
16561
16634
|
// Delegates to **ECMAScript 5**'s native `Object.keys`
|
16562
16635
|
_.keys = function(obj) {
|
16563
16636
|
if (!_.isObject(obj)) return [];
|
16564
16637
|
if (nativeKeys) return nativeKeys(obj);
|
16565
16638
|
var keys = [];
|
16566
16639
|
for (var key in obj) if (_.has(obj, key)) keys.push(key);
|
16640
|
+
// Ahem, IE < 9.
|
16641
|
+
if (hasEnumBug) collectNonEnumProps(obj, keys);
|
16642
|
+
return keys;
|
16643
|
+
};
|
16644
|
+
|
16645
|
+
// Retrieve all the property names of an object.
|
16646
|
+
_.allKeys = function(obj) {
|
16647
|
+
if (!_.isObject(obj)) return [];
|
16648
|
+
var keys = [];
|
16649
|
+
for (var key in obj) keys.push(key);
|
16650
|
+
// Ahem, IE < 9.
|
16651
|
+
if (hasEnumBug) collectNonEnumProps(obj, keys);
|
16567
16652
|
return keys;
|
16568
16653
|
};
|
16569
16654
|
|
@@ -16578,6 +16663,21 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16578
16663
|
return values;
|
16579
16664
|
};
|
16580
16665
|
|
16666
|
+
// Returns the results of applying the iteratee to each element of the object
|
16667
|
+
// In contrast to _.map it returns an object
|
16668
|
+
_.mapObject = function(obj, iteratee, context) {
|
16669
|
+
iteratee = cb(iteratee, context);
|
16670
|
+
var keys = _.keys(obj),
|
16671
|
+
length = keys.length,
|
16672
|
+
results = {},
|
16673
|
+
currentKey;
|
16674
|
+
for (var index = 0; index < length; index++) {
|
16675
|
+
currentKey = keys[index];
|
16676
|
+
results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
|
16677
|
+
}
|
16678
|
+
return results;
|
16679
|
+
};
|
16680
|
+
|
16581
16681
|
// Convert an object into a list of `[key, value]` pairs.
|
16582
16682
|
_.pairs = function(obj) {
|
16583
16683
|
var keys = _.keys(obj);
|
@@ -16610,37 +16710,38 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16610
16710
|
};
|
16611
16711
|
|
16612
16712
|
// Extend a given object with all the properties in passed-in object(s).
|
16613
|
-
_.extend =
|
16614
|
-
|
16615
|
-
|
16616
|
-
|
16617
|
-
|
16618
|
-
|
16619
|
-
|
16620
|
-
|
16621
|
-
|
16622
|
-
|
16713
|
+
_.extend = createAssigner(_.allKeys);
|
16714
|
+
|
16715
|
+
// Assigns a given object with all the own properties in the passed-in object(s)
|
16716
|
+
// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
|
16717
|
+
_.extendOwn = _.assign = createAssigner(_.keys);
|
16718
|
+
|
16719
|
+
// Returns the first key on an object that passes a predicate test
|
16720
|
+
_.findKey = function(obj, predicate, context) {
|
16721
|
+
predicate = cb(predicate, context);
|
16722
|
+
var keys = _.keys(obj), key;
|
16723
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
16724
|
+
key = keys[i];
|
16725
|
+
if (predicate(obj[key], key, obj)) return key;
|
16623
16726
|
}
|
16624
|
-
return obj;
|
16625
16727
|
};
|
16626
16728
|
|
16627
16729
|
// Return a copy of the object only containing the whitelisted properties.
|
16628
|
-
_.pick = function(
|
16629
|
-
var result = {},
|
16730
|
+
_.pick = function(object, oiteratee, context) {
|
16731
|
+
var result = {}, obj = object, iteratee, keys;
|
16630
16732
|
if (obj == null) return result;
|
16631
|
-
if (_.isFunction(
|
16632
|
-
|
16633
|
-
|
16634
|
-
var value = obj[key];
|
16635
|
-
if (iteratee(value, key, obj)) result[key] = value;
|
16636
|
-
}
|
16733
|
+
if (_.isFunction(oiteratee)) {
|
16734
|
+
keys = _.allKeys(obj);
|
16735
|
+
iteratee = optimizeCb(oiteratee, context);
|
16637
16736
|
} else {
|
16638
|
-
|
16639
|
-
|
16640
|
-
|
16641
|
-
|
16642
|
-
|
16643
|
-
|
16737
|
+
keys = flatten(arguments, false, false, 1);
|
16738
|
+
iteratee = function(value, key, obj) { return key in obj; };
|
16739
|
+
obj = Object(obj);
|
16740
|
+
}
|
16741
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
16742
|
+
var key = keys[i];
|
16743
|
+
var value = obj[key];
|
16744
|
+
if (iteratee(value, key, obj)) result[key] = value;
|
16644
16745
|
}
|
16645
16746
|
return result;
|
16646
16747
|
};
|
@@ -16650,7 +16751,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16650
16751
|
if (_.isFunction(iteratee)) {
|
16651
16752
|
iteratee = _.negate(iteratee);
|
16652
16753
|
} else {
|
16653
|
-
var keys = _.map(
|
16754
|
+
var keys = _.map(flatten(arguments, false, false, 1), String);
|
16654
16755
|
iteratee = function(value, key) {
|
16655
16756
|
return !_.contains(keys, key);
|
16656
16757
|
};
|
@@ -16659,16 +16760,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16659
16760
|
};
|
16660
16761
|
|
16661
16762
|
// Fill in a given object with default properties.
|
16662
|
-
_.defaults =
|
16663
|
-
if (!_.isObject(obj)) return obj;
|
16664
|
-
for (var i = 1, length = arguments.length; i < length; i++) {
|
16665
|
-
var source = arguments[i];
|
16666
|
-
for (var prop in source) {
|
16667
|
-
if (obj[prop] === void 0) obj[prop] = source[prop];
|
16668
|
-
}
|
16669
|
-
}
|
16670
|
-
return obj;
|
16671
|
-
};
|
16763
|
+
_.defaults = createAssigner(_.allKeys, true);
|
16672
16764
|
|
16673
16765
|
// Create a (shallow-cloned) duplicate of an object.
|
16674
16766
|
_.clone = function(obj) {
|
@@ -16684,6 +16776,19 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16684
16776
|
return obj;
|
16685
16777
|
};
|
16686
16778
|
|
16779
|
+
// Returns whether an object has a given set of `key:value` pairs.
|
16780
|
+
_.isMatch = function(object, attrs) {
|
16781
|
+
var keys = _.keys(attrs), length = keys.length;
|
16782
|
+
if (object == null) return !length;
|
16783
|
+
var obj = Object(object);
|
16784
|
+
for (var i = 0; i < length; i++) {
|
16785
|
+
var key = keys[i];
|
16786
|
+
if (attrs[key] !== obj[key] || !(key in obj)) return false;
|
16787
|
+
}
|
16788
|
+
return true;
|
16789
|
+
};
|
16790
|
+
|
16791
|
+
|
16687
16792
|
// Internal recursive comparison function for `isEqual`.
|
16688
16793
|
var eq = function(a, b, aStack, bStack) {
|
16689
16794
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
@@ -16718,74 +16823,76 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16718
16823
|
// of `NaN` are not equivalent.
|
16719
16824
|
return +a === +b;
|
16720
16825
|
}
|
16721
|
-
|
16826
|
+
|
16827
|
+
var areArrays = className === '[object Array]';
|
16828
|
+
if (!areArrays) {
|
16829
|
+
if (typeof a != 'object' || typeof b != 'object') return false;
|
16830
|
+
|
16831
|
+
// Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
16832
|
+
// from different frames are.
|
16833
|
+
var aCtor = a.constructor, bCtor = b.constructor;
|
16834
|
+
if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
|
16835
|
+
_.isFunction(bCtor) && bCtor instanceof bCtor)
|
16836
|
+
&& ('constructor' in a && 'constructor' in b)) {
|
16837
|
+
return false;
|
16838
|
+
}
|
16839
|
+
}
|
16722
16840
|
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
16723
16841
|
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
16842
|
+
|
16843
|
+
// Initializing stack of traversed objects.
|
16844
|
+
// It's done here since we only need them for objects and arrays comparison.
|
16845
|
+
aStack = aStack || [];
|
16846
|
+
bStack = bStack || [];
|
16724
16847
|
var length = aStack.length;
|
16725
16848
|
while (length--) {
|
16726
16849
|
// Linear search. Performance is inversely proportional to the number of
|
16727
16850
|
// unique nested structures.
|
16728
16851
|
if (aStack[length] === a) return bStack[length] === b;
|
16729
16852
|
}
|
16730
|
-
|
16731
|
-
// from different frames are.
|
16732
|
-
var aCtor = a.constructor, bCtor = b.constructor;
|
16733
|
-
if (
|
16734
|
-
aCtor !== bCtor &&
|
16735
|
-
// Handle Object.create(x) cases
|
16736
|
-
'constructor' in a && 'constructor' in b &&
|
16737
|
-
!(_.isFunction(aCtor) && aCtor instanceof aCtor &&
|
16738
|
-
_.isFunction(bCtor) && bCtor instanceof bCtor)
|
16739
|
-
) {
|
16740
|
-
return false;
|
16741
|
-
}
|
16853
|
+
|
16742
16854
|
// Add the first object to the stack of traversed objects.
|
16743
16855
|
aStack.push(a);
|
16744
16856
|
bStack.push(b);
|
16745
|
-
|
16857
|
+
|
16746
16858
|
// Recursively compare objects and arrays.
|
16747
|
-
if (
|
16859
|
+
if (areArrays) {
|
16748
16860
|
// Compare array lengths to determine if a deep comparison is necessary.
|
16749
|
-
|
16750
|
-
|
16751
|
-
|
16752
|
-
|
16753
|
-
|
16754
|
-
if (!(result = eq(a[size], b[size], aStack, bStack))) break;
|
16755
|
-
}
|
16861
|
+
length = a.length;
|
16862
|
+
if (length !== b.length) return false;
|
16863
|
+
// Deep compare the contents, ignoring non-numeric properties.
|
16864
|
+
while (length--) {
|
16865
|
+
if (!eq(a[length], b[length], aStack, bStack)) return false;
|
16756
16866
|
}
|
16757
16867
|
} else {
|
16758
16868
|
// Deep compare objects.
|
16759
16869
|
var keys = _.keys(a), key;
|
16760
|
-
|
16870
|
+
length = keys.length;
|
16761
16871
|
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
16762
|
-
|
16763
|
-
|
16764
|
-
|
16765
|
-
|
16766
|
-
|
16767
|
-
if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
|
16768
|
-
}
|
16872
|
+
if (_.keys(b).length !== length) return false;
|
16873
|
+
while (length--) {
|
16874
|
+
// Deep compare each member
|
16875
|
+
key = keys[length];
|
16876
|
+
if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
|
16769
16877
|
}
|
16770
16878
|
}
|
16771
16879
|
// Remove the first object from the stack of traversed objects.
|
16772
16880
|
aStack.pop();
|
16773
16881
|
bStack.pop();
|
16774
|
-
return
|
16882
|
+
return true;
|
16775
16883
|
};
|
16776
16884
|
|
16777
16885
|
// Perform a deep comparison to check if two objects are equal.
|
16778
16886
|
_.isEqual = function(a, b) {
|
16779
|
-
return eq(a, b
|
16887
|
+
return eq(a, b);
|
16780
16888
|
};
|
16781
16889
|
|
16782
16890
|
// Is a given array, string, or object empty?
|
16783
16891
|
// An "empty" object has no enumerable own-properties.
|
16784
16892
|
_.isEmpty = function(obj) {
|
16785
16893
|
if (obj == null) return true;
|
16786
|
-
if (_.isArray(obj) || _.isString(obj) || _.isArguments(obj)) return obj.length === 0;
|
16787
|
-
|
16788
|
-
return true;
|
16894
|
+
if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0;
|
16895
|
+
return _.keys(obj).length === 0;
|
16789
16896
|
};
|
16790
16897
|
|
16791
16898
|
// Is a given value a DOM element?
|
@@ -16805,14 +16912,14 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16805
16912
|
return type === 'function' || type === 'object' && !!obj;
|
16806
16913
|
};
|
16807
16914
|
|
16808
|
-
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
|
16809
|
-
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
|
16915
|
+
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
|
16916
|
+
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
|
16810
16917
|
_['is' + name] = function(obj) {
|
16811
16918
|
return toString.call(obj) === '[object ' + name + ']';
|
16812
16919
|
};
|
16813
16920
|
});
|
16814
16921
|
|
16815
|
-
// Define a fallback version of the method in browsers (ahem, IE), where
|
16922
|
+
// Define a fallback version of the method in browsers (ahem, IE < 9), where
|
16816
16923
|
// there isn't any inspectable "Arguments" type.
|
16817
16924
|
if (!_.isArguments(arguments)) {
|
16818
16925
|
_.isArguments = function(obj) {
|
@@ -16820,8 +16927,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16820
16927
|
};
|
16821
16928
|
}
|
16822
16929
|
|
16823
|
-
// Optimize `isFunction` if appropriate. Work around
|
16824
|
-
|
16930
|
+
// Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
|
16931
|
+
// IE 11 (#1621), and in Safari 8 (#1929).
|
16932
|
+
if (typeof /./ != 'function' && typeof Int8Array != 'object') {
|
16825
16933
|
_.isFunction = function(obj) {
|
16826
16934
|
return typeof obj == 'function' || false;
|
16827
16935
|
};
|
@@ -16884,28 +16992,30 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16884
16992
|
|
16885
16993
|
_.property = function(key) {
|
16886
16994
|
return function(obj) {
|
16995
|
+
return obj == null ? void 0 : obj[key];
|
16996
|
+
};
|
16997
|
+
};
|
16998
|
+
|
16999
|
+
// Generates a function for a given object that returns a given property.
|
17000
|
+
_.propertyOf = function(obj) {
|
17001
|
+
return obj == null ? function(){} : function(key) {
|
16887
17002
|
return obj[key];
|
16888
17003
|
};
|
16889
17004
|
};
|
16890
17005
|
|
16891
|
-
// Returns a predicate for checking whether an object has a given set of
|
16892
|
-
|
16893
|
-
|
17006
|
+
// Returns a predicate for checking whether an object has a given set of
|
17007
|
+
// `key:value` pairs.
|
17008
|
+
_.matcher = _.matches = function(attrs) {
|
17009
|
+
attrs = _.extendOwn({}, attrs);
|
16894
17010
|
return function(obj) {
|
16895
|
-
|
16896
|
-
obj = new Object(obj);
|
16897
|
-
for (var i = 0; i < length; i++) {
|
16898
|
-
var pair = pairs[i], key = pair[0];
|
16899
|
-
if (pair[1] !== obj[key] || !(key in obj)) return false;
|
16900
|
-
}
|
16901
|
-
return true;
|
17011
|
+
return _.isMatch(obj, attrs);
|
16902
17012
|
};
|
16903
17013
|
};
|
16904
17014
|
|
16905
17015
|
// Run a function **n** times.
|
16906
17016
|
_.times = function(n, iteratee, context) {
|
16907
17017
|
var accum = Array(Math.max(0, n));
|
16908
|
-
iteratee =
|
17018
|
+
iteratee = optimizeCb(iteratee, context, 1);
|
16909
17019
|
for (var i = 0; i < n; i++) accum[i] = iteratee(i);
|
16910
17020
|
return accum;
|
16911
17021
|
};
|
@@ -16954,10 +17064,12 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
16954
17064
|
|
16955
17065
|
// If the value of the named `property` is a function then invoke it with the
|
16956
17066
|
// `object` as context; otherwise, return it.
|
16957
|
-
_.result = function(object, property) {
|
16958
|
-
|
16959
|
-
|
16960
|
-
|
17067
|
+
_.result = function(object, property, fallback) {
|
17068
|
+
var value = object == null ? void 0 : object[property];
|
17069
|
+
if (value === void 0) {
|
17070
|
+
value = fallback;
|
17071
|
+
}
|
17072
|
+
return _.isFunction(value) ? value.call(object) : value;
|
16961
17073
|
};
|
16962
17074
|
|
16963
17075
|
// Generate a unique integer id (unique within the entire client session).
|
@@ -17072,8 +17184,8 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
17072
17184
|
// underscore functions. Wrapped objects may be chained.
|
17073
17185
|
|
17074
17186
|
// Helper function to continue chaining intermediate results.
|
17075
|
-
var result = function(obj) {
|
17076
|
-
return
|
17187
|
+
var result = function(instance, obj) {
|
17188
|
+
return instance._chain ? _(obj).chain() : obj;
|
17077
17189
|
};
|
17078
17190
|
|
17079
17191
|
// Add your own custom functions to the Underscore object.
|
@@ -17083,7 +17195,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
17083
17195
|
_.prototype[name] = function() {
|
17084
17196
|
var args = [this._wrapped];
|
17085
17197
|
push.apply(args, arguments);
|
17086
|
-
return result
|
17198
|
+
return result(this, func.apply(_, args));
|
17087
17199
|
};
|
17088
17200
|
});
|
17089
17201
|
};
|
@@ -17098,7 +17210,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
17098
17210
|
var obj = this._wrapped;
|
17099
17211
|
method.apply(obj, arguments);
|
17100
17212
|
if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
|
17101
|
-
return result
|
17213
|
+
return result(this, obj);
|
17102
17214
|
};
|
17103
17215
|
});
|
17104
17216
|
|
@@ -17106,7 +17218,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
17106
17218
|
_.each(['concat', 'join', 'slice'], function(name) {
|
17107
17219
|
var method = ArrayProto[name];
|
17108
17220
|
_.prototype[name] = function() {
|
17109
|
-
return result
|
17221
|
+
return result(this, method.apply(this._wrapped, arguments));
|
17110
17222
|
};
|
17111
17223
|
});
|
17112
17224
|
|
@@ -17115,6 +17227,14 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
17115
17227
|
return this._wrapped;
|
17116
17228
|
};
|
17117
17229
|
|
17230
|
+
// Provide unwrapping proxy for some methods used in engine operations
|
17231
|
+
// such as arithmetic and JSON stringification.
|
17232
|
+
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
|
17233
|
+
|
17234
|
+
_.prototype.toString = function() {
|
17235
|
+
return '' + this._wrapped;
|
17236
|
+
};
|
17237
|
+
|
17118
17238
|
// AMD registration happens at the end for compatibility with AMD loaders
|
17119
17239
|
// that may not enforce next-turn semantics on modules. Even though general
|
17120
17240
|
// practice for AMD registration is to be anonymous, underscore registers
|