forked from segmentio/analytics.js
/
analytics.js
14157 lines (12032 loc) · 345 KB
/
analytics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.analytics = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
/**
* Analytics.js
*
* (C) 2015 Segment.io Inc.
*/
var analytics = require('@segment/analytics.js-core');
var Integrations = require('./integrations');
/**
* Expose the `analytics` singleton.
*/
module.exports = exports = analytics;
/**
* Expose require.
*/
analytics.require = require;
/**
* Expose `VERSION`.
*/
exports.VERSION = require('../package.json').version;
/**
* Add integrations.
*/
Object.keys(Integrations).forEach(function(name) {
analytics.use(Integrations[name]);
});
},{"../package.json":123,"./integrations":2,"@segment/analytics.js-core":22}],2:[function(require,module,exports){
/* eslint quote-props: off */
'use strict';
/*
Add all integrations you want registered here.
Integration repos: https://github.com/segment-integrations?utf8=%E2%9C%93&query=analytics.js
Make sure the integrations added are also installed and saved in the package.json
*/
module.exports = {
'findhotel': require('@segment/analytics.js-integration-segmentio'),
'google-tag-manager': require('@segment/analytics.js-integration-google-tag-manager')
};
},{"@segment/analytics.js-integration-google-tag-manager":29,"@segment/analytics.js-integration-segmentio":30}],3:[function(require,module,exports){
'use strict';
/*
* Module dependencies.
*/
var arity = require('@ndhoule/arity');
var objToString = Object.prototype.toString;
/**
* Determine if a value is a function.
*
* @param {*} val
* @return {boolean}
*/
// TODO: Move to lib
var isFunction = function(val) {
return typeof val === 'function';
};
/**
* Determine if a value is a number.
*
* @param {*} val
* @return {boolean}
*/
// TODO: Move to lib
var isNumber = function(val) {
var type = typeof val;
return type === 'number' || (type === 'object' && objToString.call(val) === '[object Number]');
};
/**
* Wrap a function `fn` in a function that will invoke `fn` when invoked `n` or
* more times.
*
* @name after
* @api public
* @category Function
* @param {Number} n The number of
* @param {Function} fn The function to wrap.
* @return {Function} A function that will call `fn` after `n` or more
* invocations.
* @example
*/
var after = function after(n, fn) {
if (!isNumber(n)) {
throw new TypeError('Expected a number but received ' + typeof n);
}
if (!isFunction(fn)) {
throw new TypeError('Expected a function but received ' + typeof fn);
}
var callCount = 0;
return arity(fn.length, function() {
callCount += 1;
if (callCount < n) {
return;
}
return fn.apply(this, arguments);
});
};
/*
* Exports.
*/
module.exports = after;
},{"@ndhoule/arity":4}],4:[function(require,module,exports){
'use strict';
var objToString = Object.prototype.toString;
/**
* Determine if a value is a function.
*
* @param {*} val
* @return {boolean}
*/
// TODO: Move to lib
var isFunction = function(val) {
return typeof val === 'function';
};
/**
* Determine if a value is a number.
*
* @param {*} val
* @return {boolean}
*/
// TODO: Move to lib
var isNumber = function(val) {
var type = typeof val;
return type === 'number' || (type === 'object' && objToString.call(val) === '[object Number]');
};
/**
* Creates an array of generic, numbered argument names.
*
* @name createParams
* @api private
* @param {number} n
* @return {Array}
* @example
* argNames(2);
* //=> ['arg1', 'arg2']
*/
var createParams = function createParams(n) {
var args = [];
for (var i = 1; i <= n; i += 1) {
args.push('arg' + i);
}
return args;
};
/**
* Dynamically construct a wrapper function of `n` arity that.
*
* If at all possible, prefer a function from the arity wrapper cache above to
* avoid allocating a new function at runtime.
*
* @name createArityWrapper
* @api private
* @param {number} n
* @return {Function(Function)}
*/
var createArityWrapper = function createArityWrapper(n) {
var paramNames = createParams(n).join(', ');
var wrapperBody = ''.concat(
' return function(', paramNames, ') {\n',
' return func.apply(this, arguments);\n',
' };'
);
/* eslint-disable no-new-func */
return new Function('func', wrapperBody);
/* eslint-enable no-new-func */
};
// Cache common arity wrappers to avoid constructing them at runtime
var arityWrapperCache = [
/* eslint-disable no-unused-vars */
function(fn) {
return function() {
return fn.apply(this, arguments);
};
},
function(fn) {
return function(arg1) {
return fn.apply(this, arguments);
};
},
function(fn) {
return function(arg1, arg2) {
return fn.apply(this, arguments);
};
},
function(fn) {
return function(arg1, arg2, arg3) {
return fn.apply(this, arguments);
};
},
function(fn) {
return function(arg1, arg2, arg3, arg4) {
return fn.apply(this, arguments);
};
},
function(fn) {
return function(arg1, arg2, arg3, arg4, arg5) {
return fn.apply(this, arguments);
};
}
/* eslint-enable no-unused-vars */
];
/**
* Takes a function and an [arity](https://en.wikipedia.org/wiki/Arity) `n`, and returns a new
* function that expects `n` arguments.
*
* @name arity
* @api public
* @category Function
* @see {@link curry}
* @param {Number} n The desired arity of the returned function.
* @param {Function} fn The function to wrap.
* @return {Function} A function of n arity, wrapping `fn`.
* @example
* var add = function(a, b) {
* return a + b;
* };
*
* // Check the number of arguments this function expects by accessing `.length`:
* add.length;
* //=> 2
*
* var unaryAdd = arity(1, add);
* unaryAdd.length;
* //=> 1
*/
var arity = function arity(n, func) {
if (!isFunction(func)) {
throw new TypeError('Expected a function but got ' + typeof func);
}
n = Math.max(isNumber(n) ? n : 0, 0);
if (!arityWrapperCache[n]) {
arityWrapperCache[n] = createArityWrapper(n);
}
return arityWrapperCache[n](func);
};
/*
* Exports.
*/
module.exports = arity;
},{}],5:[function(require,module,exports){
'use strict';
/*
* Module dependencies.
*/
var type = require('component-type');
/**
* Deeply clone an object.
*
* @param {*} obj Any object.
*/
var clone = function clone(obj) {
var t = type(obj);
if (t === 'object') {
var copy = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
copy[key] = clone(obj[key]);
}
}
return copy;
}
if (t === 'array') {
var copy = new Array(obj.length);
for (var i = 0, l = obj.length; i < l; i++) {
copy[i] = clone(obj[i]);
}
return copy;
}
if (t === 'regexp') {
// from millermedeiros/amd-utils - MIT
var flags = '';
flags += obj.multiline ? 'm' : '';
flags += obj.global ? 'g' : '';
flags += obj.ignoreCase ? 'i' : '';
return new RegExp(obj.source, flags);
}
if (t === 'date') {
return new Date(obj.getTime());
}
// string, number, boolean, etc.
return obj;
};
/*
* Exports.
*/
module.exports = clone;
},{"component-type":76}],6:[function(require,module,exports){
'use strict';
/*
* Module dependencies.
*/
var drop = require('@ndhoule/drop');
var rest = require('@ndhoule/rest');
var has = Object.prototype.hasOwnProperty;
var objToString = Object.prototype.toString;
/**
* Returns `true` if a value is an object, otherwise `false`.
*
* @name isObject
* @api private
* @param {*} val The value to test.
* @return {boolean}
*/
// TODO: Move to a library
var isObject = function isObject(value) {
return Boolean(value) && typeof value === 'object';
};
/**
* Returns `true` if a value is a plain object, otherwise `false`.
*
* @name isPlainObject
* @api private
* @param {*} val The value to test.
* @return {boolean}
*/
// TODO: Move to a library
var isPlainObject = function isPlainObject(value) {
return Boolean(value) && objToString.call(value) === '[object Object]';
};
/**
* Assigns a key-value pair to a target object when the value assigned is owned,
* and where target[key] is undefined.
*
* @name shallowCombiner
* @api private
* @param {Object} target
* @param {Object} source
* @param {*} value
* @param {string} key
*/
var shallowCombiner = function shallowCombiner(target, source, value, key) {
if (has.call(source, key) && target[key] === undefined) {
target[key] = value;
}
return source;
};
/**
* Assigns a key-value pair to a target object when the value assigned is owned,
* and where target[key] is undefined; also merges objects recursively.
*
* @name deepCombiner
* @api private
* @param {Object} target
* @param {Object} source
* @param {*} value
* @param {string} key
* @return {Object}
*/
var deepCombiner = function(target, source, value, key) {
if (has.call(source, key)) {
if (isPlainObject(target[key]) && isPlainObject(value)) {
target[key] = defaultsDeep(target[key], value);
} else if (target[key] === undefined) {
target[key] = value;
}
}
return source;
};
/**
* TODO: Document
*
* @name defaultsWith
* @api private
* @param {Function} combiner
* @param {Object} target
* @param {...Object} sources
* @return {Object} Return the input `target`.
*/
var defaultsWith = function(combiner, target /*, ...sources */) {
if (!isObject(target)) {
return target;
}
combiner = combiner || shallowCombiner;
var sources = drop(2, arguments);
for (var i = 0; i < sources.length; i += 1) {
for (var key in sources[i]) {
combiner(target, sources[i], sources[i][key], key);
}
}
return target;
};
/**
* Copies owned, enumerable properties from a source object(s) to a target
* object when the value of that property on the source object is `undefined`.
* Recurses on objects.
*
* @name defaultsDeep
* @api public
* @param {Object} target
* @param {...Object} sources
* @return {Object} The input `target`.
*/
var defaultsDeep = function defaultsDeep(target /*, sources */) {
// TODO: Replace with `partial` call?
return defaultsWith.apply(null, [deepCombiner, target].concat(rest(arguments)));
};
/**
* Copies owned, enumerable properties from a source object(s) to a target
* object when the value of that property on the source object is `undefined`.
*
* @name defaults
* @api public
* @param {Object} target
* @param {...Object} sources
* @return {Object}
* @example
* var a = { a: 1 };
* var b = { a: 2, b: 2 };
*
* defaults(a, b);
* console.log(a); //=> { a: 1, b: 2 }
*/
var defaults = function(target /*, ...sources */) {
// TODO: Replace with `partial` call?
return defaultsWith.apply(null, [null, target].concat(rest(arguments)));
};
/*
* Exports.
*/
module.exports = defaults;
module.exports.deep = defaultsDeep;
},{"@ndhoule/drop":7,"@ndhoule/rest":16}],7:[function(require,module,exports){
'use strict';
var max = Math.max;
/**
* Produce a new array composed of all but the first `n` elements of an input `collection`.
*
* @name drop
* @api public
* @param {number} count The number of elements to drop.
* @param {Array} collection The collection to iterate over.
* @return {Array} A new array containing all but the first element from `collection`.
* @example
* drop(0, [1, 2, 3]); // => [1, 2, 3]
* drop(1, [1, 2, 3]); // => [2, 3]
* drop(2, [1, 2, 3]); // => [3]
* drop(3, [1, 2, 3]); // => []
* drop(4, [1, 2, 3]); // => []
*/
var drop = function drop(count, collection) {
var length = collection ? collection.length : 0;
if (!length) {
return [];
}
// Preallocating an array *significantly* boosts performance when dealing with
// `arguments` objects on v8. For a summary, see:
// https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments
var toDrop = max(Number(count) || 0, 0);
var resultsLength = max(length - toDrop, 0);
var results = new Array(resultsLength);
for (var i = 0; i < resultsLength; i += 1) {
results[i] = collection[i + toDrop];
}
return results;
};
/*
* Exports.
*/
module.exports = drop;
},{}],8:[function(require,module,exports){
'use strict';
/*
* Module dependencies.
*/
var keys = require('@ndhoule/keys');
var objToString = Object.prototype.toString;
/**
* Tests if a value is a number.
*
* @name isNumber
* @api private
* @param {*} val The value to test.
* @return {boolean} Returns `true` if `val` is a number, otherwise `false`.
*/
// TODO: Move to library
var isNumber = function isNumber(val) {
var type = typeof val;
return type === 'number' || (type === 'object' && objToString.call(val) === '[object Number]');
};
/**
* Tests if a value is an array.
*
* @name isArray
* @api private
* @param {*} val The value to test.
* @return {boolean} Returns `true` if the value is an array, otherwise `false`.
*/
// TODO: Move to library
var isArray = typeof Array.isArray === 'function' ? Array.isArray : function isArray(val) {
return objToString.call(val) === '[object Array]';
};
/**
* Tests if a value is array-like. Array-like means the value is not a function and has a numeric
* `.length` property.
*
* @name isArrayLike
* @api private
* @param {*} val
* @return {boolean}
*/
// TODO: Move to library
var isArrayLike = function isArrayLike(val) {
return val != null && (isArray(val) || (val !== 'function' && isNumber(val.length)));
};
/**
* Internal implementation of `each`. Works on arrays and array-like data structures.
*
* @name arrayEach
* @api private
* @param {Function(value, key, collection)} iterator The function to invoke per iteration.
* @param {Array} array The array(-like) structure to iterate over.
* @return {undefined}
*/
var arrayEach = function arrayEach(iterator, array) {
for (var i = 0; i < array.length; i += 1) {
// Break iteration early if `iterator` returns `false`
if (iterator(array[i], i, array) === false) {
break;
}
}
};
/**
* Internal implementation of `each`. Works on objects.
*
* @name baseEach
* @api private
* @param {Function(value, key, collection)} iterator The function to invoke per iteration.
* @param {Object} object The object to iterate over.
* @return {undefined}
*/
var baseEach = function baseEach(iterator, object) {
var ks = keys(object);
for (var i = 0; i < ks.length; i += 1) {
// Break iteration early if `iterator` returns `false`
if (iterator(object[ks[i]], ks[i], object) === false) {
break;
}
}
};
/**
* Iterate over an input collection, invoking an `iterator` function for each element in the
* collection and passing to it three arguments: `(value, index, collection)`. The `iterator`
* function can end iteration early by returning `false`.
*
* @name each
* @api public
* @param {Function(value, key, collection)} iterator The function to invoke per iteration.
* @param {Array|Object|string} collection The collection to iterate over.
* @return {undefined} Because `each` is run only for side effects, always returns `undefined`.
* @example
* var log = console.log.bind(console);
*
* each(log, ['a', 'b', 'c']);
* //-> 'a', 0, ['a', 'b', 'c']
* //-> 'b', 1, ['a', 'b', 'c']
* //-> 'c', 2, ['a', 'b', 'c']
* //=> undefined
*
* each(log, 'tim');
* //-> 't', 2, 'tim'
* //-> 'i', 1, 'tim'
* //-> 'm', 0, 'tim'
* //=> undefined
*
* // Note: Iteration order not guaranteed across environments
* each(log, { name: 'tim', occupation: 'enchanter' });
* //-> 'tim', 'name', { name: 'tim', occupation: 'enchanter' }
* //-> 'enchanter', 'occupation', { name: 'tim', occupation: 'enchanter' }
* //=> undefined
*/
var each = function each(iterator, collection) {
return (isArrayLike(collection) ? arrayEach : baseEach).call(this, iterator, collection);
};
/*
* Exports.
*/
module.exports = each;
},{"@ndhoule/keys":13}],9:[function(require,module,exports){
'use strict';
/*
* Module dependencies.
*/
var each = require('@ndhoule/each');
/**
* Check if a predicate function returns `true` for all values in a `collection`.
* Checks owned, enumerable values and exits early when `predicate` returns
* `false`.
*
* @name every
* @param {Function} predicate The function used to test values.
* @param {Array|Object|string} collection The collection to search.
* @return {boolean} True if all values passes the predicate test, otherwise false.
* @example
* var isEven = function(num) { return num % 2 === 0; };
*
* every(isEven, []); // => true
* every(isEven, [1, 2]); // => false
* every(isEven, [2, 4, 6]); // => true
*/
var every = function every(predicate, collection) {
if (typeof predicate !== 'function') {
throw new TypeError('`predicate` must be a function but was a ' + typeof predicate);
}
var result = true;
each(function(val, key, collection) {
result = !!predicate(val, key, collection);
// Exit early
if (!result) {
return false;
}
}, collection);
return result;
};
/*
* Exports.
*/
module.exports = every;
},{"@ndhoule/each":8}],10:[function(require,module,exports){
'use strict';
var has = Object.prototype.hasOwnProperty;
/**
* Copy the properties of one or more `objects` onto a destination object. Input objects are iterated over
* in left-to-right order, so duplicate properties on later objects will overwrite those from
* erevious ones. Only enumerable and own properties of the input objects are copied onto the
* resulting object.
*
* @name extend
* @api public
* @category Object
* @param {Object} dest The destination object.
* @param {...Object} sources The source objects.
* @return {Object} `dest`, extended with the properties of all `sources`.
* @example
* var a = { a: 'a' };
* var b = { b: 'b' };
* var c = { c: 'c' };
*
* extend(a, b, c);
* //=> { a: 'a', b: 'b', c: 'c' };
*/
var extend = function extend(dest /*, sources */) {
var sources = Array.prototype.slice.call(arguments, 1);
for (var i = 0; i < sources.length; i += 1) {
for (var key in sources[i]) {
if (has.call(sources[i], key)) {
dest[key] = sources[i][key];
}
}
}
return dest;
};
/*
* Exports.
*/
module.exports = extend;
},{}],11:[function(require,module,exports){
'use strict';
/*
* Module dependencies.
*/
var each = require('@ndhoule/each');
/**
* Reduces all the values in a collection down into a single value. Does so by iterating through the
* collection from left to right, repeatedly calling an `iterator` function and passing to it four
* arguments: `(accumulator, value, index, collection)`.
*
* Returns the final return value of the `iterator` function.
*
* @name foldl
* @api public
* @param {Function} iterator The function to invoke per iteration.
* @param {*} accumulator The initial accumulator value, passed to the first invocation of `iterator`.
* @param {Array|Object} collection The collection to iterate over.
* @return {*} The return value of the final call to `iterator`.
* @example
* foldl(function(total, n) {
* return total + n;
* }, 0, [1, 2, 3]);
* //=> 6
*
* var phonebook = { bob: '555-111-2345', tim: '655-222-6789', sheila: '655-333-1298' };
*
* foldl(function(results, phoneNumber) {
* if (phoneNumber[0] === '6') {
* return results.concat(phoneNumber);
* }
* return results;
* }, [], phonebook);
* // => ['655-222-6789', '655-333-1298']
*/
var foldl = function foldl(iterator, accumulator, collection) {
if (typeof iterator !== 'function') {
throw new TypeError('Expected a function but received a ' + typeof iterator);
}
each(function(val, i, collection) {
accumulator = iterator(accumulator, val, i, collection);
}, collection);
return accumulator;
};
/*
* Exports.
*/
module.exports = foldl;
},{"@ndhoule/each":8}],12:[function(require,module,exports){
'use strict';
/*
* Module dependencies.
*/
var each = require('@ndhoule/each');
var strIndexOf = String.prototype.indexOf;
/**
* Object.is/sameValueZero polyfill.
*
* @api private
* @param {*} value1
* @param {*} value2
* @return {boolean}
*/
// TODO: Move to library
var sameValueZero = function sameValueZero(value1, value2) {
// Normal values and check for 0 / -0
if (value1 === value2) {
return value1 !== 0 || 1 / value1 === 1 / value2;
}
// NaN
return value1 !== value1 && value2 !== value2;
};
/**
* Searches a given `collection` for a value, returning true if the collection
* contains the value and false otherwise. Can search strings, arrays, and
* objects.
*
* @name includes
* @api public
* @param {*} searchElement The element to search for.
* @param {Object|Array|string} collection The collection to search.
* @return {boolean}
* @example
* includes(2, [1, 2, 3]);
* //=> true
*
* includes(4, [1, 2, 3]);
* //=> false
*
* includes(2, { a: 1, b: 2, c: 3 });
* //=> true
*
* includes('a', { a: 1, b: 2, c: 3 });
* //=> false
*
* includes('abc', 'xyzabc opq');
* //=> true
*
* includes('nope', 'xyzabc opq');
* //=> false
*/
var includes = function includes(searchElement, collection) {
var found = false;
// Delegate to String.prototype.indexOf when `collection` is a string
if (typeof collection === 'string') {
return strIndexOf.call(collection, searchElement) !== -1;
}
// Iterate through enumerable/own array elements and object properties.
each(function(value) {
if (sameValueZero(value, searchElement)) {
found = true;
// Exit iteration early when found
return false;
}
}, collection);
return found;
};
/*
* Exports.
*/
module.exports = includes;
},{"@ndhoule/each":8}],13:[function(require,module,exports){
'use strict';
var hop = Object.prototype.hasOwnProperty;
var strCharAt = String.prototype.charAt;
var toStr = Object.prototype.toString;
/**
* Returns the character at a given index.
*
* @param {string} str
* @param {number} index
* @return {string|undefined}
*/
// TODO: Move to a library
var charAt = function(str, index) {
return strCharAt.call(str, index);
};
/**
* hasOwnProperty, wrapped as a function.
*
* @name has
* @api private
* @param {*} context
* @param {string|number} prop
* @return {boolean}
*/
// TODO: Move to a library
var has = function has(context, prop) {
return hop.call(context, prop);
};
/**
* Returns true if a value is a string, otherwise false.
*
* @name isString
* @api private
* @param {*} val
* @return {boolean}
*/
// TODO: Move to a library
var isString = function isString(val) {
return toStr.call(val) === '[object String]';
};
/**
* Returns true if a value is array-like, otherwise false. Array-like means a
* value is not null, undefined, or a function, and has a numeric `length`
* property.
*
* @name isArrayLike
* @api private
* @param {*} val
* @return {boolean}
*/
// TODO: Move to a library
var isArrayLike = function isArrayLike(val) {
return val != null && (typeof val !== 'function' && typeof val.length === 'number');
};
/**
* indexKeys
*
* @name indexKeys
* @api private
* @param {} target
* @param {Function} pred
* @return {Array}
*/
var indexKeys = function indexKeys(target, pred) {
pred = pred || has;
var results = [];
for (var i = 0, len = target.length; i < len; i += 1) {
if (pred(target, i)) {
results.push(String(i));
}
}
return results;
};
/**
* Returns an array of an object's owned keys.
*
* @name objectKeys
* @api private