rimless 0.1.6 → 0.2.0

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.
package/lib/index.js DELETED
@@ -1,2307 +0,0 @@
1
- /**
2
- * check if run in a webworker
3
- *
4
- * @param event
5
- */
6
- function isWorker() {
7
- return typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope;
8
- }
9
- /**
10
- * we cannot send functions through postMessage
11
- * extract the path to all functions in the schema
12
- *
13
- * @param obj
14
- */
15
- function extractMethods(obj) {
16
- const paths = [];
17
- (function parse(obj, path = "") {
18
- Object.keys(obj).forEach((prop) => {
19
- const propPath = path ? `${path}.${prop}` : prop;
20
- if (obj[prop] === Object(obj[prop])) {
21
- parse(obj[prop], propPath);
22
- }
23
- if (typeof obj[prop] === "function") {
24
- paths.push(propPath);
25
- }
26
- });
27
- }(obj));
28
- return paths;
29
- }
30
- const urlRegex = /^(https?:|file:)?\/\/([^/:]+)?(:(\d+))?/;
31
- const ports = { "http:": "80", "https:": "443" };
32
- /**
33
- * convert the url into an origin (remove paths)
34
- *
35
- * @param url
36
- */
37
- function getOriginFromURL(url) {
38
- const { location } = document;
39
- const regexResult = urlRegex.exec(url || "");
40
- let protocol;
41
- let hostname;
42
- let port;
43
- if (regexResult) {
44
- // It's an absolute URL. Use the parsed info.
45
- // regexResult[1] will be undefined if the URL starts with //
46
- [, protocol = location.protocol, hostname, , port] = regexResult;
47
- }
48
- else {
49
- // It's a relative path. Use the current location's info.
50
- protocol = location.protocol;
51
- hostname = location.hostname;
52
- port = location.port;
53
- }
54
- // If the protocol is file, the origin is "null"
55
- // The origin of a document with file protocol is an opaque origin
56
- // and its serialization "null" [1]
57
- // [1] https://html.spec.whatwg.org/multipage/origin.html#origin
58
- if (protocol === "file:") {
59
- return "null";
60
- }
61
- // If the port is the default for the protocol, we don't want to add it to the origin string
62
- // or it won't match the message's event.origin.
63
- const portSuffix = port && port !== ports[protocol] ? `:${port}` : "";
64
- return `${protocol}//${hostname}${portSuffix}`;
65
- }
66
-
67
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
68
-
69
- /**
70
- * lodash (Custom Build) <https://lodash.com/>
71
- * Build: `lodash modularize exports="npm" -o ./`
72
- * Copyright jQuery Foundation and other contributors <https://jquery.org/>
73
- * Released under MIT license <https://lodash.com/license>
74
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
75
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
76
- */
77
-
78
- /** Used as the `TypeError` message for "Functions" methods. */
79
- var FUNC_ERROR_TEXT = 'Expected a function';
80
-
81
- /** Used to stand-in for `undefined` hash values. */
82
- var HASH_UNDEFINED = '__lodash_hash_undefined__';
83
-
84
- /** Used as references for various `Number` constants. */
85
- var INFINITY = 1 / 0;
86
-
87
- /** `Object#toString` result references. */
88
- var funcTag = '[object Function]',
89
- genTag = '[object GeneratorFunction]',
90
- symbolTag = '[object Symbol]';
91
-
92
- /** Used to match property names within property paths. */
93
- var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
94
- reIsPlainProp = /^\w*$/,
95
- reLeadingDot = /^\./,
96
- rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
97
-
98
- /**
99
- * Used to match `RegExp`
100
- * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
101
- */
102
- var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
103
-
104
- /** Used to match backslashes in property paths. */
105
- var reEscapeChar = /\\(\\)?/g;
106
-
107
- /** Used to detect host constructors (Safari). */
108
- var reIsHostCtor = /^\[object .+?Constructor\]$/;
109
-
110
- /** Detect free variable `global` from Node.js. */
111
- var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
112
-
113
- /** Detect free variable `self`. */
114
- var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
115
-
116
- /** Used as a reference to the global object. */
117
- var root = freeGlobal || freeSelf || Function('return this')();
118
-
119
- /**
120
- * Gets the value at `key` of `object`.
121
- *
122
- * @private
123
- * @param {Object} [object] The object to query.
124
- * @param {string} key The key of the property to get.
125
- * @returns {*} Returns the property value.
126
- */
127
- function getValue(object, key) {
128
- return object == null ? undefined : object[key];
129
- }
130
-
131
- /**
132
- * Checks if `value` is a host object in IE < 9.
133
- *
134
- * @private
135
- * @param {*} value The value to check.
136
- * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
137
- */
138
- function isHostObject(value) {
139
- // Many host objects are `Object` objects that can coerce to strings
140
- // despite having improperly defined `toString` methods.
141
- var result = false;
142
- if (value != null && typeof value.toString != 'function') {
143
- try {
144
- result = !!(value + '');
145
- } catch (e) {}
146
- }
147
- return result;
148
- }
149
-
150
- /** Used for built-in method references. */
151
- var arrayProto = Array.prototype,
152
- funcProto = Function.prototype,
153
- objectProto = Object.prototype;
154
-
155
- /** Used to detect overreaching core-js shims. */
156
- var coreJsData = root['__core-js_shared__'];
157
-
158
- /** Used to detect methods masquerading as native. */
159
- var maskSrcKey = (function() {
160
- var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
161
- return uid ? ('Symbol(src)_1.' + uid) : '';
162
- }());
163
-
164
- /** Used to resolve the decompiled source of functions. */
165
- var funcToString = funcProto.toString;
166
-
167
- /** Used to check objects for own properties. */
168
- var hasOwnProperty = objectProto.hasOwnProperty;
169
-
170
- /**
171
- * Used to resolve the
172
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
173
- * of values.
174
- */
175
- var objectToString = objectProto.toString;
176
-
177
- /** Used to detect if a method is native. */
178
- var reIsNative = RegExp('^' +
179
- funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
180
- .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
181
- );
182
-
183
- /** Built-in value references. */
184
- var Symbol = root.Symbol,
185
- splice = arrayProto.splice;
186
-
187
- /* Built-in method references that are verified to be native. */
188
- var Map = getNative(root, 'Map'),
189
- nativeCreate = getNative(Object, 'create');
190
-
191
- /** Used to convert symbols to primitives and strings. */
192
- var symbolProto = Symbol ? Symbol.prototype : undefined,
193
- symbolToString = symbolProto ? symbolProto.toString : undefined;
194
-
195
- /**
196
- * Creates a hash object.
197
- *
198
- * @private
199
- * @constructor
200
- * @param {Array} [entries] The key-value pairs to cache.
201
- */
202
- function Hash(entries) {
203
- var index = -1,
204
- length = entries ? entries.length : 0;
205
-
206
- this.clear();
207
- while (++index < length) {
208
- var entry = entries[index];
209
- this.set(entry[0], entry[1]);
210
- }
211
- }
212
-
213
- /**
214
- * Removes all key-value entries from the hash.
215
- *
216
- * @private
217
- * @name clear
218
- * @memberOf Hash
219
- */
220
- function hashClear() {
221
- this.__data__ = nativeCreate ? nativeCreate(null) : {};
222
- }
223
-
224
- /**
225
- * Removes `key` and its value from the hash.
226
- *
227
- * @private
228
- * @name delete
229
- * @memberOf Hash
230
- * @param {Object} hash The hash to modify.
231
- * @param {string} key The key of the value to remove.
232
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
233
- */
234
- function hashDelete(key) {
235
- return this.has(key) && delete this.__data__[key];
236
- }
237
-
238
- /**
239
- * Gets the hash value for `key`.
240
- *
241
- * @private
242
- * @name get
243
- * @memberOf Hash
244
- * @param {string} key The key of the value to get.
245
- * @returns {*} Returns the entry value.
246
- */
247
- function hashGet(key) {
248
- var data = this.__data__;
249
- if (nativeCreate) {
250
- var result = data[key];
251
- return result === HASH_UNDEFINED ? undefined : result;
252
- }
253
- return hasOwnProperty.call(data, key) ? data[key] : undefined;
254
- }
255
-
256
- /**
257
- * Checks if a hash value for `key` exists.
258
- *
259
- * @private
260
- * @name has
261
- * @memberOf Hash
262
- * @param {string} key The key of the entry to check.
263
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
264
- */
265
- function hashHas(key) {
266
- var data = this.__data__;
267
- return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
268
- }
269
-
270
- /**
271
- * Sets the hash `key` to `value`.
272
- *
273
- * @private
274
- * @name set
275
- * @memberOf Hash
276
- * @param {string} key The key of the value to set.
277
- * @param {*} value The value to set.
278
- * @returns {Object} Returns the hash instance.
279
- */
280
- function hashSet(key, value) {
281
- var data = this.__data__;
282
- data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
283
- return this;
284
- }
285
-
286
- // Add methods to `Hash`.
287
- Hash.prototype.clear = hashClear;
288
- Hash.prototype['delete'] = hashDelete;
289
- Hash.prototype.get = hashGet;
290
- Hash.prototype.has = hashHas;
291
- Hash.prototype.set = hashSet;
292
-
293
- /**
294
- * Creates an list cache object.
295
- *
296
- * @private
297
- * @constructor
298
- * @param {Array} [entries] The key-value pairs to cache.
299
- */
300
- function ListCache(entries) {
301
- var index = -1,
302
- length = entries ? entries.length : 0;
303
-
304
- this.clear();
305
- while (++index < length) {
306
- var entry = entries[index];
307
- this.set(entry[0], entry[1]);
308
- }
309
- }
310
-
311
- /**
312
- * Removes all key-value entries from the list cache.
313
- *
314
- * @private
315
- * @name clear
316
- * @memberOf ListCache
317
- */
318
- function listCacheClear() {
319
- this.__data__ = [];
320
- }
321
-
322
- /**
323
- * Removes `key` and its value from the list cache.
324
- *
325
- * @private
326
- * @name delete
327
- * @memberOf ListCache
328
- * @param {string} key The key of the value to remove.
329
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
330
- */
331
- function listCacheDelete(key) {
332
- var data = this.__data__,
333
- index = assocIndexOf(data, key);
334
-
335
- if (index < 0) {
336
- return false;
337
- }
338
- var lastIndex = data.length - 1;
339
- if (index == lastIndex) {
340
- data.pop();
341
- } else {
342
- splice.call(data, index, 1);
343
- }
344
- return true;
345
- }
346
-
347
- /**
348
- * Gets the list cache value for `key`.
349
- *
350
- * @private
351
- * @name get
352
- * @memberOf ListCache
353
- * @param {string} key The key of the value to get.
354
- * @returns {*} Returns the entry value.
355
- */
356
- function listCacheGet(key) {
357
- var data = this.__data__,
358
- index = assocIndexOf(data, key);
359
-
360
- return index < 0 ? undefined : data[index][1];
361
- }
362
-
363
- /**
364
- * Checks if a list cache value for `key` exists.
365
- *
366
- * @private
367
- * @name has
368
- * @memberOf ListCache
369
- * @param {string} key The key of the entry to check.
370
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
371
- */
372
- function listCacheHas(key) {
373
- return assocIndexOf(this.__data__, key) > -1;
374
- }
375
-
376
- /**
377
- * Sets the list cache `key` to `value`.
378
- *
379
- * @private
380
- * @name set
381
- * @memberOf ListCache
382
- * @param {string} key The key of the value to set.
383
- * @param {*} value The value to set.
384
- * @returns {Object} Returns the list cache instance.
385
- */
386
- function listCacheSet(key, value) {
387
- var data = this.__data__,
388
- index = assocIndexOf(data, key);
389
-
390
- if (index < 0) {
391
- data.push([key, value]);
392
- } else {
393
- data[index][1] = value;
394
- }
395
- return this;
396
- }
397
-
398
- // Add methods to `ListCache`.
399
- ListCache.prototype.clear = listCacheClear;
400
- ListCache.prototype['delete'] = listCacheDelete;
401
- ListCache.prototype.get = listCacheGet;
402
- ListCache.prototype.has = listCacheHas;
403
- ListCache.prototype.set = listCacheSet;
404
-
405
- /**
406
- * Creates a map cache object to store key-value pairs.
407
- *
408
- * @private
409
- * @constructor
410
- * @param {Array} [entries] The key-value pairs to cache.
411
- */
412
- function MapCache(entries) {
413
- var index = -1,
414
- length = entries ? entries.length : 0;
415
-
416
- this.clear();
417
- while (++index < length) {
418
- var entry = entries[index];
419
- this.set(entry[0], entry[1]);
420
- }
421
- }
422
-
423
- /**
424
- * Removes all key-value entries from the map.
425
- *
426
- * @private
427
- * @name clear
428
- * @memberOf MapCache
429
- */
430
- function mapCacheClear() {
431
- this.__data__ = {
432
- 'hash': new Hash,
433
- 'map': new (Map || ListCache),
434
- 'string': new Hash
435
- };
436
- }
437
-
438
- /**
439
- * Removes `key` and its value from the map.
440
- *
441
- * @private
442
- * @name delete
443
- * @memberOf MapCache
444
- * @param {string} key The key of the value to remove.
445
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
446
- */
447
- function mapCacheDelete(key) {
448
- return getMapData(this, key)['delete'](key);
449
- }
450
-
451
- /**
452
- * Gets the map value for `key`.
453
- *
454
- * @private
455
- * @name get
456
- * @memberOf MapCache
457
- * @param {string} key The key of the value to get.
458
- * @returns {*} Returns the entry value.
459
- */
460
- function mapCacheGet(key) {
461
- return getMapData(this, key).get(key);
462
- }
463
-
464
- /**
465
- * Checks if a map value for `key` exists.
466
- *
467
- * @private
468
- * @name has
469
- * @memberOf MapCache
470
- * @param {string} key The key of the entry to check.
471
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
472
- */
473
- function mapCacheHas(key) {
474
- return getMapData(this, key).has(key);
475
- }
476
-
477
- /**
478
- * Sets the map `key` to `value`.
479
- *
480
- * @private
481
- * @name set
482
- * @memberOf MapCache
483
- * @param {string} key The key of the value to set.
484
- * @param {*} value The value to set.
485
- * @returns {Object} Returns the map cache instance.
486
- */
487
- function mapCacheSet(key, value) {
488
- getMapData(this, key).set(key, value);
489
- return this;
490
- }
491
-
492
- // Add methods to `MapCache`.
493
- MapCache.prototype.clear = mapCacheClear;
494
- MapCache.prototype['delete'] = mapCacheDelete;
495
- MapCache.prototype.get = mapCacheGet;
496
- MapCache.prototype.has = mapCacheHas;
497
- MapCache.prototype.set = mapCacheSet;
498
-
499
- /**
500
- * Gets the index at which the `key` is found in `array` of key-value pairs.
501
- *
502
- * @private
503
- * @param {Array} array The array to inspect.
504
- * @param {*} key The key to search for.
505
- * @returns {number} Returns the index of the matched value, else `-1`.
506
- */
507
- function assocIndexOf(array, key) {
508
- var length = array.length;
509
- while (length--) {
510
- if (eq(array[length][0], key)) {
511
- return length;
512
- }
513
- }
514
- return -1;
515
- }
516
-
517
- /**
518
- * The base implementation of `_.get` without support for default values.
519
- *
520
- * @private
521
- * @param {Object} object The object to query.
522
- * @param {Array|string} path The path of the property to get.
523
- * @returns {*} Returns the resolved value.
524
- */
525
- function baseGet(object, path) {
526
- path = isKey(path, object) ? [path] : castPath(path);
527
-
528
- var index = 0,
529
- length = path.length;
530
-
531
- while (object != null && index < length) {
532
- object = object[toKey(path[index++])];
533
- }
534
- return (index && index == length) ? object : undefined;
535
- }
536
-
537
- /**
538
- * The base implementation of `_.isNative` without bad shim checks.
539
- *
540
- * @private
541
- * @param {*} value The value to check.
542
- * @returns {boolean} Returns `true` if `value` is a native function,
543
- * else `false`.
544
- */
545
- function baseIsNative(value) {
546
- if (!isObject(value) || isMasked(value)) {
547
- return false;
548
- }
549
- var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
550
- return pattern.test(toSource(value));
551
- }
552
-
553
- /**
554
- * The base implementation of `_.toString` which doesn't convert nullish
555
- * values to empty strings.
556
- *
557
- * @private
558
- * @param {*} value The value to process.
559
- * @returns {string} Returns the string.
560
- */
561
- function baseToString(value) {
562
- // Exit early for strings to avoid a performance hit in some environments.
563
- if (typeof value == 'string') {
564
- return value;
565
- }
566
- if (isSymbol(value)) {
567
- return symbolToString ? symbolToString.call(value) : '';
568
- }
569
- var result = (value + '');
570
- return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
571
- }
572
-
573
- /**
574
- * Casts `value` to a path array if it's not one.
575
- *
576
- * @private
577
- * @param {*} value The value to inspect.
578
- * @returns {Array} Returns the cast property path array.
579
- */
580
- function castPath(value) {
581
- return isArray(value) ? value : stringToPath(value);
582
- }
583
-
584
- /**
585
- * Gets the data for `map`.
586
- *
587
- * @private
588
- * @param {Object} map The map to query.
589
- * @param {string} key The reference key.
590
- * @returns {*} Returns the map data.
591
- */
592
- function getMapData(map, key) {
593
- var data = map.__data__;
594
- return isKeyable(key)
595
- ? data[typeof key == 'string' ? 'string' : 'hash']
596
- : data.map;
597
- }
598
-
599
- /**
600
- * Gets the native function at `key` of `object`.
601
- *
602
- * @private
603
- * @param {Object} object The object to query.
604
- * @param {string} key The key of the method to get.
605
- * @returns {*} Returns the function if it's native, else `undefined`.
606
- */
607
- function getNative(object, key) {
608
- var value = getValue(object, key);
609
- return baseIsNative(value) ? value : undefined;
610
- }
611
-
612
- /**
613
- * Checks if `value` is a property name and not a property path.
614
- *
615
- * @private
616
- * @param {*} value The value to check.
617
- * @param {Object} [object] The object to query keys on.
618
- * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
619
- */
620
- function isKey(value, object) {
621
- if (isArray(value)) {
622
- return false;
623
- }
624
- var type = typeof value;
625
- if (type == 'number' || type == 'symbol' || type == 'boolean' ||
626
- value == null || isSymbol(value)) {
627
- return true;
628
- }
629
- return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
630
- (object != null && value in Object(object));
631
- }
632
-
633
- /**
634
- * Checks if `value` is suitable for use as unique object key.
635
- *
636
- * @private
637
- * @param {*} value The value to check.
638
- * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
639
- */
640
- function isKeyable(value) {
641
- var type = typeof value;
642
- return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
643
- ? (value !== '__proto__')
644
- : (value === null);
645
- }
646
-
647
- /**
648
- * Checks if `func` has its source masked.
649
- *
650
- * @private
651
- * @param {Function} func The function to check.
652
- * @returns {boolean} Returns `true` if `func` is masked, else `false`.
653
- */
654
- function isMasked(func) {
655
- return !!maskSrcKey && (maskSrcKey in func);
656
- }
657
-
658
- /**
659
- * Converts `string` to a property path array.
660
- *
661
- * @private
662
- * @param {string} string The string to convert.
663
- * @returns {Array} Returns the property path array.
664
- */
665
- var stringToPath = memoize(function(string) {
666
- string = toString(string);
667
-
668
- var result = [];
669
- if (reLeadingDot.test(string)) {
670
- result.push('');
671
- }
672
- string.replace(rePropName, function(match, number, quote, string) {
673
- result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
674
- });
675
- return result;
676
- });
677
-
678
- /**
679
- * Converts `value` to a string key if it's not a string or symbol.
680
- *
681
- * @private
682
- * @param {*} value The value to inspect.
683
- * @returns {string|symbol} Returns the key.
684
- */
685
- function toKey(value) {
686
- if (typeof value == 'string' || isSymbol(value)) {
687
- return value;
688
- }
689
- var result = (value + '');
690
- return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
691
- }
692
-
693
- /**
694
- * Converts `func` to its source code.
695
- *
696
- * @private
697
- * @param {Function} func The function to process.
698
- * @returns {string} Returns the source code.
699
- */
700
- function toSource(func) {
701
- if (func != null) {
702
- try {
703
- return funcToString.call(func);
704
- } catch (e) {}
705
- try {
706
- return (func + '');
707
- } catch (e) {}
708
- }
709
- return '';
710
- }
711
-
712
- /**
713
- * Creates a function that memoizes the result of `func`. If `resolver` is
714
- * provided, it determines the cache key for storing the result based on the
715
- * arguments provided to the memoized function. By default, the first argument
716
- * provided to the memoized function is used as the map cache key. The `func`
717
- * is invoked with the `this` binding of the memoized function.
718
- *
719
- * **Note:** The cache is exposed as the `cache` property on the memoized
720
- * function. Its creation may be customized by replacing the `_.memoize.Cache`
721
- * constructor with one whose instances implement the
722
- * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
723
- * method interface of `delete`, `get`, `has`, and `set`.
724
- *
725
- * @static
726
- * @memberOf _
727
- * @since 0.1.0
728
- * @category Function
729
- * @param {Function} func The function to have its output memoized.
730
- * @param {Function} [resolver] The function to resolve the cache key.
731
- * @returns {Function} Returns the new memoized function.
732
- * @example
733
- *
734
- * var object = { 'a': 1, 'b': 2 };
735
- * var other = { 'c': 3, 'd': 4 };
736
- *
737
- * var values = _.memoize(_.values);
738
- * values(object);
739
- * // => [1, 2]
740
- *
741
- * values(other);
742
- * // => [3, 4]
743
- *
744
- * object.a = 2;
745
- * values(object);
746
- * // => [1, 2]
747
- *
748
- * // Modify the result cache.
749
- * values.cache.set(object, ['a', 'b']);
750
- * values(object);
751
- * // => ['a', 'b']
752
- *
753
- * // Replace `_.memoize.Cache`.
754
- * _.memoize.Cache = WeakMap;
755
- */
756
- function memoize(func, resolver) {
757
- if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
758
- throw new TypeError(FUNC_ERROR_TEXT);
759
- }
760
- var memoized = function() {
761
- var args = arguments,
762
- key = resolver ? resolver.apply(this, args) : args[0],
763
- cache = memoized.cache;
764
-
765
- if (cache.has(key)) {
766
- return cache.get(key);
767
- }
768
- var result = func.apply(this, args);
769
- memoized.cache = cache.set(key, result);
770
- return result;
771
- };
772
- memoized.cache = new (memoize.Cache || MapCache);
773
- return memoized;
774
- }
775
-
776
- // Assign cache to `_.memoize`.
777
- memoize.Cache = MapCache;
778
-
779
- /**
780
- * Performs a
781
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
782
- * comparison between two values to determine if they are equivalent.
783
- *
784
- * @static
785
- * @memberOf _
786
- * @since 4.0.0
787
- * @category Lang
788
- * @param {*} value The value to compare.
789
- * @param {*} other The other value to compare.
790
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
791
- * @example
792
- *
793
- * var object = { 'a': 1 };
794
- * var other = { 'a': 1 };
795
- *
796
- * _.eq(object, object);
797
- * // => true
798
- *
799
- * _.eq(object, other);
800
- * // => false
801
- *
802
- * _.eq('a', 'a');
803
- * // => true
804
- *
805
- * _.eq('a', Object('a'));
806
- * // => false
807
- *
808
- * _.eq(NaN, NaN);
809
- * // => true
810
- */
811
- function eq(value, other) {
812
- return value === other || (value !== value && other !== other);
813
- }
814
-
815
- /**
816
- * Checks if `value` is classified as an `Array` object.
817
- *
818
- * @static
819
- * @memberOf _
820
- * @since 0.1.0
821
- * @category Lang
822
- * @param {*} value The value to check.
823
- * @returns {boolean} Returns `true` if `value` is an array, else `false`.
824
- * @example
825
- *
826
- * _.isArray([1, 2, 3]);
827
- * // => true
828
- *
829
- * _.isArray(document.body.children);
830
- * // => false
831
- *
832
- * _.isArray('abc');
833
- * // => false
834
- *
835
- * _.isArray(_.noop);
836
- * // => false
837
- */
838
- var isArray = Array.isArray;
839
-
840
- /**
841
- * Checks if `value` is classified as a `Function` object.
842
- *
843
- * @static
844
- * @memberOf _
845
- * @since 0.1.0
846
- * @category Lang
847
- * @param {*} value The value to check.
848
- * @returns {boolean} Returns `true` if `value` is a function, else `false`.
849
- * @example
850
- *
851
- * _.isFunction(_);
852
- * // => true
853
- *
854
- * _.isFunction(/abc/);
855
- * // => false
856
- */
857
- function isFunction(value) {
858
- // The use of `Object#toString` avoids issues with the `typeof` operator
859
- // in Safari 8-9 which returns 'object' for typed array and other constructors.
860
- var tag = isObject(value) ? objectToString.call(value) : '';
861
- return tag == funcTag || tag == genTag;
862
- }
863
-
864
- /**
865
- * Checks if `value` is the
866
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
867
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
868
- *
869
- * @static
870
- * @memberOf _
871
- * @since 0.1.0
872
- * @category Lang
873
- * @param {*} value The value to check.
874
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
875
- * @example
876
- *
877
- * _.isObject({});
878
- * // => true
879
- *
880
- * _.isObject([1, 2, 3]);
881
- * // => true
882
- *
883
- * _.isObject(_.noop);
884
- * // => true
885
- *
886
- * _.isObject(null);
887
- * // => false
888
- */
889
- function isObject(value) {
890
- var type = typeof value;
891
- return !!value && (type == 'object' || type == 'function');
892
- }
893
-
894
- /**
895
- * Checks if `value` is object-like. A value is object-like if it's not `null`
896
- * and has a `typeof` result of "object".
897
- *
898
- * @static
899
- * @memberOf _
900
- * @since 4.0.0
901
- * @category Lang
902
- * @param {*} value The value to check.
903
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
904
- * @example
905
- *
906
- * _.isObjectLike({});
907
- * // => true
908
- *
909
- * _.isObjectLike([1, 2, 3]);
910
- * // => true
911
- *
912
- * _.isObjectLike(_.noop);
913
- * // => false
914
- *
915
- * _.isObjectLike(null);
916
- * // => false
917
- */
918
- function isObjectLike(value) {
919
- return !!value && typeof value == 'object';
920
- }
921
-
922
- /**
923
- * Checks if `value` is classified as a `Symbol` primitive or object.
924
- *
925
- * @static
926
- * @memberOf _
927
- * @since 4.0.0
928
- * @category Lang
929
- * @param {*} value The value to check.
930
- * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
931
- * @example
932
- *
933
- * _.isSymbol(Symbol.iterator);
934
- * // => true
935
- *
936
- * _.isSymbol('abc');
937
- * // => false
938
- */
939
- function isSymbol(value) {
940
- return typeof value == 'symbol' ||
941
- (isObjectLike(value) && objectToString.call(value) == symbolTag);
942
- }
943
-
944
- /**
945
- * Converts `value` to a string. An empty string is returned for `null`
946
- * and `undefined` values. The sign of `-0` is preserved.
947
- *
948
- * @static
949
- * @memberOf _
950
- * @since 4.0.0
951
- * @category Lang
952
- * @param {*} value The value to process.
953
- * @returns {string} Returns the string.
954
- * @example
955
- *
956
- * _.toString(null);
957
- * // => ''
958
- *
959
- * _.toString(-0);
960
- * // => '-0'
961
- *
962
- * _.toString([1, 2, 3]);
963
- * // => '1,2,3'
964
- */
965
- function toString(value) {
966
- return value == null ? '' : baseToString(value);
967
- }
968
-
969
- /**
970
- * Gets the value at `path` of `object`. If the resolved value is
971
- * `undefined`, the `defaultValue` is returned in its place.
972
- *
973
- * @static
974
- * @memberOf _
975
- * @since 3.7.0
976
- * @category Object
977
- * @param {Object} object The object to query.
978
- * @param {Array|string} path The path of the property to get.
979
- * @param {*} [defaultValue] The value returned for `undefined` resolved values.
980
- * @returns {*} Returns the resolved value.
981
- * @example
982
- *
983
- * var object = { 'a': [{ 'b': { 'c': 3 } }] };
984
- *
985
- * _.get(object, 'a[0].b.c');
986
- * // => 3
987
- *
988
- * _.get(object, ['a', '0', 'b', 'c']);
989
- * // => 3
990
- *
991
- * _.get(object, 'a.b.c', 'default');
992
- * // => 'default'
993
- */
994
- function get(object, path, defaultValue) {
995
- var result = object == null ? undefined : baseGet(object, path);
996
- return result === undefined ? defaultValue : result;
997
- }
998
-
999
- var lodash_get = get;
1000
-
1001
- /**
1002
- * lodash (Custom Build) <https://lodash.com/>
1003
- * Build: `lodash modularize exports="npm" -o ./`
1004
- * Copyright jQuery Foundation and other contributors <https://jquery.org/>
1005
- * Released under MIT license <https://lodash.com/license>
1006
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
1007
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
1008
- */
1009
-
1010
- /** Used as the `TypeError` message for "Functions" methods. */
1011
- var FUNC_ERROR_TEXT$1 = 'Expected a function';
1012
-
1013
- /** Used to stand-in for `undefined` hash values. */
1014
- var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
1015
-
1016
- /** Used as references for various `Number` constants. */
1017
- var INFINITY$1 = 1 / 0,
1018
- MAX_SAFE_INTEGER = 9007199254740991;
1019
-
1020
- /** `Object#toString` result references. */
1021
- var funcTag$1 = '[object Function]',
1022
- genTag$1 = '[object GeneratorFunction]',
1023
- symbolTag$1 = '[object Symbol]';
1024
-
1025
- /** Used to match property names within property paths. */
1026
- var reIsDeepProp$1 = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
1027
- reIsPlainProp$1 = /^\w*$/,
1028
- reLeadingDot$1 = /^\./,
1029
- rePropName$1 = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
1030
-
1031
- /**
1032
- * Used to match `RegExp`
1033
- * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
1034
- */
1035
- var reRegExpChar$1 = /[\\^$.*+?()[\]{}|]/g;
1036
-
1037
- /** Used to match backslashes in property paths. */
1038
- var reEscapeChar$1 = /\\(\\)?/g;
1039
-
1040
- /** Used to detect host constructors (Safari). */
1041
- var reIsHostCtor$1 = /^\[object .+?Constructor\]$/;
1042
-
1043
- /** Used to detect unsigned integer values. */
1044
- var reIsUint = /^(?:0|[1-9]\d*)$/;
1045
-
1046
- /** Detect free variable `global` from Node.js. */
1047
- var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
1048
-
1049
- /** Detect free variable `self`. */
1050
- var freeSelf$1 = typeof self == 'object' && self && self.Object === Object && self;
1051
-
1052
- /** Used as a reference to the global object. */
1053
- var root$1 = freeGlobal$1 || freeSelf$1 || Function('return this')();
1054
-
1055
- /**
1056
- * Gets the value at `key` of `object`.
1057
- *
1058
- * @private
1059
- * @param {Object} [object] The object to query.
1060
- * @param {string} key The key of the property to get.
1061
- * @returns {*} Returns the property value.
1062
- */
1063
- function getValue$1(object, key) {
1064
- return object == null ? undefined : object[key];
1065
- }
1066
-
1067
- /**
1068
- * Checks if `value` is a host object in IE < 9.
1069
- *
1070
- * @private
1071
- * @param {*} value The value to check.
1072
- * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
1073
- */
1074
- function isHostObject$1(value) {
1075
- // Many host objects are `Object` objects that can coerce to strings
1076
- // despite having improperly defined `toString` methods.
1077
- var result = false;
1078
- if (value != null && typeof value.toString != 'function') {
1079
- try {
1080
- result = !!(value + '');
1081
- } catch (e) {}
1082
- }
1083
- return result;
1084
- }
1085
-
1086
- /** Used for built-in method references. */
1087
- var arrayProto$1 = Array.prototype,
1088
- funcProto$1 = Function.prototype,
1089
- objectProto$1 = Object.prototype;
1090
-
1091
- /** Used to detect overreaching core-js shims. */
1092
- var coreJsData$1 = root$1['__core-js_shared__'];
1093
-
1094
- /** Used to detect methods masquerading as native. */
1095
- var maskSrcKey$1 = (function() {
1096
- var uid = /[^.]+$/.exec(coreJsData$1 && coreJsData$1.keys && coreJsData$1.keys.IE_PROTO || '');
1097
- return uid ? ('Symbol(src)_1.' + uid) : '';
1098
- }());
1099
-
1100
- /** Used to resolve the decompiled source of functions. */
1101
- var funcToString$1 = funcProto$1.toString;
1102
-
1103
- /** Used to check objects for own properties. */
1104
- var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
1105
-
1106
- /**
1107
- * Used to resolve the
1108
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
1109
- * of values.
1110
- */
1111
- var objectToString$1 = objectProto$1.toString;
1112
-
1113
- /** Used to detect if a method is native. */
1114
- var reIsNative$1 = RegExp('^' +
1115
- funcToString$1.call(hasOwnProperty$1).replace(reRegExpChar$1, '\\$&')
1116
- .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1117
- );
1118
-
1119
- /** Built-in value references. */
1120
- var Symbol$1 = root$1.Symbol,
1121
- splice$1 = arrayProto$1.splice;
1122
-
1123
- /* Built-in method references that are verified to be native. */
1124
- var Map$1 = getNative$1(root$1, 'Map'),
1125
- nativeCreate$1 = getNative$1(Object, 'create');
1126
-
1127
- /** Used to convert symbols to primitives and strings. */
1128
- var symbolProto$1 = Symbol$1 ? Symbol$1.prototype : undefined,
1129
- symbolToString$1 = symbolProto$1 ? symbolProto$1.toString : undefined;
1130
-
1131
- /**
1132
- * Creates a hash object.
1133
- *
1134
- * @private
1135
- * @constructor
1136
- * @param {Array} [entries] The key-value pairs to cache.
1137
- */
1138
- function Hash$1(entries) {
1139
- var index = -1,
1140
- length = entries ? entries.length : 0;
1141
-
1142
- this.clear();
1143
- while (++index < length) {
1144
- var entry = entries[index];
1145
- this.set(entry[0], entry[1]);
1146
- }
1147
- }
1148
-
1149
- /**
1150
- * Removes all key-value entries from the hash.
1151
- *
1152
- * @private
1153
- * @name clear
1154
- * @memberOf Hash
1155
- */
1156
- function hashClear$1() {
1157
- this.__data__ = nativeCreate$1 ? nativeCreate$1(null) : {};
1158
- }
1159
-
1160
- /**
1161
- * Removes `key` and its value from the hash.
1162
- *
1163
- * @private
1164
- * @name delete
1165
- * @memberOf Hash
1166
- * @param {Object} hash The hash to modify.
1167
- * @param {string} key The key of the value to remove.
1168
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1169
- */
1170
- function hashDelete$1(key) {
1171
- return this.has(key) && delete this.__data__[key];
1172
- }
1173
-
1174
- /**
1175
- * Gets the hash value for `key`.
1176
- *
1177
- * @private
1178
- * @name get
1179
- * @memberOf Hash
1180
- * @param {string} key The key of the value to get.
1181
- * @returns {*} Returns the entry value.
1182
- */
1183
- function hashGet$1(key) {
1184
- var data = this.__data__;
1185
- if (nativeCreate$1) {
1186
- var result = data[key];
1187
- return result === HASH_UNDEFINED$1 ? undefined : result;
1188
- }
1189
- return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
1190
- }
1191
-
1192
- /**
1193
- * Checks if a hash value for `key` exists.
1194
- *
1195
- * @private
1196
- * @name has
1197
- * @memberOf Hash
1198
- * @param {string} key The key of the entry to check.
1199
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1200
- */
1201
- function hashHas$1(key) {
1202
- var data = this.__data__;
1203
- return nativeCreate$1 ? data[key] !== undefined : hasOwnProperty$1.call(data, key);
1204
- }
1205
-
1206
- /**
1207
- * Sets the hash `key` to `value`.
1208
- *
1209
- * @private
1210
- * @name set
1211
- * @memberOf Hash
1212
- * @param {string} key The key of the value to set.
1213
- * @param {*} value The value to set.
1214
- * @returns {Object} Returns the hash instance.
1215
- */
1216
- function hashSet$1(key, value) {
1217
- var data = this.__data__;
1218
- data[key] = (nativeCreate$1 && value === undefined) ? HASH_UNDEFINED$1 : value;
1219
- return this;
1220
- }
1221
-
1222
- // Add methods to `Hash`.
1223
- Hash$1.prototype.clear = hashClear$1;
1224
- Hash$1.prototype['delete'] = hashDelete$1;
1225
- Hash$1.prototype.get = hashGet$1;
1226
- Hash$1.prototype.has = hashHas$1;
1227
- Hash$1.prototype.set = hashSet$1;
1228
-
1229
- /**
1230
- * Creates an list cache object.
1231
- *
1232
- * @private
1233
- * @constructor
1234
- * @param {Array} [entries] The key-value pairs to cache.
1235
- */
1236
- function ListCache$1(entries) {
1237
- var index = -1,
1238
- length = entries ? entries.length : 0;
1239
-
1240
- this.clear();
1241
- while (++index < length) {
1242
- var entry = entries[index];
1243
- this.set(entry[0], entry[1]);
1244
- }
1245
- }
1246
-
1247
- /**
1248
- * Removes all key-value entries from the list cache.
1249
- *
1250
- * @private
1251
- * @name clear
1252
- * @memberOf ListCache
1253
- */
1254
- function listCacheClear$1() {
1255
- this.__data__ = [];
1256
- }
1257
-
1258
- /**
1259
- * Removes `key` and its value from the list cache.
1260
- *
1261
- * @private
1262
- * @name delete
1263
- * @memberOf ListCache
1264
- * @param {string} key The key of the value to remove.
1265
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1266
- */
1267
- function listCacheDelete$1(key) {
1268
- var data = this.__data__,
1269
- index = assocIndexOf$1(data, key);
1270
-
1271
- if (index < 0) {
1272
- return false;
1273
- }
1274
- var lastIndex = data.length - 1;
1275
- if (index == lastIndex) {
1276
- data.pop();
1277
- } else {
1278
- splice$1.call(data, index, 1);
1279
- }
1280
- return true;
1281
- }
1282
-
1283
- /**
1284
- * Gets the list cache value for `key`.
1285
- *
1286
- * @private
1287
- * @name get
1288
- * @memberOf ListCache
1289
- * @param {string} key The key of the value to get.
1290
- * @returns {*} Returns the entry value.
1291
- */
1292
- function listCacheGet$1(key) {
1293
- var data = this.__data__,
1294
- index = assocIndexOf$1(data, key);
1295
-
1296
- return index < 0 ? undefined : data[index][1];
1297
- }
1298
-
1299
- /**
1300
- * Checks if a list cache value for `key` exists.
1301
- *
1302
- * @private
1303
- * @name has
1304
- * @memberOf ListCache
1305
- * @param {string} key The key of the entry to check.
1306
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1307
- */
1308
- function listCacheHas$1(key) {
1309
- return assocIndexOf$1(this.__data__, key) > -1;
1310
- }
1311
-
1312
- /**
1313
- * Sets the list cache `key` to `value`.
1314
- *
1315
- * @private
1316
- * @name set
1317
- * @memberOf ListCache
1318
- * @param {string} key The key of the value to set.
1319
- * @param {*} value The value to set.
1320
- * @returns {Object} Returns the list cache instance.
1321
- */
1322
- function listCacheSet$1(key, value) {
1323
- var data = this.__data__,
1324
- index = assocIndexOf$1(data, key);
1325
-
1326
- if (index < 0) {
1327
- data.push([key, value]);
1328
- } else {
1329
- data[index][1] = value;
1330
- }
1331
- return this;
1332
- }
1333
-
1334
- // Add methods to `ListCache`.
1335
- ListCache$1.prototype.clear = listCacheClear$1;
1336
- ListCache$1.prototype['delete'] = listCacheDelete$1;
1337
- ListCache$1.prototype.get = listCacheGet$1;
1338
- ListCache$1.prototype.has = listCacheHas$1;
1339
- ListCache$1.prototype.set = listCacheSet$1;
1340
-
1341
- /**
1342
- * Creates a map cache object to store key-value pairs.
1343
- *
1344
- * @private
1345
- * @constructor
1346
- * @param {Array} [entries] The key-value pairs to cache.
1347
- */
1348
- function MapCache$1(entries) {
1349
- var index = -1,
1350
- length = entries ? entries.length : 0;
1351
-
1352
- this.clear();
1353
- while (++index < length) {
1354
- var entry = entries[index];
1355
- this.set(entry[0], entry[1]);
1356
- }
1357
- }
1358
-
1359
- /**
1360
- * Removes all key-value entries from the map.
1361
- *
1362
- * @private
1363
- * @name clear
1364
- * @memberOf MapCache
1365
- */
1366
- function mapCacheClear$1() {
1367
- this.__data__ = {
1368
- 'hash': new Hash$1,
1369
- 'map': new (Map$1 || ListCache$1),
1370
- 'string': new Hash$1
1371
- };
1372
- }
1373
-
1374
- /**
1375
- * Removes `key` and its value from the map.
1376
- *
1377
- * @private
1378
- * @name delete
1379
- * @memberOf MapCache
1380
- * @param {string} key The key of the value to remove.
1381
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1382
- */
1383
- function mapCacheDelete$1(key) {
1384
- return getMapData$1(this, key)['delete'](key);
1385
- }
1386
-
1387
- /**
1388
- * Gets the map value for `key`.
1389
- *
1390
- * @private
1391
- * @name get
1392
- * @memberOf MapCache
1393
- * @param {string} key The key of the value to get.
1394
- * @returns {*} Returns the entry value.
1395
- */
1396
- function mapCacheGet$1(key) {
1397
- return getMapData$1(this, key).get(key);
1398
- }
1399
-
1400
- /**
1401
- * Checks if a map value for `key` exists.
1402
- *
1403
- * @private
1404
- * @name has
1405
- * @memberOf MapCache
1406
- * @param {string} key The key of the entry to check.
1407
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1408
- */
1409
- function mapCacheHas$1(key) {
1410
- return getMapData$1(this, key).has(key);
1411
- }
1412
-
1413
- /**
1414
- * Sets the map `key` to `value`.
1415
- *
1416
- * @private
1417
- * @name set
1418
- * @memberOf MapCache
1419
- * @param {string} key The key of the value to set.
1420
- * @param {*} value The value to set.
1421
- * @returns {Object} Returns the map cache instance.
1422
- */
1423
- function mapCacheSet$1(key, value) {
1424
- getMapData$1(this, key).set(key, value);
1425
- return this;
1426
- }
1427
-
1428
- // Add methods to `MapCache`.
1429
- MapCache$1.prototype.clear = mapCacheClear$1;
1430
- MapCache$1.prototype['delete'] = mapCacheDelete$1;
1431
- MapCache$1.prototype.get = mapCacheGet$1;
1432
- MapCache$1.prototype.has = mapCacheHas$1;
1433
- MapCache$1.prototype.set = mapCacheSet$1;
1434
-
1435
- /**
1436
- * Assigns `value` to `key` of `object` if the existing value is not equivalent
1437
- * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1438
- * for equality comparisons.
1439
- *
1440
- * @private
1441
- * @param {Object} object The object to modify.
1442
- * @param {string} key The key of the property to assign.
1443
- * @param {*} value The value to assign.
1444
- */
1445
- function assignValue(object, key, value) {
1446
- var objValue = object[key];
1447
- if (!(hasOwnProperty$1.call(object, key) && eq$1(objValue, value)) ||
1448
- (value === undefined && !(key in object))) {
1449
- object[key] = value;
1450
- }
1451
- }
1452
-
1453
- /**
1454
- * Gets the index at which the `key` is found in `array` of key-value pairs.
1455
- *
1456
- * @private
1457
- * @param {Array} array The array to inspect.
1458
- * @param {*} key The key to search for.
1459
- * @returns {number} Returns the index of the matched value, else `-1`.
1460
- */
1461
- function assocIndexOf$1(array, key) {
1462
- var length = array.length;
1463
- while (length--) {
1464
- if (eq$1(array[length][0], key)) {
1465
- return length;
1466
- }
1467
- }
1468
- return -1;
1469
- }
1470
-
1471
- /**
1472
- * The base implementation of `_.isNative` without bad shim checks.
1473
- *
1474
- * @private
1475
- * @param {*} value The value to check.
1476
- * @returns {boolean} Returns `true` if `value` is a native function,
1477
- * else `false`.
1478
- */
1479
- function baseIsNative$1(value) {
1480
- if (!isObject$1(value) || isMasked$1(value)) {
1481
- return false;
1482
- }
1483
- var pattern = (isFunction$1(value) || isHostObject$1(value)) ? reIsNative$1 : reIsHostCtor$1;
1484
- return pattern.test(toSource$1(value));
1485
- }
1486
-
1487
- /**
1488
- * The base implementation of `_.set`.
1489
- *
1490
- * @private
1491
- * @param {Object} object The object to modify.
1492
- * @param {Array|string} path The path of the property to set.
1493
- * @param {*} value The value to set.
1494
- * @param {Function} [customizer] The function to customize path creation.
1495
- * @returns {Object} Returns `object`.
1496
- */
1497
- function baseSet(object, path, value, customizer) {
1498
- if (!isObject$1(object)) {
1499
- return object;
1500
- }
1501
- path = isKey$1(path, object) ? [path] : castPath$1(path);
1502
-
1503
- var index = -1,
1504
- length = path.length,
1505
- lastIndex = length - 1,
1506
- nested = object;
1507
-
1508
- while (nested != null && ++index < length) {
1509
- var key = toKey$1(path[index]),
1510
- newValue = value;
1511
-
1512
- if (index != lastIndex) {
1513
- var objValue = nested[key];
1514
- newValue = customizer ? customizer(objValue, key, nested) : undefined;
1515
- if (newValue === undefined) {
1516
- newValue = isObject$1(objValue)
1517
- ? objValue
1518
- : (isIndex(path[index + 1]) ? [] : {});
1519
- }
1520
- }
1521
- assignValue(nested, key, newValue);
1522
- nested = nested[key];
1523
- }
1524
- return object;
1525
- }
1526
-
1527
- /**
1528
- * The base implementation of `_.toString` which doesn't convert nullish
1529
- * values to empty strings.
1530
- *
1531
- * @private
1532
- * @param {*} value The value to process.
1533
- * @returns {string} Returns the string.
1534
- */
1535
- function baseToString$1(value) {
1536
- // Exit early for strings to avoid a performance hit in some environments.
1537
- if (typeof value == 'string') {
1538
- return value;
1539
- }
1540
- if (isSymbol$1(value)) {
1541
- return symbolToString$1 ? symbolToString$1.call(value) : '';
1542
- }
1543
- var result = (value + '');
1544
- return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
1545
- }
1546
-
1547
- /**
1548
- * Casts `value` to a path array if it's not one.
1549
- *
1550
- * @private
1551
- * @param {*} value The value to inspect.
1552
- * @returns {Array} Returns the cast property path array.
1553
- */
1554
- function castPath$1(value) {
1555
- return isArray$1(value) ? value : stringToPath$1(value);
1556
- }
1557
-
1558
- /**
1559
- * Gets the data for `map`.
1560
- *
1561
- * @private
1562
- * @param {Object} map The map to query.
1563
- * @param {string} key The reference key.
1564
- * @returns {*} Returns the map data.
1565
- */
1566
- function getMapData$1(map, key) {
1567
- var data = map.__data__;
1568
- return isKeyable$1(key)
1569
- ? data[typeof key == 'string' ? 'string' : 'hash']
1570
- : data.map;
1571
- }
1572
-
1573
- /**
1574
- * Gets the native function at `key` of `object`.
1575
- *
1576
- * @private
1577
- * @param {Object} object The object to query.
1578
- * @param {string} key The key of the method to get.
1579
- * @returns {*} Returns the function if it's native, else `undefined`.
1580
- */
1581
- function getNative$1(object, key) {
1582
- var value = getValue$1(object, key);
1583
- return baseIsNative$1(value) ? value : undefined;
1584
- }
1585
-
1586
- /**
1587
- * Checks if `value` is a valid array-like index.
1588
- *
1589
- * @private
1590
- * @param {*} value The value to check.
1591
- * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1592
- * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1593
- */
1594
- function isIndex(value, length) {
1595
- length = length == null ? MAX_SAFE_INTEGER : length;
1596
- return !!length &&
1597
- (typeof value == 'number' || reIsUint.test(value)) &&
1598
- (value > -1 && value % 1 == 0 && value < length);
1599
- }
1600
-
1601
- /**
1602
- * Checks if `value` is a property name and not a property path.
1603
- *
1604
- * @private
1605
- * @param {*} value The value to check.
1606
- * @param {Object} [object] The object to query keys on.
1607
- * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
1608
- */
1609
- function isKey$1(value, object) {
1610
- if (isArray$1(value)) {
1611
- return false;
1612
- }
1613
- var type = typeof value;
1614
- if (type == 'number' || type == 'symbol' || type == 'boolean' ||
1615
- value == null || isSymbol$1(value)) {
1616
- return true;
1617
- }
1618
- return reIsPlainProp$1.test(value) || !reIsDeepProp$1.test(value) ||
1619
- (object != null && value in Object(object));
1620
- }
1621
-
1622
- /**
1623
- * Checks if `value` is suitable for use as unique object key.
1624
- *
1625
- * @private
1626
- * @param {*} value The value to check.
1627
- * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1628
- */
1629
- function isKeyable$1(value) {
1630
- var type = typeof value;
1631
- return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1632
- ? (value !== '__proto__')
1633
- : (value === null);
1634
- }
1635
-
1636
- /**
1637
- * Checks if `func` has its source masked.
1638
- *
1639
- * @private
1640
- * @param {Function} func The function to check.
1641
- * @returns {boolean} Returns `true` if `func` is masked, else `false`.
1642
- */
1643
- function isMasked$1(func) {
1644
- return !!maskSrcKey$1 && (maskSrcKey$1 in func);
1645
- }
1646
-
1647
- /**
1648
- * Converts `string` to a property path array.
1649
- *
1650
- * @private
1651
- * @param {string} string The string to convert.
1652
- * @returns {Array} Returns the property path array.
1653
- */
1654
- var stringToPath$1 = memoize$1(function(string) {
1655
- string = toString$1(string);
1656
-
1657
- var result = [];
1658
- if (reLeadingDot$1.test(string)) {
1659
- result.push('');
1660
- }
1661
- string.replace(rePropName$1, function(match, number, quote, string) {
1662
- result.push(quote ? string.replace(reEscapeChar$1, '$1') : (number || match));
1663
- });
1664
- return result;
1665
- });
1666
-
1667
- /**
1668
- * Converts `value` to a string key if it's not a string or symbol.
1669
- *
1670
- * @private
1671
- * @param {*} value The value to inspect.
1672
- * @returns {string|symbol} Returns the key.
1673
- */
1674
- function toKey$1(value) {
1675
- if (typeof value == 'string' || isSymbol$1(value)) {
1676
- return value;
1677
- }
1678
- var result = (value + '');
1679
- return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
1680
- }
1681
-
1682
- /**
1683
- * Converts `func` to its source code.
1684
- *
1685
- * @private
1686
- * @param {Function} func The function to process.
1687
- * @returns {string} Returns the source code.
1688
- */
1689
- function toSource$1(func) {
1690
- if (func != null) {
1691
- try {
1692
- return funcToString$1.call(func);
1693
- } catch (e) {}
1694
- try {
1695
- return (func + '');
1696
- } catch (e) {}
1697
- }
1698
- return '';
1699
- }
1700
-
1701
- /**
1702
- * Creates a function that memoizes the result of `func`. If `resolver` is
1703
- * provided, it determines the cache key for storing the result based on the
1704
- * arguments provided to the memoized function. By default, the first argument
1705
- * provided to the memoized function is used as the map cache key. The `func`
1706
- * is invoked with the `this` binding of the memoized function.
1707
- *
1708
- * **Note:** The cache is exposed as the `cache` property on the memoized
1709
- * function. Its creation may be customized by replacing the `_.memoize.Cache`
1710
- * constructor with one whose instances implement the
1711
- * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
1712
- * method interface of `delete`, `get`, `has`, and `set`.
1713
- *
1714
- * @static
1715
- * @memberOf _
1716
- * @since 0.1.0
1717
- * @category Function
1718
- * @param {Function} func The function to have its output memoized.
1719
- * @param {Function} [resolver] The function to resolve the cache key.
1720
- * @returns {Function} Returns the new memoized function.
1721
- * @example
1722
- *
1723
- * var object = { 'a': 1, 'b': 2 };
1724
- * var other = { 'c': 3, 'd': 4 };
1725
- *
1726
- * var values = _.memoize(_.values);
1727
- * values(object);
1728
- * // => [1, 2]
1729
- *
1730
- * values(other);
1731
- * // => [3, 4]
1732
- *
1733
- * object.a = 2;
1734
- * values(object);
1735
- * // => [1, 2]
1736
- *
1737
- * // Modify the result cache.
1738
- * values.cache.set(object, ['a', 'b']);
1739
- * values(object);
1740
- * // => ['a', 'b']
1741
- *
1742
- * // Replace `_.memoize.Cache`.
1743
- * _.memoize.Cache = WeakMap;
1744
- */
1745
- function memoize$1(func, resolver) {
1746
- if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
1747
- throw new TypeError(FUNC_ERROR_TEXT$1);
1748
- }
1749
- var memoized = function() {
1750
- var args = arguments,
1751
- key = resolver ? resolver.apply(this, args) : args[0],
1752
- cache = memoized.cache;
1753
-
1754
- if (cache.has(key)) {
1755
- return cache.get(key);
1756
- }
1757
- var result = func.apply(this, args);
1758
- memoized.cache = cache.set(key, result);
1759
- return result;
1760
- };
1761
- memoized.cache = new (memoize$1.Cache || MapCache$1);
1762
- return memoized;
1763
- }
1764
-
1765
- // Assign cache to `_.memoize`.
1766
- memoize$1.Cache = MapCache$1;
1767
-
1768
- /**
1769
- * Performs a
1770
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1771
- * comparison between two values to determine if they are equivalent.
1772
- *
1773
- * @static
1774
- * @memberOf _
1775
- * @since 4.0.0
1776
- * @category Lang
1777
- * @param {*} value The value to compare.
1778
- * @param {*} other The other value to compare.
1779
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1780
- * @example
1781
- *
1782
- * var object = { 'a': 1 };
1783
- * var other = { 'a': 1 };
1784
- *
1785
- * _.eq(object, object);
1786
- * // => true
1787
- *
1788
- * _.eq(object, other);
1789
- * // => false
1790
- *
1791
- * _.eq('a', 'a');
1792
- * // => true
1793
- *
1794
- * _.eq('a', Object('a'));
1795
- * // => false
1796
- *
1797
- * _.eq(NaN, NaN);
1798
- * // => true
1799
- */
1800
- function eq$1(value, other) {
1801
- return value === other || (value !== value && other !== other);
1802
- }
1803
-
1804
- /**
1805
- * Checks if `value` is classified as an `Array` object.
1806
- *
1807
- * @static
1808
- * @memberOf _
1809
- * @since 0.1.0
1810
- * @category Lang
1811
- * @param {*} value The value to check.
1812
- * @returns {boolean} Returns `true` if `value` is an array, else `false`.
1813
- * @example
1814
- *
1815
- * _.isArray([1, 2, 3]);
1816
- * // => true
1817
- *
1818
- * _.isArray(document.body.children);
1819
- * // => false
1820
- *
1821
- * _.isArray('abc');
1822
- * // => false
1823
- *
1824
- * _.isArray(_.noop);
1825
- * // => false
1826
- */
1827
- var isArray$1 = Array.isArray;
1828
-
1829
- /**
1830
- * Checks if `value` is classified as a `Function` object.
1831
- *
1832
- * @static
1833
- * @memberOf _
1834
- * @since 0.1.0
1835
- * @category Lang
1836
- * @param {*} value The value to check.
1837
- * @returns {boolean} Returns `true` if `value` is a function, else `false`.
1838
- * @example
1839
- *
1840
- * _.isFunction(_);
1841
- * // => true
1842
- *
1843
- * _.isFunction(/abc/);
1844
- * // => false
1845
- */
1846
- function isFunction$1(value) {
1847
- // The use of `Object#toString` avoids issues with the `typeof` operator
1848
- // in Safari 8-9 which returns 'object' for typed array and other constructors.
1849
- var tag = isObject$1(value) ? objectToString$1.call(value) : '';
1850
- return tag == funcTag$1 || tag == genTag$1;
1851
- }
1852
-
1853
- /**
1854
- * Checks if `value` is the
1855
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
1856
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
1857
- *
1858
- * @static
1859
- * @memberOf _
1860
- * @since 0.1.0
1861
- * @category Lang
1862
- * @param {*} value The value to check.
1863
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
1864
- * @example
1865
- *
1866
- * _.isObject({});
1867
- * // => true
1868
- *
1869
- * _.isObject([1, 2, 3]);
1870
- * // => true
1871
- *
1872
- * _.isObject(_.noop);
1873
- * // => true
1874
- *
1875
- * _.isObject(null);
1876
- * // => false
1877
- */
1878
- function isObject$1(value) {
1879
- var type = typeof value;
1880
- return !!value && (type == 'object' || type == 'function');
1881
- }
1882
-
1883
- /**
1884
- * Checks if `value` is object-like. A value is object-like if it's not `null`
1885
- * and has a `typeof` result of "object".
1886
- *
1887
- * @static
1888
- * @memberOf _
1889
- * @since 4.0.0
1890
- * @category Lang
1891
- * @param {*} value The value to check.
1892
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1893
- * @example
1894
- *
1895
- * _.isObjectLike({});
1896
- * // => true
1897
- *
1898
- * _.isObjectLike([1, 2, 3]);
1899
- * // => true
1900
- *
1901
- * _.isObjectLike(_.noop);
1902
- * // => false
1903
- *
1904
- * _.isObjectLike(null);
1905
- * // => false
1906
- */
1907
- function isObjectLike$1(value) {
1908
- return !!value && typeof value == 'object';
1909
- }
1910
-
1911
- /**
1912
- * Checks if `value` is classified as a `Symbol` primitive or object.
1913
- *
1914
- * @static
1915
- * @memberOf _
1916
- * @since 4.0.0
1917
- * @category Lang
1918
- * @param {*} value The value to check.
1919
- * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
1920
- * @example
1921
- *
1922
- * _.isSymbol(Symbol.iterator);
1923
- * // => true
1924
- *
1925
- * _.isSymbol('abc');
1926
- * // => false
1927
- */
1928
- function isSymbol$1(value) {
1929
- return typeof value == 'symbol' ||
1930
- (isObjectLike$1(value) && objectToString$1.call(value) == symbolTag$1);
1931
- }
1932
-
1933
- /**
1934
- * Converts `value` to a string. An empty string is returned for `null`
1935
- * and `undefined` values. The sign of `-0` is preserved.
1936
- *
1937
- * @static
1938
- * @memberOf _
1939
- * @since 4.0.0
1940
- * @category Lang
1941
- * @param {*} value The value to process.
1942
- * @returns {string} Returns the string.
1943
- * @example
1944
- *
1945
- * _.toString(null);
1946
- * // => ''
1947
- *
1948
- * _.toString(-0);
1949
- * // => '-0'
1950
- *
1951
- * _.toString([1, 2, 3]);
1952
- * // => '1,2,3'
1953
- */
1954
- function toString$1(value) {
1955
- return value == null ? '' : baseToString$1(value);
1956
- }
1957
-
1958
- /**
1959
- * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
1960
- * it's created. Arrays are created for missing index properties while objects
1961
- * are created for all other missing properties. Use `_.setWith` to customize
1962
- * `path` creation.
1963
- *
1964
- * **Note:** This method mutates `object`.
1965
- *
1966
- * @static
1967
- * @memberOf _
1968
- * @since 3.7.0
1969
- * @category Object
1970
- * @param {Object} object The object to modify.
1971
- * @param {Array|string} path The path of the property to set.
1972
- * @param {*} value The value to set.
1973
- * @returns {Object} Returns `object`.
1974
- * @example
1975
- *
1976
- * var object = { 'a': [{ 'b': { 'c': 3 } }] };
1977
- *
1978
- * _.set(object, 'a[0].b.c', 4);
1979
- * console.log(object.a[0].b.c);
1980
- * // => 4
1981
- *
1982
- * _.set(object, ['x', '0', 'y', 'z'], 5);
1983
- * console.log(object.x[0].y.z);
1984
- * // => 5
1985
- */
1986
- function set(object, path, value) {
1987
- return object == null ? object : baseSet(object, path, value);
1988
- }
1989
-
1990
- var lodash_set = set;
1991
-
1992
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
1993
- // require the crypto API and do not support built-in fallback to lower quality random number
1994
- // generators (like Math.random()).
1995
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
1996
- // find the complete implementation of crypto (msCrypto) on IE11.
1997
- var getRandomValues = typeof crypto != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto != 'undefined' && typeof msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto);
1998
- var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
1999
-
2000
- function rng() {
2001
- if (!getRandomValues) {
2002
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
2003
- }
2004
-
2005
- return getRandomValues(rnds8);
2006
- }
2007
-
2008
- /**
2009
- * Convert array of 16 byte values to UUID string format of the form:
2010
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
2011
- */
2012
- var byteToHex = [];
2013
-
2014
- for (var i = 0; i < 256; ++i) {
2015
- byteToHex[i] = (i + 0x100).toString(16).substr(1);
2016
- }
2017
-
2018
- function bytesToUuid(buf, offset) {
2019
- var i = offset || 0;
2020
- var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
2021
-
2022
- return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join('');
2023
- }
2024
-
2025
- function v4(options, buf, offset) {
2026
- var i = buf && offset || 0;
2027
-
2028
- if (typeof options == 'string') {
2029
- buf = options === 'binary' ? new Array(16) : null;
2030
- options = null;
2031
- }
2032
-
2033
- options = options || {};
2034
- var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2035
-
2036
- rnds[6] = rnds[6] & 0x0f | 0x40;
2037
- rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
2038
-
2039
- if (buf) {
2040
- for (var ii = 0; ii < 16; ++ii) {
2041
- buf[i + ii] = rnds[ii];
2042
- }
2043
- }
2044
-
2045
- return buf || bytesToUuid(rnds);
2046
- }
2047
-
2048
- var events;
2049
- (function (events) {
2050
- events["MESSAGE"] = "message";
2051
- })(events || (events = {}));
2052
- var actions;
2053
- (function (actions) {
2054
- actions["HANDSHAKE_REQUEST"] = "RIMLESS/HANDSHAKE_REQUEST";
2055
- actions["HANDSHAKE_REPLY"] = "RIMLESS/HANDSHAKE_REPLY";
2056
- actions["RPC_REQUEST"] = "RIMLESS/RPC_REQUEST";
2057
- actions["RPC_RESOLVE"] = "RIMLESS/RPC_RESOLVE";
2058
- actions["RPC_REJECT"] = "RIMLESS/RPC_REJECT";
2059
- })(actions || (actions = {}));
2060
-
2061
- /**
2062
- * for each function in the schema
2063
- * 1. subscribe to an event that the remote can call
2064
- * 2. listen for calls from the remote. When called execute the function and emit the results.
2065
- *
2066
- * @param methods an array of method ids from the local schema
2067
- * @param _connectionID
2068
- * @return a function to cancel all subscriptions
2069
- */
2070
- function registerLocalMethods(schema = {}, methods = [], _connectionID, guest) {
2071
- const listeners = [];
2072
- methods.forEach((methodName) => {
2073
- // handle a remote calling a local method
2074
- async function handleCall(event) {
2075
- const { action, callID, connectionID, callName, args = [], } = event.data;
2076
- if (action !== actions.RPC_REQUEST)
2077
- return;
2078
- if (!callID || !callName)
2079
- return;
2080
- if (callName !== methodName)
2081
- return;
2082
- if (connectionID !== _connectionID)
2083
- return;
2084
- const payload = {
2085
- action: actions.RPC_RESOLVE,
2086
- callID,
2087
- callName,
2088
- connectionID,
2089
- error: null,
2090
- result: null,
2091
- };
2092
- // run function and return the results to the remote
2093
- try {
2094
- const result = await lodash_get(schema, methodName)(...args);
2095
- payload.result = JSON.parse(JSON.stringify(result));
2096
- }
2097
- catch (error) {
2098
- payload.error = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)));
2099
- }
2100
- if (guest)
2101
- guest.postMessage(payload);
2102
- else if (isWorker())
2103
- self.postMessage(payload);
2104
- else
2105
- event.source.postMessage(payload, event.origin);
2106
- }
2107
- // subscribe to the call event
2108
- if (guest)
2109
- guest.addEventListener(events.MESSAGE, handleCall);
2110
- else
2111
- self.addEventListener(events.MESSAGE, handleCall);
2112
- listeners.push(() => self.removeEventListener(events.MESSAGE, handleCall));
2113
- });
2114
- return () => listeners.forEach((unregister) => unregister());
2115
- }
2116
- /**
2117
- * Create a function that will make an RPC request to the remote with some arguments.
2118
- * Listen to an event that returns the results from the remote.
2119
- *
2120
- * @param _callName
2121
- * @param _connectionID
2122
- * @param event
2123
- * @param listeners
2124
- * @param guest
2125
- *
2126
- * @returns a promise with the result of the RPC
2127
- */
2128
- function createRPC(_callName, _connectionID, event, listeners = [], guest) {
2129
- return (...args) => {
2130
- return new Promise((resolve, reject) => {
2131
- const callID = v4();
2132
- // on RPC response
2133
- function handleResponse(event) {
2134
- const { callID, connectionID, callName, result, error, action } = event.data;
2135
- if (!callID || !callName)
2136
- return;
2137
- if (callName !== _callName)
2138
- return;
2139
- if (connectionID !== _connectionID)
2140
- return;
2141
- // resolve the response
2142
- if (action === actions.RPC_RESOLVE)
2143
- return resolve(result);
2144
- if (action === actions.RPC_REJECT)
2145
- return reject(error);
2146
- }
2147
- // send the RPC request with arguments
2148
- const payload = {
2149
- action: actions.RPC_REQUEST,
2150
- args: JSON.parse(JSON.stringify(args)),
2151
- callID,
2152
- callName: _callName,
2153
- connectionID: _connectionID,
2154
- };
2155
- if (guest)
2156
- guest.addEventListener(events.MESSAGE, handleResponse);
2157
- else
2158
- self.addEventListener(events.MESSAGE, handleResponse);
2159
- listeners.push(() => self.removeEventListener(events.MESSAGE, handleResponse));
2160
- if (guest)
2161
- guest.postMessage(payload);
2162
- else if (isWorker())
2163
- self.postMessage(payload);
2164
- else
2165
- (event.source || event.target).postMessage(payload, event.origin);
2166
- });
2167
- };
2168
- }
2169
- /**
2170
- * create an object based on the remote schema and methods. Functions in that object will
2171
- * emit an event that will trigger the RPC on the remote.
2172
- *
2173
- * @param schema
2174
- * @param methods
2175
- * @param _connectionID
2176
- * @param event
2177
- * @param guest
2178
- */
2179
- function registerRemoteMethods(schema = {}, methods = [], _connectionID, event, guest) {
2180
- const remote = { ...schema };
2181
- const listeners = [];
2182
- methods.forEach((methodName) => {
2183
- const rpc = createRPC(methodName, _connectionID, event, listeners, guest);
2184
- lodash_set(remote, methodName, rpc);
2185
- });
2186
- return { remote, unregisterRemote: () => listeners.forEach((unregister) => unregister()) };
2187
- }
2188
-
2189
- const REQUEST_INTERVAL = 600;
2190
- const TIMEOUT_INTERVAL = 3000;
2191
- let interval = null;
2192
- let connected = false;
2193
- function connect(schema = {}, options = {}) {
2194
- return new Promise((resolve, reject) => {
2195
- const localMethods = extractMethods(schema);
2196
- // on handshake response
2197
- function handleHandshakeResponse(event) {
2198
- if (event.data.action !== actions.HANDSHAKE_REPLY)
2199
- return;
2200
- // register local methods
2201
- const unregisterLocal = registerLocalMethods(schema, localMethods, event.data.connectionID);
2202
- // register remote methods
2203
- const { remote, unregisterRemote } = registerRemoteMethods(event.data.schema, event.data.methods, event.data.connectionID, event);
2204
- // close the connection and all listeners when called
2205
- const close = () => {
2206
- self.removeEventListener(events.MESSAGE, handleHandshakeResponse);
2207
- unregisterRemote();
2208
- unregisterLocal();
2209
- };
2210
- connected = true;
2211
- // resolve connection object
2212
- const connection = { remote, close };
2213
- return resolve(connection);
2214
- }
2215
- // subscribe to HANDSHAKE REPLY MESSAGES
2216
- self.addEventListener(events.MESSAGE, handleHandshakeResponse);
2217
- const payload = {
2218
- action: actions.HANDSHAKE_REQUEST,
2219
- methods: localMethods,
2220
- schema: JSON.parse(JSON.stringify(schema)),
2221
- };
2222
- interval = setInterval(() => {
2223
- if (connected)
2224
- return clearInterval(interval);
2225
- // publish the HANDSHAKE REQUEST
2226
- if (isWorker())
2227
- self.postMessage(payload);
2228
- else
2229
- window.parent.postMessage(payload, "*");
2230
- }, REQUEST_INTERVAL);
2231
- // timeout the connection after a time
2232
- setTimeout(() => {
2233
- if (!connected)
2234
- reject("connection timeout");
2235
- }, TIMEOUT_INTERVAL);
2236
- });
2237
- }
2238
- var guest = ({
2239
- connect,
2240
- });
2241
-
2242
- function isValidTarget(iframe, event) {
2243
- const childURL = iframe.getAttribute("src");
2244
- const childOrigin = getOriginFromURL(childURL);
2245
- const hasProperOrigin = event.origin === childOrigin;
2246
- const hasProperSource = event.source === iframe.contentWindow;
2247
- return hasProperOrigin && hasProperSource;
2248
- }
2249
- /**
2250
- * Perform a handshake with the target iframe, when the handshake is confirmed
2251
- * resolve the connection object containing RPCs and properties
2252
- *
2253
- * @param iframe
2254
- * @param schema
2255
- * @param options
2256
- * @returns Promise
2257
- */
2258
- function connect$1(guest, schema = {}, options) {
2259
- if (!guest)
2260
- throw new Error("a target is required");
2261
- // this check should be improved
2262
- const guestIsWorker = guest.onerror !== undefined &&
2263
- guest.onmessage !== undefined;
2264
- const listeners = guestIsWorker ? guest : window;
2265
- return new Promise((resolve, reject) => {
2266
- const connectionID = v4();
2267
- // on handshake request
2268
- function handleHandshake(event) {
2269
- if (!guestIsWorker && !isValidTarget(guest, event))
2270
- return;
2271
- if (event.data.action !== actions.HANDSHAKE_REQUEST)
2272
- return;
2273
- // register local methods
2274
- const localMethods = extractMethods(schema);
2275
- const unregisterLocal = registerLocalMethods(schema, localMethods, connectionID, guestIsWorker ? guest : undefined);
2276
- // register remote methods
2277
- const { remote, unregisterRemote } = registerRemoteMethods(event.data.schema, event.data.methods, connectionID, event, guestIsWorker ? guest : undefined);
2278
- const payload = {
2279
- action: actions.HANDSHAKE_REPLY,
2280
- connectionID,
2281
- methods: localMethods,
2282
- schema: JSON.parse(JSON.stringify(schema)),
2283
- };
2284
- // confirm the connection
2285
- if (guestIsWorker)
2286
- guest.postMessage(payload);
2287
- else
2288
- event.source.postMessage(payload, event.origin);
2289
- // close the connection and all listeners when called
2290
- const close = () => {
2291
- listeners.removeEventListener(events.MESSAGE, handleHandshake);
2292
- unregisterRemote();
2293
- unregisterLocal();
2294
- };
2295
- // resolve connection object
2296
- const connection = { remote, close };
2297
- return resolve(connection);
2298
- }
2299
- // subscribe to HANDSHAKE MESSAGES
2300
- listeners.addEventListener(events.MESSAGE, handleHandshake);
2301
- });
2302
- }
2303
- var host = ({
2304
- connect: connect$1,
2305
- });
2306
-
2307
- export { guest, host };