1(function () { 2 'use strict'; 3 4 // generated during release, do not modify 5 6 const PUBLIC_VERSION = '5'; 7 8 if (typeof window !== 'undefined') { 9 // @ts-expect-error 10 ((window.__svelte ??= {}).v ??= new Set()).add(PUBLIC_VERSION); 11 } 12 13 const EACH_ITEM_REACTIVE = 1; 14 const EACH_INDEX_REACTIVE = 1 << 1; 15 const EACH_ITEM_IMMUTABLE = 1 << 4; 16 17 const PROPS_IS_IMMUTABLE = 1; 18 const PROPS_IS_UPDATED = 1 << 2; 19 const PROPS_IS_BINDABLE = 1 << 3; 20 const PROPS_IS_LAZY_INITIAL = 1 << 4; 21 22 const TEMPLATE_FRAGMENT = 1; 23 const TEMPLATE_USE_IMPORT_NODE = 1 << 1; 24 25 const HYDRATION_START = '['; 26 /** used to indicate that an `{:else}...` block was rendered */ 27 const HYDRATION_START_ELSE = '[!'; 28 const HYDRATION_END = ']'; 29 const HYDRATION_ERROR = {}; 30 31 const UNINITIALIZED = Symbol(); 32 33 const NAMESPACE_HTML = 'http://www.w3.org/1999/xhtml'; 34 35 const ATTACHMENT_KEY = '@attach'; 36 37 var DEV = false; 38 39 // Store the references to globals in case someone tries to monkey patch these, causing the below 40 // to de-opt (this occurs often when using popular extensions). 41 var is_array = Array.isArray; 42 var index_of = Array.prototype.indexOf; 43 var array_from = Array.from; 44 var object_keys = Object.keys; 45 var define_property = Object.defineProperty; 46 var get_descriptor = Object.getOwnPropertyDescriptor; 47 var get_descriptors = Object.getOwnPropertyDescriptors; 48 var object_prototype = Object.prototype; 49 var array_prototype = Array.prototype; 50 var get_prototype_of = Object.getPrototypeOf; 51 var is_extensible = Object.isExtensible; 52 53 /** 54 * @param {any} thing 55 * @returns {thing is Function} 56 */ 57 function is_function(thing) { 58 return typeof thing === 'function'; 59 } 60 61 // Adapted from https://github.com/then/is-promise/blob/master/index.js 62 // Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE 63 64 /** 65 * @template [T=any] 66 * @param {any} value 67 * @returns {value is PromiseLike<T>} 68 */ 69 function is_promise(value) { 70 return typeof value?.then === 'function'; 71 } 72 73 /** @param {Array<() => void>} arr */ 74 function run_all(arr) { 75 for (var i = 0; i < arr.length; i++) { 76 arr[i](); 77 } 78 } 79 80 /** 81 * TODO replace with Promise.withResolvers once supported widely enough 82 * @template T 83 */ 84 function deferred() { 85 /** @type {(value: T) => void} */ 86 var resolve; 87 88 /** @type {(reason: any) => void} */ 89 var reject; 90 91 /** @type {Promise<T>} */ 92 var promise = new Promise((res, rej) => { 93 resolve = res; 94 reject = rej; 95 }); 96 97 // @ts-expect-error 98 return { promise, resolve, reject }; 99 } 100 101 const DERIVED = 1 << 1; 102 const EFFECT = 1 << 2; 103 const RENDER_EFFECT = 1 << 3; 104 const BLOCK_EFFECT = 1 << 4; 105 const BRANCH_EFFECT = 1 << 5; 106 const ROOT_EFFECT = 1 << 6; 107 const BOUNDARY_EFFECT = 1 << 7; 108 const UNOWNED = 1 << 8; 109 const DISCONNECTED = 1 << 9; 110 const CLEAN = 1 << 10; 111 const DIRTY = 1 << 11; 112 const MAYBE_DIRTY = 1 << 12; 113 const INERT = 1 << 13; 114 const DESTROYED = 1 << 14; 115 const EFFECT_RAN = 1 << 15; 116 /** 'Transparent' effects do not create a transition boundary */ 117 const EFFECT_TRANSPARENT = 1 << 16; 118 const INSPECT_EFFECT = 1 << 17; 119 const HEAD_EFFECT = 1 << 18; 120 const EFFECT_PRESERVED = 1 << 19; 121 const USER_EFFECT = 1 << 20; 122 123 // Flags used for async 124 const REACTION_IS_UPDATING = 1 << 21; 125 const ASYNC = 1 << 22; 126 127 const ERROR_VALUE = 1 << 23; 128 129 const STATE_SYMBOL = Symbol('$state'); 130 const LEGACY_PROPS = Symbol('legacy props'); 131 const LOADING_ATTR_SYMBOL = Symbol(''); 132 133 /** allow users to ignore aborted signal errors if `reason.name === 'StaleReactionError` */ 134 const STALE_REACTION = new (class StaleReactionError extends Error { 135 name = 'StaleReactionError'; 136 message = 'The reaction that called `getAbortSignal()` was re-run or destroyed'; 137 })(); 138 const TEXT_NODE = 3; 139 const COMMENT_NODE = 8; 140 141 /* This file is generated by scripts/process-messages/index.js. Do not edit! */ 142 143 144 /** 145 * Cannot await outside a `<svelte:boundary>` with a `pending` snippet 146 * @returns {never} 147 */ 148 function await_outside_boundary() { 149 { 150 throw new Error(`https://svelte.dev/e/await_outside_boundary`); 151 } 152 } 153 154 /** 155 * `%name%(...)` can only be used during component initialisation 156 * @param {string} name 157 * @returns {never} 158 */ 159 function lifecycle_outside_component(name) { 160 { 161 throw new Error(`https://svelte.dev/e/lifecycle_outside_component`); 162 } 163 } 164 165 /* This file is generated by scripts/process-messages/index.js. Do not edit! */ 166 167 168 /** 169 * Cannot create a `$derived(...)` with an `await` expression outside of an effect tree 170 * @returns {never} 171 */ 172 function async_derived_orphan() { 173 { 174 throw new Error(`https://svelte.dev/e/async_derived_orphan`); 175 } 176 } 177
178 /** 179 * `%rune%` cannot be used inside an effect cleanup function 180 * @param {string} rune 181 * @returns {never} 182 */ 183 function effect_in_teardown(rune) { 184 { 185 throw new Error(`https://svelte.dev/e/effect_in_teardown`); 186 } 187 } 188 189 /** 190 * Effect cannot be created inside a `$derived` value that was not itself created inside an effect 191 * @returns {never} 192 */ 193 function effect_in_unowned_derived() { 194 { 195 throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`); 196 } 197 } 198 199 /** 200 * `%rune%` can only be used inside an effect (e.g. during component initialisation) 201 * @param {string} rune 202 * @returns {never} 203 */ 204 function effect_orphan(rune) { 205 { 206 throw new Error(`https://svelte.dev/e/effect_orphan`); 207 } 208 } 209 210 /** 211 * Maximum update depth exceeded. This typically indicates that an effect reads and writes the same piece of state 212 * @returns {never} 213 */ 214 function effect_update_depth_exceeded() { 215 { 216 throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`); 217 } 218 } 219 220 /** 221 * Failed to hydrate the application 222 * @returns {never} 223 */ 224 function hydration_failed() { 225 { 226 throw new Error(`https://svelte.dev/e/hydration_failed`); 227 } 228 } 229 230 /** 231 * Cannot do `bind:%key%={undefined}` when `%key%` has a fallback value 232 * @param {string} key 233 * @returns {never} 234 */ 235 function props_invalid_value(key) { 236 { 237 throw new Error(`https://svelte.dev/e/props_invalid_value`); 238 } 239 } 240 241 /** 242 * Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`. 243 * @returns {never} 244 */ 245 function state_descriptors_fixed() { 246 { 247 throw new Error(`https://svelte.dev/e/state_descriptors_fixed`); 248 } 249 } 250 251 /** 252 * Cannot set prototype of `$state` object 253 * @returns {never} 254 */ 255 function state_prototype_fixed() { 256 { 257 throw new Error(`https://svelte.dev/e/state_prototype_fixed`); 258 } 259 } 260 261 /** 262 * Updating state inside `$derived(...)`, `$inspect(...)` or a template expression is forbidden. If the value should not be reactive, declare it without `$state` 263 * @returns {never} 264 */ 265 function state_unsafe_mutation() { 266 { 267 throw new Error(`https://svelte.dev/e/state_unsafe_mutation`); 268 } 269 } 270 271 /* This file is generated by scripts/process-messages/index.js. Do not edit! */ 272 273 274 /** 275 * Hydration failed because the initial UI does not match what was rendered on the server. The error occurred near %location% 276 * @param {string | undefined | null} [location] 277 */ 278 function hydration_mismatch(location) { 279 { 280 console.warn(`https://svelte.dev/e/hydration_mismatch`); 281 } 282 } 283 284 /** 285 * Detected a migrated `$:` reactive block in `%filename%` that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`. 286 * @param {string} filename 287 */ 288 function legacy_recursive_reactive_block(filename) { 289 { 290 console.warn(`https://svelte.dev/e/legacy_recursive_reactive_block`); 291 } 292 } 293 294 /** 295 * The `value` property of a `<select multiple>` element should be an array, but it received a non-array value. The selection will be kept as is. 296 */ 297 function select_multiple_invalid_value() { 298 { 299 console.warn(`https://svelte.dev/e/select_multiple_invalid_value`); 300 } 301 } 302 303 /** @import { TemplateNode } from '#client' */ 304 305 306 /** 307 * Use this variable to guard everything related to hydration code so it can be treeshaken out 308 * if the user doesn't use the `hydrate` method and these code paths are therefore not needed. 309 */ 310 let hydrating = false; 311 312 /** @param {boolean} value */ 313 function set_hydrating(value) { 314 hydrating = value; 315 } 316 317 /** 318 * The node that is currently being hydrated. This starts out as the first node inside the opening 319 * <!--[--> comment, and updates each time a component calls `$.child(...)` or `$.sibling(...)`. 320 * When entering a block (e.g. `{#if ...}`), `hydrate_node` is the block opening comment; by the 321 * time we leave the block it is the closing comment, which serves as the block's anchor. 322 * @type {TemplateNode} 323 */ 324 let hydrate_node; 325 326 /** @param {TemplateNode} node */ 327 function set_hydrate_node(node) { 328 if (node === null) { 329 hydration_mismatch(); 330 throw HYDRATION_ERROR; 331 } 332 333 return (hydrate_node = node); 334 } 335 336 function hydrate_next() { 337 return set_hydrate_node(/** @type {TemplateNode} */ (get_next_sibling(hydrate_node))); 338 } 339 340 /** @param {TemplateNode} node */ 341 function reset(node) { 342 if (!hydrating) return; 343 344 // If the node has remaining siblings, something has gone wrong 345 if (get_next_sibling(hydrate_node) !== null) { 346 hydration_mismatch(); 347 throw HYDRATION_ERROR; 348 } 349 350 hydrate_node = node; 351 } 352 353 /** 354 * Removes all nodes starting at `hydrate_node` up until the next hydration end comment 355 */ 356 function remove_nodes() { 357 var depth = 0; 358 var node = hydrate_node; 359 360 while (true) { 361 if (node.nodeType === COMMENT_NODE) { 362 var data = /** @type {Comment} */ (node).data; 363 364 if (data === HYDRATION_END) { 365 if (depth === 0) return node; 366 depth -= 1; 367 } else if (data === HYDRATION_START || data === HYDRATION_START_ELSE) { 368 depth += 1; 369 } 370 } 371 372 var next = /** @type {TemplateNode} */ (get_next_sibling(node)); 373 node.remove(); 374 node = next; 375 } 376 } 377
378 /** 379 * 380 * @param {TemplateNode} node 381 */ 382 function read_hydration_instruction(node) { 383 if (!node || node.nodeType !== COMMENT_NODE) { 384 hydration_mismatch(); 385 throw HYDRATION_ERROR; 386 } 387 388 return /** @type {Comment} */ (node).data; 389 } 390 391 /** @import { Equals } from '#client' */ 392 393 /** @type {Equals} */ 394 function equals(value) { 395 return value === this.v; 396 } 397 398 /** 399 * @param {unknown} a 400 * @param {unknown} b 401 * @returns {boolean} 402 */ 403 function safe_not_equal(a, b) { 404 return a != a 405 ? b == b 406 : a !== b || (a !== null && typeof a === 'object') || typeof a === 'function'; 407 } 408 409 /** @type {Equals} */ 410 function safe_equals(value) { 411 return !safe_not_equal(value, this.v); 412 } 413 414 let tracing_mode_flag = false; 415 416 /** @import { ComponentContext, DevStackEntry, Effect } from '#client' */ 417 418 /** @type {ComponentContext | null} */ 419 let component_context = null; 420 421 /** @param {ComponentContext | null} context */ 422 function set_component_context(context) { 423 component_context = context; 424 } 425 426 /** 427 * @param {Record<string, unknown>} props 428 * @param {any} runes 429 * @param {Function} [fn] 430 * @returns {void} 431 */ 432 function push(props, runes = false, fn) { 433 component_context = { 434 p: component_context, 435 c: null, 436 e: null, 437 s: props, 438 x: null, 439 l: null 440 }; 441 } 442 443 /** 444 * @template {Record<string, any>} T 445 * @param {T} [component] 446 * @returns {T} 447 */ 448 function pop(component) { 449 var context = /** @type {ComponentContext} */ (component_context); 450 var effects = context.e; 451 452 if (effects !== null) { 453 context.e = null; 454 455 for (var fn of effects) { 456 create_user_effect(fn); 457 } 458 } 459 460 if (component !== undefined) { 461 context.x = component; 462 } 463 464 component_context = context.p; 465 466 return component ?? /** @type {T} */ ({}); 467 } 468 469 /** @returns {boolean} */ 470 function is_runes() { 471 return true; 472 } 473 474 /** @import { Derived, Effect } from '#client' */ 475 /** @import { Boundary } from './dom/blocks/boundary.js' */ 476 477 const adjustments = new WeakMap(); 478 479 /** 480 * @param {unknown} error 481 */ 482 function handle_error(error) { 483 var effect = active_effect; 484 485 // for unowned deriveds, don't throw until we read the value 486 if (effect === null) { 487 /** @type {Derived} */ (active_reaction).f |= ERROR_VALUE; 488 return error; 489 } 490 491 if ((effect.f & EFFECT_RAN) === 0) { 492 // if the error occurred while creating this subtree, we let it 493 // bubble up until it hits a boundary that can handle it 494 if ((effect.f & BOUNDARY_EFFECT) === 0) { 495 if (!effect.parent && error instanceof Error) { 496 apply_adjustments(error); 497 } 498 499 throw error; 500 } 501 502 /** @type {Boundary} */ (effect.b).error(error); 503 } else { 504 // otherwise we bubble up the effect tree ourselves 505 invoke_error_boundary(error, effect); 506 } 507 } 508 509 /** 510 * @param {unknown} error 511 * @param {Effect | null} effect 512 */ 513 function invoke_error_boundary(error, effect) { 514 while (effect !== null) { 515 if ((effect.f & BOUNDARY_EFFECT) !== 0) { 516 try { 517 /** @type {Boundary} */ (effect.b).error(error); 518 return; 519 } catch (e) { 520 error = e; 521 } 522 } 523 524 effect = effect.parent; 525 } 526 527 if (error instanceof Error) { 528 apply_adjustments(error); 529 } 530 531 throw error; 532 } 533 534 /** 535 * @param {Error} error 536 */ 537 function apply_adjustments(error) { 538 const adjusted = adjustments.get(error); 539 540 if (adjusted) { 541 define_property(error, 'message', { 542 value: adjusted.message 543 }); 544 545 define_property(error, 'stack', { 546 value: adjusted.stack 547 }); 548 } 549 } 550 551 // Fallback for when requestIdleCallback is not available 552 const request_idle_callback = 553 typeof requestIdleCallback === 'undefined' 554 ? (/** @type {() => void} */ cb) => setTimeout(cb, 1) 555 : requestIdleCallback; 556 557 /** @type {Array<() => void>} */ 558 let micro_tasks = []; 559 560 /** @type {Array<() => void>} */ 561 let idle_tasks = []; 562 563 function run_micro_tasks() { 564 var tasks = micro_tasks; 565 micro_tasks = []; 566 run_all(tasks); 567 } 568 569 function run_idle_tasks() { 570 var tasks = idle_tasks; 571 idle_tasks = []; 572 run_all(tasks); 573 } 574 575 function has_pending_tasks() { 576 return micro_tasks.length > 0 || idle_tasks.length > 0; 577 } 578 579 /** 580 * @param {() => void} fn 581 */ 582 function queue_micro_task(fn) { 583 if (micro_tasks.length === 0 && !is_flushing_sync) { 584 var tasks = micro_tasks; 585 queueMicrotask(() => { 586 // If this is false, a flushSync happened in the meantime. Do _not_ run new scheduled microtasks in that case 587 // as the ordering of microtasks would be broken at that point - consider this case: 588 // - queue_micro_task schedules microtask A to flush task X 589 // - synchronously after, flushSync runs, processing task X 590 // - synchronously after, some other microtask B is scheduled, but not through queue_micro_task but for example a Promise.resolve() in user code 591 // - synchronously after, queue_micro_task schedules microtask C to flush task Y 592 // - one tick later, microtask A now resolves, flushing task Y before microtask B, which is incorrect 593 // This if check prevents that race condition (that realistically will only happen in tests) 594 if (tasks === micro_tasks) run_micro_tasks(); 595 }); 596 } 597 598 micro_tasks.push(fn); 599 } 600 601 /** 602 * @param {() => void} fn 603 */ 604 function queue_idle_task(fn) { 605 if (idle_tasks.length === 0) { 606 request_idle_callback(run_idle_tasks); 607 } 608 609 idle_tasks.push(fn); 610 } 611 612 /** 613 * Synchronously run any queued tasks. 614 */ 615 function flush_tasks() { 616 if (micro_tasks.length > 0) { 617 run_micro_tasks(); 618 } 619 620 if (idle_tasks.length > 0) { 621 run_idle_tasks(); 622 } 623 } 624
625 /** @import { Effect, Source, TemplateNode, } from '#client' */ 626 627 function get_boundary() { 628 const boundary = /** @type {Effect} */ (active_effect).b; 629 630 if (boundary === null) { 631 await_outside_boundary(); 632 } 633 634 return boundary; 635 } 636 637 /** @import { Derived, Effect, Source } from '#client' */ 638 /** @import { Batch } from './batch.js'; */ 639 640 /** 641 * @template V 642 * @param {() => V} fn 643 * @returns {Derived<V>} 644 */ 645 /*#__NO_SIDE_EFFECTS__*/ 646 function derived(fn) { 647 var flags = DERIVED | DIRTY; 648 var parent_derived = 649 active_reaction !== null && (active_reaction.f & DERIVED) !== 0 650 ? /** @type {Derived} */ (active_reaction) 651 : null; 652 653 if (active_effect === null || (parent_derived !== null && (parent_derived.f & UNOWNED) !== 0)) { 654 flags |= UNOWNED; 655 } else { 656 // Since deriveds are evaluated lazily, any effects created inside them are 657 // created too late to ensure that the parent effect is added to the tree 658 active_effect.f |= EFFECT_PRESERVED; 659 } 660 661 /** @type {Derived<V>} */ 662 const signal = { 663 ctx: component_context, 664 deps: null, 665 effects: null, 666 equals, 667 f: flags, 668 fn, 669 reactions: null, 670 rv: 0, 671 v: /** @type {V} */ (UNINITIALIZED), 672 wv: 0, 673 parent: parent_derived ?? active_effect, 674 ac: null 675 }; 676 677 return signal; 678 } 679 680 /** 681 * @template V 682 * @param {() => V | Promise<V>} fn 683 * @param {string} [location] If provided, print a warning if the value is not read immediately after update 684 * @returns {Promise<Source<V>>} 685 */ 686 /*#__NO_SIDE_EFFECTS__*/ 687 function async_derived(fn, location) { 688 let parent = /** @type {Effect | null} */ (active_effect); 689 690 if (parent === null) { 691 async_derived_orphan(); 692 } 693 694 var boundary = /** @type {Boundary} */ (parent.b); 695 696 var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined)); 697 var signal = source(/** @type {V} */ (UNINITIALIZED)); 698 699 /** @type {Promise<V> | null} */ 700 var prev = null; 701 702 // only suspend in async deriveds created on initialisation 703 var should_suspend = !active_reaction; 704 705 async_effect(() => { 706 707 try { 708 var p = fn(); 709 // Make sure to always access the then property to read any signals 710 // it might access, so that we track them as dependencies. 711 if (prev) Promise.resolve(p).catch(() => {}); // avoid unhandled rejection 712 } catch (error) { 713 p = Promise.reject(error); 714 } 715 716 var r = () => p; 717 promise = prev?.then(r, r) ?? Promise.resolve(p); 718 719 prev = promise; 720 721 var batch = /** @type {Batch} */ (current_batch); 722 var pending = boundary.is_pending(); 723 724 if (should_suspend) { 725 boundary.update_pending_count(1); 726 if (!pending) batch.increment(); 727 } 728 729 /** 730 * @param {any} value 731 * @param {unknown} error 732 */ 733 const handler = (value, error = undefined) => { 734 prev = null; 735 736 if (!pending) batch.activate(); 737 738 if (error) { 739 if (error !== STALE_REACTION) { 740 signal.f |= ERROR_VALUE; 741 742 // @ts-expect-error the error is the wrong type, but we don't care 743 internal_set(signal, error); 744 } 745 } else { 746 if ((signal.f & ERROR_VALUE) !== 0) { 747 signal.f ^= ERROR_VALUE; 748 } 749 750 internal_set(signal, value); 751 } 752 753 if (should_suspend) { 754 boundary.update_pending_count(-1); 755 if (!pending) batch.decrement(); 756 } 757 758 unset_context(); 759 }; 760 761 promise.then(handler, (e) => handler(null, e || 'unknown')); 762 763 if (batch) { 764 return () => { 765 queueMicrotask(() => batch.neuter()); 766 }; 767 } 768 }); 769 770 return new Promise((fulfil) => { 771 /** @param {Promise<V>} p */ 772 function next(p) { 773 function go() { 774 if (p === promise) { 775 fulfil(signal); 776 } else { 777 // if the effect re-runs before the initial promise 778 // resolves, delay resolution until we have a value 779 next(promise); 780 } 781 } 782 783 p.then(go, go); 784 } 785 786 next(promise); 787 }); 788 } 789 790 /** 791 * @template V 792 * @param {() => V} fn 793 * @returns {Derived<V>} 794 */ 795 /*#__NO_SIDE_EFFECTS__*/ 796 function user_derived(fn) { 797 const d = derived(fn); 798 799 push_reaction_value(d); 800 801 return d; 802 } 803 804 /** 805 * @template V 806 * @param {() => V} fn 807 * @returns {Derived<V>} 808 */ 809 /*#__NO_SIDE_EFFECTS__*/ 810 function derived_safe_equal(fn) { 811 const signal = derived(fn); 812 signal.equals = safe_equals; 813 return signal; 814 } 815 816 /** 817 * @param {Derived} derived 818 * @returns {void} 819 */ 820 function destroy_derived_effects(derived) { 821 var effects = derived.effects; 822 823 if (effects !== null) { 824 derived.effects = null; 825 826 for (var i = 0; i < effects.length; i += 1) { 827 destroy_effect(/** @type {Effect} */ (effects[i])); 828 } 829 } 830 } 831
832 /** 833 * @param {Derived} derived 834 * @returns {Effect | null} 835 */ 836 function get_derived_parent_effect(derived) { 837 var parent = derived.parent; 838 while (parent !== null) { 839 if ((parent.f & DERIVED) === 0) { 840 return /** @type {Effect} */ (parent); 841 } 842 parent = parent.parent; 843 } 844 return null; 845 } 846 847 /** 848 * @template T 849 * @param {Derived} derived 850 * @returns {T} 851 */ 852 function execute_derived(derived) { 853 var value; 854 var prev_active_effect = active_effect; 855 856 set_active_effect(get_derived_parent_effect(derived)); 857 858 { 859 try { 860 destroy_derived_effects(derived); 861 value = update_reaction(derived); 862 } finally { 863 set_active_effect(prev_active_effect); 864 } 865 } 866 867 return value; 868 } 869 870 /** 871 * @param {Derived} derived 872 * @returns {void} 873 */ 874 function update_derived(derived) { 875 var value = execute_derived(derived); 876 877 if (!derived.equals(value)) { 878 derived.v = value; 879 derived.wv = increment_write_version(); 880 } 881 882 // don't mark derived clean if we're reading it inside a 883 // cleanup function, or it will cache a stale value 884 if (is_destroying_effect) { 885 return; 886 } 887 888 { 889 var status = 890 (skip_reaction || (derived.f & UNOWNED) !== 0) && derived.deps !== null ? MAYBE_DIRTY : CLEAN; 891 892 set_signal_status(derived, status); 893 } 894 } 895 896 /** @import { Effect, Value } from '#client' */ 897 898 899 /** 900 * 901 * @param {Array<() => any>} sync 902 * @param {Array<() => Promise<any>>} async 903 * @param {(values: Value[]) => any} fn 904 */ 905 function flatten(sync, async, fn) { 906 const d = derived ; 907 908 if (async.length === 0) { 909 fn(sync.map(d)); 910 return; 911 } 912 913 var batch = current_batch; 914 var parent = /** @type {Effect} */ (active_effect); 915 916 var restore = capture(); 917 var boundary = get_boundary(); 918 919 Promise.all(async.map((expression) => async_derived(expression))) 920 .then((result) => { 921 batch?.activate(); 922 923 restore(); 924 925 try { 926 fn([...sync.map(d), ...result]); 927 } catch (error) { 928 // ignore errors in blocks that have already been destroyed 929 if ((parent.f & DESTROYED) === 0) { 930 invoke_error_boundary(error, parent); 931 } 932 } 933 934 batch?.deactivate(); 935 unset_context(); 936 }) 937 .catch((error) => { 938 boundary.error(error); 939 }); 940 } 941 942 /** 943 * Captures the current effect context so that we can restore it after 944 * some asynchronous work has happened (so that e.g. `await a + b` 945 * causes `b` to be registered as a dependency). 946 */ 947 function capture() { 948 var previous_effect = active_effect; 949 var previous_reaction = active_reaction; 950 var previous_component_context = component_context; 951 var previous_batch = current_batch; 952 953 return function restore() { 954 set_active_effect(previous_effect); 955 set_active_reaction(previous_reaction); 956 set_component_context(previous_component_context); 957 previous_batch?.activate(); 958 }; 959 } 960 961 function unset_context() { 962 set_active_effect(null); 963 set_active_reaction(null); 964 set_component_context(null); 965 } 966 967 /** @import { Derived, Effect, Source } from '#client' */ 968 969 /** @type {Set<Batch>} */ 970 const batches = new Set(); 971 972 /** @type {Batch | null} */ 973 let current_batch = null; 974 975 /** 976 * This is needed to avoid overwriting inputs in non-async mode 977 * TODO 6.0 remove this, as non-async mode will go away 978 * @type {Batch | null} 979 */ 980 let previous_batch = null; 981 982 /** @type {Set<() => void>} */ 983 let effect_pending_updates = new Set(); 984 985 /** @type {Effect[]} */ 986 let queued_root_effects = []; 987 988 /** @type {Effect | null} */ 989 let last_scheduled_effect = null; 990 991 let is_flushing = false; 992 let is_flushing_sync = false; 993 994 class Batch { 995 /** 996 * The current values of any sources that are updated in this batch 997 * They keys of this map are identical to `this.#previous` 998 * @type {Map<Source, any>} 999 */ 1000 current = new Map(); 1001 1002 /** 1003 * The values of any sources that are updated in this batch _before_ those updates took place. 1004 * They keys of this map are identical to `this.#current` 1005 * @type {Map<Source, any>} 1006 */ 1007 #previous = new Map(); 1008 1009 /** 1010 * When the batch is committed (and the DOM is updated), we need to remove old branches 1011 * and append new ones by calling the functions added inside (if/each/key/etc) blocks 1012 * @type {Set<() => void>} 1013 */ 1014 #callbacks = new Set(); 1015 1016 /** 1017 * The number of async effects that are currently in flight 1018 */ 1019 #pending = 0; 1020 1021 /** 1022 * A deferred that resolves when the batch is committed, used with `settled()` 1023 * TODO replace with Promise.withResolvers once supported widely enough 1024 * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null} 1025 */ 1026 #deferred = null; 1027 1028 /** 1029 * True if an async effect inside this batch resolved and 1030 * its parent branch was already deleted 1031 */ 1032 #neutered = false;
1033 1034 /** 1035 * Async effects (created inside `async_derived`) encountered during processing. 1036 * These run after the rest of the batch has updated, since they should 1037 * always have the latest values 1038 * @type {Effect[]} 1039 */ 1040 #async_effects = []; 1041 1042 /** 1043 * The same as `#async_effects`, but for effects inside a newly-created 1044 * `<svelte:boundary>` â these do not prevent the batch from committing 1045 * @type {Effect[]} 1046 */ 1047 #boundary_async_effects = []; 1048 1049 /** 1050 * Template effects and `$effect.pre` effects, which run when 1051 * a batch is committed 1052 * @type {Effect[]} 1053 */ 1054 #render_effects = []; 1055 1056 /** 1057 * The same as `#render_effects`, but for `$effect` (which runs after) 1058 * @type {Effect[]} 1059 */ 1060 #effects = []; 1061 1062 /** 1063 * Block effects, which may need to re-run on subsequent flushes 1064 * in order to update internal sources (e.g. each block items) 1065 * @type {Effect[]} 1066 */ 1067 #block_effects = []; 1068 1069 /** 1070 * Deferred effects (which run after async work has completed) that are DIRTY 1071 * @type {Effect[]} 1072 */ 1073 #dirty_effects = []; 1074 1075 /** 1076 * Deferred effects that are MAYBE_DIRTY 1077 * @type {Effect[]} 1078 */ 1079 #maybe_dirty_effects = []; 1080 1081 /** 1082 * A set of branches that still exist, but will be destroyed when this batch 1083 * is committed â we skip over these during `process` 1084 * @type {Set<Effect>} 1085 */ 1086 skipped_effects = new Set(); 1087 1088 /** 1089 * 1090 * @param {Effect[]} root_effects 1091 */ 1092 process(root_effects) { 1093 queued_root_effects = []; 1094 1095 previous_batch = null; 1096 1097 for (const root of root_effects) { 1098 this.#traverse_effect_tree(root); 1099 } 1100 1101 // if we didn't start any new async work, and no async work 1102 // is outstanding from a previous flush, commit 1103 if (this.#async_effects.length === 0 && this.#pending === 0) { 1104 this.#commit(); 1105 1106 var render_effects = this.#render_effects; 1107 var effects = this.#effects; 1108 1109 this.#render_effects = []; 1110 this.#effects = []; 1111 this.#block_effects = []; 1112 1113 // If sources are written to, then work needs to happen in a separate batch, else prior sources would be mixed with 1114 // newly updated sources, which could lead to infinite loops when effects run over and over again. 1115 previous_batch = current_batch; 1116 current_batch = null; 1117 1118 flush_queued_effects(render_effects); 1119 flush_queued_effects(effects); 1120 1121 // Reinstate the current batch if there was no new one created, as `process()` runs in a loop in `flush_effects()`. 1122 // That method expects `current_batch` to be set, and could run the loop again if effects result in new effects 1123 // being scheduled but without writes happening in which case no new batch is created. 1124 if (current_batch === null) { 1125 current_batch = this; 1126 } else { 1127 batches.delete(this); 1128 } 1129 1130 this.#deferred?.resolve(); 1131 } else { 1132 this.#defer_effects(this.#render_effects); 1133 this.#defer_effects(this.#effects); 1134 this.#defer_effects(this.#block_effects); 1135 } 1136 1137 for (const effect of this.#async_effects) { 1138 update_effect(effect); 1139 } 1140 1141 for (const effect of this.#boundary_async_effects) { 1142 update_effect(effect); 1143 } 1144 1145 this.#async_effects = []; 1146 this.#boundary_async_effects = []; 1147 } 1148 1149 /** 1150 * Traverse the effect tree, executing effects or stashing 1151 * them for later execution as appropriate 1152 * @param {Effect} root 1153 */ 1154 #traverse_effect_tree(root) { 1155 root.f ^= CLEAN; 1156 1157 var effect = root.first; 1158 1159 while (effect !== null) { 1160 var flags = effect.f; 1161 var is_branch = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0; 1162 var is_skippable_branch = is_branch && (flags & CLEAN) !== 0; 1163 1164 var skip = is_skippable_branch || (flags & INERT) !== 0 || this.skipped_effects.has(effect); 1165 1166 if (!skip && effect.fn !== null) { 1167 if (is_branch) { 1168 effect.f ^= CLEAN; 1169 } else if ((flags & EFFECT) !== 0) { 1170 this.#effects.push(effect); 1171 } else if ((flags & CLEAN) === 0) { 1172 if ((flags & ASYNC) !== 0) { 1173 var effects = effect.b?.is_pending() 1174 ? this.#boundary_async_effects 1175 : this.#async_effects; 1176 1177 effects.push(effect); 1178 } else if (is_dirty(effect)) { 1179 if ((effect.f & BLOCK_EFFECT) !== 0) this.#block_effects.push(effect); 1180 update_effect(effect); 1181 } 1182 } 1183 1184 var child = effect.first; 1185 1186 if (child !== null) { 1187 effect = child; 1188 continue; 1189 } 1190 } 1191 1192 var parent = effect.parent; 1193 effect = effect.next; 1194 1195 while (effect === null && parent !== null) { 1196 effect = parent.next; 1197 parent = parent.parent; 1198 } 1199 } 1200 } 1201 1202 /** 1203 * @param {Effect[]} effects 1204 */ 1205 #defer_effects(effects) { 1206 for (const e of effects) { 1207 const target = (e.f & DIRTY) !== 0 ? this.#dirty_effects : this.#maybe_dirty_effects; 1208 target.push(e); 1209
1210 // mark as clean so they get scheduled if they depend on pending async state 1211 set_signal_status(e, CLEAN); 1212 } 1213 1214 effects.length = 0; 1215 } 1216 1217 /** 1218 * Associate a change to a given source with the current 1219 * batch, noting its previous and current values 1220 * @param {Source} source 1221 * @param {any} value 1222 */ 1223 capture(source, value) { 1224 if (!this.#previous.has(source)) { 1225 this.#previous.set(source, value); 1226 } 1227 1228 this.current.set(source, source.v); 1229 } 1230 1231 activate() { 1232 current_batch = this; 1233 } 1234 1235 deactivate() { 1236 current_batch = null; 1237 previous_batch = null; 1238 1239 for (const update of effect_pending_updates) { 1240 effect_pending_updates.delete(update); 1241 update(); 1242 1243 if (current_batch !== null) { 1244 // only do one at a time 1245 break; 1246 } 1247 } 1248 } 1249 1250 neuter() { 1251 this.#neutered = true; 1252 } 1253 1254 flush() { 1255 if (queued_root_effects.length > 0) { 1256 flush_effects(); 1257 } else { 1258 this.#commit(); 1259 } 1260 1261 if (current_batch !== this) { 1262 // this can happen if a `flushSync` occurred during `flush_effects()`, 1263 // which is permitted in legacy mode despite being a terrible idea 1264 return; 1265 } 1266 1267 if (this.#pending === 0) { 1268 batches.delete(this); 1269 } 1270 1271 this.deactivate(); 1272 } 1273 1274 /** 1275 * Append and remove branches to/from the DOM 1276 */ 1277 #commit() { 1278 if (!this.#neutered) { 1279 for (const fn of this.#callbacks) { 1280 fn(); 1281 } 1282 } 1283 1284 this.#callbacks.clear(); 1285 } 1286 1287 increment() { 1288 this.#pending += 1; 1289 } 1290 1291 decrement() { 1292 this.#pending -= 1; 1293 1294 if (this.#pending === 0) { 1295 for (const e of this.#dirty_effects) { 1296 set_signal_status(e, DIRTY); 1297 schedule_effect(e); 1298 } 1299 1300 for (const e of this.#maybe_dirty_effects) { 1301 set_signal_status(e, MAYBE_DIRTY); 1302 schedule_effect(e); 1303 } 1304 1305 this.#render_effects = []; 1306 this.#effects = []; 1307 1308 this.flush(); 1309 } else { 1310 this.deactivate(); 1311 } 1312 } 1313 1314 /** @param {() => void} fn */ 1315 add_callback(fn) { 1316 this.#callbacks.add(fn); 1317 } 1318 1319 settled() { 1320 return (this.#deferred ??= deferred()).promise; 1321 } 1322 1323 static ensure() { 1324 if (current_batch === null) { 1325 const batch = (current_batch = new Batch()); 1326 batches.add(current_batch); 1327 1328 if (!is_flushing_sync) { 1329 Batch.enqueue(() => { 1330 if (current_batch !== batch) { 1331 // a flushSync happened in the meantime 1332 return; 1333 } 1334 1335 batch.flush(); 1336 }); 1337 } 1338 } 1339 1340 return current_batch; 1341 } 1342 1343 /** @param {() => void} task */ 1344 static enqueue(task) { 1345 queue_micro_task(task); 1346 } 1347 } 1348 1349 /** 1350 * Synchronously flush any pending updates. 1351 * Returns void if no callback is provided, otherwise returns the result of calling the callback. 1352 * @template [T=void] 1353 * @param {(() => T) | undefined} [fn] 1354 * @returns {T} 1355 */ 1356 function flushSync(fn) { 1357 1358 var was_flushing_sync = is_flushing_sync; 1359 is_flushing_sync = true; 1360 1361 try { 1362 var result; 1363 1364 if (fn) ; 1365 1366 while (true) { 1367 flush_tasks(); 1368 1369 if (queued_root_effects.length === 0 && !has_pending_tasks()) { 1370 current_batch?.flush(); 1371 1372 // we need to check again, in case we just updated an `$effect.pending()` 1373 if (queued_root_effects.length === 0) { 1374 // this would be reset in `flush_effects()` but since we are early returning here, 1375 // we need to reset it here as well in case the first time there's 0 queued root effects 1376 last_scheduled_effect = null; 1377 1378 return /** @type {T} */ (result); 1379 } 1380 } 1381 1382 flush_effects(); 1383 } 1384 } finally { 1385 is_flushing_sync = was_flushing_sync; 1386 } 1387 } 1388 1389 function flush_effects() { 1390 var was_updating_effect = is_updating_effect; 1391 is_flushing = true; 1392 1393 try { 1394 var flush_count = 0; 1395 set_is_updating_effect(true); 1396 1397 while (queued_root_effects.length > 0) { 1398 var batch = Batch.ensure(); 1399 1400 if (flush_count++ > 1000) { 1401 var updates, entry; if (DEV) ; 1402 1403 infinite_loop_guard(); 1404 } 1405 1406 batch.process(queued_root_effects); 1407 old_values.clear(); 1408 } 1409 } finally { 1410 is_flushing = false; 1411 set_is_updating_effect(was_updating_effect); 1412 1413 last_scheduled_effect = null; 1414 } 1415 } 1416 1417 function infinite_loop_guard() { 1418 try { 1419 effect_update_depth_exceeded(); 1420 } catch (error) { 1421 1422 // Best effort: invoke the boundary nearest the most recent 1423 // effect and hope that it's relevant to the infinite loop 1424 invoke_error_boundary(error, last_scheduled_effect); 1425 } 1426 } 1427
1428 /** @type {Effect[] | null} */ 1429 let eager_block_effects = null; 1430 1431 /** 1432 * @param {Array<Effect>} effects 1433 * @returns {void} 1434 */ 1435 function flush_queued_effects(effects) { 1436 var length = effects.length; 1437 if (length === 0) return; 1438 1439 var i = 0; 1440 1441 while (i < length) { 1442 var effect = effects[i++]; 1443 1444 if ((effect.f & (DESTROYED | INERT)) === 0 && is_dirty(effect)) { 1445 eager_block_effects = []; 1446 1447 update_effect(effect); 1448 1449 // Effects with no dependencies or teardown do not get added to the effect tree. 1450 // Deferred effects (e.g. `$effect(...)`) _are_ added to the tree because we 1451 // don't know if we need to keep them until they are executed. Doing the check 1452 // here (rather than in `update_effect`) allows us to skip the work for 1453 // immediate effects. 1454 if (effect.deps === null && effect.first === null && effect.nodes_start === null) { 1455 // if there's no teardown or abort controller we completely unlink 1456 // the effect from the graph 1457 if (effect.teardown === null && effect.ac === null) { 1458 // remove this effect from the graph 1459 unlink_effect(effect); 1460 } else { 1461 // keep the effect in the graph, but free up some memory 1462 effect.fn = null; 1463 } 1464 } 1465 1466 // If update_effect() has a flushSync() in it, we may have flushed another flush_queued_effects(), 1467 // which already handled this logic and did set eager_block_effects to null. 1468 if (eager_block_effects?.length > 0) { 1469 // TODO this feels incorrect! it gets the tests passing 1470 old_values.clear(); 1471 1472 for (const e of eager_block_effects) { 1473 update_effect(e); 1474 } 1475 1476 eager_block_effects = []; 1477 } 1478 } 1479 } 1480 1481 eager_block_effects = null; 1482 } 1483 1484 /** 1485 * @param {Effect} signal 1486 * @returns {void} 1487 */ 1488 function schedule_effect(signal) { 1489 var effect = (last_scheduled_effect = signal); 1490 1491 while (effect.parent !== null) { 1492 effect = effect.parent; 1493 var flags = effect.f; 1494 1495 // if the effect is being scheduled because a parent (each/await/etc) block 1496 // updated an internal source, bail out or we'll cause a second flush 1497 if (is_flushing && effect === active_effect && (flags & BLOCK_EFFECT) !== 0) { 1498 return; 1499 } 1500 1501 if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) { 1502 if ((flags & CLEAN) === 0) return; 1503 effect.f ^= CLEAN; 1504 } 1505 } 1506 1507 queued_root_effects.push(effect); 1508 } 1509 1510 /** @import { Derived, Effect, Source, Value } from '#client' */ 1511 1512 /** @type {Map<Source, any>} */ 1513 const old_values = new Map(); 1514 1515 /** 1516 * @template V 1517 * @param {V} v 1518 * @param {Error | null} [stack] 1519 * @returns {Source<V>} 1520 */ 1521 // TODO rename this to `state` throughout the codebase 1522 function source(v, stack) { 1523 /** @type {Value} */ 1524 var signal = { 1525 f: 0, // TODO ideally we could skip this altogether, but it causes type errors 1526 v, 1527 reactions: null, 1528 equals, 1529 rv: 0, 1530 wv: 0 1531 }; 1532 1533 return signal; 1534 } 1535 1536 /** 1537 * @template V 1538 * @param {V} v 1539 * @param {Error | null} [stack] 1540 */ 1541 /*#__NO_SIDE_EFFECTS__*/ 1542 function state(v, stack) { 1543 const s = source(v); 1544 1545 push_reaction_value(s); 1546 1547 return s; 1548 } 1549 1550 /** 1551 * @template V 1552 * @param {V} initial_value 1553 * @param {boolean} [immutable] 1554 * @returns {Source<V>} 1555 */ 1556 /*#__NO_SIDE_EFFECTS__*/ 1557 function mutable_source(initial_value, immutable = false, trackable = true) { 1558 const s = source(initial_value); 1559 if (!immutable) { 1560 s.equals = safe_equals; 1561 } 1562 1563 return s; 1564 } 1565 1566 /** 1567 * @template V 1568 * @param {Source<V>} source 1569 * @param {V} value 1570 * @param {boolean} [should_proxy] 1571 * @returns {V} 1572 */ 1573 function set(source, value, should_proxy = false) { 1574 if ( 1575 active_reaction !== null && 1576 // since we are untracking the function inside `$inspect.with` we need to add this check 1577 // to ensure we error if state is set inside an inspect effect 1578 (!untracking || (active_reaction.f & INSPECT_EFFECT) !== 0) && 1579 is_runes() && 1580 (active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | INSPECT_EFFECT)) !== 0 && 1581 !current_sources?.includes(source) 1582 ) { 1583 state_unsafe_mutation(); 1584 } 1585 1586 let new_value = should_proxy ? proxy(value) : value; 1587 1588 return internal_set(source, new_value); 1589 } 1590 1591 /** 1592 * @template V 1593 * @param {Source<V>} source 1594 * @param {V} value 1595 * @returns {V} 1596 */ 1597 function internal_set(source, value) { 1598 if (!source.equals(value)) { 1599 var old_value = source.v; 1600
1601 if (is_destroying_effect) { 1602 old_values.set(source, value); 1603 } else { 1604 old_values.set(source, old_value); 1605 } 1606 1607 source.v = value; 1608 1609 var batch = Batch.ensure(); 1610 batch.capture(source, old_value); 1611 1612 if ((source.f & DERIVED) !== 0) { 1613 // if we are assigning to a dirty derived we set it to clean/maybe dirty but we also eagerly execute it to track the dependencies 1614 if ((source.f & DIRTY) !== 0) { 1615 execute_derived(/** @type {Derived} */ (source)); 1616 } 1617 set_signal_status(source, (source.f & UNOWNED) === 0 ? CLEAN : MAYBE_DIRTY); 1618 } 1619 1620 source.wv = increment_write_version(); 1621 1622 mark_reactions(source, DIRTY); 1623 1624 // It's possible that the current reaction might not have up-to-date dependencies 1625 // whilst it's actively running. So in the case of ensuring it registers the reaction 1626 // properly for itself, we need to ensure the current effect actually gets 1627 // scheduled. i.e: `$effect(() => x++)` 1628 if ( 1629 active_effect !== null && 1630 (active_effect.f & CLEAN) !== 0 && 1631 (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 1632 ) { 1633 if (untracked_writes === null) { 1634 set_untracked_writes([source]); 1635 } else { 1636 untracked_writes.push(source); 1637 } 1638 } 1639 } 1640 1641 return value; 1642 } 1643 1644 /** 1645 * Silently (without using `get`) increment a source 1646 * @param {Source<number>} source 1647 */ 1648 function increment(source) { 1649 set(source, source.v + 1); 1650 } 1651 1652 /** 1653 * @param {Value} signal 1654 * @param {number} status should be DIRTY or MAYBE_DIRTY 1655 * @returns {void} 1656 */ 1657 function mark_reactions(signal, status) { 1658 var reactions = signal.reactions; 1659 if (reactions === null) return; 1660 var length = reactions.length; 1661 1662 for (var i = 0; i < length; i++) { 1663 var reaction = reactions[i]; 1664 var flags = reaction.f; 1665 1666 var not_dirty = (flags & DIRTY) === 0; 1667 1668 // don't set a DIRTY reaction to MAYBE_DIRTY 1669 if (not_dirty) { 1670 set_signal_status(reaction, status); 1671 } 1672 1673 if ((flags & DERIVED) !== 0) { 1674 mark_reactions(/** @type {Derived} */ (reaction), MAYBE_DIRTY); 1675 } else if (not_dirty) { 1676 if ((flags & BLOCK_EFFECT) !== 0) { 1677 if (eager_block_effects !== null) { 1678 eager_block_effects.push(/** @type {Effect} */ (reaction)); 1679 } 1680 } 1681 1682 schedule_effect(/** @type {Effect} */ (reaction)); 1683 } 1684 } 1685 } 1686 1687 /** @import { Source } from '#client' */ 1688 1689 /** 1690 * @template T 1691 * @param {T} value 1692 * @returns {T} 1693 */ 1694 function proxy(value) { 1695 // if non-proxyable, or is already a proxy, return `value` 1696 if (typeof value !== 'object' || value === null || STATE_SYMBOL in value) { 1697 return value; 1698 } 1699 1700 const prototype = get_prototype_of(value); 1701 1702 if (prototype !== object_prototype && prototype !== array_prototype) { 1703 return value; 1704 } 1705 1706 /** @type {Map<any, Source<any>>} */ 1707 var sources = new Map(); 1708 var is_proxied_array = is_array(value); 1709 var version = state(0); 1710 var parent_version = update_version; 1711 1712 /** 1713 * Executes the proxy in the context of the reaction it was originally created in, if any 1714 * @template T 1715 * @param {() => T} fn 1716 */ 1717 var with_parent = (fn) => { 1718 if (update_version === parent_version) { 1719 return fn(); 1720 } 1721 1722 // child source is being created after the initial proxy â 1723 // prevent it from being associated with the current reaction 1724 var reaction = active_reaction; 1725 var version = update_version; 1726 1727 set_active_reaction(null); 1728 set_update_version(parent_version); 1729 1730 var result = fn(); 1731 1732 set_active_reaction(reaction); 1733 set_update_version(version); 1734 1735 return result; 1736 }; 1737 1738 if (is_proxied_array) { 1739 // We need to create the length source eagerly to ensure that 1740 // mutations to the array are properly synced with our proxy 1741 sources.set('length', state(/** @type {any[]} */ (value).length)); 1742 } 1743 1744 return new Proxy(/** @type {any} */ (value), { 1745 defineProperty(_, prop, descriptor) { 1746 if ( 1747 !('value' in descriptor) || 1748 descriptor.configurable === false || 1749 descriptor.enumerable === false || 1750 descriptor.writable === false 1751 ) { 1752 // we disallow non-basic descriptors, because unless they are applied to the 1753 // target object â which we avoid, so that state can be forked â we will run 1754 // afoul of the various invariants 1755 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/getOwnPropertyDescriptor#invariants 1756 state_descriptors_fixed(); 1757 } 1758 var s = sources.get(prop); 1759 if (s === undefined) { 1760 s = with_parent(() => { 1761 var s = state(descriptor.value); 1762 sources.set(prop, s); 1763 return s; 1764 }); 1765 } else { 1766 set(s, descriptor.value, true); 1767 } 1768 1769 return true; 1770 }, 1771 1772 deleteProperty(target, prop) { 1773 var s = sources.get(prop); 1774 1775 if (s === undefined) { 1776 if (prop in target) { 1777 const s = with_parent(() => state(UNINITIALIZED)); 1778 sources.set(prop, s); 1779 increment(version); 1780 } 1781 } else { 1782 set(s, UNINITIALIZED); 1783 increment(version); 1784 } 1785 1786 return true; 1787 }, 1788 1789 get(target, prop, receiver) { 1790 if (prop === STATE_SYMBOL) { 1791 return value; 1792 } 1793 1794 var s = sources.get(prop); 1795 var exists = prop in target; 1796 1797 // create a source, but only if it's an own property and not a prototype property 1798 if (s === undefined && (!exists || get_descriptor(target, prop)?.writable)) { 1799 s = with_parent(() => { 1800 var p = proxy(exists ? target[prop] : UNINITIALIZED); 1801 var s = state(p); 1802 1803 return s; 1804 }); 1805 1806 sources.set(prop, s); 1807 } 1808 1809 if (s !== undefined) { 1810 var v = get(s); 1811 return v === UNINITIALIZED ? undefined : v; 1812 } 1813 1814 return Reflect.get(target, prop, receiver); 1815 }, 1816 1817 getOwnPropertyDescriptor(target, prop) { 1818 var descriptor = Reflect.getOwnPropertyDescriptor(target, prop); 1819 1820 if (descriptor && 'value' in descriptor) { 1821 var s = sources.get(prop); 1822 if (s) descriptor.value = get(s); 1823 } else if (descriptor === undefined) { 1824 var source = sources.get(prop); 1825 var value = source?.v; 1826 1827 if (source !== undefined && value !== UNINITIALIZED) { 1828 return { 1829 enumerable: true, 1830 configurable: true, 1831 value, 1832 writable: true 1833 }; 1834 } 1835 } 1836 1837 return descriptor; 1838 }, 1839 1840 has(target, prop) { 1841 if (prop === STATE_SYMBOL) { 1842 return true; 1843 } 1844 1845 var s = sources.get(prop); 1846 var has = (s !== undefined && s.v !== UNINITIALIZED) || Reflect.has(target, prop); 1847 1848 if ( 1849 s !== undefined || 1850 (active_effect !== null && (!has || get_descriptor(target, prop)?.writable)) 1851 ) { 1852 if (s === undefined) { 1853 s = with_parent(() => { 1854 var p = has ? proxy(target[prop]) : UNINITIALIZED; 1855 var s = state(p); 1856 1857 return s; 1858 }); 1859 1860 sources.set(prop, s); 1861 } 1862 1863 var value = get(s); 1864 if (value === UNINITIALIZED) { 1865 return false;
1866 } 1867 } 1868 1869 return has; 1870 }, 1871 1872 set(target, prop, value, receiver) { 1873 var s = sources.get(prop); 1874 var has = prop in target; 1875 1876 // variable.length = value -> clear all signals with index >= value 1877 if (is_proxied_array && prop === 'length') { 1878 for (var i = value; i < /** @type {Source<number>} */ (s).v; i += 1) { 1879 var other_s = sources.get(i + ''); 1880 if (other_s !== undefined) { 1881 set(other_s, UNINITIALIZED); 1882 } else if (i in target) { 1883 // If the item exists in the original, we need to create a uninitialized source, 1884 // else a later read of the property would result in a source being created with 1885 // the value of the original item at that index. 1886 other_s = with_parent(() => state(UNINITIALIZED)); 1887 sources.set(i + '', other_s); 1888 } 1889 } 1890 } 1891 1892 // If we haven't yet created a source for this property, we need to ensure 1893 // we do so otherwise if we read it later, then the write won't be tracked and 1894 // the heuristics of effects will be different vs if we had read the proxied 1895 // object property before writing to that property. 1896 if (s === undefined) { 1897 if (!has || get_descriptor(target, prop)?.writable) { 1898 s = with_parent(() => state(undefined)); 1899 set(s, proxy(value)); 1900 1901 sources.set(prop, s); 1902 } 1903 } else { 1904 has = s.v !== UNINITIALIZED; 1905 1906 var p = with_parent(() => proxy(value)); 1907 set(s, p); 1908 } 1909 1910 var descriptor = Reflect.getOwnPropertyDescriptor(target, prop); 1911 1912 // Set the new value before updating any signals so that any listeners get the new value 1913 if (descriptor?.set) { 1914 descriptor.set.call(receiver, value); 1915 } 1916 1917 if (!has) { 1918 // If we have mutated an array directly, we might need to 1919 // signal that length has also changed. Do it before updating metadata 1920 // to ensure that iterating over the array as a result of a metadata update 1921 // will not cause the length to be out of sync. 1922 if (is_proxied_array && typeof prop === 'string') { 1923 var ls = /** @type {Source<number>} */ (sources.get('length')); 1924 var n = Number(prop); 1925 1926 if (Number.isInteger(n) && n >= ls.v) { 1927 set(ls, n + 1); 1928 } 1929 } 1930 1931 increment(version); 1932 } 1933 1934 return true; 1935 }, 1936 1937 ownKeys(target) { 1938 get(version); 1939 1940 var own_keys = Reflect.ownKeys(target).filter((key) => { 1941 var source = sources.get(key); 1942 return source === undefined || source.v !== UNINITIALIZED; 1943 }); 1944 1945 for (var [key, source] of sources) { 1946 if (source.v !== UNINITIALIZED && !(key in target)) { 1947 own_keys.push(key); 1948 } 1949 } 1950 1951 return own_keys; 1952 }, 1953 1954 setPrototypeOf() { 1955 state_prototype_fixed(); 1956 } 1957 }); 1958 } 1959 1960 /** 1961 * @param {any} value 1962 */ 1963 function get_proxied_value(value) { 1964 try { 1965 if (value !== null && typeof value === 'object' && STATE_SYMBOL in value) { 1966 return value[STATE_SYMBOL]; 1967 } 1968 } catch { 1969 // the above if check can throw an error if the value in question 1970 // is the contentWindow of an iframe on another domain, in which 1971 // case we want to just return the value (because it's definitely 1972 // not a proxied value) so we don't break any JavaScript interacting 1973 // with that iframe (such as various payment companies client side 1974 // JavaScript libraries interacting with their iframes on the same 1975 // domain) 1976 } 1977 1978 return value; 1979 } 1980 1981 /** 1982 * @param {any} a 1983 * @param {any} b 1984 */ 1985 function is(a, b) { 1986 return Object.is(get_proxied_value(a), get_proxied_value(b)); 1987 } 1988 1989 /** @import { Effect, TemplateNode } from '#client' */ 1990 1991 // export these for reference in the compiled code, making global name deduplication unnecessary 1992 /** @type {Window} */ 1993 var $window; 1994 1995 /** @type {Document} */ 1996 var $document; 1997 1998 /** @type {boolean} */ 1999 var is_firefox; 2000 2001 /** @type {() => Node | null} */ 2002 var first_child_getter; 2003 /** @type {() => Node | null} */ 2004 var next_sibling_getter; 2005 2006 /** 2007 * Initialize these lazily to avoid issues when using the runtime in a server context 2008 * where these globals are not available while avoiding a separate server entry point 2009 */ 2010 function init_operations() { 2011 if ($window !== undefined) { 2012 return; 2013 } 2014 2015 $window = window; 2016 $document = document; 2017 is_firefox = /Firefox/.test(navigator.userAgent); 2018 2019 var element_prototype = Element.prototype; 2020 var node_prototype = Node.prototype; 2021 var text_prototype = Text.prototype; 2022 2023 // @ts-ignore 2024 first_child_getter = get_descriptor(node_prototype, 'firstChild').get; 2025 // @ts-ignore 2026 next_sibling_getter = get_descriptor(node_prototype, 'nextSibling').get; 2027 2028 if (is_extensible(element_prototype)) { 2029 // the following assignments improve perf of lookups on DOM nodes 2030 // @ts-expect-error 2031 element_prototype.__click = undefined; 2032 // @ts-expect-error 2033 element_prototype.__className = undefined; 2034 // @ts-expect-error 2035 element_prototype.__attributes = null; 2036 // @ts-expect-error 2037 element_prototype.__style = undefined; 2038 // @ts-expect-error 2039 element_prototype.__e = undefined; 2040 } 2041 2042 if (is_extensible(text_prototype)) { 2043 // @ts-expect-error 2044 text_prototype.__t = undefined; 2045 } 2046 } 2047
2048 /** 2049 * @param {string} value 2050 * @returns {Text} 2051 */ 2052 function create_text(value = '') { 2053 return document.createTextNode(value); 2054 } 2055 2056 /** 2057 * @template {Node} N 2058 * @param {N} node 2059 * @returns {Node | null} 2060 */ 2061 /*@__NO_SIDE_EFFECTS__*/ 2062 function get_first_child(node) { 2063 return first_child_getter.call(node); 2064 } 2065 2066 /** 2067 * @template {Node} N 2068 * @param {N} node 2069 * @returns {Node | null} 2070 */ 2071 /*@__NO_SIDE_EFFECTS__*/ 2072 function get_next_sibling(node) { 2073 return next_sibling_getter.call(node); 2074 } 2075 2076 /** 2077 * Don't mark this as side-effect-free, hydration needs to walk all nodes 2078 * @template {Node} N 2079 * @param {N} node 2080 * @param {boolean} is_text 2081 * @returns {Node | null} 2082 */ 2083 function child(node, is_text) { 2084 if (!hydrating) { 2085 return get_first_child(node); 2086 } 2087 2088 var child = /** @type {TemplateNode} */ (get_first_child(hydrate_node)); 2089 2090 // Child can be null if we have an element with a single child, like `<p>{text}</p>`, where `text` is empty 2091 if (child === null) { 2092 child = hydrate_node.appendChild(create_text()); 2093 } else if (is_text && child.nodeType !== TEXT_NODE) { 2094 var text = create_text(); 2095 child?.before(text); 2096 set_hydrate_node(text); 2097 return text; 2098 } 2099 2100 set_hydrate_node(child); 2101 return child; 2102 } 2103 2104 /** 2105 * Don't mark this as side-effect-free, hydration needs to walk all nodes 2106 * @param {DocumentFragment | TemplateNode[]} fragment 2107 * @param {boolean} is_text 2108 * @returns {Node | null} 2109 */ 2110 function first_child(fragment, is_text) { 2111 if (!hydrating) { 2112 // when not hydrating, `fragment` is a `DocumentFragment` (the result of calling `open_frag`) 2113 var first = /** @type {DocumentFragment} */ (get_first_child(/** @type {Node} */ (fragment))); 2114 2115 // TODO prevent user comments with the empty string when preserveComments is true 2116 if (first instanceof Comment && first.data === '') return get_next_sibling(first); 2117 2118 return first; 2119 } 2120 2121 return hydrate_node; 2122 } 2123 2124 /** 2125 * Don't mark this as side-effect-free, hydration needs to walk all nodes 2126 * @param {TemplateNode} node 2127 * @param {number} count 2128 * @param {boolean} is_text 2129 * @returns {Node | null} 2130 */ 2131 function sibling(node, count = 1, is_text = false) { 2132 let next_sibling = hydrating ? hydrate_node : node; 2133 var last_sibling; 2134 2135 while (count--) { 2136 last_sibling = next_sibling; 2137 next_sibling = /** @type {TemplateNode} */ (get_next_sibling(next_sibling)); 2138 } 2139 2140 if (!hydrating) { 2141 return next_sibling; 2142 } 2143 2144 // if a sibling {expression} is empty during SSR, there might be no 2145 // text node to hydrate â we must therefore create one 2146 if (is_text && next_sibling?.nodeType !== TEXT_NODE) { 2147 var text = create_text(); 2148 // If the next sibling is `null` and we're handling text then it's because 2149 // the SSR content was empty for the text, so we need to generate a new text 2150 // node and insert it after the last sibling 2151 if (next_sibling === null) { 2152 last_sibling?.after(text); 2153 } else { 2154 next_sibling.before(text); 2155 } 2156 set_hydrate_node(text); 2157 return text; 2158 } 2159 2160 set_hydrate_node(next_sibling); 2161 return /** @type {TemplateNode} */ (next_sibling); 2162 } 2163 2164 /** 2165 * @template {Node} N 2166 * @param {N} node 2167 * @returns {void} 2168 */ 2169 function clear_text_content(node) { 2170 node.textContent = ''; 2171 } 2172 2173 /** 2174 * Returns `true` if we're updating the current block, for example `condition` in 2175 * an `{#if condition}` block just changed. In this case, the branch should be 2176 * appended (or removed) at the same time as other updates within the 2177 * current `<svelte:boundary>` 2178 */ 2179 function should_defer_append() { 2180 return false; 2181 } 2182 2183 /** 2184 * @param {HTMLElement} dom 2185 * @param {boolean} value 2186 * @returns {void} 2187 */ 2188 function autofocus(dom, value) { 2189 if (value) { 2190 const body = document.body; 2191 dom.autofocus = true; 2192 2193 queue_micro_task(() => { 2194 if (document.activeElement === body) { 2195 dom.focus(); 2196 } 2197 }); 2198 } 2199 } 2200 2201 let listening_to_form_reset = false; 2202 2203 function add_form_reset_listener() { 2204 if (!listening_to_form_reset) { 2205 listening_to_form_reset = true; 2206 document.addEventListener( 2207 'reset', 2208 (evt) => { 2209 // Needs to happen one tick later or else the dom properties of the form 2210 // elements have not updated to their reset values yet 2211 Promise.resolve().then(() => { 2212 if (!evt.defaultPrevented) { 2213 for (const e of /**@type {HTMLFormElement} */ (evt.target).elements) { 2214 // @ts-expect-error 2215 e.__on_r?.(); 2216 } 2217 } 2218 }); 2219 }, 2220 // In the capture phase to guarantee we get noticed of it (no possiblity of stopPropagation) 2221 { capture: true } 2222 ); 2223 } 2224 } 2225
2226 /** 2227 * @template T 2228 * @param {() => T} fn 2229 */ 2230 function without_reactive_context(fn) { 2231 var previous_reaction = active_reaction; 2232 var previous_effect = active_effect; 2233 set_active_reaction(null); 2234 set_active_effect(null); 2235 try { 2236 return fn(); 2237 } finally { 2238 set_active_reaction(previous_reaction); 2239 set_active_effect(previous_effect); 2240 } 2241 } 2242 2243 /** 2244 * Listen to the given event, and then instantiate a global form reset listener if not already done, 2245 * to notify all bindings when the form is reset 2246 * @param {HTMLElement} element 2247 * @param {string} event 2248 * @param {(is_reset?: true) => void} handler 2249 * @param {(is_reset?: true) => void} [on_reset] 2250 */ 2251 function listen_to_event_and_reset_event(element, event, handler, on_reset = handler) { 2252 element.addEventListener(event, () => without_reactive_context(handler)); 2253 // @ts-expect-error 2254 const prev = element.__on_r; 2255 if (prev) { 2256 // special case for checkbox that can have multiple binds (group & checked) 2257 // @ts-expect-error 2258 element.__on_r = () => { 2259 prev(); 2260 on_reset(true); 2261 }; 2262 } else { 2263 // @ts-expect-error 2264 element.__on_r = () => on_reset(true); 2265 } 2266 2267 add_form_reset_listener(); 2268 } 2269 2270 /** @import { ComponentContext, ComponentContextLegacy, Derived, Effect, TemplateNode, TransitionManager } from '#client' */ 2271 2272 /** 2273 * @param {'$effect' | '$effect.pre' | '$inspect'} rune 2274 */ 2275 function validate_effect(rune) { 2276 if (active_effect === null && active_reaction === null) { 2277 effect_orphan(); 2278 } 2279 2280 if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0 && active_effect === null) { 2281 effect_in_unowned_derived(); 2282 } 2283 2284 if (is_destroying_effect) { 2285 effect_in_teardown(); 2286 } 2287 } 2288 2289 /** 2290 * @param {Effect} effect 2291 * @param {Effect} parent_effect 2292 */ 2293 function push_effect(effect, parent_effect) { 2294 var parent_last = parent_effect.last; 2295 if (parent_last === null) { 2296 parent_effect.last = parent_effect.first = effect; 2297 } else { 2298 parent_last.next = effect; 2299 effect.prev = parent_last; 2300 parent_effect.last = effect; 2301 } 2302 } 2303 2304 /** 2305 * @param {number} type 2306 * @param {null | (() => void | (() => void))} fn 2307 * @param {boolean} sync 2308 * @param {boolean} push 2309 * @returns {Effect} 2310 */ 2311 function create_effect(type, fn, sync, push = true) { 2312 var parent = active_effect; 2313 2314 if (parent !== null && (parent.f & INERT) !== 0) { 2315 type |= INERT; 2316 } 2317 2318 /** @type {Effect} */ 2319 var effect = { 2320 ctx: component_context, 2321 deps: null, 2322 nodes_start: null, 2323 nodes_end: null, 2324 f: type | DIRTY, 2325 first: null, 2326 fn, 2327 last: null, 2328 next: null, 2329 parent, 2330 b: parent && parent.b, 2331 prev: null, 2332 teardown: null, 2333 transitions: null, 2334 wv: 0, 2335 ac: null 2336 }; 2337 2338 if (sync) { 2339 try { 2340 update_effect(effect); 2341 effect.f |= EFFECT_RAN; 2342 } catch (e) { 2343 destroy_effect(effect); 2344 throw e; 2345 } 2346 } else if (fn !== null) { 2347 schedule_effect(effect); 2348 } 2349 2350 if (push) { 2351 /** @type {Effect | null} */ 2352 var e = effect; 2353 2354 // if an effect has already ran and doesn't need to be kept in the tree 2355 // (because it won't re-run, has no DOM, and has no teardown etc) 2356 // then we skip it and go to its child (if any) 2357 if ( 2358 sync && 2359 e.deps === null && 2360 e.teardown === null && 2361 e.nodes_start === null && 2362 e.first === e.last && // either `null`, or a singular child 2363 (e.f & EFFECT_PRESERVED) === 0 2364 ) { 2365 e = e.first; 2366 } 2367 2368 if (e !== null) { 2369 e.parent = parent; 2370 2371 if (parent !== null) { 2372 push_effect(e, parent); 2373 } 2374 2375 // if we're in a derived, add the effect there too 2376 if ( 2377 active_reaction !== null && 2378 (active_reaction.f & DERIVED) !== 0 && 2379 (type & ROOT_EFFECT) === 0 2380 ) { 2381 var derived = /** @type {Derived} */ (active_reaction); 2382 (derived.effects ??= []).push(e); 2383 } 2384 } 2385 } 2386 2387 return effect; 2388 } 2389 2390 /** 2391 * @param {() => void} fn 2392 */ 2393 function teardown(fn) { 2394 const effect = create_effect(RENDER_EFFECT, null, false); 2395 set_signal_status(effect, CLEAN); 2396 effect.teardown = fn; 2397 return effect; 2398 } 2399 2400 /** 2401 * Internal representation of `$effect(...)` 2402 * @param {() => void | (() => void)} fn 2403 */ 2404 function user_effect(fn) { 2405 validate_effect(); 2406 2407 // Non-nested `$effect(...)` in a component should be deferred 2408 // until the component is mounted 2409 var flags = /** @type {Effect} */ (active_effect).f; 2410 var defer = !active_reaction && (flags & BRANCH_EFFECT) !== 0 && (flags & EFFECT_RAN) === 0; 2411 2412 if (defer) { 2413 // Top-level `$effect(...)` in an unmounted component â defer until mount 2414 var context = /** @type {ComponentContext} */ (component_context); 2415 (context.e ??= []).push(fn); 2416 } else { 2417 // Everything else â create immediately 2418 return create_user_effect(fn); 2419 } 2420 } 2421
2422 /** 2423 * @param {() => void | (() => void)} fn 2424 */ 2425 function create_user_effect(fn) { 2426 return create_effect(EFFECT | USER_EFFECT, fn, false); 2427 } 2428 2429 /** 2430 * Internal representation of `$effect.pre(...)` 2431 * @param {() => void | (() => void)} fn 2432 * @returns {Effect} 2433 */ 2434 function user_pre_effect(fn) { 2435 validate_effect(); 2436 return create_effect(RENDER_EFFECT | USER_EFFECT, fn, true); 2437 } 2438 2439 /** 2440 * Internal representation of `$effect.root(...)` 2441 * @param {() => void | (() => void)} fn 2442 * @returns {() => void} 2443 */ 2444 function effect_root(fn) { 2445 Batch.ensure(); 2446 const effect = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn, true); 2447 2448 return () => { 2449 destroy_effect(effect); 2450 }; 2451 } 2452 2453 /** 2454 * An effect root whose children can transition out 2455 * @param {() => void} fn 2456 * @returns {(options?: { outro?: boolean }) => Promise<void>} 2457 */ 2458 function component_root(fn) { 2459 Batch.ensure(); 2460 const effect = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn, true); 2461 2462 return (options = {}) => { 2463 return new Promise((fulfil) => { 2464 if (options.outro) { 2465 pause_effect(effect, () => { 2466 destroy_effect(effect); 2467 fulfil(undefined); 2468 }); 2469 } else { 2470 destroy_effect(effect); 2471 fulfil(undefined); 2472 } 2473 }); 2474 }; 2475 } 2476 2477 /** 2478 * @param {() => void | (() => void)} fn 2479 * @returns {Effect} 2480 */ 2481 function effect(fn) { 2482 return create_effect(EFFECT, fn, false); 2483 } 2484 2485 /** 2486 * @param {() => void | (() => void)} fn 2487 * @returns {Effect} 2488 */ 2489 function async_effect(fn) { 2490 return create_effect(ASYNC | EFFECT_PRESERVED, fn, true); 2491 } 2492 2493 /** 2494 * @param {() => void | (() => void)} fn 2495 * @returns {Effect} 2496 */ 2497 function render_effect(fn, flags = 0) { 2498 return create_effect(RENDER_EFFECT | flags, fn, true); 2499 } 2500 2501 /** 2502 * @param {(...expressions: any) => void | (() => void)} fn 2503 * @param {Array<() => any>} sync 2504 * @param {Array<() => Promise<any>>} async 2505 */ 2506 function template_effect(fn, sync = [], async = []) { 2507 flatten(sync, async, (values) => { 2508 create_effect(RENDER_EFFECT, () => fn(...values.map(get)), true); 2509 }); 2510 } 2511 2512 /** 2513 * @param {(() => void)} fn 2514 * @param {number} flags 2515 */ 2516 function block(fn, flags = 0) { 2517 var effect = create_effect(BLOCK_EFFECT | flags, fn, true); 2518 return effect; 2519 } 2520 2521 /** 2522 * @param {(() => void)} fn 2523 * @param {boolean} [push] 2524 */ 2525 function branch(fn, push = true) { 2526 return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn, true, push); 2527 } 2528 2529 /** 2530 * @param {Effect} effect 2531 */ 2532 function execute_effect_teardown(effect) { 2533 var teardown = effect.teardown; 2534 if (teardown !== null) { 2535 const previously_destroying_effect = is_destroying_effect; 2536 const previous_reaction = active_reaction; 2537 set_is_destroying_effect(true); 2538 set_active_reaction(null); 2539 try { 2540 teardown.call(null); 2541 } finally { 2542 set_is_destroying_effect(previously_destroying_effect); 2543 set_active_reaction(previous_reaction); 2544 } 2545 } 2546 } 2547 2548 /** 2549 * @param {Effect} signal 2550 * @param {boolean} remove_dom 2551 * @returns {void} 2552 */ 2553 function destroy_effect_children(signal, remove_dom = false) { 2554 var effect = signal.first; 2555 signal.first = signal.last = null; 2556 2557 while (effect !== null) { 2558 const controller = effect.ac; 2559 2560 if (controller !== null) { 2561 without_reactive_context(() => { 2562 controller.abort(STALE_REACTION); 2563 }); 2564 } 2565 2566 var next = effect.next; 2567 2568 if ((effect.f & ROOT_EFFECT) !== 0) { 2569 // this is now an independent root 2570 effect.parent = null; 2571 } else { 2572 destroy_effect(effect, remove_dom); 2573 } 2574 2575 effect = next; 2576 } 2577 } 2578 2579 /** 2580 * @param {Effect} signal 2581 * @returns {void} 2582 */ 2583 function destroy_block_effect_children(signal) { 2584 var effect = signal.first; 2585 2586 while (effect !== null) { 2587 var next = effect.next; 2588 if ((effect.f & BRANCH_EFFECT) === 0) { 2589 destroy_effect(effect); 2590 } 2591 effect = next; 2592 } 2593 } 2594 2595 /** 2596 * @param {Effect} effect 2597 * @param {boolean} [remove_dom] 2598 * @returns {void} 2599 */ 2600 function destroy_effect(effect, remove_dom = true) { 2601 var removed = false; 2602 2603 if ( 2604 (remove_dom || (effect.f & HEAD_EFFECT) !== 0) && 2605 effect.nodes_start !== null && 2606 effect.nodes_end !== null 2607 ) { 2608 remove_effect_dom(effect.nodes_start, /** @type {TemplateNode} */ (effect.nodes_end)); 2609 removed = true; 2610 } 2611 2612 destroy_effect_children(effect, remove_dom && !removed); 2613 remove_reactions(effect, 0); 2614 set_signal_status(effect, DESTROYED); 2615 2616 var transitions = effect.transitions; 2617 2618 if (transitions !== null) { 2619 for (const transition of transitions) { 2620 transition.stop(); 2621 } 2622 } 2623 2624 execute_effect_teardown(effect); 2625 2626 var parent = effect.parent; 2627 2628 // If the parent doesn't have any children, then skip this work altogether 2629 if (parent !== null && parent.first !== null) { 2630 unlink_effect(effect); 2631 } 2632 2633 // `first` and `child` are nulled out in destroy_effect_children 2634 // we don't null out `parent` so that error propagation can work correctly 2635 effect.next = 2636 effect.prev = 2637 effect.teardown = 2638 effect.ctx = 2639 effect.deps = 2640 effect.fn = 2641 effect.nodes_start = 2642 effect.nodes_end = 2643 effect.ac = 2644 null; 2645 } 2646 2647 /** 2648 * 2649 * @param {TemplateNode | null} node 2650 * @param {TemplateNode} end 2651 */ 2652 function remove_effect_dom(node, end) { 2653 while (node !== null) { 2654 /** @type {TemplateNode | null} */ 2655 var next = node === end ? null : /** @type {TemplateNode} */ (get_next_sibling(node)); 2656 2657 node.remove(); 2658 node = next; 2659 } 2660 } 2661
2662 /** 2663 * Detach an effect from the effect tree, freeing up memory and 2664 * reducing the amount of work that happens on subsequent traversals 2665 * @param {Effect} effect 2666 */ 2667 function unlink_effect(effect) { 2668 var parent = effect.parent; 2669 var prev = effect.prev; 2670 var next = effect.next; 2671 2672 if (prev !== null) prev.next = next; 2673 if (next !== null) next.prev = prev; 2674 2675 if (parent !== null) { 2676 if (parent.first === effect) parent.first = next; 2677 if (parent.last === effect) parent.last = prev; 2678 } 2679 } 2680 2681 /** 2682 * When a block effect is removed, we don't immediately destroy it or yank it 2683 * out of the DOM, because it might have transitions. Instead, we 'pause' it. 2684 * It stays around (in memory, and in the DOM) until outro transitions have 2685 * completed, and if the state change is reversed then we _resume_ it. 2686 * A paused effect does not update, and the DOM subtree becomes inert. 2687 * @param {Effect} effect 2688 * @param {() => void} [callback] 2689 */ 2690 function pause_effect(effect, callback) { 2691 /** @type {TransitionManager[]} */ 2692 var transitions = []; 2693 2694 pause_children(effect, transitions, true); 2695 2696 run_out_transitions(transitions, () => { 2697 destroy_effect(effect); 2698 if (callback) callback(); 2699 }); 2700 } 2701 2702 /** 2703 * @param {TransitionManager[]} transitions 2704 * @param {() => void} fn 2705 */ 2706 function run_out_transitions(transitions, fn) { 2707 var remaining = transitions.length; 2708 if (remaining > 0) { 2709 var check = () => --remaining || fn(); 2710 for (var transition of transitions) { 2711 transition.out(check); 2712 } 2713 } else { 2714 fn(); 2715 } 2716 } 2717 2718 /** 2719 * @param {Effect} effect 2720 * @param {TransitionManager[]} transitions 2721 * @param {boolean} local 2722 */ 2723 function pause_children(effect, transitions, local) { 2724 if ((effect.f & INERT) !== 0) return; 2725 effect.f ^= INERT; 2726 2727 if (effect.transitions !== null) { 2728 for (const transition of effect.transitions) { 2729 if (transition.is_global || local) { 2730 transitions.push(transition); 2731 } 2732 } 2733 } 2734 2735 var child = effect.first; 2736 2737 while (child !== null) { 2738 var sibling = child.next; 2739 var transparent = (child.f & EFFECT_TRANSPARENT) !== 0 || (child.f & BRANCH_EFFECT) !== 0; 2740 // TODO we don't need to call pause_children recursively with a linked list in place 2741 // it's slightly more involved though as we have to account for `transparent` changing 2742 // through the tree. 2743 pause_children(child, transitions, transparent ? local : false); 2744 child = sibling; 2745 } 2746 } 2747 2748 /** 2749 * The opposite of `pause_effect`. We call this if (for example) 2750 * `x` becomes falsy then truthy: `{#if x}...{/if}` 2751 * @param {Effect} effect 2752 */ 2753 function resume_effect(effect) { 2754 resume_children(effect, true); 2755 } 2756 2757 /** 2758 * @param {Effect} effect 2759 * @param {boolean} local 2760 */ 2761 function resume_children(effect, local) { 2762 if ((effect.f & INERT) === 0) return; 2763 effect.f ^= INERT; 2764 2765 // If a dependency of this effect changed while it was paused, 2766 // schedule the effect to update. we don't use `is_dirty` 2767 // here because we don't want to eagerly recompute a derived like 2768 // `{#if foo}{foo.bar()}{/if}` if `foo` is now `undefined 2769 if ((effect.f & CLEAN) === 0) { 2770 set_signal_status(effect, DIRTY); 2771 schedule_effect(effect); 2772 } 2773 2774 var child = effect.first; 2775 2776 while (child !== null) { 2777 var sibling = child.next; 2778 var transparent = (child.f & EFFECT_TRANSPARENT) !== 0 || (child.f & BRANCH_EFFECT) !== 0; 2779 // TODO we don't need to call resume_children recursively with a linked list in place 2780 // it's slightly more involved though as we have to account for `transparent` changing 2781 // through the tree. 2782 resume_children(child, transparent ? local : false); 2783 child = sibling; 2784 } 2785 2786 if (effect.transitions !== null) { 2787 for (const transition of effect.transitions) { 2788 if (transition.is_global || local) { 2789 transition.in(); 2790 } 2791 } 2792 } 2793 } 2794 2795 /** @import { Derived, Effect, Reaction, Signal, Source, Value } from '#client' */ 2796 2797 let is_updating_effect = false; 2798 2799 /** @param {boolean} value */ 2800 function set_is_updating_effect(value) { 2801 is_updating_effect = value; 2802 } 2803 2804 let is_destroying_effect = false; 2805 2806 /** @param {boolean} value */ 2807 function set_is_destroying_effect(value) { 2808 is_destroying_effect = value; 2809 } 2810 2811 /** @type {null | Reaction} */ 2812 let active_reaction = null; 2813 2814 let untracking = false;
2815 2816 /** @param {null | Reaction} reaction */ 2817 function set_active_reaction(reaction) { 2818 active_reaction = reaction; 2819 } 2820 2821 /** @type {null | Effect} */ 2822 let active_effect = null; 2823 2824 /** @param {null | Effect} effect */ 2825 function set_active_effect(effect) { 2826 active_effect = effect; 2827 } 2828 2829 /** 2830 * When sources are created within a reaction, reading and writing 2831 * them within that reaction should not cause a re-run 2832 * @type {null | Source[]} 2833 */ 2834 let current_sources = null; 2835 2836 /** @param {Value} value */ 2837 function push_reaction_value(value) { 2838 if (active_reaction !== null && (true)) { 2839 if (current_sources === null) { 2840 current_sources = [value]; 2841 } else { 2842 current_sources.push(value); 2843 } 2844 } 2845 } 2846 2847 /** 2848 * The dependencies of the reaction that is currently being executed. In many cases, 2849 * the dependencies are unchanged between runs, and so this will be `null` unless 2850 * and until a new dependency is accessed â we track this via `skipped_deps` 2851 * @type {null | Value[]} 2852 */ 2853 let new_deps = null; 2854 2855 let skipped_deps = 0; 2856 2857 /** 2858 * Tracks writes that the effect it's executed in doesn't listen to yet, 2859 * so that the dependency can be added to the effect later on if it then reads it 2860 * @type {null | Source[]} 2861 */ 2862 let untracked_writes = null; 2863 2864 /** @param {null | Source[]} value */ 2865 function set_untracked_writes(value) { 2866 untracked_writes = value; 2867 } 2868 2869 /** 2870 * @type {number} Used by sources and deriveds for handling updates. 2871 * Version starts from 1 so that unowned deriveds differentiate between a created effect and a run one for tracing 2872 **/ 2873 let write_version = 1; 2874 2875 /** @type {number} Used to version each read of a source of derived to avoid duplicating depedencies inside a reaction */ 2876 let read_version = 0; 2877 2878 let update_version = read_version; 2879 2880 /** @param {number} value */ 2881 function set_update_version(value) { 2882 update_version = value; 2883 } 2884 2885 // If we are working with a get() chain that has no active container, 2886 // to prevent memory leaks, we skip adding the reaction. 2887 let skip_reaction = false; 2888 2889 function increment_write_version() { 2890 return ++write_version; 2891 } 2892 2893 /** 2894 * Determines whether a derived or effect is dirty. 2895 * If it is MAYBE_DIRTY, will set the status to CLEAN 2896 * @param {Reaction} reaction 2897 * @returns {boolean} 2898 */ 2899 function is_dirty(reaction) { 2900 var flags = reaction.f; 2901 2902 if ((flags & DIRTY) !== 0) { 2903 return true; 2904 } 2905 2906 if ((flags & MAYBE_DIRTY) !== 0) { 2907 var dependencies = reaction.deps; 2908 var is_unowned = (flags & UNOWNED) !== 0; 2909 2910 if (dependencies !== null) { 2911 var i; 2912 var dependency; 2913 var is_disconnected = (flags & DISCONNECTED) !== 0; 2914 var is_unowned_connected = is_unowned && active_effect !== null && !skip_reaction; 2915 var length = dependencies.length; 2916 2917 // If we are working with a disconnected or an unowned signal that is now connected (due to an active effect) 2918 // then we need to re-connect the reaction to the dependency, unless the effect has already been destroyed 2919 // (which can happen if the derived is read by an async derived) 2920 if ( 2921 (is_disconnected || is_unowned_connected) && 2922 (active_effect === null || (active_effect.f & DESTROYED) === 0) 2923 ) { 2924 var derived = /** @type {Derived} */ (reaction); 2925 var parent = derived.parent; 2926 2927 for (i = 0; i < length; i++) { 2928 dependency = dependencies[i]; 2929 2930 // We always re-add all reactions (even duplicates) if the derived was 2931 // previously disconnected, however we don't if it was unowned as we 2932 // de-duplicate dependencies in that case 2933 if (is_disconnected || !dependency?.reactions?.includes(derived)) { 2934 (dependency.reactions ??= []).push(derived); 2935 } 2936 } 2937 2938 if (is_disconnected) { 2939 derived.f ^= DISCONNECTED; 2940 } 2941 // If the unowned derived is now fully connected to the graph again (it's unowned and reconnected, has a parent 2942 // and the parent is not unowned), then we can mark it as connected again, removing the need for the unowned 2943 // flag 2944 if (is_unowned_connected && parent !== null && (parent.f & UNOWNED) === 0) {
2945 derived.f ^= UNOWNED; 2946 } 2947 } 2948 2949 for (i = 0; i < length; i++) { 2950 dependency = dependencies[i]; 2951 2952 if (is_dirty(/** @type {Derived} */ (dependency))) { 2953 update_derived(/** @type {Derived} */ (dependency)); 2954 } 2955 2956 if (dependency.wv > reaction.wv) { 2957 return true; 2958 } 2959 } 2960 } 2961 2962 // Unowned signals should never be marked as clean unless they 2963 // are used within an active_effect without skip_reaction 2964 if (!is_unowned || (active_effect !== null && !skip_reaction)) { 2965 set_signal_status(reaction, CLEAN); 2966 } 2967 } 2968 2969 return false; 2970 } 2971 2972 /** 2973 * @param {Value} signal 2974 * @param {Effect} effect 2975 * @param {boolean} [root] 2976 */ 2977 function schedule_possible_effect_self_invalidation(signal, effect, root = true) { 2978 var reactions = signal.reactions; 2979 if (reactions === null) return; 2980 2981 if (current_sources?.includes(signal)) { 2982 return; 2983 } 2984 2985 for (var i = 0; i < reactions.length; i++) { 2986 var reaction = reactions[i]; 2987 2988 if ((reaction.f & DERIVED) !== 0) { 2989 schedule_possible_effect_self_invalidation(/** @type {Derived} */ (reaction), effect, false); 2990 } else if (effect === reaction) { 2991 if (root) { 2992 set_signal_status(reaction, DIRTY); 2993 } else if ((reaction.f & CLEAN) !== 0) { 2994 set_signal_status(reaction, MAYBE_DIRTY); 2995 } 2996 schedule_effect(/** @type {Effect} */ (reaction)); 2997 } 2998 } 2999 } 3000 3001 /** @param {Reaction} reaction */ 3002 function update_reaction(reaction) { 3003 var previous_deps = new_deps; 3004 var previous_skipped_deps = skipped_deps; 3005 var previous_untracked_writes = untracked_writes; 3006 var previous_reaction = active_reaction; 3007 var previous_skip_reaction = skip_reaction; 3008 var previous_sources = current_sources; 3009 var previous_component_context = component_context; 3010 var previous_untracking = untracking; 3011 var previous_update_version = update_version; 3012 3013 var flags = reaction.f; 3014 3015 new_deps = /** @type {null | Value[]} */ (null); 3016 skipped_deps = 0; 3017 untracked_writes = null; 3018 skip_reaction = 3019 (flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null); 3020 active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null; 3021 3022 current_sources = null; 3023 set_component_context(reaction.ctx); 3024 untracking = false; 3025 update_version = ++read_version; 3026 3027 if (reaction.ac !== null) { 3028 without_reactive_context(() => { 3029 /** @type {AbortController} */ (reaction.ac).abort(STALE_REACTION); 3030 }); 3031 3032 reaction.ac = null; 3033 } 3034 3035 try { 3036 reaction.f |= REACTION_IS_UPDATING; 3037 var fn = /** @type {Function} */ (reaction.fn); 3038 var result = fn(); 3039 var deps = reaction.deps; 3040 3041 if (new_deps !== null) { 3042 var i; 3043 3044 remove_reactions(reaction, skipped_deps); 3045 3046 if (deps !== null && skipped_deps > 0) { 3047 deps.length = skipped_deps + new_deps.length; 3048 for (i = 0; i < new_deps.length; i++) { 3049 deps[skipped_deps + i] = new_deps[i]; 3050 } 3051 } else { 3052 reaction.deps = deps = new_deps; 3053 } 3054 3055 if ( 3056 !skip_reaction || 3057 // Deriveds that already have reactions can cleanup, so we still add them as reactions 3058 ((flags & DERIVED) !== 0 && 3059 /** @type {import('#client').Derived} */ (reaction).reactions !== null) 3060 ) { 3061 for (i = skipped_deps; i < deps.length; i++) { 3062 (deps[i].reactions ??= []).push(reaction); 3063 } 3064 } 3065 } else if (deps !== null && skipped_deps < deps.length) { 3066 remove_reactions(reaction, skipped_deps); 3067 deps.length = skipped_deps; 3068 } 3069 3070 // If we're inside an effect and we have untracked writes, then we need to 3071 // ensure that if any of those untracked writes result in re-invalidation 3072 // of the current effect, then that happens accordingly 3073 if ( 3074 is_runes() && 3075 untracked_writes !== null && 3076 !untracking && 3077 deps !== null && 3078 (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0 3079 ) { 3080 for (i = 0; i < /** @type {Source[]} */ (untracked_writes).length; i++) { 3081 schedule_possible_effect_self_invalidation( 3082 untracked_writes[i], 3083 /** @type {Effect} */ (reaction) 3084 ); 3085 } 3086 } 3087 3088 // If we are returning to an previous reaction then 3089 // we need to increment the read version to ensure that 3090 // any dependencies in this reaction aren't marked with 3091 // the same version 3092 if (previous_reaction !== null && previous_reaction !== reaction) { 3093 read_version++; 3094 3095 if (untracked_writes !== null) { 3096 if (previous_untracked_writes === null) { 3097 previous_untracked_writes = untracked_writes; 3098 } else { 3099 previous_untracked_writes.push(.../** @type {Source[]} */ (untracked_writes)); 3100 } 3101 } 3102 } 3103 3104 if ((reaction.f & ERROR_VALUE) !== 0) { 3105 reaction.f ^= ERROR_VALUE; 3106 } 3107 3108 return result; 3109 } catch (error) { 3110 return handle_error(error); 3111 } finally { 3112 reaction.f ^= REACTION_IS_UPDATING; 3113 new_deps = previous_deps; 3114 skipped_deps = previous_skipped_deps; 3115 untracked_writes = previous_untracked_writes; 3116 active_reaction = previous_reaction; 3117 skip_reaction = previous_skip_reaction; 3118 current_sources = previous_sources; 3119 set_component_context(previous_component_context); 3120 untracking = previous_untracking; 3121 update_version = previous_update_version; 3122 } 3123 } 3124
3125 /** 3126 * @template V 3127 * @param {Reaction} signal 3128 * @param {Value<V>} dependency 3129 * @returns {void} 3130 */ 3131 function remove_reaction(signal, dependency) { 3132 let reactions = dependency.reactions; 3133 if (reactions !== null) { 3134 var index = index_of.call(reactions, signal); 3135 if (index !== -1) { 3136 var new_length = reactions.length - 1; 3137 if (new_length === 0) { 3138 reactions = dependency.reactions = null; 3139 } else { 3140 // Swap with last element and then remove. 3141 reactions[index] = reactions[new_length]; 3142 reactions.pop(); 3143 } 3144 } 3145 } 3146 3147 // If the derived has no reactions, then we can disconnect it from the graph, 3148 // allowing it to either reconnect in the future, or be GC'd by the VM. 3149 if ( 3150 reactions === null && 3151 (dependency.f & DERIVED) !== 0 && 3152 // Destroying a child effect while updating a parent effect can cause a dependency to appear 3153 // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps` 3154 // allows us to skip the expensive work of disconnecting and immediately reconnecting it 3155 (new_deps === null || !new_deps.includes(dependency)) 3156 ) { 3157 set_signal_status(dependency, MAYBE_DIRTY); 3158 // If we are working with a derived that is owned by an effect, then mark it as being 3159 // disconnected. 3160 if ((dependency.f & (UNOWNED | DISCONNECTED)) === 0) { 3161 dependency.f ^= DISCONNECTED; 3162 } 3163 // Disconnect any reactions owned by this reaction 3164 destroy_derived_effects(/** @type {Derived} **/ (dependency)); 3165 remove_reactions(/** @type {Derived} **/ (dependency), 0); 3166 } 3167 } 3168 3169 /** 3170 * @param {Reaction} signal 3171 * @param {number} start_index 3172 * @returns {void} 3173 */ 3174 function remove_reactions(signal, start_index) { 3175 var dependencies = signal.deps; 3176 if (dependencies === null) return; 3177 3178 for (var i = start_index; i < dependencies.length; i++) { 3179 remove_reaction(signal, dependencies[i]); 3180 } 3181 } 3182 3183 /** 3184 * @param {Effect} effect 3185 * @returns {void} 3186 */ 3187 function update_effect(effect) { 3188 var flags = effect.f; 3189 3190 if ((flags & DESTROYED) !== 0) { 3191 return; 3192 } 3193 3194 set_signal_status(effect, CLEAN); 3195 3196 var previous_effect = active_effect; 3197 var was_updating_effect = is_updating_effect; 3198 3199 active_effect = effect; 3200 is_updating_effect = true; 3201 3202 try { 3203 if ((flags & BLOCK_EFFECT) !== 0) { 3204 destroy_block_effect_children(effect); 3205 } else { 3206 destroy_effect_children(effect); 3207 } 3208 3209 execute_effect_teardown(effect); 3210 var teardown = update_reaction(effect); 3211 effect.teardown = typeof teardown === 'function' ? teardown : null; 3212 effect.wv = write_version; 3213 3214 // In DEV, increment versions of any sources that were written to during the effect, 3215 // so that they are correctly marked as dirty when the effect re-runs 3216 var dep; if (DEV && tracing_mode_flag && (effect.f & DIRTY) !== 0 && effect.deps !== null) ; 3217 } finally { 3218 is_updating_effect = was_updating_effect; 3219 active_effect = previous_effect; 3220 } 3221 } 3222 3223 /** 3224 * Returns a promise that resolves once any pending state changes have been applied. 3225 * @returns {Promise<void>} 3226 */ 3227 async function tick() { 3228 3229 await Promise.resolve(); 3230 3231 // By calling flushSync we guarantee that any pending state changes are applied after one tick. 3232 // TODO look into whether we can make flushing subsequent updates synchronously in the future. 3233 flushSync(); 3234 } 3235 3236 /** 3237 * @template V 3238 * @param {Value<V>} signal 3239 * @returns {V} 3240 */ 3241 function get(signal) { 3242 var flags = signal.f; 3243 var is_derived = (flags & DERIVED) !== 0; 3244 3245 // Register the dependency on the current reaction signal. 3246 if (active_reaction !== null && !untracking) { 3247 // if we're in a derived that is being read inside an _async_ derived, 3248 // it's possible that the effect was already destroyed. In this case, 3249 // we don't add the dependency, because that would create a memory leak 3250 var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0; 3251 3252 if (!destroyed && !current_sources?.includes(signal)) { 3253 var deps = active_reaction.deps; 3254 3255 if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) { 3256 // we're in the effect init/update cycle 3257 if (signal.rv < read_version) { 3258 signal.rv = read_version; 3259 3260 // If the signal is accessing the same dependencies in the same 3261 // order as it did last time, increment `skipped_deps` 3262 // rather than updating `new_deps`, which creates GC cost 3263 if (new_deps === null && deps !== null && deps[skipped_deps] === signal) { 3264 skipped_deps++; 3265 } else if (new_deps === null) { 3266 new_deps = [signal]; 3267 } else if (!skip_reaction || !new_deps.includes(signal)) { 3268 // Normally we can push duplicated dependencies to `new_deps`, but if we're inside 3269 // an unowned derived because skip_reaction is true, then we need to ensure that 3270 // we don't have duplicates 3271 new_deps.push(signal); 3272 } 3273 } 3274 } else { 3275 // we're adding a dependency outside the init/update cycle 3276 // (i.e. after an `await`) 3277 (active_reaction.deps ??= []).push(signal); 3278 3279 var reactions = signal.reactions; 3280 3281 if (reactions === null) { 3282 signal.reactions = [active_reaction]; 3283 } else if (!reactions.includes(active_reaction)) { 3284 reactions.push(active_reaction); 3285 } 3286 } 3287 } 3288 } else if ( 3289 is_derived && 3290 /** @type {Derived} */ (signal).deps === null && 3291 /** @type {Derived} */ (signal).effects === null 3292 ) { 3293 var derived = /** @type {Derived} */ (signal); 3294 var parent = derived.parent; 3295 3296 if (parent !== null && (parent.f & UNOWNED) === 0) { 3297 // If the derived is owned by another derived then mark it as unowned 3298 // as the derived value might have been referenced in a different c
3298ontext 3299 // since and thus its parent might not be its true owner anymore 3300 derived.f ^= UNOWNED; 3301 } 3302 } 3303 3304 if (is_destroying_effect) { 3305 if (old_values.has(signal)) { 3306 return old_values.get(signal); 3307 } 3308 3309 if (is_derived) { 3310 derived = /** @type {Derived} */ (signal); 3311 3312 var value = derived.v; 3313 3314 // if the derived is dirty and has reactions, or depends on the values that just changed, re-execute 3315 // (a derived can be maybe_dirty due to the effect destroy removing its last reaction) 3316 if ( 3317 ((derived.f & CLEAN) === 0 && derived.reactions !== null) || 3318 depends_on_old_values(derived) 3319 ) { 3320 value = execute_derived(derived); 3321 } 3322 3323 old_values.set(derived, value); 3324 3325 return value; 3326 } 3327 } else if (is_derived) { 3328 derived = /** @type {Derived} */ (signal); 3329 3330 if (is_dirty(derived)) { 3331 update_derived(derived); 3332 } 3333 } 3334 3335 if ((signal.f & ERROR_VALUE) !== 0) { 3336 throw signal.v; 3337 } 3338 3339 return signal.v; 3340 } 3341 3342 /** @param {Derived} derived */ 3343 function depends_on_old_values(derived) { 3344 if (derived.v === UNINITIALIZED) return true; // we don't know, so assume the worst 3345 if (derived.deps === null) return false; 3346 3347 for (const dep of derived.deps) { 3348 if (old_values.has(dep)) { 3349 return true; 3350 } 3351 3352 if ((dep.f & DERIVED) !== 0 && depends_on_old_values(/** @type {Derived} */ (dep))) { 3353 return true; 3354 } 3355 } 3356 3357 return false; 3358 } 3359 3360 /** 3361 * When used inside a [`$derived`](https://svelte.dev/docs/svelte/$derived) or [`$effect`](https://svelte.dev/docs/svelte/$effect), 3362 * any state read inside `fn` will not be treated as a dependency. 3363 * 3364 * ```ts 3365 * $effect(() => { 3366 * // this will run when `data` changes, but not when `time` changes 3367 * save(data, { 3368 * timestamp: untrack(() => time) 3369 * }); 3370 * }); 3371 * ``` 3372 * @template T 3373 * @param {() => T} fn 3374 * @returns {T} 3375 */ 3376 function untrack(fn) { 3377 var previous_untracking = untracking; 3378 try { 3379 untracking = true; 3380 return fn(); 3381 } finally { 3382 untracking = previous_untracking; 3383 } 3384 } 3385 3386 const STATUS_MASK = -7169; 3387 3388 /** 3389 * @param {Signal} signal 3390 * @param {number} status 3391 * @returns {void} 3392 */ 3393 function set_signal_status(signal, status) { 3394 signal.f = (signal.f & STATUS_MASK) | status; 3395 } 3396 3397 /** @type {Set<string>} */ 3398 const all_registered_events = new Set(); 3399 3400 /** @type {Set<(events: Array<string>) => void>} */ 3401 const root_event_handles = new Set(); 3402 3403 /** 3404 * @param {string} event_name 3405 * @param {EventTarget} dom 3406 * @param {EventListener} [handler] 3407 * @param {AddEventListenerOptions} [options] 3408 */ 3409 function create_event(event_name, dom, handler, options = {}) { 3410 /** 3411 * @this {EventTarget} 3412 */ 3413 function target_handler(/** @type {Event} */ event) { 3414 if (!options.capture) { 3415 // Only call in the bubble phase, else delegated events would be called before the capturing events 3416 handle_event_propagation.call(dom, event); 3417 } 3418 if (!event.cancelBubble) { 3419 return without_reactive_context(() => { 3420 return handler?.call(this, event); 3421 }); 3422 } 3423 } 3424 3425 // Chrome has a bug where pointer events don't work when attached to a DOM element that has been cloned 3426 // with cloneNode() and the DOM element is disconnected from the document. To ensure the event works, we 3427 // defer the attachment till after it's been appended to the document. TODO: remove this once Chrome fixes 3428 // this bug. The same applies to wheel events and touch events. 3429 if ( 3430 event_name.startsWith('pointer') || 3431 event_name.startsWith('touch') || 3432 event_name === 'wheel' 3433 ) { 3434 queue_micro_task(() => { 3435 dom.addEventListener(event_name, target_handler, options); 3436 }); 3437 } else { 3438 dom.addEventListener(event_name, target_handler, options); 3439 } 3440 3441 return target_handler; 3442 } 3443 3444 /** 3445 * @param {string} event_name 3446 * @param {Element} dom 3447 * @param {EventListener} [handler] 3448 * @param {boolean} [capture] 3449 * @param {boolean} [passive] 3450 * @returns {void} 3451 */ 3452 function event(event_name, dom, handler, capture, passive) { 3453 var options = { capture, passive }; 3454 var target_handler = create_event(event_name, dom, handler, options); 3455 3456 if ( 3457 dom === document.body || 3458 // @ts-ignore 3459 dom === window || 3460 // @ts-ignore 3461 dom === document || 3462 // Firefox has quirky behavior, it can happen that we still get "canplay" events when the element is already removed 3463 dom instanceof HTMLMediaElement 3464 ) { 3465 teardown(() => { 3466 dom.removeEventListener(event_name, target_handler, options); 3467 }); 3468 } 3469 } 3470
3471 /** 3472 * @param {Array<string>} events 3473 * @returns {void} 3474 */ 3475 function delegate(events) { 3476 for (var i = 0; i < events.length; i++) { 3477 all_registered_events.add(events[i]); 3478 } 3479 3480 for (var fn of root_event_handles) { 3481 fn(events); 3482 } 3483 } 3484 3485 // used to store the reference to the currently propagated event 3486 // to prevent garbage collection between microtasks in Firefox 3487 // If the event object is GCed too early, the expando __root property 3488 // set on the event object is lost, causing the event delegation 3489 // to process the event twice 3490 let last_propagated_event = null; 3491 3492 /** 3493 * @this {EventTarget} 3494 * @param {Event} event 3495 * @returns {void} 3496 */ 3497 function handle_event_propagation(event) { 3498 var handler_element = this; 3499 var owner_document = /** @type {Node} */ (handler_element).ownerDocument; 3500 var event_name = event.type; 3501 var path = event.composedPath?.() || []; 3502 var current_target = /** @type {null | Element} */ (path[0] || event.target); 3503 3504 last_propagated_event = event; 3505 3506 // composedPath contains list of nodes the event has propagated through. 3507 // We check __root to skip all nodes below it in case this is a 3508 // parent of the __root node, which indicates that there's nested 3509 // mounted apps. In this case we don't want to trigger events multiple times. 3510 var path_idx = 0; 3511 3512 // the `last_propagated_event === event` check is redundant, but 3513 // without it the variable will be DCE'd and things will 3514 // fail mysteriously in Firefox 3515 // @ts-expect-error is added below 3516 var handled_at = last_propagated_event === event && event.__root; 3517 3518 if (handled_at) { 3519 var at_idx = path.indexOf(handled_at); 3520 if ( 3521 at_idx !== -1 && 3522 (handler_element === document || handler_element === /** @type {any} */ (window)) 3523 ) { 3524 // This is the fallback document listener or a window listener, but the event was already handled 3525 // -> ignore, but set handle_at to document/window so that we're resetting the event 3526 // chain in case someone manually dispatches the same event object again. 3527 // @ts-expect-error 3528 event.__root = handler_element; 3529 return; 3530 } 3531 3532 // We're deliberately not skipping if the index is higher, because 3533 // someone could create an event programmatically and emit it multiple times, 3534 // in which case we want to handle the whole propagation chain properly each time. 3535 // (this will only be a false negative if the event is dispatched multiple times and 3536 // the fallback document listener isn't reached in between, but that's super rare) 3537 var handler_idx = path.indexOf(handler_element); 3538 if (handler_idx === -1) { 3539 // handle_idx can theoretically be -1 (happened in some JSDOM testing scenarios with an event listener on the window object) 3540 // so guard against that, too, and assume that everything was handled at this point. 3541 return; 3542 } 3543 3544 if (at_idx <= handler_idx) { 3545 path_idx = at_idx; 3546 } 3547 } 3548 3549 current_target = /** @type {Element} */ (path[path_idx] || event.target); 3550 // there can only be one delegated event per element, and we either already handled the current target, 3551 // or this is the very first target in the chain which has a non-delegated listener, in which case it's safe 3552 // to handle a possible delegated event on it later (through the root delegation listener for example). 3553 if (current_target === handler_element) return; 3554 3555 // Proxy currentTarget to correct target 3556 define_property(event, 'currentTarget', { 3557 configurable: true, 3558 get() { 3559 return current_target || owner_document; 3560 } 3561 }); 3562 3563 // This started because of Chromium issue https://chromestatus.com/feature/5128696823545856, 3564 // where removal or moving of of the DOM can cause sync `blur` events to fire, which can cause logic 3565 // to run inside the current `active_reaction`, which isn't what we want at all. However, on reflection, 3566 // it's probably best that all event handled by Svelte have this behaviour, as we don't really want 3567 // an event handler to run in the context of another reaction or effect. 3568 var previous_reaction = active_reaction; 3569 var previous_effect = active_effect; 3570 set_active_reaction(null); 3571 set_active_effect(null); 3572 3573 try { 3574 /** 3575 * @type {unknown} 3576 */ 3577 var throw_error; 3578 /** 3579 * @type {unknown[]} 3580 */ 3581 var other_errors = []; 3582 3583 while (current_target !== null) { 3584 /** @type {null | Element} */ 3585 var parent_element = 3586 current_target.assignedSlot || 3587 current_target.parentNode || 3588 /** @type {any} */ (current_target).host || 3589 null; 3590 3591 try { 3592 // @ts-expect-error 3593 var delegated = current_target['__' + event_name]; 3594 3595 if ( 3596 delegated != null && 3597 (!(/** @type {any} */ (current_target).disabled) || 3598 // DOM could've been updated already by the time this is reached, so we check this as well 3599 // -> the target could not have been disabled because it emits the event in the first place 3600 event.target === current_target) 3601 ) { 3602 if (is_array(delegated)) { 3603 var [fn, ...data] = delegated; 3604 fn.apply(current_target, [event, ...data]); 3605 } else { 3606 delegated.call(current_target, event); 3607 } 3608 } 3609 } catch (error) { 3610 if (throw_error) { 3611 other_errors.push(error); 3612 } else { 3613 throw_error = error; 3614 } 3615 } 3616 if (event.cancelBubble || parent_element === handler_element || parent_element === null) { 3617 break; 3618 } 3619 current_target = parent_element; 3620 } 3621 3622 if (throw_error) { 3623 for (let error of other_errors) { 3624 // Throw the rest of the errors, one-by-one on a microtask 3625 queueMicrotask(() => { 3626 throw error; 3627 }); 3628 } 3629 throw throw_error; 3630 } 3631 } finally { 3632 // @ts-expect-error is used above 3633 event.__root = handler_element; 3634 // @ts-ignore remove proxy on currentTarget 3635 delete event.currentTarget; 3636 set_active_reaction(previous_reaction); 3637 set_active_effect(previous_effect); 3638 } 3639 } 3640
3641 /** @param {string} html */ 3642 function create_fragment_from_html(html) { 3643 var elem = document.createElement('template'); 3644 elem.innerHTML = html.replaceAll('<!>', '<!---->'); // XHTML compliance 3645 return elem.content; 3646 } 3647 3648 /** @import { Effect, TemplateNode } from '#client' */ 3649 /** @import { TemplateStructure } from './types' */ 3650 3651 /** 3652 * @param {TemplateNode} start 3653 * @param {TemplateNode | null} end 3654 */ 3655 function assign_nodes(start, end) { 3656 var effect = /** @type {Effect} */ (active_effect); 3657 if (effect.nodes_start === null) { 3658 effect.nodes_start = start; 3659 effect.nodes_end = end; 3660 } 3661 } 3662 3663 /** 3664 * @param {string} content 3665 * @param {number} flags 3666 * @returns {() => Node | Node[]} 3667 */ 3668 /*#__NO_SIDE_EFFECTS__*/ 3669 function from_html(content, flags) { 3670 var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0; 3671 var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0; 3672 3673 /** @type {Node} */ 3674 var node; 3675 3676 /** 3677 * Whether or not the first item is a text/element node. If not, we need to 3678 * create an additional comment node to act as `effect.nodes.start` 3679 */ 3680 var has_start = !content.startsWith('<!>'); 3681 3682 return () => { 3683 if (hydrating) { 3684 assign_nodes(hydrate_node, null); 3685 return hydrate_node; 3686 } 3687 3688 if (node === undefined) { 3689 node = create_fragment_from_html(has_start ? content : '<!>' + content); 3690 if (!is_fragment) node = /** @type {Node} */ (get_first_child(node)); 3691 } 3692 3693 var clone = /** @type {TemplateNode} */ ( 3694 use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true) 3695 ); 3696 3697 if (is_fragment) { 3698 var start = /** @type {TemplateNode} */ (get_first_child(clone)); 3699 var end = /** @type {TemplateNode} */ (clone.lastChild); 3700 3701 assign_nodes(start, end); 3702 } else { 3703 assign_nodes(clone, clone); 3704 } 3705 3706 return clone; 3707 }; 3708 } 3709 3710 function comment() { 3711 // we're not delegating to `template` here for performance reasons 3712 if (hydrating) { 3713 assign_nodes(hydrate_node, null); 3714 return hydrate_node; 3715 } 3716 3717 var frag = document.createDocumentFragment(); 3718 var start = document.createComment(''); 3719 var anchor = create_text(); 3720 frag.append(start, anchor); 3721 3722 assign_nodes(start, anchor); 3723 3724 return frag; 3725 } 3726 3727 /** 3728 * Assign the created (or in hydration mode, traversed) dom elements to the current block 3729 * and insert the elements into the dom (in client mode). 3730 * @param {Text | Comment | Element} anchor 3731 * @param {DocumentFragment | Element} dom 3732 */ 3733 function append(anchor, dom) { 3734 if (hydrating) { 3735 /** @type {Effect} */ (active_effect).nodes_end = hydrate_node; 3736 hydrate_next(); 3737 return; 3738 } 3739 3740 if (anchor === null) { 3741 // edge case â void `<svelte:element>` with content 3742 return; 3743 } 3744 3745 anchor.before(/** @type {Node} */ (dom)); 3746 } 3747 3748 /** 3749 * @param {string} name 3750 */ 3751 function is_capture_event(name) { 3752 return name.endsWith('capture') && name !== 'gotpointercapture' && name !== 'lostpointercapture'; 3753 } 3754 3755 /** List of Element events that will be delegated */ 3756 const DELEGATED_EVENTS = [ 3757 'beforeinput', 3758 'click', 3759 'change', 3760 'dblclick', 3761 'contextmenu', 3762 'focusin', 3763 'focusout', 3764 'input', 3765 'keydown', 3766 'keyup', 3767 'mousedown', 3768 'mousemove', 3769 'mouseout', 3770 'mouseover', 3771 'mouseup', 3772 'pointerdown', 3773 'pointermove', 3774 'pointerout', 3775 'pointerover', 3776 'pointerup', 3777 'touchend', 3778 'touchmove', 3779 'touchstart' 3780 ]; 3781 3782 /** 3783 * Returns `true` if `event_name` is a delegated event 3784 * @param {string} event_name 3785 */ 3786 function is_delegated(event_name) { 3787 return DELEGATED_EVENTS.includes(event_name); 3788 } 3789 3790 /** 3791 * @type {Record<string, string>} 3792 * List of attribute names that should be aliased to their property names 3793 * because they behave differently between setting them as an attribute and 3794 * setting them as a property. 3795 */ 3796 const ATTRIBUTE_ALIASES = { 3797 // no `class: 'className'` because we handle that separately 3798 formnovalidate: 'formNoValidate', 3799 ismap: 'isMap', 3800 nomodule: 'noModule', 3801 playsinline: 'playsInline', 3802 readonly: 'readOnly', 3803 defaultvalue: 'defaultValue', 3804 defaultchecked: 'defaultChecked', 3805 srcobject: 'srcObject', 3806 novalidate: 'noValidate', 3807 allowfullscreen: 'allowFullscreen', 3808 disablepictureinpicture: 'disablePictureInPicture', 3809 disableremoteplayback: 'disableRemotePlayback' 3810 }; 3811 3812 /** 3813 * @param {string} name 3814 */ 3815 function normalize_attribute(name) { 3816 name = name.toLowerCase(); 3817 return ATTRIBUTE_ALIASES[name] ?? name; 3818 } 3819 3820 /** 3821 * Subset of delegated events which should be passive by default. 3822 * These two are already passive via browser defaults on window, document and body. 3823 * But since 3824 * - we're delegating them 3825 * - they happen often 3826 * - they apply to mobile which is generally less performant 3827 * we're marking them as passive by default for other elements, too. 3828 */ 3829 const PASSIVE_EVENTS = ['touchstart', 'touchmove']; 3830 3831 /** 3832 * Returns `true` if `name` is a passive event 3833 * @param {string} name 3834 */ 3835 function is_passive_event(name) { 3836 return PASSIVE_EVENTS.includes(name); 3837 } 3838 3839 /** @import { ComponentContext, Effect, TemplateNode } from '#client' */
3840 /** @import { Component, ComponentType, SvelteComponent, MountOptions } from '../../index.js' */ 3841 3842 /** 3843 * @param {Element} text 3844 * @param {string} value 3845 * @returns {void} 3846 */ 3847 function set_text(text, value) { 3848 // For objects, we apply string coercion (which might make things like $state array references in the template reactive) before diffing 3849 var str = value == null ? '' : typeof value === 'object' ? value + '' : value; 3850 // @ts-expect-error 3851 if (str !== (text.__t ??= text.nodeValue)) { 3852 // @ts-expect-error 3853 text.__t = str; 3854 text.nodeValue = str + ''; 3855 } 3856 } 3857 3858 /** 3859 * Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component. 3860 * Transitions will play during the initial render unless the `intro` option is set to `false`. 3861 * 3862 * @template {Record<string, any>} Props 3863 * @template {Record<string, any>} Exports 3864 * @param {ComponentType<SvelteComponent<Props>> | Component<Props, Exports, any>} component 3865 * @param {MountOptions<Props>} options 3866 * @returns {Exports} 3867 */ 3868 function mount(component, options) { 3869 return _mount(component, options); 3870 } 3871 3872 /** 3873 * Hydrates a component on the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component 3874 * 3875 * @template {Record<string, any>} Props 3876 * @template {Record<string, any>} Exports 3877 * @param {ComponentType<SvelteComponent<Props>> | Component<Props, Exports, any>} component 3878 * @param {{} extends Props ? { 3879 * target: Document | Element | ShadowRoot; 3880 * props?: Props; 3881 * events?: Record<string, (e: any) => any>; 3882 * context?: Map<any, any>; 3883 * intro?: boolean; 3884 * recover?: boolean; 3885 * } : { 3886 * target: Document | Element | ShadowRoot; 3887 * props: Props; 3888 * events?: Record<string, (e: any) => any>; 3889 * context?: Map<any, any>; 3890 * intro?: boolean; 3891 * recover?: boolean; 3892 * }} options 3893 * @returns {Exports} 3894 */ 3895 function hydrate(component, options) { 3896 init_operations(); 3897 options.intro = options.intro ?? false; 3898 const target = options.target; 3899 const was_hydrating = hydrating; 3900 const previous_hydrate_node = hydrate_node; 3901 3902 try { 3903 var anchor = /** @type {TemplateNode} */ (get_first_child(target)); 3904 while ( 3905 anchor && 3906 (anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */ (anchor).data !== HYDRATION_START) 3907 ) { 3908 anchor = /** @type {TemplateNode} */ (get_next_sibling(anchor)); 3909 } 3910 3911 if (!anchor) { 3912 throw HYDRATION_ERROR; 3913 } 3914 3915 set_hydrating(true); 3916 set_hydrate_node(/** @type {Comment} */ (anchor)); 3917 hydrate_next(); 3918 3919 const instance = _mount(component, { ...options, anchor }); 3920 3921 if ( 3922 hydrate_node === null || 3923 hydrate_node.nodeType !== COMMENT_NODE || 3924 /** @type {Comment} */ (hydrate_node).data !== HYDRATION_END 3925 ) { 3926 hydration_mismatch(); 3927 throw HYDRATION_ERROR; 3928 } 3929 3930 set_hydrating(false); 3931 3932 return /** @type {Exports} */ (instance); 3933 } catch (error) { 3934 // re-throw Svelte errors - they are certainly not related to hydration 3935 if ( 3936 error instanceof Error && 3937 error.message.split('\n').some((line) => line.startsWith('https://svelte.dev/e/')) 3938 ) { 3939 throw error; 3940 } 3941 if (error !== HYDRATION_ERROR) { 3942 // eslint-disable-next-line no-console 3943 console.warn('Failed to hydrate: ', error); 3944 } 3945 3946 if (options.recover === false) { 3947 hydration_failed(); 3948 } 3949 3950 // If an error occured above, the operations might not yet have been initialised. 3951 init_operations(); 3952 clear_text_content(target); 3953 3954 set_hydrating(false); 3955 return mount(component, options); 3956 } finally { 3957 set_hydrating(was_hydrating); 3958 set_hydrate_node(previous_hydrate_node); 3959 } 3960 } 3961 3962 /** @type {Map<string, number>} */ 3963 const document_listeners = new Map(); 3964 3965 /** 3966 * @template {Record<string, any>} Exports 3967 * @param {ComponentType<SvelteComponent<any>> | Component<any>} Component 3968 * @param {MountOptions} options 3969 * @returns {Exports} 3970 */ 3971 function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) { 3972 init_operations(); 3973 3974 /** @type {Set<string>} */ 3975 var registered_events = new Set(); 3976 3977 /** @param {Array<string>} events */ 3978 var event_handle = (events) => { 3979 for (var i = 0; i < events.length; i++) { 3980 var event_name = events[i]; 3981 3982 if (registered_events.has(event_name)) continue; 3983 registered_events.add(event_name); 3984 3985 var passive = is_passive_event(event_name); 3986 3987 // Add the event listener to both the container and the document. 3988 // The container listener ensures we catch events from within in case 3989 // the outer content stops propagation of the event. 3990 target.addEventListener(event_name, handle_event_propagation, { passive }); 3991 3992 var n = document_listeners.get(event_name); 3993 3994 if (n === undefined) { 3995 // The document listener ensures we catch events that originate from elements that were 3996 // manually moved outside of the container (e.g. via manual portals). 3997 document.addEventListener(event_name, handle_event_propagation, { passive }); 3998 document_listeners.set(event_name, 1); 3999 } else { 4000 document_listeners.set(event_name, n + 1); 4001 } 4002 } 4003 }; 4004 4005 event_handle(array_from(all_registered_events)); 4006 root_event_handles.add(event_handle); 4007 4008 /** @type {Exports} */ 4009 // @ts-expect-error will be defined because the render effect runs synchronously 4010 var component = undefined; 4011 4012 var unmount = component_root(() => { 4013 var anchor_node = anchor ?? target.appendChild(create_text()); 4014 4015 branch(() => { 4016 if (context) { 4017 push({}); 4018 var ctx = /** @type {ComponentContext} */ (component_context); 4019 ctx.c = context; 4020 } 4021 4022 if (events) { 4023 // We can't spread the object or else we'd lose the state proxy stuff, if it is one 4024 /** @type {any} */ (props).$$events = events; 4025 } 4026 4027 if (hydrating) { 4028 assign_nodes(/** @type {TemplateNode} */ (anchor_node), null); 4029 } 4030 // @ts-expect-error the public typings are not what the actual function looks like 4031 component = Component(anchor_node, props) || {}; 4032 4033 if (hydrating) { 4034 /** @type {Effect} */ (active_effect).nodes_end = hydrate_node; 4035 } 4036 4037 if (context) { 4038 pop(); 4039 } 4040 }); 4041 4042 return () => { 4043 for (var event_name of registered_events) { 4044 target.removeEventListener(event_name, handle_event_propagation); 4045 4046 var n = /** @type {number} */ (document_listeners.get(event_name)); 4047 4048 if (--n === 0) { 4049 document.removeEventListener(event_name, handle_event_propagation); 4050 document_listeners.delete(event_name); 4051 } else { 4052 document_listeners.set(event_name, n); 4053 } 4054 } 4055 4056 root_event_handles.delete(event_handle); 4057 4058 if (anchor_node !== anchor) { 4059 anchor_node.parentNode?.removeChild(anchor_node); 4060 } 4061 }; 4062 }); 4063 4064 mounted_components.set(component, unmount); 4065 return component; 4066 } 4067 4068 /** 4069 * References of the components that were mounted or hydrated. 4070 * Uses a `WeakMap` to avoid memory leaks. 4071 */ 4072 let mounted_components = new WeakMap(); 4073 4074 /** 4075 * Unmounts a component that was previously mounted using `mount` or `hydrate`. 4076 * 4077 * Since 5.13.0, if `options.outro` is `true`, [transitions](https://svelte.dev/docs/svelte/transition) will play before the component is removed from the DOM. 4078 * 4079 * Returns a `Promise` that resolves after transitions have completed if `options.outro` is true, or immediately otherwise (prior to 5.13.0, returns `void`). 4080 * 4081 * ```js 4082 * import { mount, unmount } from 'svelte'; 4083 * import App from './App.svelte'; 4084 * 4085 * const app = mount(App, { target: document.body }); 4086 * 4087 * // later... 4088 * unmount(app, { outro: true }); 4089 * ``` 4090 * @param {Record<string, any>} component 4091 * @param {{ outro?: boolean }} [options] 4092 * @returns {Promise<void>} 4093 */ 4094 function unmount(component, options) { 4095 const fn = mounted_components.get(component); 4096 4097 if (fn) { 4098 mounted_components.delete(component); 4099 return fn(options); 4100 } 4101 4102 return Promise.resolve(); 4103 } 4104 4105 /** @import { ComponentContext, ComponentContextLegacy } from '#client' */ 4106 /** @import { EventDispatcher } from './index.js' */ 4107 /** @import { NotFunction } from './internal/types.js' */ 4108 4109 /** 4110 * `onMount`, like [`$effect`](https://svelte.dev/docs/svelte/$effect), schedules a function to run as soon as the component has been mounted to the DOM. 4111 * Unlike `$effect`, the provided function only runs once. 4112 * 4113 * It must be called during the component's initialisation (but doesn't need to live _inside_ the component; 4114 * it can be called from an external module). If a function is returned _synchronously_ from `onMount`, 4115 * it will be called when the component is unmounted. 4116 * 4117 * `onMount` functions do not run during [server-side rendering](https://svelte.dev/docs/svelte/svelte-server#render). 4118 * 4119 * @template T 4120 * @param {() => NotFunction<T> | Promise<NotFunction<T>> | (() => any)} fn 4121 * @returns {void} 4122 */ 4123 function onMount(fn) { 4124 if (component_context === null) { 4125 lifecycle_outside_component(); 4126 } 4127 4128 { 4129 user_effect(() => { 4130 const cleanup = untrack(fn); 4131 if (typeof cleanup === 'function') return /** @type {() => void} */ (cleanup); 4132 }); 4133 } 4134 } 4135
4136 /** 4137 * Schedules a callback to run immediately before the component is unmounted. 4138 * 4139 * Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the 4140 * only one that runs inside a server-side component. 4141 * 4142 * @param {() => any} fn 4143 * @returns {void} 4144 */ 4145 function onDestroy(fn) { 4146 if (component_context === null) { 4147 lifecycle_outside_component(); 4148 } 4149 4150 onMount(() => () => untrack(fn)); 4151 } 4152 4153 /** @import { Effect, Source, TemplateNode } from '#client' */ 4154 4155 const PENDING = 0; 4156 const THEN = 1; 4157 const CATCH = 2; 4158 4159 /** @typedef {typeof PENDING | typeof THEN | typeof CATCH} AwaitState */ 4160 4161 /** 4162 * @template V 4163 * @param {TemplateNode} node 4164 * @param {(() => Promise<V>)} get_input 4165 * @param {null | ((anchor: Node) => void)} pending_fn 4166 * @param {null | ((anchor: Node, value: Source<V>) => void)} then_fn 4167 * @param {null | ((anchor: Node, error: unknown) => void)} catch_fn 4168 * @returns {void} 4169 */ 4170 function await_block(node, get_input, pending_fn, then_fn, catch_fn) { 4171 if (hydrating) { 4172 hydrate_next(); 4173 } 4174 4175 var anchor = node; 4176 var active_component_context = component_context; 4177 4178 /** @type {V | Promise<V> | typeof UNINITIALIZED} */ 4179 var input = UNINITIALIZED; 4180 4181 /** @type {Effect | null} */ 4182 var pending_effect; 4183 4184 /** @type {Effect | null} */ 4185 var then_effect; 4186 4187 /** @type {Effect | null} */ 4188 var catch_effect; 4189 4190 var input_source = source(/** @type {V} */ (undefined)) 4191 ; 4192 var error_source = source(undefined) ; 4193 var resolved = false; 4194 /** 4195 * @param {AwaitState} state 4196 * @param {boolean} restore 4197 */ 4198 function update(state, restore) { 4199 resolved = true; 4200 4201 if (restore) { 4202 set_active_effect(effect); 4203 set_active_reaction(effect); // TODO do we need both? 4204 set_component_context(active_component_context); 4205 } 4206 4207 try { 4208 if (state === PENDING && pending_fn) { 4209 if (pending_effect) resume_effect(pending_effect); 4210 else pending_effect = branch(() => pending_fn(anchor)); 4211 } 4212 4213 if (state === THEN && then_fn) { 4214 if (then_effect) resume_effect(then_effect); 4215 else then_effect = branch(() => then_fn(anchor, input_source)); 4216 } 4217 4218 if (state === CATCH && catch_fn) { 4219 if (catch_effect) resume_effect(catch_effect); 4220 else catch_effect = branch(() => catch_fn(anchor, error_source)); 4221 } 4222 4223 if (state !== PENDING && pending_effect) { 4224 pause_effect(pending_effect, () => (pending_effect = null)); 4225 } 4226 4227 if (state !== THEN && then_effect) { 4228 pause_effect(then_effect, () => (then_effect = null)); 4229 } 4230 4231 if (state !== CATCH && catch_effect) { 4232 pause_effect(catch_effect, () => (catch_effect = null)); 4233 } 4234 } finally { 4235 if (restore) { 4236 4237 set_component_context(null); 4238 set_active_reaction(null); 4239 set_active_effect(null); 4240 4241 // without this, the DOM does not update until two ticks after the promise 4242 // resolves, which is unexpected behaviour (and somewhat irksome to test) 4243 flushSync(); 4244 } 4245 } 4246 } 4247 4248 var effect = block(() => { 4249 if (input === (input = get_input())) return; 4250 4251 /** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */ 4252 // @ts-ignore coercing `anchor` to a `Comment` causes TypeScript and Prettier to fight 4253 let mismatch = hydrating && is_promise(input) === (anchor.data === HYDRATION_START_ELSE); 4254 4255 if (mismatch) { 4256 // Hydration mismatch: remove everything inside the anchor and start fresh 4257 anchor = remove_nodes(); 4258 4259 set_hydrate_node(anchor); 4260 set_hydrating(false); 4261 mismatch = true; 4262 } 4263 4264 if (is_promise(input)) { 4265 var promise = input; 4266 4267 resolved = false; 4268 4269 promise.then( 4270 (value) => { 4271 if (promise !== input) return; 4272 // we technically could use `set` here since it's on the next microtick 4273 // but let's use internal_set for consistency and just to be safe 4274 internal_set(input_source, value); 4275 update(THEN, true); 4276 }, 4277 (error) => { 4278 if (promise !== input) return; 4279 // we technically could use `set` here since it's on the next microtick 4280 // but let's use internal_set for consistency and just to be safe 4281 internal_set(error_source, error); 4282 update(CATCH, true); 4283 if (!catch_fn) { 4284 // Rethrow the error if no catch block exists 4285 throw error_source.v; 4286 } 4287 } 4288 ); 4289 4290 if (hydrating) { 4291 if (pending_fn) { 4292 pending_effect = branch(() => pending_fn(anchor)); 4293 } 4294 } else { 4295 // Wait a microtask before checking if we should show the pending state as 4296 // the promise might have resolved by the next microtask. 4297 queue_micro_task(() => { 4298 if (!resolved) update(PENDING, true); 4299 }); 4300 } 4301 } else { 4302 internal_set(input_source, input); 4303 update(THEN, false); 4304 } 4305 4306 if (mismatch) { 4307 // continue in hydration mode 4308 set_hydrating(true); 4309 } 4310 4311 // Set the input to something else, in order to disable the promise callbacks 4312 return () => (input = UNINITIALIZED); 4313 }); 4314 4315 if (hydrating) { 4316 anchor = hydrate_node; 4317 } 4318 } 4319
4320 /** @import { Effect, TemplateNode } from '#client' */ 4321 /** @import { Batch } from '../../reactivity/batch.js'; */ 4322 4323 // TODO reinstate https://github.com/sveltejs/svelte/pull/15250 4324 4325 /** 4326 * @param {TemplateNode} node 4327 * @param {(branch: (fn: (anchor: Node) => void, flag?: boolean) => void) => void} fn 4328 * @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local' 4329 * @returns {void} 4330 */ 4331 function if_block(node, fn, elseif = false) { 4332 if (hydrating) { 4333 hydrate_next(); 4334 } 4335 4336 var anchor = node; 4337 4338 /** @type {Effect | null} */ 4339 var consequent_effect = null; 4340 4341 /** @type {Effect | null} */ 4342 var alternate_effect = null; 4343 4344 /** @type {typeof UNINITIALIZED | boolean | null} */ 4345 var condition = UNINITIALIZED; 4346 4347 var flags = elseif ? EFFECT_TRANSPARENT : 0; 4348 4349 var has_branch = false; 4350 4351 const set_branch = (/** @type {(anchor: Node) => void} */ fn, flag = true) => { 4352 has_branch = true; 4353 update_branch(flag, fn); 4354 }; 4355 4356 /** @type {DocumentFragment | null} */ 4357 var offscreen_fragment = null; 4358 4359 function commit() { 4360 if (offscreen_fragment !== null) { 4361 // remove the anchor 4362 /** @type {Text} */ (offscreen_fragment.lastChild).remove(); 4363 4364 anchor.before(offscreen_fragment); 4365 offscreen_fragment = null; 4366 } 4367 4368 var active = condition ? consequent_effect : alternate_effect; 4369 var inactive = condition ? alternate_effect : consequent_effect; 4370 4371 if (active) { 4372 resume_effect(active); 4373 } 4374 4375 if (inactive) { 4376 pause_effect(inactive, () => { 4377 if (condition) { 4378 alternate_effect = null; 4379 } else { 4380 consequent_effect = null; 4381 } 4382 }); 4383 } 4384 } 4385 4386 const update_branch = ( 4387 /** @type {boolean | null} */ new_condition, 4388 /** @type {null | ((anchor: Node) => void)} */ fn 4389 ) => { 4390 if (condition === (condition = new_condition)) return; 4391 4392 /** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */ 4393 let mismatch = false; 4394 4395 if (hydrating) { 4396 const is_else = read_hydration_instruction(anchor) === HYDRATION_START_ELSE; 4397 4398 if (!!condition === is_else) { 4399 // Hydration mismatch: remove everything inside the anchor and start fresh. 4400 // This could happen with `{#if browser}...{/if}`, for example 4401 anchor = remove_nodes(); 4402 4403 set_hydrate_node(anchor); 4404 set_hydrating(false); 4405 mismatch = true; 4406 } 4407 } 4408 4409 var defer = should_defer_append(); 4410 var target = anchor; 4411 4412 if (defer) { 4413 offscreen_fragment = document.createDocumentFragment(); 4414 offscreen_fragment.append((target = create_text())); 4415 } 4416 4417 if (condition) { 4418 consequent_effect ??= fn && branch(() => fn(target)); 4419 } else { 4420 alternate_effect ??= fn && branch(() => fn(target)); 4421 } 4422 4423 if (defer) { 4424 var batch = /** @type {Batch} */ (current_batch); 4425 4426 var active = condition ? consequent_effect : alternate_effect; 4427 var inactive = condition ? alternate_effect : consequent_effect; 4428 4429 if (active) batch.skipped_effects.delete(active); 4430 if (inactive) batch.skipped_effects.add(inactive); 4431 4432 batch.add_callback(commit); 4433 } else { 4434 commit(); 4435 } 4436 4437 if (mismatch) { 4438 // continue in hydration mode 4439 set_hydrating(true); 4440 } 4441 }; 4442 4443 block(() => { 4444 has_branch = false; 4445 fn(set_branch); 4446 if (!has_branch) { 4447 update_branch(null, null); 4448 } 4449 }, flags); 4450 4451 if (hydrating) { 4452 anchor = hydrate_node; 4453 } 4454 } 4455 4456 /** @import { EachItem, EachState, Effect, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */ 4457 /** @import { Batch } from '../../reactivity/batch.js'; */ 4458 4459 /** 4460 * @param {any} _ 4461 * @param {number} i 4462 */ 4463 function index(_, i) { 4464 return i; 4465 } 4466 4467 /** 4468 * Pause multiple effects simultaneously, and coordinate their 4469 * subsequent destruction. Used in each blocks 4470 * @param {EachState} state 4471 * @param {EachItem[]} items 4472 * @param {null | Node} controlled_anchor 4473 */ 4474 function pause_effects(state, items, controlled_anchor) { 4475 var items_map = state.items; 4476 4477 /** @type {TransitionManager[]} */ 4478 var transitions = []; 4479 var length = items.length; 4480 4481 for (var i = 0; i < length; i++) { 4482 pause_children(items[i].e, transitions, true); 4483 } 4484 4485 var is_controlled = length > 0 && transitions.length === 0 && controlled_anchor !== null; 4486 // If we have a controlled anchor, it means that the each block
4486is inside a single 4487 // DOM element, so we can apply a fast-path for clearing the contents of the element. 4488 if (is_controlled) { 4489 var parent_node = /** @type {Element} */ ( 4490 /** @type {Element} */ (controlled_anchor).parentNode 4491 ); 4492 clear_text_content(parent_node); 4493 parent_node.append(/** @type {Element} */ (controlled_anchor)); 4494 items_map.clear(); 4495 link(state, items[0].prev, items[length - 1].next); 4496 } 4497 4498 run_out_transitions(transitions, () => { 4499 for (var i = 0; i < length; i++) { 4500 var item = items[i]; 4501 if (!is_controlled) { 4502 items_map.delete(item.k); 4503 link(state, item.prev, item.next); 4504 } 4505 destroy_effect(item.e, !is_controlled); 4506 } 4507 }); 4508 } 4509 4510 /** 4511 * @template V 4512 * @param {Element | Comment} node The next sibling node, or the parent node if this is a 'controlled' block 4513 * @param {number} flags 4514 * @param {() => V[]} get_collection 4515 * @param {(value: V, index: number) => any} get_key 4516 * @param {(anchor: Node, item: MaybeSource<V>, index: MaybeSource<number>) => void} render_fn 4517 * @param {null | ((anchor: Node) => void)} fallback_fn 4518 * @returns {void} 4519 */ 4520 function each(node, flags, get_collection, get_key, render_fn, fallback_fn = null) { 4521 var anchor = node; 4522 4523 /** @type {EachState} */ 4524 var state = { flags, items: new Map(), first: null }; 4525 4526 { 4527 var parent_node = /** @type {Element} */ (node); 4528 4529 anchor = hydrating 4530 ? set_hydrate_node(/** @type {Comment | Text} */ (get_first_child(parent_node))) 4531 : parent_node.appendChild(create_text()); 4532 } 4533 4534 if (hydrating) { 4535 hydrate_next(); 4536 } 4537 4538 /** @type {Effect | null} */ 4539 var fallback = null; 4540 4541 var was_empty = false; 4542 4543 /** @type {Map<any, EachItem>} */ 4544 var offscreen_items = new Map(); 4545 4546 // TODO: ideally we could use derived for runes mode but because of the ability 4547 // to use a store which can be mutated, we can't do that here as mutating a store 4548 // will still result in the collection array being the same from the store 4549 var each_array = derived_safe_equal(() => { 4550 var collection = get_collection(); 4551 4552 return is_array(collection) ? collection : collection == null ? [] : array_from(collection); 4553 }); 4554 4555 /** @type {V[]} */ 4556 var array; 4557 4558 /** @type {Effect} */ 4559 var each_effect; 4560 4561 function commit() { 4562 reconcile( 4563 each_effect, 4564 array, 4565 state, 4566 offscreen_items, 4567 anchor, 4568 render_fn, 4569 flags, 4570 get_key, 4571 get_collection 4572 ); 4573 4574 if (fallback_fn !== null) { 4575 if (array.length === 0) { 4576 if (fallback) { 4577 resume_effect(fallback); 4578 } else { 4579 fallback = branch(() => fallback_fn(anchor)); 4580 } 4581 } else if (fallback !== null) { 4582 pause_effect(fallback, () => { 4583 fallback = null; 4584 }); 4585 } 4586 } 4587 } 4588 4589 block(() => { 4590 // store a reference to the effect so that we can update the start/end nodes in reconciliation 4591 each_effect ??= /** @type {Effect} */ (active_effect); 4592 4593 array = /** @type {V[]} */ (get(each_array)); 4594 var length = array.length; 4595 4596 if (was_empty && length === 0) { 4597 // ignore updates if the array is empty, 4598 // and it already was empty on previous run 4599 return; 4600 } 4601 was_empty = length === 0; 4602 4603 /** `true` if there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */ 4604 let mismatch = false; 4605 4606 if (hydrating) { 4607 var is_else = read_hydration_instruction(anchor) === HYDRATION_START_ELSE; 4608 4609 if (is_else !== (length === 0)) { 4610 // hydration mismatch â remove the server-rendered DOM and start over 4611 anchor = remove_nodes(); 4612 4613 set_hydrate_node(anchor); 4614 set_hydrating(false); 4615 mismatch = true; 4616 } 4617 } 4618 4619 // this is separate to the previous block because `hydrating` might change 4620 if (hydrating) { 4621 /** @type {EachItem | null} */ 4622 var prev = null; 4623 4624 /** @type {EachItem} */ 4625 var item; 4626 4627 for (var i = 0; i < length; i++) { 4628 if ( 4629 hydrate_node.nodeType === COMMENT_NODE && 4630 /** @type {Comment} */ (hydrate_node).data === HYDRATION_END 4631 ) { 4632 // The server rendered fewer items than expected, 4633 // so break out and continue appending non-hydrated items 4634 anchor = /** @type {Comment} */ (hydrate_node); 4635 mismatch = true; 4636 set_hydrating(false); 4637 break; 4638 } 4639 4640 var value = array[i]; 4641 var key = get_key(value, i); 4642 item = create_item( 4643 hydrate_node, 4644 state, 4645 prev, 4646 null, 4647 value, 4648 key, 4649 i, 4650 render_fn, 4651 flags, 4652 get_collection 4653 ); 4654 state.items.set(key, item); 4655 4656 prev = item; 4657 } 4658 4659 // remove excess nodes 4660 if (length > 0) { 4661 set_hydrate_node(remove_nodes()); 4662 } 4663 } 4664 4665 if (hydrating) { 4666 if (length === 0 && fallback_fn) { 4667 fallback = branch(() => fallback_fn(anchor)); 4668 } 4669 } else { 4670 if (should_defer_append()) { 4671 var keys = new Set(); 4672 var batch = /** @type {Batch} */ (current_batch); 4673 4674 for (i = 0; i < length; i += 1) { 4675 value = array[i]; 4676 key = get_key(value, i); 4677 4678 var existing = state.items.get(key) ?? offscreen_items.get(key); 4679 4680 if (existing) { 4681 // update before reconciliation, to trigger any async updates 4682 { 4683 update_item(existing, value, i); 4684 } 4685 } else { 4686 item = create_item( 4687 null, 4688 state, 4689 null, 4690 null, 4691 value, 4692 key, 4693 i, 4694 render_fn, 4695 flags, 4696 get_collection, 4697 true 4698 ); 4699 4700 offscreen_items.set(key, item); 4701 } 4702 4703 keys.add(key); 4704 } 4705 4706 for (const [key, item] of state.items) { 4707 if (!keys.has(key)) { 4708 batch.skipped_effects.add(item.e); 4709 } 4710 } 4711 4712 batch.add_callback(commit); 4713 } else { 4714 commit(); 4715 } 4716 } 4717 4718 if (mismatch) { 4719 // continue in hydration mode 4720 set_hydrating(true); 4721 } 4722 4723 // When we mount the each block for the first time, the collection won't be 4724 // connected to this effect as the effect hasn't finished running yet and its deps 4725 // won't be assigned. However, it's possible that when reconciling the each block 4726 // that a mutation occurred and it's made the collection MAYBE_DIRTY, so reading the 4727 // collection again can provide consistency to the reactive graph again as the deriveds 4728 // will now be `CLEAN`. 4729 get(each_array); 4730 }); 4731 4732 if (hydrating) { 4733 anchor = hydrate_node; 4734 } 4735 } 4736
4737 /** 4738 * Add, remove, or reorder items output by an each block as its input changes 4739 * @template V 4740 * @param {Effect} each_effect 4741 * @param {Array<V>} array 4742 * @param {EachState} state 4743 * @param {Map<any, EachItem>} offscreen_items 4744 * @param {Element | Comment | Text} anchor 4745 * @param {(anchor: Node, item: MaybeSource<V>, index: number | Source<number>, collection: () => V[]) => void} render_fn 4746 * @param {number} flags 4747 * @param {(value: V, index: number) => any} get_key 4748 * @param {() => V[]} get_collection 4749 * @returns {void} 4750 */ 4751 function reconcile( 4752 each_effect, 4753 array, 4754 state, 4755 offscreen_items, 4756 anchor, 4757 render_fn, 4758 flags, 4759 get_key, 4760 get_collection 4761 ) { 4762 4763 var length = array.length; 4764 var items = state.items; 4765 var first = state.first; 4766 var current = first; 4767 4768 /** @type {undefined | Set<EachItem>} */ 4769 var seen; 4770 4771 /** @type {EachItem | null} */ 4772 var prev = null; 4773 4774 /** @type {EachItem[]} */ 4775 var matched = []; 4776 4777 /** @type {EachItem[]} */ 4778 var stashed = []; 4779 4780 /** @type {V} */ 4781 var value; 4782 4783 /** @type {any} */ 4784 var key; 4785 4786 /** @type {EachItem | undefined} */ 4787 var item; 4788 4789 /** @type {number} */ 4790 var i; 4791 4792 for (i = 0; i < length; i += 1) { 4793 value = array[i]; 4794 key = get_key(value, i); 4795 4796 item = items.get(key); 4797 4798 if (item === undefined) { 4799 var pending = offscreen_items.get(key); 4800 4801 if (pending !== undefined) { 4802 offscreen_items.delete(key); 4803 items.set(key, pending); 4804 4805 var next = prev ? prev.next : current; 4806 4807 link(state, prev, pending); 4808 link(state, pending, next); 4809 4810 move(pending, next, anchor); 4811 prev = pending; 4812 } else { 4813 var child_anchor = current ? /** @type {TemplateNode} */ (current.e.nodes_start) : anchor; 4814 4815 prev = create_item( 4816 child_anchor, 4817 state, 4818 prev, 4819 prev === null ? state.first : prev.next, 4820 value, 4821 key, 4822 i, 4823 render_fn, 4824 flags, 4825 get_collection 4826 ); 4827 } 4828 4829 items.set(key, prev); 4830 4831 matched = []; 4832 stashed = []; 4833 4834 current = prev.next; 4835 continue; 4836 } 4837 4838 { 4839 update_item(item, value, i); 4840 } 4841 4842 if ((item.e.f & INERT) !== 0) { 4843 resume_effect(item.e); 4844 } 4845 4846 if (item !== current) { 4847 if (seen !== undefined && seen.has(item)) { 4848 if (matched.length < stashed.length) { 4849 // more efficient to move later items to the front 4850 var start = stashed[0]; 4851 var j; 4852 4853 prev = start.prev; 4854 4855 var a = matched[0]; 4856 var b = matched[matched.length - 1]; 4857 4858 for (j = 0; j < matched.length; j += 1) { 4859 move(matched[j], start, anchor); 4860 } 4861 4862 for (j = 0; j < stashed.length; j += 1) { 4863 seen.delete(stashed[j]); 4864 } 4865 4866 link(state, a.prev, b.next); 4867 link(state, prev, a); 4868 link(state, b, start); 4869 4870 current = start; 4871 prev = b; 4872 i -= 1; 4873 4874 matched = []; 4875 stashed = []; 4876 } else { 4877 // more efficient to move earlier items to the back 4878 seen.delete(item); 4879 move(item, current, anchor); 4880 4881 link(state, item.prev, item.next); 4882 link(state, item, prev === null ? state.first : prev.next); 4883 link(state, prev, item); 4884 4885 prev = item; 4886 } 4887 4888 continue; 4889 } 4890 4891 matched = []; 4892 stashed = []; 4893 4894 while (current !== null && current.k !== key) { 4895 // If the each block isn't inert and an item has an effect that is already inert, 4896 // skip over adding it to our seen Set as the item is already being handled 4897 if ((current.e.f & INERT) === 0) { 4898 (seen ??= new Set()).add(current); 4899 } 4900 stashed.push(current); 4901 current = current.next; 4902 } 4903 4904 if (current === null) { 4905 continue; 4906 } 4907 4908 item = current; 4909 } 4910 4911 matched.push(item); 4912 prev = item; 4913 current = item.next; 4914 } 4915 4916 if (current !== null || seen !== undefined) { 4917 var to_destroy = seen === undefined ? [] : array_from(seen); 4918 4919 while (current !== null) { 4920 // If the each block isn't inert, then inert effects are currently outroing and will be removed once the transition is finished 4921 if ((current.e.f & INERT) === 0) { 4922 to_destroy.push(current); 4923 } 4924 current = current.next; 4925 } 4926 4927 var destroy_length = to_destroy.length; 4928 4929 if (destroy_length > 0) { 4930 var controlled_anchor = length === 0 ? anchor : null; 4931 4932 pause_effects(state, to_destroy, controlled_anchor); 4933 } 4934 } 4935 4936 each_effect.first = state.first && state.first.e; 4937 each_effect.last = prev && prev.e; 4938 4939 for (var unused of offscreen_items.values()) { 4940 destroy_effect(unused.e); 4941 } 4942 4943 offscreen_items.clear(); 4944 } 4945 4946 /** 4947 * @param {EachItem} item 4948 * @param {any} value 4949 * @param {number} index 4950 * @param {number} type 4951 * @returns {void} 4952 */ 4953 function update_item(item, value, index, type) { 4954 { 4955 internal_set(item.v, value); 4956 } 4957 4958 { 4959 item.i = index; 4960 } 4961 } 4962
4963 /** 4964 * @template V 4965 * @param {Node | null} anchor 4966 * @param {EachState} state 4967 * @param {EachItem | null} prev 4968 * @param {EachItem | null} next 4969 * @param {V} value 4970 * @param {unknown} key 4971 * @param {number} index 4972 * @param {(anchor: Node, item: V | Source<V>, index: number | Value<number>, collection: () => V[]) => void} render_fn 4973 * @param {number} flags 4974 * @param {() => V[]} get_collection 4975 * @param {boolean} [deferred] 4976 * @returns {EachItem} 4977 */ 4978 function create_item( 4979 anchor, 4980 state, 4981 prev, 4982 next, 4983 value, 4984 key, 4985 index, 4986 render_fn, 4987 flags, 4988 get_collection, 4989 deferred 4990 ) { 4991 var reactive = (flags & EACH_ITEM_REACTIVE) !== 0; 4992 var mutable = (flags & EACH_ITEM_IMMUTABLE) === 0; 4993 4994 var v = reactive ? (mutable ? mutable_source(value, false, false) : source(value)) : value; 4995 var i = (flags & EACH_INDEX_REACTIVE) === 0 ? index : source(index); 4996 4997 /** @type {EachItem} */ 4998 var item = { 4999 i, 5000 v, 5001 k: key, 5002 a: null, 5003 // @ts-expect-error 5004 e: null, 5005 prev, 5006 next 5007 }; 5008 5009 try { 5010 if (anchor === null) { 5011 var fragment = document.createDocumentFragment(); 5012 fragment.append((anchor = create_text())); 5013 } 5014 5015 item.e = branch(() => render_fn(/** @type {Node} */ (anchor), v, i, get_collection), hydrating); 5016 5017 item.e.prev = prev && prev.e; 5018 item.e.next = next && next.e; 5019 5020 if (prev === null) { 5021 if (!deferred) { 5022 state.first = item; 5023 } 5024 } else { 5025 prev.next = item; 5026 prev.e.next = item.e; 5027 } 5028 5029 if (next !== null) { 5030 next.prev = item; 5031 next.e.prev = item.e; 5032 } 5033 5034 return item; 5035 } finally { 5036 } 5037 } 5038 5039 /** 5040 * @param {EachItem} item 5041 * @param {EachItem | null} next 5042 * @param {Text | Element | Comment} anchor 5043 */ 5044 function move(item, next, anchor) { 5045 var end = item.next ? /** @type {TemplateNode} */ (item.next.e.nodes_start) : anchor; 5046 5047 var dest = next ? /** @type {TemplateNode} */ (next.e.nodes_start) : anchor; 5048 var node = /** @type {TemplateNode} */ (item.e.nodes_start); 5049 5050 while (node !== null && node !== end) { 5051 var next_node = /** @type {TemplateNode} */ (get_next_sibling(node)); 5052 dest.before(node); 5053 node = next_node; 5054 } 5055 } 5056 5057 /** 5058 * @param {EachState} state 5059 * @param {EachItem | null} prev 5060 * @param {EachItem | null} next 5061 */ 5062 function link(state, prev, next) { 5063 if (prev === null) { 5064 state.first = next; 5065 } else { 5066 prev.next = next; 5067 prev.e.next = next && next.e; 5068 } 5069 5070 if (next !== null) { 5071 next.prev = prev; 5072 next.e.prev = prev && prev.e; 5073 } 5074 } 5075 5076 /** @import { Effect, TemplateNode } from '#client' */ 5077 5078 /** 5079 * @param {Element | Text | Comment} node 5080 * @param {() => string} get_value 5081 * @param {boolean} [svg] 5082 * @param {boolean} [mathml] 5083 * @param {boolean} [skip_warning] 5084 * @returns {void} 5085 */ 5086 function html(node, get_value, svg = false, mathml = false, skip_warning = false) { 5087 var anchor = node; 5088 5089 var value = ''; 5090 5091 template_effect(() => { 5092 var effect = /** @type {Effect} */ (active_effect); 5093 5094 if (value === (value = get_value() ?? '')) { 5095 if (hydrating) hydrate_next(); 5096 return; 5097 } 5098 5099 if (effect.nodes_start !== null) { 5100 remove_effect_dom(effect.nodes_start, /** @type {TemplateNode} */ (effect.nodes_end)); 5101 effect.nodes_start = effect.nodes_end = null; 5102 } 5103 5104 if (value === '') return; 5105 5106 if (hydrating) { 5107 // We're deliberately not trying to repair mismatches between server and client, 5108 // as it's costly and error-prone (and it's an edge case to have a mismatch anyway) 5109 /** @type {Comment} */ (hydrate_node).data; 5110 var next = hydrate_next(); 5111 var last = next; 5112 5113 while ( 5114 next !== null && 5115 (next.nodeType !== COMMENT_NODE || /** @type {Comment} */ (next).data !== '') 5116 ) { 5117 last = next; 5118 next = /** @type {TemplateNode} */ (get_next_sibling(next)); 5119 } 5120 5121 if (next === null) { 5122 hydration_mismatch(); 5123 throw HYDRATION_ERROR; 5124 } 5125 5126 assign_nodes(hydrate_node, last); 5127 anchor = set_hydrate_node(next); 5128 return; 5129 } 5130 5131 var html = value + ''; 5132 if (svg) html = `<svg>${html}</svg>`; 5133 else if (mathml) html = `<math>${html}</math>`; 5134 5135 // Don't use create_fragment_with_script_from_html here because that would mean script tags are executed. 5136 // @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons. 5137 /** @type {DocumentFragment | Element} */ 5138 var node = create_fragment_from_html(html); 5139 5140 if (svg || mathml) { 5141 node = /** @type {Element} */ (get_first_child(node)); 5142 } 5143 5144 assign_nodes( 5145 /** @type {TemplateNode} */ (get_first_child(node)), 5146 /** @type {TemplateNode} */ (node.lastChild) 5147 ); 5148 5149 if (svg || mathml) { 5150 while (get_first_child(node)) { 5151 anchor.before(/** @type {Node} */ (get_first_child(node))); 5152 } 5153 } else { 5154 anchor.before(node); 5155 } 5156 }); 5157 } 5158 5159 /** @import { Effect } from '#client' */ 5160 5161 // TODO in 6.0 or 7.0, when we remove legacy mode, we can simplify this by 5162 // getting rid of the block/branch stuff and just letting the effect rip. 5163 // see https://github.com/sveltejs/svelte/pull/15962 5164 5165 /** 5166 * @param {Element} node 5167 * @param {() => (node: Element) => void} get_fn 5168 */
vendor: 7,159 bytes, lines 5169-5452
5169 function attach(node, get_fn) { 5170 /** @type {false | undefined | ((node: Element) => void)} */ 5171 var fn = undefined; 5172 5173 /** @type {Effect | null} */ 5174 var e; 5175 5176 block(() => { 5177 if (fn !== (fn = get_fn())) { 5178 if (e) { 5179 destroy_effect(e); 5180 e = null; 5181 } 5182 5183 if (fn) { 5184 e = branch(() => { 5185 effect(() => /** @type {(node: Element) => void} */ (fn)(node)); 5186 }); 5187 } 5188 } 5189 }); 5190 } 5191 5192 function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx$1(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n} 5193 5194 /** 5195 * Small wrapper around clsx to preserve Svelte's (weird) handling of falsy values. 5196 * TODO Svelte 6 revisit this, and likely turn all falsy values into the empty string (what clsx also does) 5197 * @param {any} value 5198 */ 5199 function clsx(value) { 5200 if (typeof value === 'object') { 5201 return clsx$1(value); 5202 } else { 5203 return value ?? ''; 5204 } 5205 } 5206 5207 const whitespace = [...' \t\n\r\f\u00a0\u000b\ufeff']; 5208 5209 /** 5210 * @param {any} value 5211 * @param {string | null} [hash] 5212 * @param {Record<string, boolean>} [directives] 5213 * @returns {string | null} 5214 */ 5215 function to_class(value, hash, directives) { 5216 var classname = value == null ? '' : '' + value; 5217 5218 if (hash) { 5219 classname = classname ? classname + ' ' + hash : hash; 5220 } 5221 5222 if (directives) { 5223 for (var key in directives) { 5224 if (directives[key]) { 5225 classname = classname ? classname + ' ' + key : key; 5226 } else if (classname.length) { 5227 var len = key.length; 5228 var a = 0; 5229 5230 while ((a = classname.indexOf(key, a)) >= 0) { 5231 var b = a + len; 5232 5233 if ( 5234 (a === 0 || whitespace.includes(classname[a - 1])) && 5235 (b === classname.length || whitespace.includes(classname[b])) 5236 ) { 5237 classname = (a === 0 ? '' : classname.substring(0, a)) + classname.substring(b + 1); 5238 } else { 5239 a = b; 5240 } 5241 } 5242 } 5243 } 5244 } 5245 5246 return classname === '' ? null : classname; 5247 } 5248 5249 /** 5250 * 5251 * @param {Record<string,any>} styles 5252 * @param {boolean} important 5253 */ 5254 function append_styles(styles, important = false) { 5255 var separator = important ? ' !important;' : ';'; 5256 var css = ''; 5257 5258 for (var key in styles) { 5259 var value = styles[key]; 5260 if (value != null && value !== '') { 5261 css += ' ' + key + ': ' + value + separator; 5262 } 5263 } 5264 5265 return css; 5266 } 5267 5268 /** 5269 * @param {string} name 5270 * @returns {string} 5271 */ 5272 function to_css_name(name) { 5273 if (name[0] !== '-' || name[1] !== '-') { 5274 return name.toLowerCase(); 5275 } 5276 return name; 5277 } 5278 5279 /** 5280 * @param {any} value 5281 * @param {Record<string, any> | [Record<string, any>, Record<string, any>]} [styles] 5282 * @returns {string | null} 5283 */ 5284 function to_style(value, styles) { 5285 if (styles) { 5286 var new_style = ''; 5287 5288 /** @type {Record<string,any> | undefined} */ 5289 var normal_styles; 5290 5291 /** @type {Record<string,any> | undefined} */ 5292 var important_styles; 5293 5294 if (Array.isArray(styles)) { 5295 normal_styles = styles[0]; 5296 important_styles = styles[1]; 5297 } else { 5298 normal_styles = styles; 5299 } 5300 5301 if (value) { 5302 value = String(value) 5303 .replaceAll(/\s*\/\*.*?\*\/\s*/g, '') 5304 .trim(); 5305 5306 /** @type {boolean | '"' | "'"} */ 5307 var in_str = false; 5308 var in_apo = 0; 5309 var in_comment = false; 5310 5311 var reserved_names = []; 5312 5313 if (normal_styles) { 5314 reserved_names.push(...Object.keys(normal_styles).map(to_css_name)); 5315 } 5316 if (important_styles) { 5317 reserved_names.push(...Object.keys(important_styles).map(to_css_name)); 5318 } 5319 5320 var start_index = 0; 5321 var name_index = -1; 5322 5323 const len = value.length; 5324 for (var i = 0; i < len; i++) { 5325 var c = value[i]; 5326 5327 if (in_comment) { 5328 if (c === '/' && value[i - 1] === '*') { 5329 in_comment = false; 5330 } 5331 } else if (in_str) { 5332 if (in_str === c) { 5333 in_str = false; 5334 } 5335 } else if (c === '/' && value[i + 1] === '*') { 5336 in_comment = true; 5337 } else if (c === '"' || c === "'") { 5338 in_str = c; 5339 } else if (c === '(') { 5340 in_apo++; 5341 } else if (c === ')') { 5342 in_apo--; 5343 } 5344 5345 if (!in_comment && in_str === false && in_apo === 0) { 5346 if (c === ':' && name_index === -1) { 5347 name_index = i; 5348 } else if (c === ';' || i === len - 1) { 5349 if (name_index !== -1) { 5350 var name = to_css_name(value.substring(start_index, name_index).trim()); 5351 5352 if (!reserved_names.includes(name)) { 5353 if (c !== ';') { 5354 i++; 5355 } 5356 5357 var property = value.substring(start_index, i).trim(); 5358 new_style += ' ' + property + ';'; 5359 } 5360 } 5361 5362 start_index = i + 1; 5363 name_index = -1; 5364 } 5365 } 5366 } 5367 } 5368 5369 if (normal_styles) { 5370 new_style += append_styles(normal_styles); 5371 } 5372 5373 if (important_styles) { 5374 new_style += append_styles(important_styles, true); 5375 } 5376 5377 new_style = new_style.trim(); 5378 return new_style === '' ? null : new_style; 5379 } 5380 5381 return value == null ? null : String(value); 5382 } 5383 5384 /** 5385 * @param {Element} dom 5386 * @param {boolean | number} is_html 5387 * @param {string | null} value 5388 * @param {string} [hash] 5389 * @param {Record<string, any>} [prev_classes] 5390 * @param {Record<string, any>} [next_classes] 5391 * @returns {Record<string, boolean> | undefined} 5392 */ 5393 function set_class(dom, is_html, value, hash, prev_classes, next_classes) { 5394 // @ts-expect-error need to add __className to patched prototype 5395 var prev = dom.__className; 5396 5397 if ( 5398 hydrating || 5399 prev !== value || 5400 prev === undefined // for edge case of `class={undefined}` 5401 ) { 5402 var next_class_name = to_class(value, hash, next_classes); 5403 5404 if (!hydrating || next_class_name !== dom.getAttribute('class')) { 5405 // Removing the attribute when the value is only an empty string causes 5406 // performance issues vs simply making the className an empty string. So 5407 // we should only remove the class if the value is nullish 5408 // and there no hash/directives : 5409 if (next_class_name == null) { 5410 dom.removeAttribute('class'); 5411 } else if (is_html) { 5412 dom.className = next_class_name; 5413 } else { 5414 dom.setAttribute('class', next_class_name); 5415 } 5416 } 5417 5418 // @ts-expect-error need to add __className to patched prototype 5419 dom.__className = value; 5420 } else if (next_classes && prev_classes !== next_classes) { 5421 for (var key in next_classes) { 5422 var is_present = !!next_classes[key]; 5423 5424 if (prev_classes == null || is_present !== !!prev_classes[key]) { 5425 dom.classList.toggle(key, is_present); 5426 } 5427 } 5428 } 5429 5430 return next_classes; 5431 } 5432 5433 /** 5434 * @param {Element & ElementCSSInlineStyle} dom 5435 * @param {Record<string, any>} prev 5436 * @param {Record<string, any>} next 5437 * @param {string} [priority] 5438 */ 5439 function update_styles(dom, prev = {}, next, priority) { 5440 for (var key in next) { 5441 var value = next[key]; 5442 5443 if (prev[key] !== value) { 5444 if (next[key] == null) { 5445 dom.style.removeProperty(key); 5446 } else { 5447 dom.style.setProperty(key, value, priority); 5448 } 5449 } 5450 } 5451 } 5452
5453 /** 5454 * @param {Element & ElementCSSInlineStyle} dom 5455 * @param {string | null} value 5456 * @param {Record<string, any> | [Record<string, any>, Record<string, any>]} [prev_styles] 5457 * @param {Record<string, any> | [Record<string, any>, Record<string, any>]} [next_styles] 5458 */ 5459 function set_style(dom, value, prev_styles, next_styles) { 5460 // @ts-expect-error 5461 var prev = dom.__style; 5462 5463 if (hydrating || prev !== value) { 5464 var next_style_attr = to_style(value, next_styles); 5465 5466 if (!hydrating || next_style_attr !== dom.getAttribute('style')) { 5467 if (next_style_attr == null) { 5468 dom.removeAttribute('style'); 5469 } else { 5470 dom.style.cssText = next_style_attr; 5471 } 5472 } 5473 5474 // @ts-expect-error 5475 dom.__style = value; 5476 } else if (next_styles) { 5477 if (Array.isArray(next_styles)) { 5478 update_styles(dom, prev_styles?.[0], next_styles[0]); 5479 update_styles(dom, prev_styles?.[1], next_styles[1], 'important'); 5480 } else { 5481 update_styles(dom, prev_styles, next_styles); 5482 } 5483 } 5484 5485 return next_styles; 5486 } 5487 5488 /** 5489 * Selects the correct option(s) (depending on whether this is a multiple select) 5490 * @template V 5491 * @param {HTMLSelectElement} select 5492 * @param {V} value 5493 * @param {boolean} mounting 5494 */ 5495 function select_option(select, value, mounting = false) { 5496 if (select.multiple) { 5497 // If value is null or undefined, keep the selection as is 5498 if (value == undefined) { 5499 return; 5500 } 5501 5502 // If not an array, warn and keep the selection as is 5503 if (!is_array(value)) { 5504 return select_multiple_invalid_value(); 5505 } 5506 5507 // Otherwise, update the selection 5508 for (var option of select.options) { 5509 option.selected = value.includes(get_option_value(option)); 5510 } 5511 5512 return; 5513 } 5514 5515 for (option of select.options) { 5516 var option_value = get_option_value(option); 5517 if (is(option_value, value)) { 5518 option.selected = true; 5519 return; 5520 } 5521 } 5522 5523 if (!mounting || value !== undefined) { 5524 select.selectedIndex = -1; // no option should be selected 5525 } 5526 } 5527 5528 /** 5529 * Selects the correct option(s) if `value` is given, 5530 * and then sets up a mutation observer to sync the 5531 * current selection to the dom when it changes. Such 5532 * changes could for example occur when options are 5533 * inside an `#each` block. 5534 * @param {HTMLSelectElement} select 5535 */ 5536 function init_select(select) { 5537 var observer = new MutationObserver(() => { 5538 // @ts-ignore 5539 select_option(select, select.__value); 5540 // Deliberately don't update the potential binding value, 5541 // the model should be preserved unless explicitly changed 5542 }); 5543 5544 observer.observe(select, { 5545 // Listen to option element changes 5546 childList: true, 5547 subtree: true, // because of <optgroup> 5548 // Listen to option element value attribute changes 5549 // (doesn't get notified of select value changes, 5550 // because that property is not reflected as an attribute) 5551 attributes: true, 5552 attributeFilter: ['value'] 5553 }); 5554 5555 teardown(() => { 5556 observer.disconnect(); 5557 }); 5558 } 5559 5560 /** @param {HTMLOptionElement} option */ 5561 function get_option_value(option) { 5562 // __value only exists if the <option> has a value attribute 5563 if ('__value' in option) { 5564 return option.__value; 5565 } else { 5566 return option.value; 5567 } 5568 } 5569 5570 /** @import { Effect } from '#client' */ 5571 5572 const CLASS = Symbol('class'); 5573 const STYLE = Symbol('style'); 5574 5575 const IS_CUSTOM_ELEMENT = Symbol('is custom element'); 5576 const IS_HTML = Symbol('is html'); 5577 5578 /** 5579 * The value/checked attribute in the template actually corresponds to the defaultValue property, so we need 5580 * to remove it upon hydration to avoid a bug when someone resets the form value. 5581 * @param {HTMLInputElement} input 5582 * @returns {void} 5583 */ 5584 function remove_input_defaults(input) { 5585 if (!hydrating) return; 5586 5587 var already_removed = false; 5588 5589 // We try and remove the default attributes later, rather than sync during hydration. 5590 // Doing it sync during hydration has a negative impact on performance, but deferring the
5591 // work in an idle task alleviates this greatly. If a form reset event comes in before 5592 // the idle callback, then we ensure the input defaults are cleared just before. 5593 var remove_defaults = () => { 5594 if (already_removed) return; 5595 already_removed = true; 5596 5597 // Remove the attributes but preserve the values 5598 if (input.hasAttribute('value')) { 5599 var value = input.value; 5600 set_attribute(input, 'value', null); 5601 input.value = value; 5602 } 5603 5604 if (input.hasAttribute('checked')) { 5605 var checked = input.checked; 5606 set_attribute(input, 'checked', null); 5607 input.checked = checked; 5608 } 5609 }; 5610 5611 // @ts-expect-error 5612 input.__on_r = remove_defaults; 5613 queue_idle_task(remove_defaults); 5614 add_form_reset_listener(); 5615 } 5616 5617 /** 5618 * Sets the `selected` attribute on an `option` element. 5619 * Not set through the property because that doesn't reflect to the DOM, 5620 * which means it wouldn't be taken into account when a form is reset. 5621 * @param {HTMLOptionElement} element 5622 * @param {boolean} selected 5623 */ 5624 function set_selected(element, selected) { 5625 if (selected) { 5626 // The selected option could've changed via user selection, and 5627 // setting the value without this check would set it back. 5628 if (!element.hasAttribute('selected')) { 5629 element.setAttribute('selected', ''); 5630 } 5631 } else { 5632 element.removeAttribute('selected'); 5633 } 5634 } 5635 5636 /** 5637 * @param {Element} element 5638 * @param {string} attribute 5639 * @param {string | null} value 5640 * @param {boolean} [skip_warning] 5641 */ 5642 function set_attribute(element, attribute, value, skip_warning) { 5643 var attributes = get_attributes(element); 5644 5645 if (hydrating) { 5646 attributes[attribute] = element.getAttribute(attribute); 5647 5648 if ( 5649 attribute === 'src' || 5650 attribute === 'srcset' || 5651 (attribute === 'href' && element.nodeName === 'LINK') 5652 ) { 5653 5654 // If we reset these attributes, they would result in another network request, which we want to avoid. 5655 // We assume they are the same between client and server as checking if they are equal is expensive 5656 // (we can't just compare the strings as they can be different between client and server but result in the 5657 // same url, so we would need to create hidden anchor elements to compare them) 5658 return; 5659 } 5660 } 5661 5662 if (attributes[attribute] === (attributes[attribute] = value)) return; 5663 5664 if (attribute === 'loading') { 5665 // @ts-expect-error 5666 element[LOADING_ATTR_SYMBOL] = value; 5667 } 5668 5669 if (value == null) { 5670 element.removeAttribute(attribute); 5671 } else if (typeof value !== 'string' && get_setters(element).includes(attribute)) { 5672 // @ts-ignore 5673 element[attribute] = value; 5674 } else { 5675 element.setAttribute(attribute, value); 5676 } 5677 } 5678 5679 /** 5680 * @param {HTMLElement} node 5681 * @param {string} prop 5682 * @param {any} value 5683 */ 5684 function set_custom_element_data(node, prop, value) { 5685 // We need to ensure that setting custom element props, which can 5686 // invoke lifecycle methods on other custom elements, does not also 5687 // associate those lifecycle methods with the current active reaction 5688 // or effect 5689 var previous_reaction = active_reaction; 5690 var previous_effect = active_effect; 5691 5692 // If we're hydrating but the custom element is from Svelte, and it already scaffolded, 5693 // then it might run block logic in hydration mode, which we have to prevent. 5694 let was_hydrating = hydrating; 5695 if (hydrating) { 5696 set_hydrating(false); 5697 } 5698 5699 set_active_reaction(null); 5700 set_active_effect(null); 5701 5702 try { 5703 if ( 5704 // `style` should use `set_attribute` rather than the setter 5705 prop !== 'style' && 5706 // Don't compute setters for custom elements while they aren't registered yet, 5707 // because during their upgrade/instantiation they might add more setters. 5708 // Instead, fall back to a simple "an object, then set as property" heuristic. 5709 (setters_cache.has(node.getAttribute('is') || node.nodeName) || 5710 // customElements may not be available in browser extension contexts 5711 !customElements || 5712 customElements.get(node.getAttribute('is') || node.tagName.toLowerCase()) 5713 ? get_setters(node).includes(prop) 5714 : value && typeof value === 'object') 5715 ) { 5716 // @ts-expect-error 5717 node[prop] = value; 5718 } else { 5719 // We did getters etc checks already, stringify before passing to set_attribute 5720 // to ensure it doesn't invoke the same logic again, and potentially populating 5721 // the setters cache too early. 5722 set_attribute(node, prop, value == null ? value : String(value)); 5723 } 5724 } finally { 5725 set_active_reaction(previous_reaction); 5726 set_active_effect(previous_effect); 5727 if (was_hydrating) { 5728 set_hydrating(true); 5729 } 5730 } 5731 } 5732
5733 /** 5734 * Spreads attributes onto a DOM element, taking into account the currently set attributes 5735 * @param {Element & ElementCSSInlineStyle} element 5736 * @param {Record<string | symbol, any> | undefined} prev 5737 * @param {Record<string | symbol, any>} next New attributes - this function mutates this object 5738 * @param {string} [css_hash] 5739 * @param {boolean} [should_remove_defaults] 5740 * @param {boolean} [skip_warning] 5741 * @returns {Record<string, any>} 5742 */ 5743 function set_attributes( 5744 element, 5745 prev, 5746 next, 5747 css_hash, 5748 should_remove_defaults = false, 5749 skip_warning = false 5750 ) { 5751 if (hydrating && should_remove_defaults && element.tagName === 'INPUT') { 5752 var input = /** @type {HTMLInputElement} */ (element); 5753 var attribute = input.type === 'checkbox' ? 'defaultChecked' : 'defaultValue'; 5754 5755 if (!(attribute in next)) { 5756 remove_input_defaults(input); 5757 } 5758 } 5759 5760 var attributes = get_attributes(element); 5761 5762 var is_custom_element = attributes[IS_CUSTOM_ELEMENT]; 5763 var preserve_attribute_case = !attributes[IS_HTML]; 5764 5765 // If we're hydrating but the custom element is from Svelte, and it already scaffolded, 5766 // then it might run block logic in hydration mode, which we have to prevent. 5767 let is_hydrating_custom_element = hydrating && is_custom_element; 5768 if (is_hydrating_custom_element) { 5769 set_hydrating(false); 5770 } 5771 5772 var current = prev || {}; 5773 var is_option_element = element.tagName === 'OPTION'; 5774 5775 for (var key in prev) { 5776 if (!(key in next)) { 5777 next[key] = null; 5778 } 5779 } 5780 5781 if (next.class) { 5782 next.class = clsx(next.class); 5783 } else if (next[CLASS]) { 5784 next.class = null; /* force call to set_class() */ 5785 } 5786 5787 if (next[STYLE]) { 5788 next.style ??= null; /* force call to set_style() */ 5789 } 5790 5791 var setters = get_setters(element); 5792 5793 // since key is captured we use const 5794 for (const key in next) { 5795 // let instead of var because referenced in a closure 5796 let value = next[key]; 5797 5798 // Up here because we want to do this for the initial value, too, even if it's undefined, 5799 // and this wouldn't be reached in case of undefined because of the equality check below 5800 if (is_option_element && key === 'value' && value == null) { 5801 // The <option> element is a special case because removing the value attribute means 5802 // the value is set to the text content of the option element, and setting the value 5803 // to null or undefined means the value is set to the string "null" or "undefined". 5804 // To align with how we handle this case in non-spread-scenarios, this logic is needed. 5805 // There's a super-edge-case bug here that is left in in favor of smaller code size: 5806 // Because of the "set missing props to null" logic above, we can't differentiate 5807 // between a missing value and an explicitly set value of null or undefined. That means 5808 // that once set, the value attribute of an <option> element can't be removed. This is 5809 // a very rare edge case, and removing the attribute altogether isn't possible either 5810 // for the <option value={undefined}> case, so we're not losing any functionality here. 5811 // @ts-ignore 5812 element.value = element.__value = ''; 5813 current[key] = value; 5814 continue; 5815 } 5816 5817 if (key === 'class') { 5818 var is_html = element.namespaceURI === 'http://www.w3.org/1999/xhtml'; 5819 set_class(element, is_html, value, css_hash, prev?.[CLASS], next[CLASS]); 5820 current[key] = value; 5821 current[CLASS] = next[CLASS]; 5822 continue; 5823 } 5824 5825 if (key === 'style') { 5826 set_style(element, value, prev?.[STYLE], next[STYLE]); 5827 current[key] = value; 5828 current[STYLE] = next[STYLE]; 5829 continue; 5830 } 5831 5832 var prev_value = current[key]; 5833 5834 // Skip if value is unchanged, unless it's `undefined` and the element still has the attribute 5835 if (value === prev_value && !(value === undefined && element.hasAttribute(key))) { 5836 continue; 5837 } 5838 5839 current[key] = value; 5840 5841 var prefix = key[0] + key[1]; // this is faster than key.slice(0, 2) 5842 if (prefix === '$$') continue; 5843 5844 if (prefix === 'on') { 5845 /** @type {{ capture?: true }} */ 5846 const opts = {}; 5847 const event_handle_key = '$$' + key; 5848 let event_name = key.slice(2); 5849 var delegated = is_delegated(event_name); 5850 5851 if (is_capture_event(event_name)) { 5852 event_name = event_name.slice(0, -7); 5853 opts.capture = true; 5854 } 5855 5856 if (!delegated && prev_value) { 5857 // Listening to same event but different handler -> our handle function below takes care of this 5858 // If we were to remove and add listeners in this case, it c
5858ould happen that the event is "swallowed" 5859 // (the browser seems to not know yet that a new one exists now) and doesn't reach the handler 5860 // https://github.com/sveltejs/svelte/issues/11903 5861 if (value != null) continue; 5862 5863 element.removeEventListener(event_name, current[event_handle_key], opts); 5864 current[event_handle_key] = null; 5865 } 5866 5867 if (value != null) { 5868 if (!delegated) { 5869 /** 5870 * @this {any} 5871 * @param {Event} evt 5872 */ 5873 function handle(evt) { 5874 current[key].call(this, evt); 5875 } 5876 5877 current[event_handle_key] = create_event(event_name, element, handle, opts); 5878 } else { 5879 // @ts-ignore 5880 element[`__${event_name}`] = value; 5881 delegate([event_name]); 5882 } 5883 } else if (delegated) { 5884 // @ts-ignore 5885 element[`__${event_name}`] = undefined; 5886 } 5887 } else if (key === 'style') { 5888 // avoid using the setter 5889 set_attribute(element, key, value); 5890 } else if (key === 'autofocus') { 5891 autofocus(/** @type {HTMLElement} */ (element), Boolean(value)); 5892 } else if (!is_custom_element && (key === '__value' || (key === 'value' && value != null))) { 5893 // @ts-ignore We're not running this for custom elements because __value is actually 5894 // how Lit stores the current value on the element, and messing with that would break things. 5895 element.value = element.__value = value; 5896 } else if (key === 'selected' && is_option_element) { 5897 set_selected(/** @type {HTMLOptionElement} */ (element), value); 5898 } else { 5899 var name = key; 5900 if (!preserve_attribute_case) { 5901 name = normalize_attribute(name); 5902 } 5903 5904 var is_default = name === 'defaultValue' || name === 'defaultChecked'; 5905 5906 if (value == null && !is_custom_element && !is_default) { 5907 attributes[key] = null; 5908 5909 if (name === 'value' || name === 'checked') { 5910 // removing value/checked also removes defaultValue/defaultChecked â preserve 5911 let input = /** @type {HTMLInputElement} */ (element); 5912 const use_default = prev === undefined; 5913 if (name === 'value') { 5914 let previous = input.defaultValue; 5915 input.removeAttribute(name); 5916 input.defaultValue = previous; 5917 // @ts-ignore 5918 input.value = input.__value = use_default ? previous : null; 5919 } else { 5920 let previous = input.defaultChecked; 5921 input.removeAttribute(name); 5922 input.defaultChecked = previous; 5923 input.checked = use_default ? previous : false; 5924 } 5925 } else { 5926 element.removeAttribute(key); 5927 } 5928 } else if ( 5929 is_default || 5930 (setters.includes(name) && (is_custom_element || typeof value !== 'string')) 5931 ) { 5932 // @ts-ignore 5933 element[name] = value; 5934 // remove it from attributes's cache 5935 if (name in attributes) attributes[name] = UNINITIALIZED; 5936 } else if (typeof value !== 'function') { 5937 set_attribute(element, name, value); 5938 } 5939 } 5940 } 5941 5942 if (is_hydrating_custom_element) { 5943 set_hydrating(true); 5944 } 5945 5946 return current; 5947 } 5948 5949 /** 5950 * @param {Element & ElementCSSInlineStyle} element 5951 * @param {(...expressions: any) => Record<string | symbol, any>} fn 5952 * @param {Array<() => any>} sync 5953 * @param {Array<() => Promise<any>>} async 5954 * @param {string} [css_hash] 5955 * @param {boolean} [should_remove_defaults] 5956 * @param {boolean} [skip_warning] 5957 */ 5958 function attribute_effect( 5959 element, 5960 fn, 5961 sync = [], 5962 async = [], 5963 css_hash, 5964 should_remove_defaults = false, 5965 skip_warning = false 5966 ) { 5967 flatten(sync, async, (values) => { 5968 /** @type {Record<string | symbol, any> | undefined} */ 5969 var prev = undefined; 5970 5971 /** @type {Record<symbol, Effect>} */ 5972 var effects = {}; 5973 5974 var is_select = element.nodeName === 'SELECT'; 5975 var inited = false; 5976 5977 block(() => { 5978 var next = fn(...values.map(get)); 5979 /** @type {Record<string | symbol, any>} */ 5980 var current = set_attributes( 5981 element, 5982 prev, 5983 next, 5984 css_hash, 5985 should_remove_defaults, 5986 skip_warning 5987 ); 5988 5989 if (inited && is_select && 'value' in next) { 5990 select_option(/** @type {HTMLSelectElement} */ (element), next.value); 5991 } 5992 5993 for (let symbol of Object.getOwnPropertySymbols(effects)) { 5994 if (!next[symbol]) destroy_effect(effects[symbol]); 5995 } 5996 5997 for (let symbol of Object.getOwnPropertySymbols(next)) { 5998 var n = next[symbol]; 5999 6000 if (symbol.description === ATTACHMENT_KEY && (!prev || n !== prev[symbol])) { 6001 if (effects[symbol]) destroy_effect(effects[symbol]); 6002 effects[symbol] = branch(() => attach(element, () => n)); 6003 } 6004 6005 current[symbol] = n; 6006 } 6007 6008 prev = current; 6009 }); 6010 6011 if (is_select) { 6012 var select = /** @type {HTMLSelectElement} */ (element); 6013 6014 effect(() => { 6015 select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value, true); 6016 init_select(select); 6017 }); 6018 } 6019 6020 inited = true; 6021 }); 6022 } 6023 6024 /** 6025 * 6026 * @param {Element} element 6027 */ 6028 function get_attributes(element) { 6029 return /** @type {Record<string | symbol, unknown>} **/ ( 6030 // @ts-expect-error 6031 element.__attributes ??= { 6032 [IS_CUSTOM_ELEMENT]: element.nodeName.includes('-'), 6033 [IS_HTML]: element.namespaceURI === NAMESPACE_HTML 6034 } 6035 ); 6036 } 6037 6038 /** @type {Map<string, string[]>} */
6039 var setters_cache = new Map(); 6040 6041 /** @param {Element} element */ 6042 function get_setters(element) { 6043 var cache_key = element.getAttribute('is') || element.nodeName; 6044 var setters = setters_cache.get(cache_key); 6045 if (setters) return setters; 6046 setters_cache.set(cache_key, (setters = [])); 6047 6048 var descriptors; 6049 var proto = element; // In the case of custom elements there might be setters on the instance 6050 var element_proto = Element.prototype; 6051 6052 // Stop at Element, from there on there's only unnecessary setters we're not interested in 6053 // Do not use contructor.name here as that's unreliable in some browser environments 6054 while (element_proto !== proto) { 6055 descriptors = get_descriptors(proto); 6056 6057 for (var key in descriptors) { 6058 if (descriptors[key].set) { 6059 setters.push(key); 6060 } 6061 } 6062 6063 proto = get_prototype_of(proto); 6064 } 6065 6066 return setters; 6067 } 6068 6069 /** @import { Batch } from '../../../reactivity/batch.js' */ 6070 6071 /** 6072 * @param {HTMLInputElement} input 6073 * @param {() => unknown} get 6074 * @param {(value: unknown) => void} set 6075 * @returns {void} 6076 */ 6077 function bind_value(input, get, set = get) { 6078 var batches = new WeakSet(); 6079 6080 listen_to_event_and_reset_event(input, 'input', async (is_reset) => { 6081 6082 /** @type {any} */ 6083 var value = is_reset ? input.defaultValue : input.value; 6084 value = is_numberlike_input(input) ? to_number(value) : value; 6085 set(value); 6086 6087 if (current_batch !== null) { 6088 batches.add(current_batch); 6089 } 6090 6091 // Because `{#each ...}` blocks work by updating sources inside the flush, 6092 // we need to wait a tick before checking to see if we should forcibly 6093 // update the input and reset the selection state 6094 await tick(); 6095 6096 // Respect any validation in accessors 6097 if (value !== (value = get())) { 6098 var start = input.selectionStart; 6099 var end = input.selectionEnd; 6100 6101 // the value is coerced on assignment 6102 input.value = value ?? ''; 6103 6104 // Restore selection 6105 if (end !== null) { 6106 input.selectionStart = start; 6107 input.selectionEnd = Math.min(end, input.value.length); 6108 } 6109 } 6110 }); 6111 6112 if ( 6113 // If we are hydrating and the value has since changed, 6114 // then use the updated value from the input instead. 6115 (hydrating && input.defaultValue !== input.value) || 6116 // If defaultValue is set, then value == defaultValue 6117 // TODO Svelte 6: remove input.value check and set to empty string? 6118 (untrack(get) == null && input.value) 6119 ) { 6120 set(is_numberlike_input(input) ? to_number(input.value) : input.value); 6121 6122 if (current_batch !== null) { 6123 batches.add(current_batch); 6124 } 6125 } 6126 6127 render_effect(() => { 6128 6129 var value = get(); 6130 6131 if (input === document.activeElement) { 6132 // we need both, because in non-async mode, render effects run before previous_batch is set 6133 var batch = /** @type {Batch} */ (previous_batch ?? current_batch); 6134 6135 // Never rewrite the contents of a focused input. We can get here if, for example, 6136 // an update is deferred because of async work depending on the input: 6137 // 6138 // <input bind:value={query}> 6139 // <p>{await find(query)}</p> 6140 if (batches.has(batch)) { 6141 return; 6142 } 6143 } 6144 6145 if (is_numberlike_input(input) && value === to_number(input.value)) { 6146 // handles 0 vs 00 case (see https://github.com/sveltejs/svelte/issues/9959) 6147 return; 6148 } 6149 6150 if (input.type === 'date' && !value && !input.value) { 6151 // Handles the case where a temporarily invalid date is set (while typing, for example with a leading 0 for the day) 6152 // and prevents this state from clearing the other parts of the date input (see https://github.com/sveltejs/svelte/issues/7897) 6153 return; 6154 } 6155 6156 // don't set the value of the input if it's the same to allow 6157 // minlength to work properly 6158 if (value !== input.value) { 6159 // @ts-expect-error the value is coerced on assignment 6160 input.value = value ?? ''; 6161 } 6162 }); 6163 } 6164 6165 /** 6166 * @param {HTMLInputElement} input 6167 */ 6168 function is_numberlike_input(input) { 6169 var type = input.type; 6170 return type === 'number' || type === 'range'; 6171 } 6172 6173 /** 6174 * @param {string} value 6175 */ 6176 function to_number(value) { 6177 return value === '' ? null : +value; 6178 } 6179 6180 /** 6181 * @param {any} bound_value 6182 * @param {Element} element_or_component 6183 * @returns {boolean} 6184 */ 6185 function is_bound_this(bound_value, element_or_component) { 6186 return ( 6187 bound_value === element_or_component || bound_value?.[STATE_SYMBOL] === element_or_component 6188 ); 6189 } 6190 6191 /** 6192 * @param {any} element_or_component 6193 * @param {(value: unknown, ...parts: unknown[]) => void} update 6194 * @param {(...parts: unknown[]) => unknown} get_value 6195 * @param {() => unknown[]} [get_parts] Set if the this binding is used inside an each block, 6196 * returns all the parts of the each block context that are used in the expression 6197 * @returns {void} 6198 */ 6199 function bind_this(element_or_component = {}, update, get_value, get_parts) { 6200 effect(() => { 6201 /** @type {unknown[]} */ 6202 var old_parts; 6203 6204 /** @type {unknown[]} */ 6205 var parts; 6206 6207 render_effect(() => { 6208 old_parts = parts; 6209 // We only track changes to the parts, not the value itself to avoid unnecessary reruns. 6210 parts = get_parts?.() || []; 6211 6212 untrack(() => { 6213 if (element_or_component !== get_value(...parts)) { 6214 update(element_or_component, ...parts); 6215 // If this is an effect rerun (cause: each block context changes), then nullfiy the binding at 6216 // the previous position if it isn't already taken over by a different effect. 6217 if (old_parts && is_bound_this(get_value(...old_parts), element_or_component)) { 6218 update(null, ...old_parts); 6219 } 6220 } 6221 }); 6222 }); 6223 6224 return () => { 6225 // We cannot use effects in the teardown phase, we we use a microtask instead. 6226 queue_micro_task(() => { 6227 if (parts && is_bound_this(get_value(...parts), element_or_component)) { 6228 update(null, ...parts); 6229 } 6230 }); 6231 }; 6232 }); 6233 6234 return element_or_component; 6235 } 6236 6237 /** @import { StoreReferencesContainer } from '#client' */ 6238 /** @import { Store } from '#shared' */ 6239 6240 /** 6241 * Whether or not the prop currently being read is a store binding, as in 6242 * `<Child bind:x={$y} />`. If it is, we treat the prop as mutable even in 6243 * runes mode, and skip `binding_property_non_reactive` validation 6244 */ 6245 let is_store_binding = false;
6246 6247 /** 6248 * Returns a tuple that indicates whether `fn()` reads a prop that is a store binding. 6249 * Used to prevent `binding_property_non_reactive` validation false positives and 6250 * ensure that these props are treated as mutable even in runes mode 6251 * @template T 6252 * @param {() => T} fn 6253 * @returns {[T, boolean]} 6254 */ 6255 function capture_store_binding(fn) { 6256 var previous_is_store_binding = is_store_binding; 6257 6258 try { 6259 is_store_binding = false; 6260 return [fn(), is_store_binding]; 6261 } finally { 6262 is_store_binding = previous_is_store_binding; 6263 } 6264 } 6265 6266 /** @import { Effect, Source } from './types.js' */ 6267 6268 /** 6269 * The proxy handler for rest props (i.e. `const { x, ...rest } = $props()`). 6270 * Is passed the full `$$props` object and excludes the named props. 6271 * @type {ProxyHandler<{ props: Record<string | symbol, unknown>, exclude: Array<string | symbol>, name?: string }>}} 6272 */ 6273 const rest_props_handler = { 6274 get(target, key) { 6275 if (target.exclude.includes(key)) return; 6276 return target.props[key]; 6277 }, 6278 set(target, key) { 6279 6280 return false; 6281 }, 6282 getOwnPropertyDescriptor(target, key) { 6283 if (target.exclude.includes(key)) return; 6284 if (key in target.props) { 6285 return { 6286 enumerable: true, 6287 configurable: true, 6288 value: target.props[key] 6289 }; 6290 } 6291 }, 6292 has(target, key) { 6293 if (target.exclude.includes(key)) return false; 6294 return key in target.props; 6295 }, 6296 ownKeys(target) { 6297 return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key)); 6298 } 6299 }; 6300 6301 /** 6302 * @param {Record<string, unknown>} props 6303 * @param {string[]} exclude 6304 * @param {string} [name] 6305 * @returns {Record<string, unknown>} 6306 */ 6307 /*#__NO_SIDE_EFFECTS__*/ 6308 function rest_props(props, exclude, name) { 6309 return new Proxy( 6310 { props, exclude }, 6311 rest_props_handler 6312 ); 6313 } 6314 6315 /** 6316 * The proxy handler for spread props. Handles the incoming array of props 6317 * that looks like `() => { dynamic: props }, { static: prop }, ..` and wraps 6318 * them so that the whole thing is passed to the component as the `$$props` argument. 6319 * @type {ProxyHandler<{ props: Array<Record<string | symbol, unknown> | (() => Record<string | symbol, unknown>)> }>}} 6320 */ 6321 const spread_props_handler = { 6322 get(target, key) { 6323 let i = target.props.length; 6324 while (i--) { 6325 let p = target.props[i]; 6326 if (is_function(p)) p = p(); 6327 if (typeof p === 'object' && p !== null && key in p) return p[key]; 6328 } 6329 }, 6330 set(target, key, value) { 6331 let i = target.props.length; 6332 while (i--) { 6333 let p = target.props[i]; 6334 if (is_function(p)) p = p(); 6335 const desc = get_descriptor(p, key); 6336 if (desc && desc.set) { 6337 desc.set(value); 6338 return true; 6339 } 6340 } 6341 return false; 6342 }, 6343 getOwnPropertyDescriptor(target, key) { 6344 let i = target.props.length; 6345 while (i--) { 6346 let p = target.props[i]; 6347 if (is_function(p)) p = p(); 6348 if (typeof p === 'object' && p !== null && key in p) { 6349 const descriptor = get_descriptor(p, key); 6350 if (descriptor && !descriptor.configurable) { 6351 // Prevent a "Non-configurability Report Error": The target is an array, it does 6352 // not actually contain this property. If it is now described as non-configurable, 6353 // the proxy throws a validation error. Setting it to true avoids that. 6354 descriptor.configurable = true; 6355 } 6356 return descriptor; 6357 } 6358 } 6359 }, 6360 has(target, key) { 6361 // To prevent a false positive `is_entry_props` in the `prop` function 6362 if (key === STATE_SYMBOL || key === LEGACY_PROPS) return false; 6363 6364 for (let p of target.props) { 6365 if (is_function(p)) p = p(); 6366 if (p != null && key in p) return true; 6367 } 6368 6369 return false; 6370 }, 6371 ownKeys(target) { 6372 /** @type {Array<string | symbol>} */ 6373 const keys = []; 6374 6375 for (let p of target.props) { 6376 if (is_function(p)) p = p(); 6377 if (!p) continue; 6378 6379 for (const key in p) { 6380 if (!keys.includes(key)) keys.push(key); 6381 } 6382 6383 for (const key of Object.getOwnPropertySymbols(p)) { 6384 if (!keys.includes(key)) keys.push(key); 6385 } 6386 } 6387 6388 return keys; 6389 } 6390 }; 6391 6392 /** 6393 * @param {Array<Record<string, unknown> | (() => Record<string, unknown>)>} props 6394 * @returns {any} 6395 */ 6396 function spread_props(...props) { 6397 return new Proxy({ props }, spread_props_handler); 6398 } 6399 6400 /** 6401 * This function is responsible for synchronizing a possibly bound prop with the inner component state. 6402 * It is used whenever the compiler sees that the component writes to the prop, or when it has a default prop_value. 6403 * @template V 6404 * @param {Record<string, unknown>} props 6405 * @param {string} key 6406 * @param {number} flags 6407 * @param {V | (() => V)} [fallback] 6408 * @returns {(() => V | ((arg: V) => V) | ((arg: V, mutation: boolean) => V))} 6409 */ 6410 function prop(props, key, flags, fallback) { 6411 var bindable = (flags & PROPS_IS_BINDABLE) !== 0; 6412 var lazy = (flags & PROPS_IS_LAZY_INITIAL) !== 0; 6413 6414 var fallback_value = /** @type {V} */ (fallback); 6415 var fallback_dirty = true; 6416 6417 var get_fallback = () => { 6418 if (fallback_dirty) { 6419 fallback_dirty = false;
6420 6421 fallback_value = lazy 6422 ? untrack(/** @type {() => V} */ (fallback)) 6423 : /** @type {V} */ (fallback); 6424 } 6425 6426 return fallback_value; 6427 }; 6428 6429 /** @type {((v: V) => void) | undefined} */ 6430 var setter; 6431 6432 if (bindable) { 6433 // Can be the case when someone does `mount(Component, props)` with `let props = $state({...})` 6434 // or `createClassComponent(Component, props)` 6435 var is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props; 6436 6437 setter = 6438 get_descriptor(props, key)?.set ?? 6439 (is_entry_props && key in props ? (v) => (props[key] = v) : undefined); 6440 } 6441 6442 var initial_value; 6443 var is_store_sub = false; 6444 6445 if (bindable) { 6446 [initial_value, is_store_sub] = capture_store_binding(() => /** @type {V} */ (props[key])); 6447 } else { 6448 initial_value = /** @type {V} */ (props[key]); 6449 } 6450 6451 if (initial_value === undefined && fallback !== undefined) { 6452 initial_value = get_fallback(); 6453 6454 if (setter) { 6455 props_invalid_value(); 6456 setter(initial_value); 6457 } 6458 } 6459 6460 /** @type {() => V} */ 6461 var getter; 6462 6463 { 6464 getter = () => { 6465 var value = /** @type {V} */ (props[key]); 6466 if (value === undefined) return get_fallback(); 6467 fallback_dirty = true; 6468 return value; 6469 }; 6470 } 6471 6472 // prop is never written to â we only need a getter 6473 if ((flags & PROPS_IS_UPDATED) === 0) { 6474 return getter; 6475 } 6476 6477 // prop is written to, but the parent component had `bind:foo` which 6478 // means we can just call `$$props.foo = value` directly 6479 if (setter) { 6480 var legacy_parent = props.$$legacy; 6481 return /** @type {() => V} */ ( 6482 function (/** @type {V} */ value, /** @type {boolean} */ mutation) { 6483 if (arguments.length > 0) { 6484 // We don't want to notify if the value was mutated and the parent is in runes mode. 6485 // In that case the state proxy (if it exists) should take care of the notification. 6486 // If the parent is not in runes mode, we need to notify on mutation, too, that the prop 6487 // has changed because the parent will not be able to detect the change otherwise. 6488 if (!mutation || legacy_parent || is_store_sub) { 6489 /** @type {Function} */ (setter)(mutation ? getter() : value); 6490 } 6491 6492 return value; 6493 } 6494 6495 return getter(); 6496 } 6497 ); 6498 } 6499 6500 // Either prop is written to, but there's no binding, which means we 6501 // create a derived that we can write to locally. 6502 // Or we are in legacy mode where we always create a derived to replicate that 6503 // Svelte 4 did not trigger updates when a primitive value was updated to the same value. 6504 var overridden = false; 6505 6506 var d = ((flags & PROPS_IS_IMMUTABLE) !== 0 ? derived : derived_safe_equal)(() => { 6507 overridden = false; 6508 return getter(); 6509 }); 6510 6511 // Capture the initial value if it's bindable 6512 if (bindable) get(d); 6513 6514 var parent_effect = /** @type {Effect} */ (active_effect); 6515 6516 return /** @type {() => V} */ ( 6517 function (/** @type {any} */ value, /** @type {boolean} */ mutation) { 6518 if (arguments.length > 0) { 6519 const new_value = mutation ? get(d) : bindable ? proxy(value) : value; 6520 6521 set(d, new_value); 6522 overridden = true; 6523 6524 if (fallback_value !== undefined) { 6525 fallback_value = new_value; 6526 } 6527 6528 return value; 6529 } 6530 6531 // special case â avoid recalculating the derived if we're in a 6532 // teardown function and the prop was overridden locally, or the 6533 // component was already destroyed (this latter part is necessary 6534 // because `bind:this` can read props after the component has 6535 // been destroyed. TODO simplify `bind:this` 6536 if ((is_destroying_effect && overridden) || (parent_effect.f & DESTROYED) !== 0) { 6537 return d.v; 6538 } 6539 6540 return get(d); 6541 } 6542 ); 6543 } 6544 6545 /** @import { ComponentConstructorOptions, ComponentType, SvelteComponent, Component } from 'svelte' */ 6546 6547 /** 6548 * Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component. 6549 * 6550 * @deprecated Use this only as a temporary solution to migrate your imperative component code to Svelte 5. 6551 * 6552 * @template {Record<string, any>} Props 6553 * @template {Record<string, any>} Exports 6554 * @template {Record<string, any>} Events 6555 * @template {Record<string, any>} Slots 6556 * 6557 * @param {ComponentConstructorOptions<Props> & { 6558 * component: ComponentType<SvelteComponent<Props, Events, Slots>> | Component<Props>; 6559 * }} options 6560 * @returns {SvelteComponent<Props, Events, Slots> & Exports} 6561 */ 6562 function createClassComponent(options) { 6563 // @ts-expect-error $$prop_def etc are not actually defined 6564 return new Svelte4Component(options); 6565 } 6566 6567 /** 6568 * Support using the component as both a class and function during the transition period 6569 * @typedef {{new (o: ComponentConstructorOptions): SvelteComponent;(...args: Parameters<Component<Record<string, any>>>): ReturnType<Component<Record<string, any>, Record<string, any>>>;}} LegacyComponentType 6570 */ 6571 6572 class Svelte4Component { 6573 /** @type {any} */ 6574 #events; 6575 6576 /** @type {Record<string, any>} */ 6577 #instance; 6578 6579 /** 6580 * @param {ComponentConstructorOptions & { 6581 * component: any; 6582 * }} options 6583 */ 6584 constructor(options) { 6585 var sources = new Map(); 6586 6587 /** 6588 * @param {string | symbol} key 6589 * @param {unknown} value 6590 */ 6591 var add_source = (key, value) => { 6592 var s = mutable_source(value, false, false); 6593 sources.set(key, s); 6594 return s; 6595 }; 6596 6597 // Replicate coarse-grained props through a proxy that has a version source for 6598 // each property, which is incremented on updates to the property itself. Do not 6599 // use our $state proxy because that one has fine-grained reactivity. 6600 const props = new Proxy( 6601 { ...(options.props || {}), $$events: {} }, 6602 { 6603 get(target, prop) { 6604 return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop))); 6605 }, 6606 has(target, prop) {
6607 // Necessary to not throw "invalid binding" validation errors on the component side 6608 if (prop === LEGACY_PROPS) return true; 6609 6610 get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop))); 6611 return Reflect.has(target, prop); 6612 }, 6613 set(target, prop, value) { 6614 set(sources.get(prop) ?? add_source(prop, value), value); 6615 return Reflect.set(target, prop, value); 6616 } 6617 } 6618 ); 6619 6620 this.#instance = (options.hydrate ? hydrate : mount)(options.component, { 6621 target: options.target, 6622 anchor: options.anchor, 6623 props, 6624 context: options.context, 6625 intro: options.intro ?? false, 6626 recover: options.recover 6627 }); 6628 6629 // We don't flushSync for custom element wrappers or if the user doesn't want it, 6630 // or if we're in async mode since `flushSync()` will fail 6631 if ((!options?.props?.$$host || options.sync === false)) { 6632 flushSync(); 6633 } 6634 6635 this.#events = props.$$events; 6636 6637 for (const key of Object.keys(this.#instance)) { 6638 if (key === '$set' || key === '$destroy' || key === '$on') continue; 6639 define_property(this, key, { 6640 get() { 6641 return this.#instance[key]; 6642 }, 6643 /** @param {any} value */ 6644 set(value) { 6645 this.#instance[key] = value; 6646 }, 6647 enumerable: true 6648 }); 6649 } 6650 6651 this.#instance.$set = /** @param {Record<string, any>} next */ (next) => { 6652 Object.assign(props, next); 6653 }; 6654 6655 this.#instance.$destroy = () => { 6656 unmount(this.#instance); 6657 }; 6658 } 6659 6660 /** @param {Record<string, any>} props */ 6661 $set(props) { 6662 this.#instance.$set(props); 6663 } 6664 6665 /** 6666 * @param {string} event 6667 * @param {(...args: any[]) => any} callback 6668 * @returns {any} 6669 */ 6670 $on(event, callback) { 6671 this.#events[event] = this.#events[event] || []; 6672 6673 /** @param {any[]} args */ 6674 const cb = (...args) => callback.call(this, ...args); 6675 this.#events[event].push(cb); 6676 return () => { 6677 this.#events[event] = this.#events[event].filter(/** @param {any} fn */ (fn) => fn !== cb); 6678 }; 6679 } 6680 6681 $destroy() { 6682 this.#instance.$destroy(); 6683 } 6684 } 6685 6686 /** 6687 * Runs the given function once immediately on the server, and works like `$effect.pre` on the client. 6688 * 6689 * @deprecated Use this only as a temporary solution to migrate your component code to Svelte 5. 6690 * @param {() => void | (() => void)} fn 6691 * @returns {void} 6692 */ 6693 function run(fn) { 6694 user_pre_effect(() => { 6695 fn(); 6696 var effect = /** @type {import('#client').Effect} */ (active_effect); 6697 // If the effect is immediately made dirty again, mark it as maybe dirty to emulate legacy behaviour 6698 if ((effect.f & DIRTY) !== 0) { 6699 legacy_recursive_reactive_block(); 6700 set_signal_status(effect, MAYBE_DIRTY); 6701 } 6702 }); 6703 } 6704 6705 /** 6706 * @typedef {Object} CustomElementPropDefinition 6707 * @property {string} [attribute] 6708 * @property {boolean} [reflect] 6709 * @property {'String'|'Boolean'|'Number'|'Array'|'Object'} [type] 6710 */ 6711 6712 /** @type {any} */ 6713 let SvelteElement; 6714 6715 if (typeof HTMLElement === 'function') { 6716 SvelteElement = class extends HTMLElement { 6717 /** The Svelte component constructor */ 6718 $$ctor; 6719 /** Slots */ 6720 $$s; 6721 /** @type {any} The Svelte component instance */ 6722 $$c; 6723 /** Whether or not the custom element is connected */ 6724 $$cn = false; 6725 /** @type {Record<string, any>} Component props data */ 6726 $$d = {}; 6727 /** `true` if currently in the process of reflecting component props back to attributes */ 6728 $$r = false; 6729 /** @type {Record<string, CustomElementPropDefinition>} Props definition (name, reflected, type etc) */ 6730 $$p_d = {}; 6731 /** @type {Record<string, EventListenerOrEventListenerObject[]>} Event listeners */ 6732 $$l = {}; 6733 /** @type {Map<EventListenerOrEventListenerObject, Function>} Event listener unsubscribe functions */ 6734 $$l_u = new Map(); 6735 /** @type {any} The managed render effect for reflecting attributes */ 6736 $$me; 6737 6738 /** 6739 * @param {*} $$componentCtor 6740 * @param {*} $$slots 6741 * @param {*} use_shadow_dom 6742 */ 6743 constructor($$componentCtor, $$slots, use_shadow_dom) { 6744 super(); 6745 this.$$ctor = $$componentCtor; 6746 this.$$s = $$slots; 6747 if (use_shadow_dom) { 6748 this.attachShadow({ mode: 'open' }); 6749 } 6750 } 6751 6752 /** 6753 * @param {string} type 6754 * @param {EventListenerOrEventListenerObject} listener 6755 * @param {boolean | AddEventListenerOptions} [options] 6756 */ 6757 addEventListener(type, listener, options) { 6758 // We can't determine upfront if the event is a custom event or not, so we have to 6759 // listen to both. If someone uses a custom event with the same name as a regular
vendor: 4,117 bytes, lines 6760-6895
6760 // browser event, this fires twice - we can't avoid that. 6761 this.$$l[type] = this.$$l[type] || []; 6762 this.$$l[type].push(listener); 6763 if (this.$$c) { 6764 const unsub = this.$$c.$on(type, listener); 6765 this.$$l_u.set(listener, unsub); 6766 } 6767 super.addEventListener(type, listener, options); 6768 } 6769 6770 /** 6771 * @param {string} type 6772 * @param {EventListenerOrEventListenerObject} listener 6773 * @param {boolean | AddEventListenerOptions} [options] 6774 */ 6775 removeEventListener(type, listener, options) { 6776 super.removeEventListener(type, listener, options); 6777 if (this.$$c) { 6778 const unsub = this.$$l_u.get(listener); 6779 if (unsub) { 6780 unsub(); 6781 this.$$l_u.delete(listener); 6782 } 6783 } 6784 } 6785 6786 async connectedCallback() { 6787 this.$$cn = true; 6788 if (!this.$$c) { 6789 // We wait one tick to let possible child slot elements be created/mounted 6790 await Promise.resolve(); 6791 if (!this.$$cn || this.$$c) { 6792 return; 6793 } 6794 /** @param {string} name */ 6795 function create_slot(name) { 6796 /** 6797 * @param {Element} anchor 6798 */ 6799 return (anchor) => { 6800 const slot = document.createElement('slot'); 6801 if (name !== 'default') slot.name = name; 6802 6803 append(anchor, slot); 6804 }; 6805 } 6806 /** @type {Record<string, any>} */ 6807 const $$slots = {}; 6808 const existing_slots = get_custom_elements_slots(this); 6809 for (const name of this.$$s) { 6810 if (name in existing_slots) { 6811 if (name === 'default' && !this.$$d.children) { 6812 this.$$d.children = create_slot(name); 6813 $$slots.default = true; 6814 } else { 6815 $$slots[name] = create_slot(name); 6816 } 6817 } 6818 } 6819 for (const attribute of this.attributes) { 6820 // this.$$data takes precedence over this.attributes 6821 const name = this.$$g_p(attribute.name); 6822 if (!(name in this.$$d)) { 6823 this.$$d[name] = get_custom_element_value(name, attribute.value, this.$$p_d, 'toProp'); 6824 } 6825 } 6826 // Port over props that were set programmatically before ce was initialized 6827 for (const key in this.$$p_d) { 6828 // @ts-expect-error 6829 if (!(key in this.$$d) && this[key] !== undefined) { 6830 // @ts-expect-error 6831 this.$$d[key] = this[key]; // don't transform, these were set through JavaScript 6832 // @ts-expect-error 6833 delete this[key]; // remove the property that shadows the getter/setter 6834 } 6835 } 6836 this.$$c = createClassComponent({ 6837 component: this.$$ctor, 6838 target: this.shadowRoot || this, 6839 props: { 6840 ...this.$$d, 6841 $$slots, 6842 $$host: this 6843 } 6844 }); 6845 6846 // Reflect component props as attributes 6847 this.$$me = effect_root(() => { 6848 render_effect(() => { 6849 this.$$r = true; 6850 for (const key of object_keys(this.$$c)) { 6851 if (!this.$$p_d[key]?.reflect) continue; 6852 this.$$d[key] = this.$$c[key]; 6853 const attribute_value = get_custom_element_value( 6854 key, 6855 this.$$d[key], 6856 this.$$p_d, 6857 'toAttribute' 6858 ); 6859 if (attribute_value == null) { 6860 this.removeAttribute(this.$$p_d[key].attribute || key); 6861 } else { 6862 this.setAttribute(this.$$p_d[key].attribute || key, attribute_value); 6863 } 6864 } 6865 this.$$r = false; 6866 }); 6867 }); 6868 6869 for (const type in this.$$l) { 6870 for (const listener of this.$$l[type]) { 6871 const unsub = this.$$c.$on(type, listener); 6872 this.$$l_u.set(listener, unsub); 6873 } 6874 } 6875 this.$$l = {}; 6876 } 6877 } 6878 6879 // We don't need this when working within Svelte code, but for compatibility of people using this outside of Svelte 6880 // and setting attributes through setAttribute etc, this is helpful 6881 6882 /** 6883 * @param {string} attr 6884 * @param {string} _oldValue 6885 * @param {string} newValue 6886 */ 6887 attributeChangedCallback(attr, _oldValue, newValue) { 6888 if (this.$$r) return; 6889 attr = this.$$g_p(attr); 6890 this.$$d[attr] = get_custom_element_value(attr, newValue, this.$$p_d, 'toProp'); 6891 this.$$c?.$set({ [attr]: this.$$d[attr] }); 6892 } 6893 6894 disconnectedCallback() { 6895 this.$$cn = false;
6896 // In a microtask, because this could be a move within the DOM 6897 Promise.resolve().then(() => { 6898 if (!this.$$cn && this.$$c) { 6899 this.$$c.$destroy(); 6900 this.$$me(); 6901 this.$$c = undefined; 6902 } 6903 }); 6904 } 6905 6906 /** 6907 * @param {string} attribute_name 6908 */ 6909 $$g_p(attribute_name) { 6910 return ( 6911 object_keys(this.$$p_d).find( 6912 (key) => 6913 this.$$p_d[key].attribute === attribute_name || 6914 (!this.$$p_d[key].attribute && key.toLowerCase() === attribute_name) 6915 ) || attribute_name 6916 ); 6917 } 6918 }; 6919 } 6920 6921 /** 6922 * @param {string} prop 6923 * @param {any} value 6924 * @param {Record<string, CustomElementPropDefinition>} props_definition 6925 * @param {'toAttribute' | 'toProp'} [transform] 6926 */ 6927 function get_custom_element_value(prop, value, props_definition, transform) { 6928 const type = props_definition[prop]?.type; 6929 value = type === 'Boolean' && typeof value !== 'boolean' ? value != null : value; 6930 if (!transform || !props_definition[prop]) { 6931 return value; 6932 } else if (transform === 'toAttribute') { 6933 switch (type) { 6934 case 'Object': 6935 case 'Array': 6936 return value == null ? null : JSON.stringify(value); 6937 case 'Boolean': 6938 return value ? '' : null; 6939 case 'Number': 6940 return value == null ? null : value; 6941 default: 6942 return value; 6943 } 6944 } else { 6945 switch (type) { 6946 case 'Object': 6947 case 'Array': 6948 return value && JSON.parse(value); 6949 case 'Boolean': 6950 return value; // conversion already handled above 6951 case 'Number': 6952 return value != null ? +value : value; 6953 default: 6954 return value; 6955 } 6956 } 6957 } 6958 6959 /** 6960 * @param {HTMLElement} element 6961 */ 6962 function get_custom_elements_slots(element) { 6963 /** @type {Record<string, true>} */ 6964 const result = {}; 6965 element.childNodes.forEach((node) => { 6966 result[/** @type {Element} node */ (node).slot || 'default'] = true; 6967 }); 6968 return result; 6969 } 6970 6971 /** 6972 * @internal 6973 * 6974 * Turn a Svelte component into a custom element. 6975 * @param {any} Component A Svelte component function 6976 * @param {Record<string, CustomElementPropDefinition>} props_definition The props to observe 6977 * @param {string[]} slots The slots to create 6978 * @param {string[]} exports Explicitly exported values, other than props 6979 * @param {boolean} use_shadow_dom Whether to use shadow DOM 6980 * @param {(ce: new () => HTMLElement) => new () => HTMLElement} [extend] 6981 */ 6982 function create_custom_element( 6983 Component, 6984 props_definition, 6985 slots, 6986 exports, 6987 use_shadow_dom, 6988 extend 6989 ) { 6990 let Class = class extends SvelteElement { 6991 constructor() { 6992 super(Component, slots, use_shadow_dom); 6993 this.$$p_d = props_definition; 6994 } 6995 static get observedAttributes() { 6996 return object_keys(props_definition).map((key) => 6997 (props_definition[key].attribute || key).toLowerCase() 6998 ); 6999 } 7000 }; 7001 object_keys(props_definition).forEach((prop) => { 7002 define_property(Class.prototype, prop, { 7003 get() { 7004 return this.$$c && prop in this.$$c ? this.$$c[prop] : this.$$d[prop]; 7005 }, 7006 set(value) { 7007 value = get_custom_element_value(prop, value, props_definition); 7008 this.$$d[prop] = value; 7009 var component = this.$$c; 7010 7011 if (component) { 7012 // // If the instance has an accessor, use that instead 7013 var setter = get_descriptor(component, prop)?.get; 7014 7015 if (setter) { 7016 component[prop] = value; 7017 } else { 7018 component.$set({ [prop]: value }); 7019 } 7020 } 7021 } 7022 }); 7023 }); 7024 exports.forEach((property) => { 7025 define_property(Class.prototype, property, { 7026 get() { 7027 return this.$$c?.[property]; 7028 } 7029 }); 7030 }); 7031 Component.element = /** @type {any} */ Class; 7032 return Class; 7033 } 7034 7035 class Utils { 7036 7037 static assetsBasePath = 7038 document 7039 .currentScript 7040 .getAttribute('sdg-assets-base-path') 7041 || new URL(document.currentScript.src).pathname 7042 .split('/') 7043 .slice(0, -2) 7044 .join('/') 7045 || '/' 7046 static cssRelativePath = 7047 `${this.assetsBasePath}/css/` 7048 .replace('//','/') 7049 static imagesRelativePath = 7050 `${this.assetsBasePath}/img/` 7051 .replace('//','/') 7052 static cssFileName = 7053 getCssFileName(document.currentScript.getAttribute('sdg-css-filename'), document.currentScript.src); 7054 static cssPath = 7055 getCssPath( 7056 document.currentScript.getAttribute('sdg-css-path'), 7057 document.currentScript.src, 7058 this.cssRelativePath, 7059 this.cssFileName 7060 ); 7061 static sharedTexts = 7062 { openInNewTab : 7063 { fr: 'Ce lien sâouvrira dans un nouvel onglet.' 7064 , en: 'This link will open in a new tab.' 7065 } 7066 } 7067 7068 /** 7069 * Get current page language based on HTML lang attribute 7070 * @returns {string} language code (fr/en). 7071 */ 7072 static getPageLanguage() { 7073 return document.getElementsByTagName("html")[0].getAttribute("lang") || "fr"; 7074 } 7075 7076 static isTruthy(value) { 7077 if (typeof value === 'boolean') { 7078 return value; 7079 } 7080 if (typeof value === 'string') { 7081 return value.toLowerCase() === 'true' || !!parseInt(value); // Vérifie si la chaîne est "true" (insensible à la casse) 7082 } 7083 if (typeof value === 'number') { 7084 return !!value; // Vérifie si le nombre est égal à 1 7085 } 7086 return false;
7087 } 7088 7089 /** 7090 * extract and clean prefixed attributes 7091 * example: 7092 * computeFieldsAttributes("radio", {"radio-class": "my-radio", "radio-data-foo": "foo", "other": "other value"}) 7093 * return {"class":"my-radio", "data-foo":"foo"} 7094 * 7095 </div> 7096 * @param {(string|string[])} prefix - Une chaîne de caractères ou un tableau de chaînes. 7097 * @param restProps - object of attributes 7098 * @returns {*} - object of attributes 7099 */ 7100 static computeFieldsAttributes(prefix , restProps) { 7101 let output = {}, 7102 _prefix = prefix + '-'; 7103 Object 7104 .entries(restProps) 7105 .forEach(([prop,value]) => { 7106 if (prop.startsWith(_prefix)) { 7107 const prefixProp = prop.replace(new RegExp('^' + _prefix), ''); 7108 output[prefixProp] = value; 7109 } 7110 }); 7111 7112 return output; 7113 } 7114 7115 /** 7116 * Checks if the current node or one of its children is currently in focus 7117 * @param node The element's node to check 7118 * @returns {boolean} If the current node or one of its children is currently in focus 7119 */ 7120 static componentIsActive(node) { 7121 if (!node) { 7122 return false; 7123 } 7124 7125 const root = node.getRootNode(); 7126 return node.contains(root.activeElement); 7127 } 7128 7129 /** 7130 * Waits for a specified amount of time 7131 * @param ms The amount of time to wait 7132 * @returns {Promise<unknown>} The resolution of the sleep action 7133 */ 7134 static sleep(ms) { 7135 return new Promise(resolve => setTimeout(resolve, ms)); 7136 } 7137 7138 static generateId(prefix = '') { 7139 return prefix + "-" + (Math.floor(Math.random() * 90000) + 10000); 7140 } 7141 7142 7143 /** 7144 * Returns the word in lowercase and with accented letters replaced by their non-accented counterparts 7145 * @param str 7146 * @returns {string} 7147 */ 7148 static cleanupSearchPrompt(str) { 7149 let word = String(str); 7150 7151 const replaceAccents = (str, search, replace) => { 7152 return str.replaceAll(new RegExp(search, 'gi'), replace); 7153 }; 7154 7155 // Supprime les accents. 7156 word = replaceAccents(word, /[éèêë]/gi, 'e'); 7157 word = replaceAccents(word, /[à äâ]/gi, 'a'); 7158 word = replaceAccents(word, /[ùûü]/gi, 'u'); 7159 word = replaceAccents(word, /[ïî]/gi, 'i'); 7160 word = replaceAccents(word, /[ôö]/gi, 'i'); 7161 word = replaceAccents(word, /Å/gi, 'oe'); 7162 word = replaceAccents(word, /æ/gi, 'ae'); 7163 7164 // Remplace les caractères spéciaux par des espaces. 7165 word = word.replaceAll(/[-_ââ]/gi, ' '); 7166 word = word.replaceAll(/â/gi, "'"); 7167 7168 // Convertit le mot en minuscules. 7169 return word.toLowerCase(); 7170 } 7171 7172 static now() { 7173 return (new Date()).getTime(); 7174 } 7175 7176 /** 7177 * Creates a MutationObserver instance with selector nesting check 7178 * @param rootElement 7179 * @param callback 7180 * @param selector 7181 * @returns {MutationObserver | null} 7182 */ 7183 static createMutationObserver(rootElement, callback, selector) { 7184 if (!selector) { 7185 selector = rootElement.tagName.toLowerCase(); 7186 } 7187 if (rootElement.querySelector(selector)) { 7188 console.warn(`Imbrication d'éléments "${selector}" détectée. Le MutationObserver n'est pas créé`); 7189 return null; 7190 } 7191 7192 return new MutationObserver(callback); 7193 } 7194 } 7195 7196 function getCacheBustingParam(cssPath, currentScriptSrc) { 7197 const pattern = /\?.*$/; 7198 7199 const cssCacheBustingParam = cssPath?.match(pattern); 7200 if (cssCacheBustingParam && cssCacheBustingParam.length > 0) { 7201 return ''; 7202 } 7203 7204 const scriptCacheBustingParam = currentScriptSrc?.match(pattern); 7205 if (scriptCacheBustingParam && scriptCacheBustingParam.length > 0) { 7206 return scriptCacheBustingParam[0]; 7207 } 7208 7209 return ''; 7210 } 7211 7212 function getCssFileName(sdgCssFilename, src) { 7213 const cssPattern =/^.*\.css/; 7214 7215 if (!cssPattern.test(sdgCssFilename)) { 7216 return 'qc-sdg.min.css' + getCacheBustingParam( 7217 'qc-sdg.min.css', src 7218 ); 7219 } else { 7220 return sdgCssFilename + getCacheBustingParam( 7221 sdgCssFilename, src 7222 ); 7223 } 7224 } 7225 7226 function getCssPath(sdgCssPath, src, cssRelativePath, cssFileName) { 7227 const cssPattern =/^.*\.css/; 7228 7229 if (!cssPattern.test(sdgCssPath)) { 7230 return cssRelativePath + cssFileName; 7231 } else { 7232 return sdgCssPath + getCacheBustingParam( 7233 sdgCssPath, src 7234 ); 7235 } 7236 } 7237 7238 var mappings={adresse:"place","arrow-up":"arrow_upward",calendar:"calendar_today",checkmark:"check","chevron-up-thin":"expand_less","chevron-up":"expand_less","chevron-droite":"chevron_right","chevron-gauche":"chevron_left","crochet-bas":"expand_more",clipboard:"content_paste",clock:"schedule",dots:"more_horiz",email:"mail",error:"cancel",exclamation:"warning","external-link":"open_in_new","information-tooltip":"information-tooltip",information:"info","ligth-bulb":"lightbulb",minu
7238s:"remove","on-line":"videocam",phone:"call",plus:"add",printer:"print","question-mark":"help","question-tooltip":"question-tooltip","search-thin":"search",search:"search",success:"check_circle",tableMatiere:"toc",user:"person",warning:"warning",website:"laptop_chromebook",xclose:"close",note:"edit_note"};var deprecationMessage="L'icône '{old}' est dépréciée. Utilisez type=\"{new}\" à la place.";var iconMapping = {mappings:mappings,deprecationMessage:deprecationMessage}; 7239 7240 var icons=["place","arrow_upward","arrow_downward","arrow_back","arrow_forward","arrow_left_alt","arrow_right_alt","north","calendar_today","check","expand_less","expand_more","chevron_right","chevron_left","content_paste","emoji_objects","schedule","mail","cancel","warning","open_in_new","info","lightbulb","remove","edit_note","call","add","help","search","check_circle","person","laptop_chromebook","close","description","more_horiz","note","print","toc","download","videocam","fax","add_circle","do_not_disturb_on"];var iconSelection = {icons:icons}; 7241 7242 var codepoints={place:"E55F",arrow_upward:"E5D8",arrow_downward:"E5DB",arrow_back:"E5C4",arrow_forward:"E5C8",arrow_left_alt:"EF7D",arrow_right_alt:"E941",north:"F1E0",calendar_today:"E935",check:"E5CA",expand_less:"E5CE",expand_more:"E5CF",chevron_right:"E5CC",chevron_left:"E5CB",content_paste:"E14F",emoji_objects:"EA24",schedule:"E8B5",mail:"E158",cancel:"E5C9",warning:"E002",open_in_new:"E89E",info:"E88E",lightbulb:"E0F0",remove:"E15B",edit_note:"E745",call:"E0B0",add:"E145",help:"E887",search:"E8B6",check_circle:"E86C",person:"E7FD",laptop_chromebook:"E31F",close:"E5CD",description:"E873",more_horiz:"E5D3",print:"E8AD",toc:"E8DE",download:"F090",videocam:"E04B",note:"E66D",fax:"EAD8",add_circle:"E147",do_not_disturb_on:"E644"};var iconCodepoints = {codepoints:codepoints}; 7243 7244 var root_1$2 = from_html(`<span> </span>`); 7245 var root_2$1 = from_html(`<div></div>`); 7246 7247 function Icon($$anchor, $$props) { 7248 push($$props, true); 7249 7250 let type = prop($$props, 'type', 7), 7251 label = prop($$props, 'label', 7), 7252 size = prop($$props, 'size', 7), 7253 color = prop($$props, 'color', 7), 7254 width = prop($$props, 'width', 7, 'auto'), 7255 height = prop($$props, 'height', 7, 'auto'), 7256 src = prop($$props, 'src', 7, ''), 7257 rotate = prop($$props, 'rotate', 7, 0), 7258 variant = prop($$props, 'variant', 7, 'outlined'), 7259 variationSettings = prop($$props, 'variationSettings', 7, null), 7260 renderMode = prop($$props, 'renderMode', 7, null // null = hérite du mode global, 'font' ou 'svg' pour forcer 7261 ), 7262 useMaterial = prop($$props, 'use-material', 7, false // Force l'utilisation du nom material sans passer par le mapping legacy 7263 ), 7264 codepointProp = prop($$props, 'codepoint', 7, null // Codepoint Unicode direct (ex: "E873") pour afficher une icône hors du subset 7265 ), 7266 rootElement = prop($$props, 'rootElement', 15), 7267 vAlign = prop($$props, 'vAlign', 7, '-.125em' // pour alignement avec le texte par défaut 7268 ), 7269 rest = rest_props($$props, [ 7270 '$$slots', 7271 '$$events', 7272 '$$legacy', 7273 '$$host', 7274 'type', 7275 'label', 7276 'size', 7277 'color', 7278 'width', 7279 'height', 7280 'src', 7281 'rotate', 7282 'variant', 7283 'variationSettings', 7284 'renderMode', 7285 'use-material', 7286 'codepoint', 7287 'rootElement', 7288 'vAlign' 7289 ]); 7290 7291 let attributes = user_derived(() => width() === 'auto' 7292 ? { 'data-img-size': size() ? size() : src() ? "md" : null } 7293 : {}); 7294 7295 // Résolution du nom canonique (legacy â modern) 7296 // Si use-material est activé, on utilise le type tel quel sans passer par le mapping 7297 let resolvedType = user_derived(() => { 7298 if (!type()) return type(); 7299 if (useMaterial() != null && useMaterial() !== false) return type(); 7300 7301 const mapped = iconMapping.mappings[type()]; 7302 7303 return mapped && mapped !== type() ? mapped : type(); 7304 }); 7305 7306 // Récupérer le codepoint Unicode pour le mode font 7307 // Priorité : codepoint fourni en attribut > résolution via le nom 7308 let codepoint = user_derived(() => codepointProp() 7309 ? codepointProp() 7310 : get(resolvedType) ? iconCodepoints.codepoints[get(resolvedType)] : null); 7311 7312 // Caractère Unicode correspondant au codepoint 7313 let unicodeChar = user_derived(() => get(codepoint) 7314 ? String.fromCodePoint(parseInt(get(codepoint), 16)) 7315 : null); 7316 7317 // Déterminer le mode de rendu effectif : 7318 // - src fourni â toujours SVG (mask-image custom) 7319 // - renderMode === 'svg' â forcer mode SVG 7320 // - sinon (null ou 'font') ET codepoint trouvé â mode font 7321 let isFontMode = user_derived(() => !src() && renderMode() !== 'svg' && get(unicodeChar) !== null); 7322 7323 // Mécanisme de dépréciation : avertit si un nom legacy ou inconnu est utilisé 7324 user_effect(() => { 7325 if (!type()) return; 7326 if (useMaterial() != null && useMaterial() !== false) return; // Pas de vérification legacy si use-material est activé 7327 7328 const mappedName = iconMapping.mappings[type()]; 7329 7330 if (mappedName && mappedName !== type()) { 7331 // Nom legacy détecté â émettre un avertissement de dépréciation 7332 console.warn(iconMapping.deprecationMessage.replace('{old}', type()).replace('{new}', mappedName)); 7333 } else if (!mappedName && !iconSelection.icons.includes(type())) { 7334 // Nom inconnu â ni dans le mapping, ni dans la sélection 7335 console.warn(`[qc-icon] Icône inconnue : "${type()}". Vérifiez le nom ou utilisez l'attribut src.`); 7336 } 7337 }); 7338 7339 var $$exports = { 7340 get type() { 7341 return type(); 7342 }, 7343 7344 set type($$value) { 7345 type($$value); 7346 flushSync(); 7347 }, 7348 7349 get label() { 7350 return label(); 7351 }, 7352 7353 set label($$value) { 7354 label($$value); 7355 flushSync(); 7356 }, 7357 7358 get size() { 7359 return size(); 7360 }, 7361 7362 set size($$value) { 7363 size($$value); 7364 flushSync(); 7365 }, 7366 7367 get color() { 7368 return color(); 7369 }, 7370 7371 set color($$value) { 7372 color($$value); 7373 flushSync(); 7374 }, 7375 7376 get width() { 7377 return width(); 7378 }, 7379 7380 set width($$value = 'auto') { 7381 width($$value); 7382 flushSync(); 7383 }, 7384 7385 get height() { 7386 return height(); 7387 }, 7388 7389 set height($$value = 'auto') { 7390 height($$value); 7391 flushSync(); 7392 }, 7393 7394 get src() { 7395 return src(); 7396 }, 7397 7398 set src($$value = '') { 7399 src($$value); 7400 flushSync(); 7401 }, 7402 7403 get rotate() { 7404 return rotate(); 7405 }, 7406 7407 set rotate($$value = 0) { 7408 rotate($$value); 7409 flushSync(); 7410 }, 7411 7412 get variant() { 7413 return variant(); 7414 }, 7415 7416 set variant($$value = 'outlined') { 7417 variant($$value); 7418 flushSync(); 7419 }, 7420 7421 get variationSettings() { 7422 return variationSettings(); 7423 }, 7424 7425 set variationSettings($$value = null) { 7426 variationSettings($$value); 7427 flushSync(); 7428 }, 7429 7430 get renderMode() { 7431 return renderMode(); 7432 }, 7433 7434 set renderMode($$value = null) { 7435 renderMode($$value); 7436 flushSync(); 7437 }, 7438 7439 get 'use-material'() { 7440 return useMaterial(); 7441 }, 7442 7443 set 'use-material'($$value = false) { 7444 useMaterial($$value); 7445 flushSync(); 7446 }, 7447 7448 get codepoint() { 7449 return codepointProp(); 7450 }, 7451 7452 set codepoint($$value = null) { 7453 codepointProp($$value); 7454 flushSync(); 7455 }, 7456 7457 get rootElement() { 7458 return rootElement(); 7459 }, 7460 7461 set rootElement($$value) { 7462 rootElement($$value); 7463 flushSync(); 7464 }, 7465 7466 get vAlign() { 7467 return vAlign(); 7468 }, 7469 7470 set vAlign($$value = '-.125em') { 7471 vAlign($$value); 7472 flushSync(); 7473 } 7474 }; 7475 7476 var fragment = comment(); 7477 var node = first_child(fragment); 7478 7479 { 7480 var consequent = ($$anchor) => { 7481 var span = root_1$2(); 7482 7483 attribute_effect( 7484 span, 7485 ($0) => ({ 7486 role: 'img', 7487 ...rest, 7488 class: ["qc-icon", "qc-icon-font", $$props.class], 7489 'aria-label': label(), 7490 7491 style: color() 7492 ? `--img-color: var(--qc-color-${color()});` 7493 : 'inherit', 7494 7495 'data-img-type': get(resolvedType), 7496 'data-img-variant': variant(), 7497 ...get(attributes), 7498 'aria-hidden': label() ? undefined : true, 7499 [STYLE]: $0 7500 }), 7501 [ 7502 () => ({ 7503 '--img-rotate': rotate() && rotate() + "deg", 7504 '--img-valign': vAlign(), 7505 '--img-variation': variationSettings() 7506 }) 7507 ] 7508 ); 7509 7510 var text = child(span, true); 7511 7512 reset(span); 7513 bind_this(span, ($$value) => rootElement($$value), () => rootElement()); 7514 template_effect(() => set_text(text, get(unicodeChar))); 7515 append($$anchor, span); 7516 }; 7517 7518 var alternate = ($$anchor) => { 7519 var div = root_2$1(); 7520 7521 attribute_effect( 7522 div, 7523 ($0) => ({ 7524 role: 'img', 7525 class: ["qc-icon", src() && "qc-icon-custom"], 7526 'aria-label': label(), 7527 7528 style: `--img-color: var(--qc-color-${color() || 'text-primary'}); 7529 --img-width: ${width()}; 7530 --img-height: ${height()}; 7531 --img-src: url('${src()}'); 7532 `, 7533 7534 'data-img-type': type(), 7535 'data-img-variant': variant(), 7536 ...get(attributes), 7537 ...rest, 7538 'aria-hidden': label() ? undefined : true, 7539 [STYLE]: $0 7540 }), 7541 [() => ({ '--img-rotate': rotate() && rotate() + "deg" })] 7542 ); 7543 7544 bind_this(div, ($$value) => rootElement($$value), () => rootElement()); 7545 append($$anchor, div); 7546 }; 7547 7548 if_block(node, ($$render) => { 7549 if (get(isFontMode)) $$render(consequent); else $$render(alternate, false); 7550 }); 7551 } 7552 7553 append($$anchor, fragment); 7554 7555 return pop($$exports); 7556 } 7557
7558 create_custom_element( 7559 Icon, 7560 { 7561 type: {}, 7562 label: {}, 7563 size: {}, 7564 color: {}, 7565 width: {}, 7566 height: {}, 7567 src: {}, 7568 rotate: {}, 7569 variant: {}, 7570 variationSettings: {}, 7571 renderMode: {}, 7572 'use-material': {}, 7573 codepoint: {}, 7574 rootElement: {}, 7575 vAlign: {} 7576 }, 7577 [], 7578 [], 7579 true 7580 ); 7581 7582 var root$5 = from_html(`<button><!></button>`); 7583 7584 function IconButton($$anchor, $$props) { 7585 push($$props, true); 7586 7587 const size = prop($$props, 'size', 7, 'xl'), 7588 label = prop($$props, 'label', 7), 7589 icon = prop($$props, 'icon', 7), 7590 iconSize = prop($$props, 'iconSize', 7), 7591 iconColor = prop($$props, 'iconColor', 7), 7592 className = prop($$props, 'class', 7, ''), 7593 src = prop($$props, 'src', 7), 7594 rest = rest_props($$props, [ 7595 '$$slots', 7596 '$$events', 7597 '$$legacy', 7598 '$$host', 7599 'size', 7600 'label', 7601 'icon', 7602 'iconSize', 7603 'iconColor', 7604 'class', 7605 'src' 7606 ]); 7607 7608 var $$exports = { 7609 get size() { 7610 return size(); 7611 }, 7612 7613 set size($$value = 'xl') { 7614 size($$value); 7615 flushSync(); 7616 }, 7617 7618 get label() { 7619 return label(); 7620 }, 7621 7622 set label($$value) { 7623 label($$value); 7624 flushSync(); 7625 }, 7626 7627 get icon() { 7628 return icon(); 7629 }, 7630 7631 set icon($$value) { 7632 icon($$value); 7633 flushSync(); 7634 }, 7635 7636 get iconSize() { 7637 return iconSize(); 7638 }, 7639 7640 set iconSize($$value) { 7641 iconSize($$value); 7642 flushSync(); 7643 }, 7644 7645 get iconColor() { 7646 return iconColor(); 7647 }, 7648 7649 set iconColor($$value) { 7650 iconColor($$value); 7651 flushSync(); 7652 }, 7653 7654 get class() { 7655 return className(); 7656 }, 7657 7658 set class($$value = '') { 7659 className($$value); 7660 flushSync(); 7661 }, 7662 7663 get src() { 7664 return src(); 7665 }, 7666 7667 set src($$value) { 7668 src($$value); 7669 flushSync(); 7670 } 7671 }; 7672 7673 var button = root$5(); 7674 7675 attribute_effect(button, () => ({ 7676 'data-button-size': size(), 7677 class: `qc-icon-button ${className()}`, 7678 ...rest 7679 })); 7680 7681 var node = child(button); 7682 7683 { 7684 var consequent = ($$anchor) => { 7685 { 7686 let $0 = user_derived(() => src() ? src() : null); 7687 7688 Icon($$anchor, { 7689 get type() { 7690 return icon(); 7691 }, 7692 7693 get size() { 7694 return iconSize(); 7695 }, 7696 7697 get color() { 7698 return iconColor(); 7699 }, 7700 7701 'aria-hidden': 'true', 7702 7703 get label() { 7704 return label(); 7705 }, 7706 7707 get src() { 7708 return get($0); 7709 } 7710 }); 7711 } 7712 }; 7713 7714 if_block(node, ($$render) => { 7715 if (icon()) $$render(consequent); 7716 }); 7717 } 7718 7719 reset(button); 7720 append($$anchor, button); 7721 7722 return pop($$exports); 7723 } 7724 7725 create_custom_element( 7726 IconButton, 7727 { 7728 size: {}, 7729 label: {}, 7730 icon: {}, 7731 iconSize: {}, 7732 iconColor: {}, 7733 class: {}, 7734 src: {} 7735 }, 7736 [], 7737 [], 7738 true 7739 ); 7740 7741 var root_1$1 = from_html(`<span class="qc-required" aria-hidden="true">*</span>`); 7742 var root$4 = from_html(`<span class="qc-label-text"><!></span><!>`, 1); 7743 7744 function LabelText($$anchor, $$props) { 7745 push($$props, true); 7746 7747 let text = prop($$props, 'text', 7), 7748 required = prop($$props, 'required', 7); 7749 7750 var $$exports = { 7751 get text() { 7752 return text(); 7753 }, 7754 7755 set text($$value) { 7756 text($$value); 7757 flushSync(); 7758 }, 7759 7760 get required() { 7761 return required(); 7762 }, 7763 7764 set required($$value) { 7765 required($$value); 7766 flushSync(); 7767 } 7768 }; 7769 7770 var fragment = root$4(); 7771 var span = first_child(fragment); 7772 var node = child(span); 7773 7774 html(node, text); 7775 reset(span); 7776 7777 var node_1 = sibling(span); 7778 7779 { 7780 var consequent = ($$anchor) => { 7781 var span_1 = root_1$1(); 7782 7783 append($$anchor, span_1); 7784 }; 7785 7786 if_block(node_1, ($$render) => { 7787 if (required()) $$render(consequent); 7788 }); 7789 } 7790 7791 append($$anchor, fragment); 7792 7793 return pop($$exports); 7794 } 7795 7796 create_custom_element(LabelText, { text: {}, required: {} }, [], [], true); 7797 7798 var root$3 = from_html(`<label><!></label>`); 7799 7800 function Label($$anchor, $$props) { 7801 push($$props, true); 7802 7803 let forId = prop($$props, 'forId', 7), 7804 text = prop($$props, 'text', 7), 7805 required = prop($$props, 'required', 7, false), 7806 compact = prop($$props, 'compact', 7, false), 7807 bold = prop($$props, 'bold', 7, false), 7808 disabled = prop($$props, 'disabled', 7, false), 7809 rootElement = prop($$props, 'rootElement', 15), 7810 rest = rest_props($$props, [ 7811 '$$slots', 7812 '$$events', 7813 '$$legacy', 7814 '$$host', 7815 'forId', 7816 'text', 7817 'required', 7818 'compact', 7819 'bold', 7820 'disabled', 7821 'rootElement' 7822 ]); 7823 7824 var $$exports = { 7825 get forId() { 7826 return forId(); 7827 }, 7828 7829 set forId($$value) { 7830 forId($$value); 7831 flushSync(); 7832 }, 7833 7834 get text() { 7835 return text(); 7836 }, 7837 7838 set text($$value) { 7839 text($$value); 7840 flushSync(); 7841 }, 7842 7843 get required() { 7844 return required(); 7845 }, 7846 7847 set required($$value = false) { 7848 required($$value); 7849 flushSync(); 7850 }, 7851 7852 get compact() { 7853 return compact(); 7854 }, 7855 7856 set compact($$value = false) { 7857 compact($$value); 7858 flushSync(); 7859 }, 7860 7861 get bold() { 7862 return bold(); 7863 }, 7864 7865 set bold($$value = false) { 7866 bold($$value); 7867 flushSync(); 7868 }, 7869 7870 get disabled() { 7871 return disabled(); 7872 }, 7873 7874 set disabled($$value = false) { 7875 disabled($$value); 7876 flushSync(); 7877 }, 7878 7879 get rootElement() { 7880 return rootElement(); 7881 }, 7882 7883 set rootElement($$value) { 7884 rootElement($$value); 7885 flushSync(); 7886 } 7887 }; 7888 7889 var label = root$3(); 7890 7891 attribute_effect(label, () => ({ 7892 for: forId(), 7893 7894 class: [ 7895 "qc-label", 7896 compact() && "qc-compact", 7897 bold() && "qc-bold", 7898 disabled() && "qc-disabled" 7899 ], 7900 7901 ...rest 7902 })); 7903 7904 var node = child(label); 7905 7906 LabelText(node, { 7907 get text() { 7908 return text(); 7909 }, 7910 7911 get required() { 7912 return required(); 7913 } 7914 }); 7915 7916 reset(label); 7917 bind_this(label, ($$value) => rootElement($$value), () => rootElement()); 7918 append($$anchor, label); 7919 7920 return pop($$exports); 7921 } 7922
7923 create_custom_element( 7924 Label, 7925 { 7926 forId: {}, 7927 text: {}, 7928 required: {}, 7929 compact: {}, 7930 bold: {}, 7931 disabled: {}, 7932 rootElement: {} 7933 }, 7934 [], 7935 [], 7936 true 7937 ); 7938 7939 var root$2 = from_html(`<!> <div><!> <input/> <!></div>`, 1); 7940 7941 function SearchInput($$anchor, $$props) { 7942 push($$props, true); 7943 7944 const lang = Utils.getPageLanguage(); 7945 7946 let value = prop($$props, 'value', 15, ''), 7947 label = prop($$props, 'label', 7, ''), 7948 size = prop($$props, 'size', 7, ''), 7949 debounce = prop($$props, 'debounce', 7, 0), 7950 ariaLabel = prop($$props, 'ariaLabel', 7, lang === "fr" ? "Rechercher..." : "Search..."), 7951 clearAriaLabel = prop($$props, 'clearAriaLabel', 7, lang === "fr" ? "Effacer le texte" : "Clear text"), 7952 leftIcon = prop($$props, 'leftIcon', 7, false), 7953 id = prop($$props, 'id', 23, () => `qc-search-input-${Math.random().toString(36).slice(2, 11)}`), 7954 rest = rest_props($$props, [ 7955 '$$slots', 7956 '$$events', 7957 '$$legacy', 7958 '$$host', 7959 'value', 7960 'label', 7961 'size', 7962 'debounce', 7963 'ariaLabel', 7964 'clearAriaLabel', 7965 'leftIcon', 7966 'id' 7967 ]); 7968 7969 const leftIconNormalized = user_derived(() => leftIcon() === true || leftIcon() === "true" || leftIcon() === ""); 7970 const isDisabled = user_derived(() => $$props.disabled === true || $$props.disabled === "true" || $$props.disabled === ""); 7971 let searchInput; 7972 7973 // Valeur interne liée à l'input â toujours synchrone avec la saisie 7974 let inputValue = state(proxy(value() ?? '')); 7975 7976 let timer; 7977 7978 // Synchroniser inputValue quand value change de l'extérieur (clear, reset) 7979 // untrack sur inputValue pour ne réagir qu'aux changements de `value` 7980 user_effect(() => { 7981 const v = value() ?? ''; 7982 7983 if (v !== untrack(() => get(inputValue))) { 7984 set(inputValue, v, true); 7985 } 7986 }); 7987 7988 function handleInput() { 7989 if (debounce() > 0) { 7990 clearTimeout(timer); 7991 7992 timer = setTimeout( 7993 () => { 7994 value(get(inputValue)); 7995 searchInput?.dispatchEvent(new CustomEvent('qc-change', { bubbles: true, detail: value() })); 7996 }, 7997 debounce() 7998 ); 7999 } else { 8000 value(get(inputValue)); 8001 } 8002 } 8003 8004 function clearValue(e) { 8005 e.preventDefault(); 8006 clearTimeout(timer); 8007 set(inputValue, ""); 8008 value(""); 8009 searchInput?.dispatchEvent(new CustomEvent('qc-change', { bubbles: true, detail: value() })); 8010 searchInput?.focus(); 8011 } 8012 8013 onDestroy(() => clearTimeout(timer)); 8014 8015 function focus() { 8016 searchInput?.focus(); 8017 } 8018 8019 var $$exports = { 8020 focus, 8021 8022 get value() { 8023 return value(); 8024 }, 8025 8026 set value($$value = '') { 8027 value($$value); 8028 flushSync(); 8029 }, 8030 8031 get label() { 8032 return label(); 8033 }, 8034 8035 set label($$value = '') { 8036 label($$value); 8037 flushSync(); 8038 }, 8039 8040 get size() { 8041 return size(); 8042 }, 8043 8044 set size($$value = '') { 8045 size($$value); 8046 flushSync(); 8047 }, 8048 8049 get debounce() { 8050 return debounce(); 8051 }, 8052 8053 set debounce($$value = 0) { 8054 debounce($$value); 8055 flushSync(); 8056 }, 8057 8058 get ariaLabel() { 8059 return ariaLabel(); 8060 }, 8061 8062 set ariaLabel($$value = lang === "fr" ? "Rechercher..." : "Search...") { 8063 ariaLabel($$value); 8064 flushSync(); 8065 }, 8066 8067 get clearAriaLabel() { 8068 return clearAriaLabel(); 8069 }, 8070 8071 set clearAriaLabel($$value = lang === "fr" ? "Effacer le texte" : "Clear text") { 8072 clearAriaLabel($$value); 8073 flushSync(); 8074 }, 8075 8076 get leftIcon() { 8077 return leftIcon(); 8078 }, 8079 8080 set leftIcon($$value = false) { 8081 leftIcon($$value); 8082 flushSync(); 8083 }, 8084 8085 get id() { 8086 return id(); 8087 }, 8088 8089 set id( 8090 $$value = `qc-search-input-${Math.random().toString(36).slice(2, 11)}` 8091 ) { 8092 id($$value); 8093 flushSync(); 8094 } 8095 }; 8096 8097 var fragment = root$2(); 8098 var node = first_child(fragment); 8099 8100 { 8101 var consequent = ($$anchor) => { 8102 Label($$anchor, { 8103 get disabled() { 8104 return get(isDisabled); 8105 }, 8106 8107 get text() { 8108 return label(); 8109 }, 8110 8111 get forId() { 8112 return id(); 8113 } 8114 }); 8115 }; 8116 8117 if_block(node, ($$render) => { 8118 if (label()) $$render(consequent); 8119 }); 8120 } 8121 8122 var div = sibling(node, 2); 8123 var node_1 = child(div); 8124 8125 { 8126 var consequent_1 = ($$anchor) => { 8127 { 8128 let $0 = user_derived(() => get(isDisabled) ? 'is-disabled' : ''); 8129 8130 Icon($$anchor, { 8131 type: 'search', 8132 iconColor: 'grey-regular', 8133 8134 get class() { 8135 return get($0); 8136 }, 8137 8138 size: 'nm' 8139 }); 8140 } 8141 }; 8142 8143 if_block(node_1, ($$render) => { 8144 if (get(leftIconNormalized)) $$render(consequent_1); 8145 }); 8146 } 8147 8148 var input = sibling(node_1, 2); 8149 8150 attribute_effect( 8151 input, 8152 () => ({
8153 oninput: handleInput, 8154 type: 'search', 8155 autocomplete: 'off', 8156 'aria-label': label() ? undefined : ariaLabel(), 8157 class: get(isDisabled) ? "qc-disabled" : "", 8158 id: id(), 8159 ...rest 8160 }), 8161 void 0, 8162 void 0, 8163 void 0, 8164 true 8165 ); 8166 8167 bind_this(input, ($$value) => searchInput = $$value, () => searchInput); 8168 8169 var node_2 = sibling(input, 2); 8170 8171 { 8172 var consequent_2 = ($$anchor) => { 8173 IconButton($$anchor, { 8174 type: 'button', 8175 icon: 'close', 8176 iconColor: 'blue-piv', 8177 iconSize: 'nm', 8178 8179 get 'aria-label'() { 8180 return clearAriaLabel(); 8181 }, 8182 8183 onclick: clearValue 8184 }); 8185 }; 8186 8187 if_block(node_2, ($$render) => { 8188 if (get(inputValue)) $$render(consequent_2); 8189 }); 8190 } 8191 8192 reset(div); 8193 8194 template_effect(() => { 8195 set_class(div, 1, clsx([ 8196 "qc-search-input", 8197 get(leftIconNormalized) && "qc-search-left-icon", 8198 get(leftIconNormalized) && get(isDisabled) && "qc-search-left-icon-disabled" 8199 ])); 8200 8201 set_attribute(div, 'size', size()); 8202 }); 8203 8204 bind_value(input, () => get(inputValue), ($$value) => set(inputValue, $$value)); 8205 append($$anchor, fragment); 8206 8207 return pop($$exports); 8208 } 8209 8210 create_custom_element( 8211 SearchInput, 8212 { 8213 value: {}, 8214 label: {}, 8215 size: {}, 8216 debounce: {}, 8217 ariaLabel: {}, 8218 clearAriaLabel: {}, 8219 leftIcon: {}, 8220 id: {} 8221 }, 8222 [], 8223 ['focus'], 8224 true 8225 ); 8226 8227 var root$1 = from_html(`<div><!> <!></div>`); 8228 8229 function SearchBar($$anchor, $$props) { 8230 push($$props, true); 8231 8232 const lang = Utils.getPageLanguage(); 8233 8234 let value = prop($$props, 'value', 15, ''), 8235 name = prop($$props, 'name', 7, 'q'), 8236 pivBackground = prop($$props, 'pivBackground', 7, false), 8237 rest = rest_props($$props, [ 8238 '$$slots', 8239 '$$events', 8240 '$$legacy', 8241 '$$host', 8242 'value', 8243 'name', 8244 'pivBackground' 8245 ]); 8246 8247 let defaultsAttributes = { 8248 input: { 8249 "placeholder": lang === "fr" ? "Rechercherâ¦" : "Search", 8250 "aria-label": lang === "fr" ? "Rechercherâ¦" : "Search" 8251 }}; 8252 8253 let inputProps = user_derived(() => ({ 8254 ...defaultsAttributes.input, 8255 ...Utils.computeFieldsAttributes("input", rest), 8256 name: name() 8257 })), 8258 submitProps = user_derived(() => ({ 8259 ...defaultsAttributes.input, 8260 ...Utils.computeFieldsAttributes("submit", rest) 8261 })); 8262 8263 var $$exports = { 8264 get value() { 8265 return value(); 8266 }, 8267 8268 set value($$value = '') { 8269 value($$value); 8270 flushSync(); 8271 }, 8272 8273 get name() { 8274 return name(); 8275 }, 8276 8277 set name($$value = 'q') { 8278 name($$value); 8279 flushSync(); 8280 }, 8281 8282 get pivBackground() { 8283 return pivBackground(); 8284 }, 8285 8286 set pivBackground($$value = false) { 8287 pivBackground($$value); 8288 flushSync(); 8289 } 8290 }; 8291 8292 var div = root$1(); 8293 let classes; 8294 var node = child(div); 8295 8296 SearchInput(node, spread_props(() => get(inputProps), { 8297 size: 'full-width', 8298 8299 get value() { 8300 return value(); 8301 }, 8302 8303 set value($$value) { 8304 value($$value); 8305 } 8306 })); 8307 8308 var node_1 = sibling(node, 2); 8309 8310 { 8311 let $0 = user_derived(() => pivBackground() ? 'blue-piv' : 'background'); 8312 8313 IconButton(node_1, spread_props( 8314 { 8315 type: 'submit', 8316 8317 get iconColor() { 8318 return get($0); 8319 }, 8320 8321 icon: 'search', 8322 iconSize: 'nm' 8323 }, 8324 () => get(submitProps) 8325 )); 8326 } 8327 8328 reset(div); 8329 template_effect(($0) => classes = set_class(div, 1, 'qc-search-bar', null, classes, $0), [() => ({ 'piv-background': pivBackground() })]); 8330 append($$anchor, div); 8331 8332 return pop($$exports); 8333 } 8334 8335 create_custom_element(SearchBar, { value: {}, name: {}, pivBackground: {} }, [], [], true); 8336 8337 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; 8338 8339 var lodash$1 = {exports: {}}; 8340 8341 /** 8342 * @license 8343 * Lodash <https://lodash.com/> 8344 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/> 8345 * Released under MIT license <https://lodash.com/license> 8346 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> 8347 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors 8348 */ 8349 var lodash = lodash$1.exports; 8350 8351 var hasRequiredLodash; 8352 8353 function requireLodash () { 8354 if (hasRequiredLodash) return lodash$1.exports; 8355 hasRequiredLodash = 1;
vendor: 7,103 bytes, lines 8356-8545
8356 (function (module, exports) { 8357 (function() { 8358 8359 /** Used as a safe reference for `undefined` in pre-ES5 environments. */ 8360 var undefined$1; 8361 8362 /** Used as the semantic version number. */ 8363 var VERSION = '4.17.21'; 8364 8365 /** Used as the size to enable large array optimizations. */ 8366 var LARGE_ARRAY_SIZE = 200; 8367 8368 /** Error message constants. */ 8369 var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.', 8370 FUNC_ERROR_TEXT = 'Expected a function', 8371 INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`'; 8372 8373 /** Used to stand-in for `undefined` hash values. */ 8374 var HASH_UNDEFINED = '__lodash_hash_undefined__'; 8375 8376 /** Used as the maximum memoize cache size. */ 8377 var MAX_MEMOIZE_SIZE = 500; 8378 8379 /** Used as the internal argument placeholder. */ 8380 var PLACEHOLDER = '__lodash_placeholder__'; 8381 8382 /** Used to compose bitmasks for cloning. */ 8383 var CLONE_DEEP_FLAG = 1, 8384 CLONE_FLAT_FLAG = 2, 8385 CLONE_SYMBOLS_FLAG = 4; 8386 8387 /** Used to compose bitmasks for value comparisons. */ 8388 var COMPARE_PARTIAL_FLAG = 1, 8389 COMPARE_UNORDERED_FLAG = 2; 8390 8391 /** Used to compose bitmasks for function metadata. */ 8392 var WRAP_BIND_FLAG = 1, 8393 WRAP_BIND_KEY_FLAG = 2, 8394 WRAP_CURRY_BOUND_FLAG = 4, 8395 WRAP_CURRY_FLAG = 8, 8396 WRAP_CURRY_RIGHT_FLAG = 16, 8397 WRAP_PARTIAL_FLAG = 32, 8398 WRAP_PARTIAL_RIGHT_FLAG = 64, 8399 WRAP_ARY_FLAG = 128, 8400 WRAP_REARG_FLAG = 256, 8401 WRAP_FLIP_FLAG = 512; 8402 8403 /** Used as default options for `_.truncate`. */ 8404 var DEFAULT_TRUNC_LENGTH = 30, 8405 DEFAULT_TRUNC_OMISSION = '...'; 8406 8407 /** Used to detect hot functions by number of calls within a span of milliseconds. */ 8408 var HOT_COUNT = 800, 8409 HOT_SPAN = 16; 8410 8411 /** Used to indicate the type of lazy iteratees. */ 8412 var LAZY_FILTER_FLAG = 1, 8413 LAZY_MAP_FLAG = 2, 8414 LAZY_WHILE_FLAG = 3; 8415 8416 /** Used as references for various `Number` constants. */ 8417 var INFINITY = 1 / 0, 8418 MAX_SAFE_INTEGER = 9007199254740991, 8419 MAX_INTEGER = 1.7976931348623157e+308, 8420 NAN = 0 / 0; 8421 8422 /** Used as references for the maximum length and index of an array. */ 8423 var MAX_ARRAY_LENGTH = 4294967295, 8424 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, 8425 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; 8426 8427 /** Used to associate wrap methods with their bit flags. */ 8428 var wrapFlags = [ 8429 ['ary', WRAP_ARY_FLAG], 8430 ['bind', WRAP_BIND_FLAG], 8431 ['bindKey', WRAP_BIND_KEY_FLAG], 8432 ['curry', WRAP_CURRY_FLAG], 8433 ['curryRight', WRAP_CURRY_RIGHT_FLAG], 8434 ['flip', WRAP_FLIP_FLAG], 8435 ['partial', WRAP_PARTIAL_FLAG], 8436 ['partialRight', WRAP_PARTIAL_RIGHT_FLAG], 8437 ['rearg', WRAP_REARG_FLAG] 8438 ]; 8439 8440 /** `Object#toString` result references. */ 8441 var argsTag = '[object Arguments]', 8442 arrayTag = '[object Array]', 8443 asyncTag = '[object AsyncFunction]', 8444 boolTag = '[object Boolean]', 8445 dateTag = '[object Date]', 8446 domExcTag = '[object DOMException]', 8447 errorTag = '[object Error]', 8448 funcTag = '[object Function]', 8449 genTag = '[object GeneratorFunction]', 8450 mapTag = '[object Map]', 8451 numberTag = '[object Number]', 8452 nullTag = '[object Null]', 8453 objectTag = '[object Object]', 8454 promiseTag = '[object Promise]', 8455 proxyTag = '[object Proxy]', 8456 regexpTag = '[object RegExp]', 8457 setTag = '[object Set]', 8458 stringTag = '[object String]', 8459 symbolTag = '[object Symbol]', 8460 undefinedTag = '[object Undefined]', 8461 weakMapTag = '[object WeakMap]', 8462 weakSetTag = '[object WeakSet]'; 8463 8464 var arrayBufferTag = '[object ArrayBuffer]', 8465 dataViewTag = '[object DataView]', 8466 float32Tag = '[object Float32Array]', 8467 float64Tag = '[object Float64Array]', 8468 int8Tag = '[object Int8Array]', 8469 int16Tag = '[object Int16Array]', 8470 int32Tag = '[object Int32Array]', 8471 uint8Tag = '[object Uint8Array]', 8472 uint8ClampedTag = '[object Uint8ClampedArray]', 8473 uint16Tag = '[object Uint16Array]', 8474 uint32Tag = '[object Uint32Array]'; 8475 8476 /** Used to match empty string literals in compiled template source. */ 8477 var reEmptyStringLeading = /\b__p \+= '';/g, 8478 reEmptyStringMiddle = /\b(__p \+=) '' \+/g, 8479 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; 8480 8481 /** Used to match HTML entities and HTML characters. */ 8482 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, 8483 reUnescapedHtml = /[&<>"']/g, 8484 reHasEscapedHtml = RegExp(reEscapedHtml.source), 8485 reHasUnescapedHtml = RegExp(reUnescapedHtml.source); 8486 8487 /** Used to match template delimiters. */ 8488 var reEscape = /<%-([\s\S]+?)%>/g, 8489 reEvaluate = /<%([\s\S]+?)%>/g, 8490 reInterpolate = /<%=([\s\S]+?)%>/g; 8491 8492 /** Used to match property names within property paths. */ 8493 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, 8494 reIsPlainProp = /^\w*$/, 8495 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; 8496 8497 /** 8498 * Used to match `RegExp` 8499 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). 8500 */ 8501 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, 8502 reHasRegExpChar = RegExp(reRegExpChar.source); 8503 8504 /** Used to match leading whitespace. */ 8505 var reTrimStart = /^\s+/; 8506 8507 /** Used to match a single whitespace character. */ 8508 var reWhitespace = /\s/; 8509 8510 /** Used to match wrap detail comments. */ 8511 var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, 8512 reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, 8513 reSplitDetails = /,? & /; 8514 8515 /** Used to match words composed of alphanumeric characters. */ 8516 var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; 8517 8518 /** 8519 * Used to validate the `validate` option in `_.template` variable. 8520 * 8521 * Forbids characters which could potentially change the meaning of the function argument definition: 8522 * - "()," (modification of function parameters) 8523 * - "=" (default value) 8524 * - "[]{}" (destructuring of function parameters) 8525 * - "/" (beginning of a comment) 8526 * - whitespace 8527 */ 8528 var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/; 8529 8530 /** Used to match backslashes in property paths. */ 8531 var reEscapeChar = /\\(\\)?/g; 8532 8533 /** 8534 * Used to match 8535 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). 8536 */ 8537 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; 8538 8539 /** Used to match `RegExp` flags from their coerced string values. */ 8540 var reFlags = /\w*$/; 8541 8542 /** Used to detect bad signed hexadecimal string values. */ 8543 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; 8544 8545 /** Used to detect binary string values. */
vendor: 5,997 bytes, lines 8546-8663
8546 var reIsBinary = /^0b[01]+$/i; 8547 8548 /** Used to detect host constructors (Safari). */ 8549 var reIsHostCtor = /^\[object .+?Constructor\]$/; 8550 8551 /** Used to detect octal string values. */ 8552 var reIsOctal = /^0o[0-7]+$/i; 8553 8554 /** Used to detect unsigned integer values. */ 8555 var reIsUint = /^(?:0|[1-9]\d*)$/; 8556 8557 /** Used to match Latin Unicode letters (excluding mathematical operators). */ 8558 var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; 8559 8560 /** Used to ensure capturing order of template delimiters. */ 8561 var reNoMatch = /($^)/; 8562 8563 /** Used to match unescaped characters in compiled string literals. */ 8564 var reUnescapedString = /['\n\r\u2028\u2029\\]/g; 8565 8566 /** Used to compose unicode character classes. */ 8567 var rsAstralRange = '\\ud800-\\udfff', 8568 rsComboMarksRange = '\\u0300-\\u036f', 8569 reComboHalfMarksRange = '\\ufe20-\\ufe2f', 8570 rsComboSymbolsRange = '\\u20d0-\\u20ff', 8571 rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, 8572 rsDingbatRange = '\\u2700-\\u27bf', 8573 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', 8574 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', 8575 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', 8576 rsPunctuationRange = '\\u2000-\\u206f', 8577 rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', 8578 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', 8579 rsVarRange = '\\ufe0e\\ufe0f', 8580 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; 8581 8582 /** Used to compose unicode capture groups. */ 8583 var rsApos = "['\u2019]", 8584 rsAstral = '[' + rsAstralRange + ']', 8585 rsBreak = '[' + rsBreakRange + ']', 8586 rsCombo = '[' + rsComboRange + ']', 8587 rsDigits = '\\d+', 8588 rsDingbat = '[' + rsDingbatRange + ']', 8589 rsLower = '[' + rsLowerRange + ']', 8590 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', 8591 rsFitz = '\\ud83c[\\udffb-\\udfff]', 8592 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', 8593 rsNonAstral = '[^' + rsAstralRange + ']', 8594 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', 8595 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', 8596 rsUpper = '[' + rsUpperRange + ']', 8597 rsZWJ = '\\u200d'; 8598 8599 /** Used to compose unicode regexes. */ 8600 var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', 8601 rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', 8602 rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', 8603 rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', 8604 reOptMod = rsModifier + '?', 8605 rsOptVar = '[' + rsVarRange + ']?', 8606 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', 8607 rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', 8608 rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', 8609 rsSeq = rsOptVar + reOptMod + rsOptJoin, 8610 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, 8611 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; 8612 8613 /** Used to match apostrophes. */ 8614 var reApos = RegExp(rsApos, 'g'); 8615 8616 /** 8617 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and 8618 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). 8619 */ 8620 var reComboMark = RegExp(rsCombo, 'g'); 8621 8622 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ 8623 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); 8624 8625 /** Used to match complex or compound words. */ 8626 var reUnicodeWord = RegExp([ 8627 rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', 8628 rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', 8629 rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, 8630 rsUpper + '+' + rsOptContrUpper, 8631 rsOrdUpper, 8632 rsOrdLower, 8633 rsDigits, 8634 rsEmoji 8635 ].join('|'), 'g'); 8636 8637 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ 8638 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); 8639 8640 /** Used to detect strings that need a more robust regexp to match words. */ 8641 var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; 8642 8643 /** Used to assign default `context` object properties. */ 8644 var contextProps = [ 8645 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', 8646 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', 8647 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', 8648 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', 8649 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' 8650 ]; 8651 8652 /** Used to make template sourceURLs easier to identify. */ 8653 var templateCounter = -1; 8654 8655 /** Used to identify `toStringTag` values of typed arrays. */ 8656 var typedArrayTags = {}; 8657 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = 8658 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = 8659 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = 8660 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = 8661 typedArrayTags[uint32Tag] = true; 8662 typedArrayTags[argsTag] = typedArrayTags[arrayTag] = 8663 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
vendor: 6,283 bytes, lines 8664-8798
8664 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = 8665 typedArrayTags[errorTag] = typedArrayTags[funcTag] = 8666 typedArrayTags[mapTag] = typedArrayTags[numberTag] = 8667 typedArrayTags[objectTag] = typedArrayTags[regexpTag] = 8668 typedArrayTags[setTag] = typedArrayTags[stringTag] = 8669 typedArrayTags[weakMapTag] = false; 8670 8671 /** Used to identify `toStringTag` values supported by `_.clone`. */ 8672 var cloneableTags = {}; 8673 cloneableTags[argsTag] = cloneableTags[arrayTag] = 8674 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = 8675 cloneableTags[boolTag] = cloneableTags[dateTag] = 8676 cloneableTags[float32Tag] = cloneableTags[float64Tag] = 8677 cloneableTags[int8Tag] = cloneableTags[int16Tag] = 8678 cloneableTags[int32Tag] = cloneableTags[mapTag] = 8679 cloneableTags[numberTag] = cloneableTags[objectTag] = 8680 cloneableTags[regexpTag] = cloneableTags[setTag] = 8681 cloneableTags[stringTag] = cloneableTags[symbolTag] = 8682 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = 8683 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; 8684 cloneableTags[errorTag] = cloneableTags[funcTag] = 8685 cloneableTags[weakMapTag] = false; 8686 8687 /** Used to map Latin Unicode letters to basic Latin letters. */ 8688 var deburredLetters = { 8689 // Latin-1 Supplement block. 8690 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', 8691 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', 8692 '\xc7': 'C', '\xe7': 'c', 8693 '\xd0': 'D', '\xf0': 'd', 8694 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', 8695 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', 8696 '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', 8697 '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', 8698 '\xd1': 'N', '\xf1': 'n', 8699 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', 8700 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', 8701 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', 8702 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', 8703 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', 8704 '\xc6': 'Ae', '\xe6': 'ae', 8705 '\xde': 'Th', '\xfe': 'th', 8706 '\xdf': 'ss', 8707 // Latin Extended-A block. 8708 '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', 8709 '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', 8710 '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', 8711 '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', 8712 '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', 8713 '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', 8714 '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', 8715 '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', 8716 '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', 8717 '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', 8718 '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', 8719 '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', 8720 '\u0134': 'J', '\u0135': 'j', 8721 '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', 8722 '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', 8723 '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', 8724 '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', 8725 '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', 8726 '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', 8727 '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', 8728 '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', 8729 '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', 8730 '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', 8731 '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', 8732 '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', 8733 '\u0163': 't', '\u0165': 't', '\u0167': 't', 8734 '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', 8735 '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', 8736 '\u0174': 'W', '\u0175': 'w', 8737 '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', 8738 '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', 8739 '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', 8740 '\u0132': 'IJ', '\u0133': 'ij', 8741 '\u0152': 'Oe', '\u0153': 'oe', 8742 '\u0149': "'n", '\u017f': 's' 8743 }; 8744 8745 /** Used to map characters to HTML entities. */ 8746 var htmlEscapes = { 8747 '&': '&', 8748 '<': '<', 8749 '>': '>', 8750 '"': '"', 8751 "'": ''' 8752 }; 8753 8754 /** Used to map HTML entities to characters. */ 8755 var htmlUnescapes = { 8756 '&': '&', 8757 '<': '<', 8758 '>': '>', 8759 '"': '"', 8760 ''': "'" 8761 }; 8762 8763 /** Used to escape characters for inclusion in compiled string literals. */ 8764 var stringEscapes = { 8765 '\\': '\\', 8766 "'": "'", 8767 '\n': 'n', 8768 '\r': 'r', 8769 '\u2028': 'u2028', 8770 '\u2029': 'u2029' 8771 }; 8772 8773 /** Built-in method references without a dependency on `root`. */ 8774 var freeParseFloat = parseFloat, 8775 freeParseInt = parseInt; 8776 8777 /** Detect free variable `global` from Node.js. */ 8778 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; 8779 8780 /** Detect free variable `self`. */ 8781 var freeSelf = typeof self == 'object' && self && self.Object === Object && self; 8782 8783 /** Used as a reference to the global object. */ 8784 var root = freeGlobal || freeSelf || Function('return this')(); 8785 8786 /** Detect free variable `exports`. */ 8787 var freeExports = exports && !exports.nodeType && exports; 8788 8789 /** Detect free variable `module`. */ 8790 var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module; 8791 8792 /** Detect the popular CommonJS extension `module.exports`. */ 8793 var moduleExports = freeModule && freeModule.exports === freeExports; 8794 8795 /** Detect free variable `process` from Node.js. */ 8796 var freeProcess = moduleExports && freeGlobal.process; 8797 8798 /** Used to access faster Node.js helpers. */
vendor: 9,661 bytes, lines 8799-9092
8799 var nodeUtil = (function() { 8800 try { 8801 // Use `util.types` for Node.js 10+. 8802 var types = freeModule && freeModule.require && freeModule.require('util').types; 8803 8804 if (types) { 8805 return types; 8806 } 8807 8808 // Legacy `process.binding('util')` for Node.js < 10. 8809 return freeProcess && freeProcess.binding && freeProcess.binding('util'); 8810 } catch (e) {} 8811 }()); 8812 8813 /* Node.js helper references. */ 8814 var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, 8815 nodeIsDate = nodeUtil && nodeUtil.isDate, 8816 nodeIsMap = nodeUtil && nodeUtil.isMap, 8817 nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, 8818 nodeIsSet = nodeUtil && nodeUtil.isSet, 8819 nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; 8820 8821 /*--------------------------------------------------------------------------*/ 8822 8823 /** 8824 * A faster alternative to `Function#apply`, this function invokes `func` 8825 * with the `this` binding of `thisArg` and the arguments of `args`. 8826 * 8827 * @private 8828 * @param {Function} func The function to invoke. 8829 * @param {*} thisArg The `this` binding of `func`. 8830 * @param {Array} args The arguments to invoke `func` with. 8831 * @returns {*} Returns the result of `func`. 8832 */ 8833 function apply(func, thisArg, args) { 8834 switch (args.length) { 8835 case 0: return func.call(thisArg); 8836 case 1: return func.call(thisArg, args[0]); 8837 case 2: return func.call(thisArg, args[0], args[1]); 8838 case 3: return func.call(thisArg, args[0], args[1], args[2]); 8839 } 8840 return func.apply(thisArg, args); 8841 } 8842 8843 /** 8844 * A specialized version of `baseAggregator` for arrays. 8845 * 8846 * @private 8847 * @param {Array} [array] The array to iterate over. 8848 * @param {Function} setter The function to set `accumulator` values. 8849 * @param {Function} iteratee The iteratee to transform keys. 8850 * @param {Object} accumulator The initial aggregated object. 8851 * @returns {Function} Returns `accumulator`. 8852 */ 8853 function arrayAggregator(array, setter, iteratee, accumulator) { 8854 var index = -1, 8855 length = array == null ? 0 : array.length; 8856 8857 while (++index < length) { 8858 var value = array[index]; 8859 setter(accumulator, value, iteratee(value), array); 8860 } 8861 return accumulator; 8862 } 8863 8864 /** 8865 * A specialized version of `_.forEach` for arrays without support for 8866 * iteratee shorthands. 8867 * 8868 * @private 8869 * @param {Array} [array] The array to iterate over. 8870 * @param {Function} iteratee The function invoked per iteration. 8871 * @returns {Array} Returns `array`. 8872 */ 8873 function arrayEach(array, iteratee) { 8874 var index = -1, 8875 length = array == null ? 0 : array.length; 8876 8877 while (++index < length) { 8878 if (iteratee(array[index], index, array) === false) { 8879 break; 8880 } 8881 } 8882 return array; 8883 } 8884 8885 /** 8886 * A specialized version of `_.forEachRight` for arrays without support for 8887 * iteratee shorthands. 8888 * 8889 * @private 8890 * @param {Array} [array] The array to iterate over. 8891 * @param {Function} iteratee The function invoked per iteration. 8892 * @returns {Array} Returns `array`. 8893 */ 8894 function arrayEachRight(array, iteratee) { 8895 var length = array == null ? 0 : array.length; 8896 8897 while (length--) { 8898 if (iteratee(array[length], length, array) === false) { 8899 break; 8900 } 8901 } 8902 return array; 8903 } 8904 8905 /** 8906 * A specialized version of `_.every` for arrays without support for 8907 * iteratee shorthands. 8908 * 8909 * @private 8910 * @param {Array} [array] The array to iterate over. 8911 * @param {Function} predicate The function invoked per iteration. 8912 * @returns {boolean} Returns `true` if all elements pass the predicate check, 8913 * else `false`. 8914 */ 8915 function arrayEvery(array, predicate) { 8916 var index = -1, 8917 length = array == null ? 0 : array.length; 8918 8919 while (++index < length) { 8920 if (!predicate(array[index], index, array)) { 8921 return false; 8922 } 8923 } 8924 return true; 8925 } 8926 8927 /** 8928 * A specialized version of `_.filter` for arrays without support for 8929 * iteratee shorthands. 8930 * 8931 * @private 8932 * @param {Array} [array] The array to iterate over. 8933 * @param {Function} predicate The function invoked per iteration. 8934 * @returns {Array} Returns the new filtered array. 8935 */ 8936 function arrayFilter(array, predicate) { 8937 var index = -1, 8938 length = array == null ? 0 : array.length, 8939 resIndex = 0, 8940 result = []; 8941 8942 while (++index < length) { 8943 var value = array[index]; 8944 if (predicate(value, index, array)) { 8945 result[resIndex++] = value; 8946 } 8947 } 8948 return result; 8949 } 8950 8951 /** 8952 * A specialized version of `_.includes` for arrays without support for 8953 * specifying an index to search from. 8954 * 8955 * @private 8956 * @param {Array} [array] The array to inspect. 8957 * @param {*} target The value to search for. 8958 * @returns {boolean} Returns `true` if `target` is found, else `false`. 8959 */ 8960 function arrayIncludes(array, value) { 8961 var length = array == null ? 0 : array.length; 8962 return !!length && baseIndexOf(array, value, 0) > -1; 8963 } 8964 8965 /** 8966 * This function is like `arrayIncludes` except that it accepts a comparator. 8967 * 8968 * @private 8969 * @param {Array} [array] The array to inspect. 8970 * @param {*} target The value to search for. 8971 * @param {Function} comparator The comparator invoked per element. 8972 * @returns {boolean} Returns `true` if `target` is found, else `false`. 8973 */ 8974 function arrayIncludesWith(array, value, comparator) { 8975 var index = -1, 8976 length = array == null ? 0 : array.length; 8977 8978 while (++index < length) { 8979 if (comparator(value, array[index])) { 8980 return true; 8981 } 8982 } 8983 return false; 8984 } 8985 8986 /** 8987 * A specialized version of `_.map` for arrays without support for iteratee 8988 * shorthands. 8989 * 8990 * @private 8991 * @param {Array} [array] The array to iterate over. 8992 * @param {Function} iteratee The function invoked per iteration. 8993 * @returns {Array} Returns the new mapped array. 8994 */ 8995 function arrayMap(array, iteratee) { 8996 var index = -1, 8997 length = array == null ? 0 : array.length, 8998 result = Array(length); 8999 9000 while (++index < length) { 9001 result[index] = iteratee(array[index], index, array); 9002 } 9003 return result; 9004 } 9005 9006 /** 9007 * Appends the elements of `values` to `array`. 9008 * 9009 * @private 9010 * @param {Array} array The array to modify. 9011 * @param {Array} values The values to append. 9012 * @returns {Array} Returns `array`. 9013 */ 9014 function arrayPush(array, values) { 9015 var index = -1, 9016 length = values.length, 9017 offset = array.length; 9018 9019 while (++index < length) { 9020 array[offset + index] = values[index]; 9021 } 9022 return array; 9023 } 9024 9025 /** 9026 * A specialized version of `_.reduce` for arrays without support for 9027 * iteratee shorthands. 9028 * 9029 * @private 9030 * @param {Array} [array] The array to iterate over. 9031 * @param {Function} iteratee The function invoked per iteration. 9032 * @param {*} [accumulator] The initial value. 9033 * @param {boolean} [initAccum] Specify using the first element of `array` as 9034 * the initial value. 9035 * @returns {*} Returns the accumulated value. 9036 */ 9037 function arrayReduce(array, iteratee, accumulator, initAccum) { 9038 var index = -1, 9039 length = array == null ? 0 : array.length; 9040 9041 if (initAccum && length) { 9042 accumulator = array[++index]; 9043 } 9044 while (++index < length) { 9045 accumulator = iteratee(accumulator, array[index], index, array); 9046 } 9047 return accumulator; 9048 } 9049 9050 /** 9051 * A specialized version of `_.reduceRight` for arrays without support for 9052 * iteratee shorthands. 9053 * 9054 * @private 9055 * @param {Array} [array] The array to iterate over. 9056 * @param {Function} iteratee The function invoked per iteration. 9057 * @param {*} [accumulator] The initial value. 9058 * @param {boolean} [initAccum] Specify using the last element of `array` as 9059 * the initial value. 9060 * @returns {*} Returns the accumulated value. 9061 */ 9062 function arrayReduceRight(array, iteratee, accumulator, initAccum) { 9063 var length = array == null ? 0 : array.length; 9064 if (initAccum && length) { 9065 accumulator = array[--length]; 9066 } 9067 while (length--) { 9068 accumulator = iteratee(accumulator, array[length], length, array); 9069 } 9070 return accumulator; 9071 } 9072 9073 /** 9074 * A specialized version of `_.some` for arrays without support for iteratee 9075 * shorthands. 9076 * 9077 * @private 9078 * @param {Array} [array] The array to iterate over. 9079 * @param {Function} predicate The function invoked per iteration. 9080 * @returns {boolean} Returns `true` if any element passes the predicate check, 9081 * else `false`. 9082 */ 9083 function arraySome(array, predicate) { 9084 var index = -1, 9085 length = array == null ? 0 : array.length; 9086 9087 while (++index < length) { 9088 if (predicate(array[index], index, array)) { 9089 return true; 9090 } 9091 } 9092 return false;
vendor: 7,631 bytes, lines 9093-9324
9093 } 9094 9095 /** 9096 * Gets the size of an ASCII `string`. 9097 * 9098 * @private 9099 * @param {string} string The string inspect. 9100 * @returns {number} Returns the string size. 9101 */ 9102 var asciiSize = baseProperty('length'); 9103 9104 /** 9105 * Converts an ASCII `string` to an array. 9106 * 9107 * @private 9108 * @param {string} string The string to convert. 9109 * @returns {Array} Returns the converted array. 9110 */ 9111 function asciiToArray(string) { 9112 return string.split(''); 9113 } 9114 9115 /** 9116 * Splits an ASCII `string` into an array of its words. 9117 * 9118 * @private 9119 * @param {string} The string to inspect. 9120 * @returns {Array} Returns the words of `string`. 9121 */ 9122 function asciiWords(string) { 9123 return string.match(reAsciiWord) || []; 9124 } 9125 9126 /** 9127 * The base implementation of methods like `_.findKey` and `_.findLastKey`, 9128 * without support for iteratee shorthands, which iterates over `collection` 9129 * using `eachFunc`. 9130 * 9131 * @private 9132 * @param {Array|Object} collection The collection to inspect. 9133 * @param {Function} predicate The function invoked per iteration. 9134 * @param {Function} eachFunc The function to iterate over `collection`. 9135 * @returns {*} Returns the found element or its key, else `undefined`. 9136 */ 9137 function baseFindKey(collection, predicate, eachFunc) { 9138 var result; 9139 eachFunc(collection, function(value, key, collection) { 9140 if (predicate(value, key, collection)) { 9141 result = key; 9142 return false; 9143 } 9144 }); 9145 return result; 9146 } 9147 9148 /** 9149 * The base implementation of `_.findIndex` and `_.findLastIndex` without 9150 * support for iteratee shorthands. 9151 * 9152 * @private 9153 * @param {Array} array The array to inspect. 9154 * @param {Function} predicate The function invoked per iteration. 9155 * @param {number} fromIndex The index to search from. 9156 * @param {boolean} [fromRight] Specify iterating from right to left. 9157 * @returns {number} Returns the index of the matched value, else `-1`. 9158 */ 9159 function baseFindIndex(array, predicate, fromIndex, fromRight) { 9160 var length = array.length, 9161 index = fromIndex + (fromRight ? 1 : -1); 9162 9163 while ((fromRight ? index-- : ++index < length)) { 9164 if (predicate(array[index], index, array)) { 9165 return index; 9166 } 9167 } 9168 return -1; 9169 } 9170 9171 /** 9172 * The base implementation of `_.indexOf` without `fromIndex` bounds checks. 9173 * 9174 * @private 9175 * @param {Array} array The array to inspect. 9176 * @param {*} value The value to search for. 9177 * @param {number} fromIndex The index to search from. 9178 * @returns {number} Returns the index of the matched value, else `-1`. 9179 */ 9180 function baseIndexOf(array, value, fromIndex) { 9181 return value === value 9182 ? strictIndexOf(array, value, fromIndex) 9183 : baseFindIndex(array, baseIsNaN, fromIndex); 9184 } 9185 9186 /** 9187 * This function is like `baseIndexOf` except that it accepts a comparator. 9188 * 9189 * @private 9190 * @param {Array} array The array to inspect. 9191 * @param {*} value The value to search for. 9192 * @param {number} fromIndex The index to search from. 9193 * @param {Function} comparator The comparator invoked per element. 9194 * @returns {number} Returns the index of the matched value, else `-1`. 9195 */ 9196 function baseIndexOfWith(array, value, fromIndex, comparator) { 9197 var index = fromIndex - 1, 9198 length = array.length; 9199 9200 while (++index < length) { 9201 if (comparator(array[index], value)) { 9202 return index; 9203 } 9204 } 9205 return -1; 9206 } 9207 9208 /** 9209 * The base implementation of `_.isNaN` without support for number objects. 9210 * 9211 * @private 9212 * @param {*} value The value to check. 9213 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. 9214 */ 9215 function baseIsNaN(value) { 9216 return value !== value; 9217 } 9218 9219 /** 9220 * The base implementation of `_.mean` and `_.meanBy` without support for 9221 * iteratee shorthands. 9222 * 9223 * @private 9224 * @param {Array} array The array to iterate over. 9225 * @param {Function} iteratee The function invoked per iteration. 9226 * @returns {number} Returns the mean. 9227 */ 9228 function baseMean(array, iteratee) { 9229 var length = array == null ? 0 : array.length; 9230 return length ? (baseSum(array, iteratee) / length) : NAN; 9231 } 9232 9233 /** 9234 * The base implementation of `_.property` without support for deep paths. 9235 * 9236 * @private 9237 * @param {string} key The key of the property to get. 9238 * @returns {Function} Returns the new accessor function. 9239 */ 9240 function baseProperty(key) { 9241 return function(object) { 9242 return object == null ? undefined$1 : object[key]; 9243 }; 9244 } 9245 9246 /** 9247 * The base implementation of `_.propertyOf` without support for deep paths. 9248 * 9249 * @private 9250 * @param {Object} object The object to query. 9251 * @returns {Function} Returns the new accessor function. 9252 */ 9253 function basePropertyOf(object) { 9254 return function(key) { 9255 return object == null ? undefined$1 : object[key]; 9256 }; 9257 } 9258 9259 /** 9260 * The base implementation of `_.reduce` and `_.reduceRight`, without support 9261 * for iteratee shorthands, which iterates over `collection` using `eachFunc`. 9262 * 9263 * @private 9264 * @param {Array|Object} collection The collection to iterate over. 9265 * @param {Function} iteratee The function invoked per iteration. 9266 * @param {*} accumulator The initial value. 9267 * @param {boolean} initAccum Specify using the first or last element of 9268 * `collection` as the initial value. 9269 * @param {Function} eachFunc The function to iterate over `collection`. 9270 * @returns {*} Returns the accumulated value. 9271 */ 9272 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { 9273 eachFunc(collection, function(value, index, collection) { 9274 accumulator = initAccum 9275 ? (initAccum = false, value) 9276 : iteratee(accumulator, value, index, collection); 9277 }); 9278 return accumulator; 9279 } 9280 9281 /** 9282 * The base implementation of `_.sortBy` which uses `comparer` to define the 9283 * sort order of `array` and replaces criteria objects with their corresponding 9284 * values. 9285 * 9286 * @private 9287 * @param {Array} array The array to sort. 9288 * @param {Function} comparer The function to define sort order. 9289 * @returns {Array} Returns `array`. 9290 */ 9291 function baseSortBy(array, comparer) { 9292 var length = array.length; 9293 9294 array.sort(comparer); 9295 while (length--) { 9296 array[length] = array[length].value; 9297 } 9298 return array; 9299 } 9300 9301 /** 9302 * The base implementation of `_.sum` and `_.sumBy` without support for 9303 * iteratee shorthands. 9304 * 9305 * @private 9306 * @param {Array} array The array to iterate over. 9307 * @param {Function} iteratee The function invoked per iteration. 9308 * @returns {number} Returns the sum. 9309 */ 9310 function baseSum(array, iteratee) { 9311 var result, 9312 index = -1, 9313 length = array.length; 9314 9315 while (++index < length) { 9316 var current = iteratee(array[index]); 9317 if (current !== undefined$1) { 9318 result = result === undefined$1 ? current : (result + current); 9319 } 9320 } 9321 return result; 9322 } 9323 9324 /**
9325 * The base implementation of `_.times` without support for iteratee shorthands 9326 * or max array length checks. 9327 * 9328 * @private 9329 * @param {number} n The number of times to invoke `iteratee`. 9330 * @param {Function} iteratee The function invoked per iteration. 9331 * @returns {Array} Returns the array of results. 9332 */ 9333 function baseTimes(n, iteratee) { 9334 var index = -1, 9335 result = Array(n); 9336 9337 while (++index < n) { 9338 result[index] = iteratee(index); 9339 } 9340 return result; 9341 } 9342 9343 /** 9344 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array 9345 * of key-value pairs for `object` corresponding to the property names of `props`. 9346 * 9347 * @private 9348 * @param {Object} object The object to query. 9349 * @param {Array} props The property names to get values for. 9350 * @returns {Object} Returns the key-value pairs. 9351 */ 9352 function baseToPairs(object, props) { 9353 return arrayMap(props, function(key) { 9354 return [key, object[key]]; 9355 }); 9356 } 9357 9358 /** 9359 * The base implementation of `_.trim`. 9360 * 9361 * @private 9362 * @param {string} string The string to trim. 9363 * @returns {string} Returns the trimmed string. 9364 */ 9365 function baseTrim(string) { 9366 return string 9367 ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') 9368 : string; 9369 } 9370 9371 /** 9372 * The base implementation of `_.unary` without support for storing metadata. 9373 * 9374 * @private 9375 * @param {Function} func The function to cap arguments for. 9376 * @returns {Function} Returns the new capped function. 9377 */ 9378 function baseUnary(func) { 9379 return function(value) { 9380 return func(value); 9381 }; 9382 } 9383 9384 /** 9385 * The base implementation of `_.values` and `_.valuesIn` which creates an 9386 * array of `object` property values corresponding to the property names 9387 * of `props`. 9388 * 9389 * @private 9390 * @param {Object} object The object to query. 9391 * @param {Array} props The property names to get values for. 9392 * @returns {Object} Returns the array of property values. 9393 */ 9394 function baseValues(object, props) { 9395 return arrayMap(props, function(key) { 9396 return object[key]; 9397 }); 9398 } 9399 9400 /** 9401 * Checks if a `cache` value for `key` exists. 9402 * 9403 * @private 9404 * @param {Object} cache The cache to query. 9405 * @param {string} key The key of the entry to check. 9406 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 9407 */ 9408 function cacheHas(cache, key) { 9409 return cache.has(key); 9410 } 9411 9412 /** 9413 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol 9414 * that is not found in the character symbols. 9415 * 9416 * @private 9417 * @param {Array} strSymbols The string symbols to inspect. 9418 * @param {Array} chrSymbols The character symbols to find. 9419 * @returns {number} Returns the index of the first unmatched string symbol. 9420 */ 9421 function charsStartIndex(strSymbols, chrSymbols) { 9422 var index = -1, 9423 length = strSymbols.length; 9424 9425 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} 9426 return index; 9427 } 9428 9429 /** 9430 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol 9431 * that is not found in the character symbols. 9432 * 9433 * @private 9434 * @param {Array} strSymbols The string symbols to inspect. 9435 * @param {Array} chrSymbols The character symbols to find. 9436 * @returns {number} Returns the index of the last unmatched string symbol. 9437 */ 9438 function charsEndIndex(strSymbols, chrSymbols) { 9439 var index = strSymbols.length; 9440 9441 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} 9442 return index; 9443 } 9444 9445 /** 9446 * Gets the number of `placeholder` occurrences in `array`. 9447 * 9448 * @private 9449 * @param {Array} array The array to inspect. 9450 * @param {*} placeholder The placeholder to search for. 9451 * @returns {number} Returns the placeholder count. 9452 */ 9453 function countHolders(array, placeholder) { 9454 var length = array.length, 9455 result = 0; 9456 9457 while (length--) { 9458 if (array[length] === placeholder) { 9459 ++result; 9460 } 9461 } 9462 return result; 9463 } 9464 9465 /** 9466 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A 9467 * letters to basic Latin letters. 9468 * 9469 * @private 9470 * @param {string} letter The matched letter to deburr. 9471 * @returns {string} Returns the deburred letter. 9472 */ 9473 var deburrLetter = basePropertyOf(deburredLetters); 9474 9475 /** 9476 * Used by `_.escape` to convert characters to HTML entities. 9477 * 9478 * @private 9479 * @param {string} chr The matched character to escape. 9480 * @returns {string} Returns the escaped character. 9481 */ 9482 var escapeHtmlChar = basePropertyOf(htmlEscapes); 9483 9484 /** 9485 * Used by `_.template` to escape characters for inclusion in compiled string literals. 9486 * 9487 * @private 9488 * @param {string} chr The matched character to escape. 9489 * @returns {string} Returns the escaped character. 9490 */ 9491 function escapeStringChar(chr) { 9492 return '\\' + stringEscapes[chr]; 9493 } 9494 9495 /** 9496 * Gets the value at `key` of `object`. 9497 * 9498 * @private 9499 * @param {Object} [object] The object to query. 9500 * @param {string} key The key of the property to get. 9501 * @returns {*} Returns the property value. 9502 */ 9503 function getValue(object, key) { 9504 return object == null ? undefined$1 : object[key]; 9505 } 9506 9507 /** 9508 * Checks if `string` contains Unicode symbols. 9509 * 9510 * @private 9511 * @param {string} string The string to inspect. 9512 * @returns {boolean} Returns `true` if a symbol is found, else `false`. 9513 */ 9514 function hasUnicode(string) { 9515 return reHasUnicode.test(string); 9516 } 9517 9518 /** 9519 * Checks if `string` contains a word composed of Unicode symbols. 9520 * 9521 * @private 9522 * @param {string} string The string to inspect. 9523 * @returns {boolean} Returns `true` if a word is found, else `false`. 9524 */ 9525 function hasUnicodeWord(string) { 9526 return reHasUnicodeWord.test(string); 9527 } 9528 9529 /** 9530 * Converts `iterator` to an array.
vendor: 8,696 bytes, lines 9531-9829
9531 * 9532 * @private 9533 * @param {Object} iterator The iterator to convert. 9534 * @returns {Array} Returns the converted array. 9535 */ 9536 function iteratorToArray(iterator) { 9537 var data, 9538 result = []; 9539 9540 while (!(data = iterator.next()).done) { 9541 result.push(data.value); 9542 } 9543 return result; 9544 } 9545 9546 /** 9547 * Converts `map` to its key-value pairs. 9548 * 9549 * @private 9550 * @param {Object} map The map to convert. 9551 * @returns {Array} Returns the key-value pairs. 9552 */ 9553 function mapToArray(map) { 9554 var index = -1, 9555 result = Array(map.size); 9556 9557 map.forEach(function(value, key) { 9558 result[++index] = [key, value]; 9559 }); 9560 return result; 9561 } 9562 9563 /** 9564 * Creates a unary function that invokes `func` with its argument transformed. 9565 * 9566 * @private 9567 * @param {Function} func The function to wrap. 9568 * @param {Function} transform The argument transform. 9569 * @returns {Function} Returns the new function. 9570 */ 9571 function overArg(func, transform) { 9572 return function(arg) { 9573 return func(transform(arg)); 9574 }; 9575 } 9576 9577 /** 9578 * Replaces all `placeholder` elements in `array` with an internal placeholder 9579 * and returns an array of their indexes. 9580 * 9581 * @private 9582 * @param {Array} array The array to modify. 9583 * @param {*} placeholder The placeholder to replace. 9584 * @returns {Array} Returns the new array of placeholder indexes. 9585 */ 9586 function replaceHolders(array, placeholder) { 9587 var index = -1, 9588 length = array.length, 9589 resIndex = 0, 9590 result = []; 9591 9592 while (++index < length) { 9593 var value = array[index]; 9594 if (value === placeholder || value === PLACEHOLDER) { 9595 array[index] = PLACEHOLDER; 9596 result[resIndex++] = index; 9597 } 9598 } 9599 return result; 9600 } 9601 9602 /** 9603 * Converts `set` to an array of its values. 9604 * 9605 * @private 9606 * @param {Object} set The set to convert. 9607 * @returns {Array} Returns the values. 9608 */ 9609 function setToArray(set) { 9610 var index = -1, 9611 result = Array(set.size); 9612 9613 set.forEach(function(value) { 9614 result[++index] = value; 9615 }); 9616 return result; 9617 } 9618 9619 /** 9620 * Converts `set` to its value-value pairs. 9621 * 9622 * @private 9623 * @param {Object} set The set to convert. 9624 * @returns {Array} Returns the value-value pairs. 9625 */ 9626 function setToPairs(set) { 9627 var index = -1, 9628 result = Array(set.size); 9629 9630 set.forEach(function(value) { 9631 result[++index] = [value, value]; 9632 }); 9633 return result; 9634 } 9635 9636 /** 9637 * A specialized version of `_.indexOf` which performs strict equality 9638 * comparisons of values, i.e. `===`. 9639 * 9640 * @private 9641 * @param {Array} array The array to inspect. 9642 * @param {*} value The value to search for. 9643 * @param {number} fromIndex The index to search from. 9644 * @returns {number} Returns the index of the matched value, else `-1`. 9645 */ 9646 function strictIndexOf(array, value, fromIndex) { 9647 var index = fromIndex - 1, 9648 length = array.length; 9649 9650 while (++index < length) { 9651 if (array[index] === value) { 9652 return index; 9653 } 9654 } 9655 return -1; 9656 } 9657 9658 /** 9659 * A specialized version of `_.lastIndexOf` which performs strict equality 9660 * comparisons of values, i.e. `===`. 9661 * 9662 * @private 9663 * @param {Array} array The array to inspect. 9664 * @param {*} value The value to search for. 9665 * @param {number} fromIndex The index to search from. 9666 * @returns {number} Returns the index of the matched value, else `-1`. 9667 */ 9668 function strictLastIndexOf(array, value, fromIndex) { 9669 var index = fromIndex + 1; 9670 while (index--) { 9671 if (array[index] === value) { 9672 return index; 9673 } 9674 } 9675 return index; 9676 } 9677 9678 /** 9679 * Gets the number of symbols in `string`. 9680 * 9681 * @private 9682 * @param {string} string The string to inspect. 9683 * @returns {number} Returns the string size. 9684 */ 9685 function stringSize(string) { 9686 return hasUnicode(string) 9687 ? unicodeSize(string) 9688 : asciiSize(string); 9689 } 9690 9691 /** 9692 * Converts `string` to an array. 9693 * 9694 * @private 9695 * @param {string} string The string to convert. 9696 * @returns {Array} Returns the converted array. 9697 */ 9698 function stringToArray(string) { 9699 return hasUnicode(string) 9700 ? unicodeToArray(string) 9701 : asciiToArray(string); 9702 } 9703 9704 /** 9705 * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace 9706 * character of `string`. 9707 * 9708 * @private 9709 * @param {string} string The string to inspect. 9710 * @returns {number} Returns the index of the last non-whitespace character. 9711 */ 9712 function trimmedEndIndex(string) { 9713 var index = string.length; 9714 9715 while (index-- && reWhitespace.test(string.charAt(index))) {} 9716 return index; 9717 } 9718 9719 /** 9720 * Used by `_.unescape` to convert HTML entities to characters. 9721 * 9722 * @private 9723 * @param {string} chr The matched character to unescape. 9724 * @returns {string} Returns the unescaped character. 9725 */ 9726 var unescapeHtmlChar = basePropertyOf(htmlUnescapes); 9727 9728 /** 9729 * Gets the size of a Unicode `string`. 9730 * 9731 * @private 9732 * @param {string} string The string inspect. 9733 * @returns {number} Returns the string size. 9734 */ 9735 function unicodeSize(string) { 9736 var result = reUnicode.lastIndex = 0; 9737 while (reUnicode.test(string)) { 9738 ++result; 9739 } 9740 return result; 9741 } 9742 9743 /** 9744 * Converts a Unicode `string` to an array. 9745 * 9746 * @private 9747 * @param {string} string The string to convert. 9748 * @returns {Array} Returns the converted array. 9749 */ 9750 function unicodeToArray(string) { 9751 return string.match(reUnicode) || []; 9752 } 9753 9754 /** 9755 * Splits a Unicode `string` into an array of its words. 9756 * 9757 * @private 9758 * @param {string} The string to inspect. 9759 * @returns {Array} Returns the words of `string`. 9760 */ 9761 function unicodeWords(string) { 9762 return string.match(reUnicodeWord) || []; 9763 } 9764 9765 /*--------------------------------------------------------------------------*/ 9766 9767 /** 9768 * Create a new pristine `lodash` function using the `context` object. 9769 * 9770 * @static 9771 * @memberOf _ 9772 * @since 1.1.0 9773 * @category Util 9774 * @param {Object} [context=root] The context object. 9775 * @returns {Function} Returns a new `lodash` function. 9776 * @example 9777 * 9778 * _.mixin({ 'foo': _.constant('foo') }); 9779 * 9780 * var lodash = _.runInContext(); 9781 * lodash.mixin({ 'bar': lodash.constant('bar') }); 9782 * 9783 * _.isFunction(_.foo); 9784 * // => true 9785 * _.isFunction(_.bar); 9786 * // => false 9787 * 9788 * lodash.isFunction(lodash.foo); 9789 * // => false 9790 * lodash.isFunction(lodash.bar); 9791 * // => true 9792 * 9793 * // Create a suped-up `defer` in Node.js. 9794 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; 9795 */ 9796 var runInContext = (function runInContext(context) { 9797 context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps)); 9798 9799 /** Built-in constructor references. */ 9800 var Array = context.Array, 9801 Date = context.Date, 9802 Error = context.Error, 9803 Function = context.Function, 9804 Math = context.Math, 9805 Object = context.Object, 9806 RegExp = context.RegExp, 9807 String = context.String, 9808 TypeError = context.TypeError; 9809 9810 /** Used for built-in method references. */ 9811 var arrayProto = Array.prototype, 9812 funcProto = Function.prototype, 9813 objectProto = Object.prototype; 9814 9815 /** Used to detect overreaching core-js shims. */ 9816 var coreJsData = context['__core-js_shared__']; 9817 9818 /** Used to resolve the decompiled source of functions. */ 9819 var funcToString = funcProto.toString; 9820 9821 /** Used to check objects for own properties. */ 9822 var hasOwnProperty = objectProto.hasOwnProperty; 9823 9824 /** Used to generate unique IDs. */ 9825 var idCounter = 0; 9826 9827 /** Used to detect methods masquerading as native. */ 9828 var maskSrcKey = (function() { 9829 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
vendor: 2,256 bytes, lines 9830-9882
9830 return uid ? ('Symbol(src)_1.' + uid) : ''; 9831 }()); 9832 9833 /** 9834 * Used to resolve the 9835 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) 9836 * of values. 9837 */ 9838 var nativeObjectToString = objectProto.toString; 9839 9840 /** Used to infer the `Object` constructor. */ 9841 var objectCtorString = funcToString.call(Object); 9842 9843 /** Used to restore the original `_` reference in `_.noConflict`. */ 9844 var oldDash = root._; 9845 9846 /** Used to detect if a method is native. */ 9847 var reIsNative = RegExp('^' + 9848 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') 9849 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' 9850 ); 9851 9852 /** Built-in value references. */ 9853 var Buffer = moduleExports ? context.Buffer : undefined$1, 9854 Symbol = context.Symbol, 9855 Uint8Array = context.Uint8Array, 9856 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined$1, 9857 getPrototype = overArg(Object.getPrototypeOf, Object), 9858 objectCreate = Object.create, 9859 propertyIsEnumerable = objectProto.propertyIsEnumerable, 9860 splice = arrayProto.splice, 9861 spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined$1, 9862 symIterator = Symbol ? Symbol.iterator : undefined$1, 9863 symToStringTag = Symbol ? Symbol.toStringTag : undefined$1; 9864 9865 var defineProperty = (function() { 9866 try { 9867 var func = getNative(Object, 'defineProperty'); 9868 func({}, '', {}); 9869 return func; 9870 } catch (e) {} 9871 }()); 9872 9873 /** Mocked built-ins. */ 9874 var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, 9875 ctxNow = Date && Date.now !== root.Date.now && Date.now, 9876 ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout; 9877 9878 /* Built-in method references for those with the same name as other `lodash` methods. */ 9879 var nativeCeil = Math.ceil, 9880 nativeFloor = Math.floor, 9881 nativeGetSymbols = Object.getOwnPropertySymbols, 9882 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined$1,
9883 nativeIsFinite = context.isFinite, 9884 nativeJoin = arrayProto.join, 9885 nativeKeys = overArg(Object.keys, Object), 9886 nativeMax = Math.max, 9887 nativeMin = Math.min, 9888 nativeNow = Date.now, 9889 nativeParseInt = context.parseInt, 9890 nativeRandom = Math.random, 9891 nativeReverse = arrayProto.reverse; 9892 9893 /* Built-in method references that are verified to be native. */ 9894 var DataView = getNative(context, 'DataView'), 9895 Map = getNative(context, 'Map'), 9896 Promise = getNative(context, 'Promise'), 9897 Set = getNative(context, 'Set'), 9898 WeakMap = getNative(context, 'WeakMap'), 9899 nativeCreate = getNative(Object, 'create'); 9900 9901 /** Used to store function metadata. */ 9902 var metaMap = WeakMap && new WeakMap; 9903 9904 /** Used to lookup unminified function names. */ 9905 var realNames = {}; 9906 9907 /** Used to detect maps, sets, and weakmaps. */ 9908 var dataViewCtorString = toSource(DataView), 9909 mapCtorString = toSource(Map), 9910 promiseCtorString = toSource(Promise), 9911 setCtorString = toSource(Set), 9912 weakMapCtorString = toSource(WeakMap); 9913 9914 /** Used to convert symbols to primitives and strings. */ 9915 var symbolProto = Symbol ? Symbol.prototype : undefined$1, 9916 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined$1, 9917 symbolToString = symbolProto ? symbolProto.toString : undefined$1; 9918 9919 /*------------------------------------------------------------------------*/ 9920 9921 /** 9922 * Creates a `lodash` object which wraps `value` to enable implicit method 9923 * chain sequences. Methods that operate on and return arrays, collections, 9924 * and functions can be chained together. Methods that retrieve a single value 9925 * or may return a primitive value will automatically end the chain sequence 9926 * and return the unwrapped value. Otherwise, the value must be unwrapped 9927 * with `_#value`. 9928 * 9929 * Explicit chain sequences, which must be unwrapped with `_#value`, may be 9930 * enabled using `_.chain`. 9931 * 9932 * The execution of chained methods is lazy, that is, it's deferred until 9933 * `_#value` is implicitly or explicitly called. 9934 * 9935 * Lazy evaluation allows several methods to support shortcut fusion. 9936 * Shortcut fusion is an optimization to merge iteratee calls; this avoids 9937 * the creation of intermediate arrays and can greatly reduce the number of 9938 * iteratee executions. Sections of a chain sequence qualify for shortcut 9939 * fusion if the section is applied to an array and iteratees accept only 9940 * one argument. The heuristic for whether a section qualifies for shortcut 9941 * fusion is subject to change. 9942 * 9943 * Chaining is supported in custom builds as long as the `_#value` method is 9944 * directly or indirectly included in the build. 9945 * 9946 * In addition to lodash methods, wrappers have `Array` and `String` methods. 9947 * 9948 * The wrapper `Array` methods are: 9949 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` 9950 * 9951 * The wrapper `String` methods are: 9952 * `replace` and `split` 9953 * 9954 * The wrapper methods that support shortcut fusion are: 9955 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, 9956 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, 9957 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` 9958 * 9959 * The chainable wrapper methods are: 9960 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, 9961 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, 9962 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, 9963 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, 9964 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, 9965 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, 9966 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, 9967 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, 9968 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, 9969 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, 9970 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, 9971 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, 9972 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, 9973 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, 9974 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, 9975 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, 9976 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, 9977 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, 9978 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, 9979 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, 9980 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, 9981 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, 9982 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, 9983 * `zipObject`, `zipObjectDeep`, and `zipWith` 9984 * 9985 * The wrapper methods that are **not** chainable by default are:
9986 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, 9987 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, 9988 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, 9989 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, 9990 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`, 9991 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, 9992 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, 9993 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, 9994 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, 9995 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, 9996 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, 9997 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, 9998 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, 9999 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, 10000 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, 10001 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`, 10002 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, 10003 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, 10004 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, 10005 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`, 10006 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`, 10007 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`, 10008 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, 10009 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, 10010 * `upperFirst`, `value`, and `words` 10011 * 10012 * @name _ 10013 * @constructor 10014 * @category Seq 10015 * @param {*} value The value to wrap in a `lodash` instance. 10016 * @returns {Object} Returns the new `lodash` wrapper instance. 10017 * @example 10018 * 10019 * function square(n) { 10020 * return n * n; 10021 * } 10022 * 10023 * var wrapped = _([1, 2, 3]); 10024 * 10025 * // Returns an unwrapped value. 10026 * wrapped.reduce(_.add); 10027 * // => 6 10028 * 10029 * // Returns a wrapped value. 10030 * var squares = wrapped.map(square); 10031 * 10032 * _.isArray(squares); 10033 * // => false 10034 * 10035 * _.isArray(squares.value()); 10036 * // => true 10037 */ 10038 function lodash(value) { 10039 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { 10040 if (value instanceof LodashWrapper) { 10041 return value; 10042 } 10043 if (hasOwnProperty.call(value, '__wrapped__')) { 10044 return wrapperClone(value); 10045 } 10046 } 10047 return new LodashWrapper(value); 10048 } 10049 10050 /** 10051 * The base implementation of `_.create` without support for assigning 10052 * properties to the created object. 10053 * 10054 * @private 10055 * @param {Object} proto The object to inherit from. 10056 * @returns {Object} Returns the new object. 10057 */ 10058 var baseCreate = (function() { 10059 function object() {} 10060 return function(proto) { 10061 if (!isObject(proto)) { 10062 return {}; 10063 } 10064 if (objectCreate) { 10065 return objectCreate(proto); 10066 } 10067 object.prototype = proto; 10068 var result = new object; 10069 object.prototype = undefined$1; 10070 return result; 10071 }; 10072 }()); 10073 10074 /** 10075 * The function whose prototype chain sequence wrappers inherit from. 10076 * 10077 * @private 10078 */ 10079 function baseLodash() { 10080 // No operation performed. 10081 } 10082 10083 /** 10084 * The base constructor for creating `lodash` wrapper objects. 10085 * 10086 * @private 10087 * @param {*} value The value to wrap. 10088 * @param {boolean} [chainAll] Enable explicit method chain sequences. 10089 */ 10090 function LodashWrapper(value, chainAll) { 10091 this.__wrapped__ = value; 10092 this.__actions__ = []; 10093 this.__chain__ = !!chainAll; 10094 this.__index__ = 0; 10095 this.__values__ = undefined$1; 10096 } 10097 10098 /** 10099 * By default, the template delimiters used by lodash are like those in 10100 * embedded Ruby (ERB) as well as ES2015 template strings. Change the 10101 * following template settings to use alternative delimiters. 10102 * 10103 * @static 10104 * @memberOf _ 10105 * @type {Object} 10106 */ 10107 lodash.templateSettings = { 10108 10109 /** 10110 * Used to detect `data` property values to be HTML-escaped. 10111 * 10112 * @memberOf _.templateSettings 10113 * @type {RegExp} 10114 */ 10115 'escape': reEscape, 10116 10117 /** 10118 * Used to detect code to be evaluated. 10119 * 10120 * @memberOf _.templateSettings 10121 * @type {RegExp} 10122 */ 10123 'evaluate': reEvaluate, 10124 10125 /** 10126 * Used to detect `data` property values to inject. 10127 * 10128 * @memberOf _.templateSettings 10129 * @type {RegExp} 10130 */ 10131 'interpolate': reInterpolate, 10132 10133 /** 10134 * Used to reference the data object in the template text. 10135 * 10136 * @memberOf _.templateSettings 10137 * @type {string} 10138 */ 10139 'variable': '', 10140 10141 /** 10142 * Used to import variables into the compiled template. 10143 * 10144 * @memberOf _.templateSettings 10145 * @type {Object} 10146 */ 10147 'imports': { 10148 10149 /** 10150 * A reference to the `lodash` function. 10151 * 10152 * @memberOf _.templateSettings.imports 10153 * @type {Function} 10154 */ 10155 '_': lodash 10156 } 10157 }; 10158 10159 // Ensure wrappers are instances of `baseLodash`.
vendor: 14,117 bytes, lines 10160-10638
10160 lodash.prototype = baseLodash.prototype; 10161 lodash.prototype.constructor = lodash; 10162 10163 LodashWrapper.prototype = baseCreate(baseLodash.prototype); 10164 LodashWrapper.prototype.constructor = LodashWrapper; 10165 10166 /*------------------------------------------------------------------------*/ 10167 10168 /** 10169 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. 10170 * 10171 * @private 10172 * @constructor 10173 * @param {*} value The value to wrap. 10174 */ 10175 function LazyWrapper(value) { 10176 this.__wrapped__ = value; 10177 this.__actions__ = []; 10178 this.__dir__ = 1; 10179 this.__filtered__ = false; 10180 this.__iteratees__ = []; 10181 this.__takeCount__ = MAX_ARRAY_LENGTH; 10182 this.__views__ = []; 10183 } 10184 10185 /** 10186 * Creates a clone of the lazy wrapper object. 10187 * 10188 * @private 10189 * @name clone 10190 * @memberOf LazyWrapper 10191 * @returns {Object} Returns the cloned `LazyWrapper` object. 10192 */ 10193 function lazyClone() { 10194 var result = new LazyWrapper(this.__wrapped__); 10195 result.__actions__ = copyArray(this.__actions__); 10196 result.__dir__ = this.__dir__; 10197 result.__filtered__ = this.__filtered__; 10198 result.__iteratees__ = copyArray(this.__iteratees__); 10199 result.__takeCount__ = this.__takeCount__; 10200 result.__views__ = copyArray(this.__views__); 10201 return result; 10202 } 10203 10204 /** 10205 * Reverses the direction of lazy iteration. 10206 * 10207 * @private 10208 * @name reverse 10209 * @memberOf LazyWrapper 10210 * @returns {Object} Returns the new reversed `LazyWrapper` object. 10211 */ 10212 function lazyReverse() { 10213 if (this.__filtered__) { 10214 var result = new LazyWrapper(this); 10215 result.__dir__ = -1; 10216 result.__filtered__ = true; 10217 } else { 10218 result = this.clone(); 10219 result.__dir__ *= -1; 10220 } 10221 return result; 10222 } 10223 10224 /** 10225 * Extracts the unwrapped value from its lazy wrapper. 10226 * 10227 * @private 10228 * @name value 10229 * @memberOf LazyWrapper 10230 * @returns {*} Returns the unwrapped value. 10231 */ 10232 function lazyValue() { 10233 var array = this.__wrapped__.value(), 10234 dir = this.__dir__, 10235 isArr = isArray(array), 10236 isRight = dir < 0, 10237 arrLength = isArr ? array.length : 0, 10238 view = getView(0, arrLength, this.__views__), 10239 start = view.start, 10240 end = view.end, 10241 length = end - start, 10242 index = isRight ? end : (start - 1), 10243 iteratees = this.__iteratees__, 10244 iterLength = iteratees.length, 10245 resIndex = 0, 10246 takeCount = nativeMin(length, this.__takeCount__); 10247 10248 if (!isArr || (!isRight && arrLength == length && takeCount == length)) { 10249 return baseWrapperValue(array, this.__actions__); 10250 } 10251 var result = []; 10252 10253 outer: 10254 while (length-- && resIndex < takeCount) { 10255 index += dir; 10256 10257 var iterIndex = -1, 10258 value = array[index]; 10259 10260 while (++iterIndex < iterLength) { 10261 var data = iteratees[iterIndex], 10262 iteratee = data.iteratee, 10263 type = data.type, 10264 computed = iteratee(value); 10265 10266 if (type == LAZY_MAP_FLAG) { 10267 value = computed; 10268 } else if (!computed) { 10269 if (type == LAZY_FILTER_FLAG) { 10270 continue outer; 10271 } else { 10272 break outer; 10273 } 10274 } 10275 } 10276 result[resIndex++] = value; 10277 } 10278 return result; 10279 } 10280 10281 // Ensure `LazyWrapper` is an instance of `baseLodash`. 10282 LazyWrapper.prototype = baseCreate(baseLodash.prototype); 10283 LazyWrapper.prototype.constructor = LazyWrapper; 10284 10285 /*------------------------------------------------------------------------*/ 10286 10287 /** 10288 * Creates a hash object. 10289 * 10290 * @private 10291 * @constructor 10292 * @param {Array} [entries] The key-value pairs to cache. 10293 */ 10294 function Hash(entries) { 10295 var index = -1, 10296 length = entries == null ? 0 : entries.length; 10297 10298 this.clear(); 10299 while (++index < length) { 10300 var entry = entries[index]; 10301 this.set(entry[0], entry[1]); 10302 } 10303 } 10304 10305 /** 10306 * Removes all key-value entries from the hash. 10307 * 10308 * @private 10309 * @name clear 10310 * @memberOf Hash 10311 */ 10312 function hashClear() { 10313 this.__data__ = nativeCreate ? nativeCreate(null) : {}; 10314 this.size = 0; 10315 } 10316 10317 /** 10318 * Removes `key` and its value from the hash. 10319 * 10320 * @private 10321 * @name delete 10322 * @memberOf Hash 10323 * @param {Object} hash The hash to modify. 10324 * @param {string} key The key of the value to remove. 10325 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 10326 */ 10327 function hashDelete(key) { 10328 var result = this.has(key) && delete this.__data__[key]; 10329 this.size -= result ? 1 : 0; 10330 return result; 10331 } 10332 10333 /** 10334 * Gets the hash value for `key`. 10335 * 10336 * @private 10337 * @name get 10338 * @memberOf Hash 10339 * @param {string} key The key of the value to get. 10340 * @returns {*} Returns the entry value. 10341 */ 10342 function hashGet(key) { 10343 var data = this.__data__; 10344 if (nativeCreate) { 10345 var result = data[key]; 10346 return result === HASH_UNDEFINED ? undefined$1 : result; 10347 } 10348 return hasOwnProperty.call(data, key) ? data[key] : undefined$1; 10349 } 10350 10351 /** 10352 * Checks if a hash value for `key` exists. 10353 * 10354 * @private 10355 * @name has 10356 * @memberOf Hash 10357 * @param {string} key The key of the entry to check. 10358 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 10359 */ 10360 function hashHas(key) { 10361 var data = this.__data__; 10362 return nativeCreate ? (data[key] !== undefined$1) : hasOwnProperty.call(data, key); 10363 } 10364 10365 /** 10366 * Sets the hash `key` to `value`. 10367 * 10368 * @private 10369 * @name set 10370 * @memberOf Hash 10371 * @param {string} key The key of the value to set. 10372 * @param {*} value The value to set. 10373 * @returns {Object} Returns the hash instance. 10374 */ 10375 function hashSet(key, value) { 10376 var data = this.__data__; 10377 this.size += this.has(key) ? 0 : 1; 10378 data[key] = (nativeCreate && value === undefined$1) ? HASH_UNDEFINED : value; 10379 return this; 10380 } 10381 10382 // Add methods to `Hash`. 10383 Hash.prototype.clear = hashClear; 10384 Hash.prototype['delete'] = hashDelete; 10385 Hash.prototype.get = hashGet; 10386 Hash.prototype.has = hashHas; 10387 Hash.prototype.set = hashSet; 10388 10389 /*------------------------------------------------------------------------*/ 10390 10391 /** 10392 * Creates an list cache object. 10393 * 10394 * @private 10395 * @constructor 10396 * @param {Array} [entries] The key-value pairs to cache. 10397 */ 10398 function ListCache(entries) { 10399 var index = -1, 10400 length = entries == null ? 0 : entries.length; 10401 10402 this.clear(); 10403 while (++index < length) { 10404 var entry = entries[index]; 10405 this.set(entry[0], entry[1]); 10406 } 10407 } 10408 10409 /** 10410 * Removes all key-value entries from the list cache. 10411 * 10412 * @private 10413 * @name clear 10414 * @memberOf ListCache 10415 */ 10416 function listCacheClear() { 10417 this.__data__ = []; 10418 this.size = 0; 10419 } 10420 10421 /** 10422 * Removes `key` and its value from the list cache. 10423 * 10424 * @private 10425 * @name delete 10426 * @memberOf ListCache 10427 * @param {string} key The key of the value to remove. 10428 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 10429 */ 10430 function listCacheDelete(key) { 10431 var data = this.__data__, 10432 index = assocIndexOf(data, key); 10433 10434 if (index < 0) { 10435 return false; 10436 } 10437 var lastIndex = data.length - 1; 10438 if (index == lastIndex) { 10439 data.pop(); 10440 } else { 10441 splice.call(data, index, 1); 10442 } 10443 --this.size; 10444 return true; 10445 } 10446 10447 /** 10448 * Gets the list cache value for `key`. 10449 * 10450 * @private 10451 * @name get 10452 * @memberOf ListCache 10453 * @param {string} key The key of the value to get. 10454 * @returns {*} Returns the entry value. 10455 */ 10456 function listCacheGet(key) { 10457 var data = this.__data__, 10458 index = assocIndexOf(data, key); 10459 10460 return index < 0 ? undefined$1 : data[index][1]; 10461 } 10462 10463 /** 10464 * Checks if a list cache value for `key` exists. 10465 * 10466 * @private 10467 * @name has 10468 * @memberOf ListCache 10469 * @param {string} key The key of the entry to check. 10470 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 10471 */ 10472 function listCacheHas(key) { 10473 return assocIndexOf(this.__data__, key) > -1; 10474 } 10475 10476 /** 10477 * Sets the list cache `key` to `value`. 10478 * 10479 * @private 10480 * @name set 10481 * @memberOf ListCache 10482 * @param {string} key The key of the value to set. 10483 * @param {*} value The value to set. 10484 * @returns {Object} Returns the list cache instance. 10485 */ 10486 function listCacheSet(key, value) { 10487 var data = this.__data__, 10488 index = assocIndexOf(data, key); 10489 10490 if (index < 0) { 10491 ++this.size; 10492 data.push([key, value]); 10493 } else { 10494 data[index][1] = value; 10495 } 10496 return this; 10497 } 10498 10499 // Add methods to `ListCache`. 10500 ListCache.prototype.clear = listCacheClear; 10501 ListCache.prototype['delete'] = listCacheDelete; 10502 ListCache.prototype.get = listCacheGet; 10503 ListCache.prototype.has = listCacheHas; 10504 ListCache.prototype.set = listCacheSet; 10505 10506 /*------------------------------------------------------------------------*/ 10507 10508 /** 10509 * Creates a map cache object to store key-value pairs. 10510 * 10511 * @private 10512 * @constructor 10513 * @param {Array} [entries] The key-value pairs to cache. 10514 */ 10515 function MapCache(entries) { 10516 var index = -1, 10517 length = entries == null ? 0 : entries.length; 10518 10519 this.clear(); 10520 while (++index < length) { 10521 var entry = entries[index]; 10522 this.set(entry[0], entry[1]); 10523 } 10524 } 10525 10526 /** 10527 * Removes all key-value entries from the map. 10528 * 10529 * @private 10530 * @name clear 10531 * @memberOf MapCache 10532 */ 10533 function mapCacheClear() { 10534 this.size = 0; 10535 this.__data__ = { 10536 'hash': new Hash, 10537 'map': new (Map || ListCache), 10538 'string': new Hash 10539 }; 10540 } 10541 10542 /** 10543 * Removes `key` and its value from the map. 10544 * 10545 * @private 10546 * @name delete 10547 * @memberOf MapCache 10548 * @param {string} key The key of the value to remove. 10549 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 10550 */ 10551 function mapCacheDelete(key) { 10552 var result = getMapData(this, key)['delete'](key); 10553 this.size -= result ? 1 : 0; 10554 return result; 10555 } 10556 10557 /** 10558 * Gets the map value for `key`. 10559 * 10560 * @private 10561 * @name get 10562 * @memberOf MapCache 10563 * @param {string} key The key of the value to get. 10564 * @returns {*} Returns the entry value. 10565 */ 10566 function mapCacheGet(key) { 10567 return getMapData(this, key).get(key); 10568 } 10569 10570 /** 10571 * Checks if a map value for `key` exists. 10572 * 10573 * @private 10574 * @name has 10575 * @memberOf MapCache 10576 * @param {string} key The key of the entry to check. 10577 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 10578 */ 10579 function mapCacheHas(key) { 10580 return getMapData(this, key).has(key); 10581 } 10582 10583 /** 10584 * Sets the map `key` to `value`. 10585 * 10586 * @private 10587 * @name set 10588 * @memberOf MapCache 10589 * @param {string} key The key of the value to set. 10590 * @param {*} value The value to set. 10591 * @returns {Object} Returns the map cache instance. 10592 */ 10593 function mapCacheSet(key, value) { 10594 var data = getMapData(this, key), 10595 size = data.size; 10596 10597 data.set(key, value); 10598 this.size += data.size == size ? 0 : 1; 10599 return this; 10600 } 10601 10602 // Add methods to `MapCache`. 10603 MapCache.prototype.clear = mapCacheClear; 10604 MapCache.prototype['delete'] = mapCacheDelete; 10605 MapCache.prototype.get = mapCacheGet; 10606 MapCache.prototype.has = mapCacheHas; 10607 MapCache.prototype.set = mapCacheSet; 10608 10609 /*------------------------------------------------------------------------*/ 10610 10611 /** 10612 * 10613 * Creates an array cache object to store unique values. 10614 * 10615 * @private 10616 * @constructor 10617 * @param {Array} [values] The values to cache. 10618 */ 10619 function SetCache(values) { 10620 var index = -1, 10621 length = values == null ? 0 : values.length; 10622 10623 this.__data__ = new MapCache; 10624 while (++index < length) { 10625 this.add(values[index]); 10626 } 10627 } 10628 10629 /** 10630 * Adds `value` to the array cache. 10631 * 10632 * @private 10633 * @name add 10634 * @memberOf SetCache 10635 * @alias push 10636 * @param {*} value The value to cache. 10637 * @returns {Object} Returns the cache instance. 10638 */
vendor: 4,113 bytes, lines 10639-10775
10639 function setCacheAdd(value) { 10640 this.__data__.set(value, HASH_UNDEFINED); 10641 return this; 10642 } 10643 10644 /** 10645 * Checks if `value` is in the array cache. 10646 * 10647 * @private 10648 * @name has 10649 * @memberOf SetCache 10650 * @param {*} value The value to search for. 10651 * @returns {number} Returns `true` if `value` is found, else `false`. 10652 */ 10653 function setCacheHas(value) { 10654 return this.__data__.has(value); 10655 } 10656 10657 // Add methods to `SetCache`. 10658 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; 10659 SetCache.prototype.has = setCacheHas; 10660 10661 /*------------------------------------------------------------------------*/ 10662 10663 /** 10664 * Creates a stack cache object to store key-value pairs. 10665 * 10666 * @private 10667 * @constructor 10668 * @param {Array} [entries] The key-value pairs to cache. 10669 */ 10670 function Stack(entries) { 10671 var data = this.__data__ = new ListCache(entries); 10672 this.size = data.size; 10673 } 10674 10675 /** 10676 * Removes all key-value entries from the stack. 10677 * 10678 * @private 10679 * @name clear 10680 * @memberOf Stack 10681 */ 10682 function stackClear() { 10683 this.__data__ = new ListCache; 10684 this.size = 0; 10685 } 10686 10687 /** 10688 * Removes `key` and its value from the stack. 10689 * 10690 * @private 10691 * @name delete 10692 * @memberOf Stack 10693 * @param {string} key The key of the value to remove. 10694 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 10695 */ 10696 function stackDelete(key) { 10697 var data = this.__data__, 10698 result = data['delete'](key); 10699 10700 this.size = data.size; 10701 return result; 10702 } 10703 10704 /** 10705 * Gets the stack value for `key`. 10706 * 10707 * @private 10708 * @name get 10709 * @memberOf Stack 10710 * @param {string} key The key of the value to get. 10711 * @returns {*} Returns the entry value. 10712 */ 10713 function stackGet(key) { 10714 return this.__data__.get(key); 10715 } 10716 10717 /** 10718 * Checks if a stack value for `key` exists. 10719 * 10720 * @private 10721 * @name has 10722 * @memberOf Stack 10723 * @param {string} key The key of the entry to check. 10724 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 10725 */ 10726 function stackHas(key) { 10727 return this.__data__.has(key); 10728 } 10729 10730 /** 10731 * Sets the stack `key` to `value`. 10732 * 10733 * @private 10734 * @name set 10735 * @memberOf Stack 10736 * @param {string} key The key of the value to set. 10737 * @param {*} value The value to set. 10738 * @returns {Object} Returns the stack cache instance. 10739 */ 10740 function stackSet(key, value) { 10741 var data = this.__data__; 10742 if (data instanceof ListCache) { 10743 var pairs = data.__data__; 10744 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { 10745 pairs.push([key, value]); 10746 this.size = ++data.size; 10747 return this; 10748 } 10749 data = this.__data__ = new MapCache(pairs); 10750 } 10751 data.set(key, value); 10752 this.size = data.size; 10753 return this; 10754 } 10755 10756 // Add methods to `Stack`. 10757 Stack.prototype.clear = stackClear; 10758 Stack.prototype['delete'] = stackDelete; 10759 Stack.prototype.get = stackGet; 10760 Stack.prototype.has = stackHas; 10761 Stack.prototype.set = stackSet; 10762 10763 /*------------------------------------------------------------------------*/ 10764 10765 /** 10766 * Creates an array of the enumerable property names of the array-like `value`. 10767 * 10768 * @private 10769 * @param {*} value The value to query. 10770 * @param {boolean} inherited Specify returning inherited property names. 10771 * @returns {Array} Returns the array of property names. 10772 */ 10773 function arrayLikeKeys(value, inherited) { 10774 var isArr = isArray(value), 10775 isArg = !isArr && isArguments(value),
vendor: 68,165 bytes, lines 10776-12676
10776 isBuff = !isArr && !isArg && isBuffer(value), 10777 isType = !isArr && !isArg && !isBuff && isTypedArray(value), 10778 skipIndexes = isArr || isArg || isBuff || isType, 10779 result = skipIndexes ? baseTimes(value.length, String) : [], 10780 length = result.length; 10781 10782 for (var key in value) { 10783 if ((inherited || hasOwnProperty.call(value, key)) && 10784 !(skipIndexes && ( 10785 // Safari 9 has enumerable `arguments.length` in strict mode. 10786 key == 'length' || 10787 // Node.js 0.10 has enumerable non-index properties on buffers. 10788 (isBuff && (key == 'offset' || key == 'parent')) || 10789 // PhantomJS 2 has enumerable non-index properties on typed arrays. 10790 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || 10791 // Skip index properties. 10792 isIndex(key, length) 10793 ))) { 10794 result.push(key); 10795 } 10796 } 10797 return result; 10798 } 10799 10800 /** 10801 * A specialized version of `_.sample` for arrays. 10802 * 10803 * @private 10804 * @param {Array} array The array to sample. 10805 * @returns {*} Returns the random element. 10806 */ 10807 function arraySample(array) { 10808 var length = array.length; 10809 return length ? array[baseRandom(0, length - 1)] : undefined$1; 10810 } 10811 10812 /** 10813 * A specialized version of `_.sampleSize` for arrays. 10814 * 10815 * @private 10816 * @param {Array} array The array to sample. 10817 * @param {number} n The number of elements to sample. 10818 * @returns {Array} Returns the random elements. 10819 */ 10820 function arraySampleSize(array, n) { 10821 return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); 10822 } 10823 10824 /** 10825 * A specialized version of `_.shuffle` for arrays. 10826 * 10827 * @private 10828 * @param {Array} array The array to shuffle. 10829 * @returns {Array} Returns the new shuffled array. 10830 */ 10831 function arrayShuffle(array) { 10832 return shuffleSelf(copyArray(array)); 10833 } 10834 10835 /** 10836 * This function is like `assignValue` except that it doesn't assign 10837 * `undefined` values. 10838 * 10839 * @private 10840 * @param {Object} object The object to modify. 10841 * @param {string} key The key of the property to assign. 10842 * @param {*} value The value to assign. 10843 */ 10844 function assignMergeValue(object, key, value) { 10845 if ((value !== undefined$1 && !eq(object[key], value)) || 10846 (value === undefined$1 && !(key in object))) { 10847 baseAssignValue(object, key, value); 10848 } 10849 } 10850 10851 /** 10852 * Assigns `value` to `key` of `object` if the existing value is not equivalent 10853 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 10854 * for equality comparisons. 10855 * 10856 * @private 10857 * @param {Object} object The object to modify. 10858 * @param {string} key The key of the property to assign. 10859 * @param {*} value The value to assign. 10860 */ 10861 function assignValue(object, key, value) { 10862 var objValue = object[key]; 10863 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || 10864 (value === undefined$1 && !(key in object))) { 10865 baseAssignValue(object, key, value); 10866 } 10867 } 10868 10869 /** 10870 * Gets the index at which the `key` is found in `array` of key-value pairs. 10871 * 10872 * @private 10873 * @param {Array} array The array to inspect. 10874 * @param {*} key The key to search for. 10875 * @returns {number} Returns the index of the matched value, else `-1`. 10876 */ 10877 function assocIndexOf(array, key) { 10878 var length = array.length; 10879 while (length--) { 10880 if (eq(array[length][0], key)) { 10881 return length; 10882 } 10883 } 10884 return -1; 10885 } 10886 10887 /** 10888 * Aggregates elements of `collection` on `accumulator` with keys transformed 10889 * by `iteratee` and values set by `setter`. 10890 * 10891 * @private 10892 * @param {Array|Object} collection The collection to iterate over. 10893 * @param {Function} setter The function to set `accumulator` values. 10894 * @param {Function} iteratee The iteratee to transform keys. 10895 * @param {Object} accumulator The initial aggregated object. 10896 * @returns {Function} Returns `accumulator`. 10897 */ 10898 function baseAggregator(collection, setter, iteratee, accumulator) { 10899 baseEach(collection, function(value, key, collection) { 10900 setter(accumulator, value, iteratee(value), collection); 10901 }); 10902 return accumulator; 10903 } 10904 10905 /** 10906 * The base implementation of `_.assign` without support for multiple sources 10907 * or `customizer` functions. 10908 * 10909 * @private 10910 * @param {Object} object The destination object. 10911 * @param {Object} source The source object. 10912 * @returns {Object} Returns `object`. 10913 */ 10914 function baseAssign(object, source) { 10915 return object && copyObject(source, keys(source), object); 10916 } 10917 10918 /** 10919 * The base implementation of `_.assignIn` without support for multiple sources 10920 * or `customizer` functions. 10921 * 10922 * @private 10923 * @param {Object} object The destination object. 10924 * @param {Object} source The source object. 10925 * @returns {Object} Returns `object`. 10926 */ 10927 function baseAssignIn(object, source) { 10928 return object && copyObject(source, keysIn(source), object); 10929 } 10930 10931 /** 10932 * The base implementation of `assignValue` and `assignMergeValue` without 10933 * value checks. 10934 * 10935 * @private 10936 * @param {Object} object The object to modify. 10937 * @param {string} key The key of the property to assign. 10938 * @param {*} value The value to assign. 10939 */ 10940 function baseAssignValue(object, key, value) { 10941 if (key == '__proto__' && defineProperty) { 10942 defineProperty(object, key, { 10943 'configurable': true, 10944 'enumerable': true, 10945 'value': value, 10946 'writable': true 10947 }); 10948 } else { 10949 object[key] = value; 10950 } 10951 } 10952 10953 /** 10954 * The base implementation of `_.at` without support for individual paths. 10955 * 10956 * @private 10957 * @param {Object} object The object to iterate over. 10958 * @param {string[]} paths The property paths to pick. 10959 * @returns {Array} Returns the picked elements. 10960 */ 10961 function baseAt(object, paths) { 10962 var index = -1, 10963 length = paths.length, 10964 result = Array(length), 10965 skip = object == null; 10966 10967 while (++index < length) { 10968 result[index] = skip ? undefined$1 : get(object, paths[index]); 10969 } 10970 return result; 10971 } 10972 10973 /** 10974 * The base implementation of `_.clamp` which doesn't coerce arguments. 10975 * 10976 * @private 10977 * @param {number} number The number to clamp. 10978 * @param {number} [lower] The lower bound. 10979 * @param {number} upper The upper bound. 10980 * @returns {number} Returns the clamped number. 10981 */ 10982 function baseClamp(number, lower, upper) { 10983 if (number === number) { 10984 if (upper !== undefined$1) { 10985 number = number <= upper ? number : upper; 10986 } 10987 if (lower !== undefined$1) { 10988 number = number >= lower ? number : lower; 10989 } 10990 } 10991 return number; 10992 } 10993 10994 /** 10995 * The base implementation of `_.clone` and `_.cloneDeep` which tracks 10996 * traversed objects. 10997 * 10998 * @private 10999 * @param {*} value The value to clone. 11000 * @param {boolean} bitmask The bitmask flags. 11001 * 1 - Deep clone 11002 * 2 - Flatten inherited properties 11003 * 4 - Clone symbols 11004 * @param {Function} [customizer] The function to customize cloning. 11005 * @param {string} [key] The key of `value`. 11006 * @param {Object} [object] The parent object of `value`. 11007 * @param {Object} [stack] Tracks traversed objects and their clone counterparts. 11008 * @returns {*} Returns the cloned value. 11009 */ 11010 function baseClone(value, bitmask, customizer, key, object, stack) { 11011 var result, 11012 isDeep = bitmask & CLONE_DEEP_FLAG, 11013 isFlat = bitmask & CLONE_FLAT_FLAG, 11014 isFull = bitmask & CLONE_SYMBOLS_FLAG; 11015 11016 if (customizer) { 11017 result = object ? customizer(value, key, object, stack) : customizer(value); 11018 } 11019 if (result !== undefined$1) { 11020 return result; 11021 } 11022 if (!isObject(value)) { 11023 return value; 11024 } 11025 var isArr = isArray(value); 11026 if (isArr) { 11027 result = initCloneArray(value); 11028 if (!isDeep) { 11029 return copyArray(value, result); 11030 } 11031 } else { 11032 var tag = getTag(value), 11033 isFunc = tag == funcTag || tag == genTag; 11034 11035 if (isBuffer(value)) { 11036 return cloneBuffer(value, isDeep); 11037 } 11038 if (tag == objectTag || tag == argsTag || (isFunc && !object)) { 11039 result = (isFlat || isFunc) ? {} : initCloneObject(value); 11040 if (!isDeep) { 11041 return isFlat 11042 ? copySymbolsIn(value, baseAssignIn(result, value)) 11043 : copySymbols(value, baseAssign(result, value)); 11044 } 11045 } else { 11046 if (!cloneableTags[tag]) { 11047 return object ? value : {}; 11048 } 11049 result = initCloneByTag(value, tag, isDeep); 11050 } 11051 } 11052 // Check for circular references and return its corresponding clone. 11053 stack || (stack = new Stack); 11054 var stacked = stack.get(value); 11055 if (stacked) { 11056 return stacked; 11057 } 11058 stack.set(value, result); 11059 11060 if (isSet(value)) { 11061 value.forEach(function(subValue) { 11062 result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)); 11063 }); 11064 } else if (isMap(value)) { 11065 value.forEach(function(subValue, key) { 11066 result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)); 11067 }); 11068 } 11069 11070 var keysFunc = isFull 11071 ? (isFlat ? getAllKeysIn : getAllKeys) 11072 : (isFlat ? keysIn : keys); 11073 11074 var props = isArr ? undefined$1 : keysFunc(value); 11075 arrayEach(props || value, function(subValue, key) { 11076 if (props) { 11077 key = subValue; 11078 subValue = value[key]; 11079 } 11080 // Recursively populate clone (susceptible to call stack limits). 11081 assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack)); 11082 }); 11083 return result; 11084 } 11085 11086 /** 11087 * The base implementation of `_.conforms` which doesn't clone `source`. 11088 * 11089 * @private 11090 * @param {Object} source The object of property predicates to conform to. 11091 * @returns {Function} Returns the new spec function. 11092 */ 11093 function baseConforms(source) { 11094 var props = keys(source); 11095 return function(object) { 11096 return baseConformsTo(object, source, props); 11097 }; 11098 } 11099 11100 /** 11101 * The base implementation of `_.conformsTo` which accepts `props` to check. 11102 * 11103 * @private 11104 * @param {Object} object The object to inspect. 11105 * @param {Object} source The object of property predicates to conform to. 11106 * @returns {boolean} Returns `true` if `object` conforms, else `false`. 11107 */ 11108 function baseConformsTo(object, source, props) { 11109 var length = props.length; 11110 if (object == null) { 11111 return !length; 11112 } 11113 object = Object(object); 11114 while (length--) { 11115 var key = props[length], 11116 predicate = source[key], 11117 value = object[key]; 11118 11119 if ((value === undefined$1 && !(key in object)) || !predicate(value)) { 11120 return false; 11121 } 11122 } 11123 return true; 11124 } 11125 11126 /** 11127 * The base implementation of `_.delay` and `_.defer` which accepts `args` 11128 * to provide to `func`. 11129 * 11130 * @private 11131 * @param {Function} func The function to delay. 11132 * @param {number} wait The number of milliseconds to delay invocation. 11133 * @param {Array} args The arguments to provide to `func`. 11134 * @returns {number|Object} Returns the timer id or timeout object. 11135 */ 11136 function baseDelay(func, wait, args) { 11137 if (typeof func != 'function') { 11138 throw new TypeError(FUNC_ERROR_TEXT); 11139 } 11140 return setTimeout(function() { func.apply(undefined$1, args); }, wait); 11141 } 11142 11143 /** 11144 * The base implementation of methods like `_.difference` without support 11145 * for excluding multiple arrays or iteratee shorthands. 11146 * 11147 * @private 11148 * @param {Array} array The array to inspect. 11149 * @param {Array} values The values to exclude. 11150 * @param {Function} [iteratee] The iteratee invoked per element. 11151 * @param {Function} [comparator] The comparator invoked per element. 11152 * @returns {Array} Returns the new array of filtered values. 11153 */ 11154 function baseDifference(array, values, iteratee, comparator) { 11155 var index = -1, 11156 includes = arrayIncludes, 11157 isCommon = true, 11158 length = array.length, 11159 result = [], 11160 valuesLength = values.length; 11161 11162 if (!length) { 11163 return result; 11164 } 11165 if (iteratee) { 11166 values = arrayMap(values, baseUnary(iteratee)); 11167 } 11168 if (comparator) { 11169 includes = arrayIncludesWith; 11170 isCommon = false; 11171 } 11172 else if (values.length >= LARGE_ARRAY_SIZE) { 11173 includes = cacheHas; 11174 isCommon = false; 11175 values = new SetCache(values); 11176 } 11177 outer: 11178 while (++index < length) { 11179 var value = array[index], 11180 computed = iteratee == null ? value : iteratee(value); 11181 11182 value = (comparator || value !== 0) ? value : 0; 11183 if (isCommon && computed === computed) { 11184 var valuesIndex = valuesLength; 11185 while (valuesIndex--) { 11186 if (values[valuesIndex] === computed) { 11187 continue outer; 11188 } 11189 } 11190 result.push(value); 11191 } 11192 else if (!includes(values, computed, comparator)) { 11193 result.push(value); 11194 } 11195 } 11196 return result; 11197 } 11198 11199 /** 11200 * The base implementation of `_.forEach` without support for iteratee shorthands. 11201 * 11202 * @private 11203 * @param {Array|Object} collection The collection to iterate over. 11204 * @param {Function} iteratee The function invoked per iteration. 11205 * @returns {Array|Object} Returns `collection`. 11206 */ 11207 var baseEach = createBaseEach(baseForOwn); 11208 11209 /** 11210 * The base implementation of `_.forEachRight` without support for iteratee shorthands. 11211 * 11212 * @private 11213 * @param {Array|Object} collection The collection to iterate over. 11214 * @param {Function} iteratee The function invoked per iteration. 11215 * @returns {Array|Object} Returns `collection`. 11216 */ 11217 var baseEachRight = createBaseEach(baseForOwnRight, true); 11218 11219 /** 11220 * The base implementation of `_.every` without support for iteratee shorthands. 11221 * 11222 * @private 11223 * @param {Array|Object} collection The collection to iterate over. 11224 * @param {Function} predicate The function invoked per iteration. 11225 * @returns {boolean} Returns `true` if all elements pass the predicate check, 11226 * else `false` 11227 */ 11228 function baseEvery(collection, predicate) { 11229 var result = true; 11230 baseEach(collection, function(value, index, collection) { 11231 result = !!predicate(value, index, collection); 11232 return result; 11233 }); 11234 return result; 11235 } 11236 11237 /** 11238 * The base implementation of methods like `_.max` and `_.min` which accepts a 11239 * `comparator` to determine the extremum value. 11240 * 11241 * @private 11242 * @param {Array} array The array to iterate over. 11243 * @param {Function} iteratee The iteratee invoked per iteration. 11244 * @param {Function} comparator The comparator used to compare values. 11245 * @returns {*} Returns the extremum value. 11246 */ 11247 function baseExtremum(array, iteratee, comparator) { 11248 var index = -1, 11249 length = array.length; 11250 11251 while (++index < length) { 11252 var value = array[index], 11253 current = iteratee(value); 11254 11255 if (current != null && (computed === undefined$1 11256 ? (current === current && !isSymbol(current)) 11257 : comparator(current, computed) 11258 )) { 11259 var computed = current, 11260 result = value; 11261 } 11262 } 11263 return result; 11264 } 11265 11266 /** 11267 * The base implementation of `_.fill` without an iteratee call guard. 11268 * 11269 * @private 11270 * @param {Array} array The array to fill. 11271 * @param {*} value The value to fill `array` with. 11272 * @param {number} [start=0] The start position. 11273 * @param {number} [end=array.length] The end position. 11274 * @returns {Array} Returns `array`. 11275 */ 11276 function baseFill(array, value, start, end) { 11277 var length = array.length; 11278 11279 start = toInteger(start); 11280 if (start < 0) { 11281 start = -start > length ? 0 : (length + start); 11282 } 11283 end = (end === undefined$1 || end > length) ? length : toInteger(end); 11284 if (end < 0) { 11285 end += length; 11286 } 11287 end = start > end ? 0 : toLength(end); 11288 while (start < end) { 11289 array[start++] = value; 11290 } 11291 return array; 11292 } 11293 11294 /** 11295 * The base implementation of `_.filter` without support for iteratee shorthands. 11296 * 11297 * @private 11298 * @param {Array|Object} collection The collection to iterate over. 11299 * @param {Function} predicate The function invoked per iteration. 11300 * @returns {Array} Returns the new filtered array. 11301 */ 11302 function baseFilter(collection, predicate) { 11303 var result = []; 11304 baseEach(collection, function(value, index, collection) { 11305 if (predicate(value, index, collection)) { 11306 result.push(value); 11307 } 11308 }); 11309 return result; 11310 } 11311 11312 /** 11313 * The base implementation of `_.flatten` with support for restricting flattening. 11314 * 11315 * @private 11316 * @param {Array} array The array to flatten. 11317 * @param {number} depth The maximum recursion depth. 11318 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration. 11319 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. 11320 * @param {Array} [result=[]] The initial result value. 11321 * @returns {Array} Returns the new flattened array. 11322 */ 11323 function baseFlatten(array, depth, predicate, isStrict, result) { 11324 var index = -1, 11325 length = array.length; 11326 11327 predicate || (predicate = isFlattenable); 11328 result || (result = []); 11329 11330 while (++index < length) { 11331 var value = array[index]; 11332 if (depth > 0 && predicate(value)) { 11333 if (depth > 1) { 11334 // Recursively flatten arrays (susceptible to call stack limits). 11335 baseFlatten(value, depth - 1, predicate, isStrict, result); 11336 } else { 11337 arrayPush(result, value); 11338 } 11339 } else if (!isStrict) { 11340 result[result.length] = value; 11341 } 11342 } 11343 return result; 11344 } 11345 11346 /** 11347 * The base implementation of `baseForOwn` which iterates over `object` 11348 * properties returned by `keysFunc` and invokes `iteratee` for each property. 11349 * Iteratee functions may exit iteration early by explicitly returning `false`. 11350 * 11351 * @private 11352 * @param {Object} object The object to iterate over. 11353 * @param {Function} iteratee The function invoked per iteration. 11354 * @param {Function} keysFunc The function to get the keys of `object`. 11355 * @returns {Object} Returns `object`. 11356 */ 11357 var baseFor = createBaseFor(); 11358 11359 /** 11360 * This function is like `baseFor` except that it iterates over properties 11361 * in the opposite order. 11362 * 11363 * @private 11364 * @param {Object} object The object to iterate over. 11365 * @param {Function} iteratee The function invoked per iteration. 11366 * @param {Function} keysFunc The function to get the keys of `object`. 11367 * @returns {Object} Returns `object`. 11368 */ 11369 var baseForRight = createBaseFor(true); 11370 11371 /** 11372 * The base implementation of `_.forOwn` without support for iteratee shorthands. 11373 * 11374 * @private 11375 * @param {Object} object The object to iterate over. 11376 * @param {Function} iteratee The function invoked per iteration. 11377 * @returns {Object} Returns `object`. 11378 */ 11379 function baseForOwn(object, iteratee) { 11380 return object && baseFor(object, iteratee, keys); 11381 } 11382 11383 /** 11384 * The base implementation of `_.forOwnRight` without support for iteratee shorthands. 11385 * 11386 * @private 11387 * @param {Object} object The object to iterate over. 11388 * @param {Function} iteratee The function invoked per iteration. 11389 * @returns {Object} Returns `object`. 11390 */ 11391 function baseForOwnRight(object, iteratee) { 11392 return object && baseForRight(object, iteratee, keys); 11393 } 11394 11395 /** 11396 * The base implementation of `_.functions` which creates an array of 11397 * `object` function property names filtered from `props`. 11398 * 11399 * @private 11400 * @param {Object} object The object to inspect. 11401 * @param {Array} props The property names to filter. 11402 * @returns {Array} Returns the function names. 11403 */ 11404 function baseFunctions(object, props) { 11405 return arrayFilter(props, function(key) { 11406 return isFunction(object[key]); 11407 }); 11408 } 11409 11410 /** 11411 * The base implementation of `_.get` without support for default values. 11412 * 11413 * @private 11414 * @param {Object} object The object to query. 11415 * @param {Array|string} path The path of the property to get. 11416 * @returns {*} Returns the resolved value. 11417 */ 11418 function baseGet(object, path) { 11419 path = castPath(path, object); 11420 11421 var index = 0, 11422 length = path.length; 11423 11424 while (object != null && index < length) { 11425 object = object[toKey(path[index++])]; 11426 } 11427 return (index && index == length) ? object : undefined$1; 11428 } 11429 11430 /** 11431 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses 11432 * `keysFunc` and `symbolsFunc` to get the enumerable property names and 11433 * symbols of `object`. 11434 * 11435 * @private 11436 * @param {Object} object The object to query. 11437 * @param {Function} keysFunc The function to get the keys of `object`. 11438 * @param {Function} symbolsFunc The function to get the symbols of `object`. 11439 * @returns {Array} Returns the array of property names and symbols. 11440 */ 11441 function baseGetAllKeys(object, keysFunc, symbolsFunc) { 11442 var result = keysFunc(object); 11443 return isArray(object) ? result : arrayPush(result, symbolsFunc(object)); 11444 } 11445 11446 /** 11447 * The base implementation of `getTag` without fallbacks for buggy environments. 11448 * 11449 * @private 11450 * @param {*} value The value to query. 11451 * @returns {string} Returns the `toStringTag`. 11452 */ 11453 function baseGetTag(value) { 11454 if (value == null) { 11455 return value === undefined$1 ? undefinedTag : nullTag; 11456 } 11457 return (symToStringTag && symToStringTag in Object(value)) 11458 ? getRawTag(value) 11459 : objectToString(value); 11460 } 11461 11462 /** 11463 * The base implementation of `_.gt` which doesn't coerce arguments. 11464 * 11465 * @private 11466 * @param {*} value The value to compare. 11467 * @param {*} other The other value to compare. 11468 * @returns {boolean} Returns `true` if `value` is greater than `other`, 11469 * else `false`. 11470 */ 11471 function baseGt(value, other) { 11472 return value > other; 11473 } 11474 11475 /** 11476 * The base implementation of `_.has` without support for deep paths. 11477 * 11478 * @private 11479 * @param {Object} [object] The object to query. 11480 * @param {Array|string} key The key to check. 11481 * @returns {boolean} Returns `true` if `key` exists, else `false`. 11482 */ 11483 function baseHas(object, key) { 11484 return object != null && hasOwnProperty.call(object, key); 11485 } 11486 11487 /** 11488 * The base implementation of `_.hasIn` without support for deep paths. 11489 * 11490 * @private 11491 * @param {Object} [object] The object to query. 11492 * @param {Array|string} key The key to check. 11493 * @returns {boolean} Returns `true` if `key` exists, else `false`. 11494 */ 11495 function baseHasIn(object, key) { 11496 return object != null && key in Object(object); 11497 } 11498 11499 /** 11500 * The base implementation of `_.inRange` which doesn't coerce arguments. 11501 * 11502 * @private 11503 * @param {number} number The number to check. 11504 * @param {number} start The start of the range. 11505 * @param {number} end The end of the range. 11506 * @returns {boolean} Returns `true` if `number` is in the range, else `false`. 11507 */ 11508 function baseInRange(number, start, end) { 11509 return number >= nativeMin(start, end) && number < nativeMax(start, end); 11510 } 11511 11512 /** 11513 * The base implementation of methods like `_.intersection`, without support 11514 * for iteratee shorthands, that accepts an array of arrays to inspect. 11515 * 11516 * @private 11517 * @param {Array} arrays The arrays to inspect. 11518 * @param {Function} [iteratee] The iteratee invoked per element. 11519 * @param {Function} [comparator] The comparator invoked per element. 11520 * @returns {Array} Returns the new array of shared values. 11521 */ 11522 function baseIntersection(arrays, iteratee, comparator) { 11523 var includes = comparator ? arrayIncludesWith : arrayIncludes, 11524 length = arrays[0].length, 11525 othLength = arrays.length, 11526 othIndex = othLength, 11527 caches = Array(othLength), 11528 maxLength = Infinity, 11529 result = []; 11530 11531 while (othIndex--) { 11532 var array = arrays[othIndex]; 11533 if (othIndex && iteratee) { 11534 array = arrayMap(array, baseUnary(iteratee)); 11535 } 11536 maxLength = nativeMin(array.length, maxLength); 11537 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) 11538 ? new SetCache(othIndex && array) 11539 : undefined$1; 11540 } 11541 array = arrays[0]; 11542 11543 var index = -1, 11544 seen = caches[0]; 11545 11546 outer: 11547 while (++index < length && result.length < maxLength) { 11548 var value = array[index], 11549 computed = iteratee ? iteratee(value) : value; 11550 11551 value = (comparator || value !== 0) ? value : 0; 11552 if (!(seen 11553 ? cacheHas(seen, computed) 11554 : includes(result, computed, comparator) 11555 )) { 11556 othIndex = othLength; 11557 while (--othIndex) { 11558 var cache = caches[othIndex]; 11559 if (!(cache 11560 ? cacheHas(cache, computed) 11561 : includes(arrays[othIndex], computed, comparator)) 11562 ) { 11563 continue outer; 11564 } 11565 } 11566 if (seen) { 11567 seen.push(computed); 11568 } 11569 result.push(value); 11570 } 11571 } 11572 return result; 11573 } 11574 11575 /** 11576 * The base implementation of `_.invert` and `_.invertBy` which inverts 11577 * `object` with values transformed by `iteratee` and set by `setter`. 11578 * 11579 * @private 11580 * @param {Object} object The object to iterate over. 11581 * @param {Function} setter The function to set `accumulator` values. 11582 * @param {Function} iteratee The iteratee to transform values. 11583 * @param {Object} accumulator The initial inverted object. 11584 * @returns {Function} Returns `accumulator`. 11585 */ 11586 function baseInverter(object, setter, iteratee, accumulator) { 11587 baseForOwn(object, function(value, key, object) { 11588 setter(accumulator, iteratee(value), key, object); 11589 }); 11590 return accumulator; 11591 } 11592 11593 /** 11594 * The base implementation of `_.invoke` without support for individual 11595 * method arguments. 11596 * 11597 * @private 11598 * @param {Object} object The object to query. 11599 * @param {Array|string} path The path of the method to invoke. 11600 * @param {Array} args The arguments to invoke the method with. 11601 * @returns {*} Returns the result of the invoked method. 11602 */ 11603 function baseInvoke(object, path, args) { 11604 path = castPath(path, object); 11605 object = parent(object, path); 11606 var func = object == null ? object : object[toKey(last(path))]; 11607 return func == null ? undefined$1 : apply(func, object, args); 11608 } 11609 11610 /** 11611 * The base implementation of `_.isArguments`. 11612 * 11613 * @private 11614 * @param {*} value The value to check. 11615 * @returns {boolean} Returns `true` if `value` is an `arguments` object, 11616 */ 11617 function baseIsArguments(value) { 11618 return isObjectLike(value) && baseGetTag(value) == argsTag; 11619 } 11620 11621 /** 11622 * The base implementation of `_.isArrayBuffer` without Node.js optimizations. 11623 * 11624 * @private 11625 * @param {*} value The value to check. 11626 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. 11627 */ 11628 function baseIsArrayBuffer(value) { 11629 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag; 11630 } 11631 11632 /** 11633 * The base implementation of `_.isDate` without Node.js optimizations. 11634 * 11635 * @private 11636 * @param {*} value The value to check. 11637 * @returns {boolean} Returns `true` if `value` is a date object, else `false`. 11638 */ 11639 function baseIsDate(value) { 11640 return isObjectLike(value) && baseGetTag(value) == dateTag; 11641 } 11642 11643 /** 11644 * The base implementation of `_.isEqual` which supports partial comparisons 11645 * and tracks traversed objects. 11646 * 11647 * @private 11648 * @param {*} value The value to compare. 11649 * @param {*} other The other value to compare. 11650 * @param {boolean} bitmask The bitmask flags. 11651 * 1 - Unordered comparison 11652 * 2 - Partial comparison 11653 * @param {Function} [customizer] The function to customize comparisons. 11654 * @param {Object} [stack] Tracks traversed `value` and `other` objects. 11655 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 11656 */ 11657 function baseIsEqual(value, other, bitmask, customizer, stack) { 11658 if (value === other) { 11659 return true; 11660 } 11661 if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) { 11662 return value !== value && other !== other; 11663 } 11664 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack); 11665 } 11666 11667 /** 11668 * A specialized version of `baseIsEqual` for arrays and objects which performs 11669 * deep comparisons and tracks traversed objects enabling objects with circular 11670 * references to be compared. 11671 * 11672 * @private 11673 * @param {Object} object The object to compare. 11674 * @param {Object} other The other object to compare. 11675 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 11676 * @param {Function} customizer The function to customize comparisons. 11677 * @param {Function} equalFunc The function to determine equivalents of values. 11678 * @param {Object} [stack] Tracks traversed `object` and `other` objects. 11679 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. 11680 */ 11681 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { 11682 var objIsArr = isArray(object), 11683 othIsArr = isArray(other), 11684 objTag = objIsArr ? arrayTag : getTag(object), 11685 othTag = othIsArr ? arrayTag : getTag(other); 11686 11687 objTag = objTag == argsTag ? objectTag : objTag; 11688 othTag = othTag == argsTag ? objectTag : othTag; 11689 11690 var objIsObj = objTag == objectTag, 11691 othIsObj = othTag == objectTag, 11692 isSameTag = objTag == othTag; 11693 11694 if (isSameTag && isBuffer(object)) { 11695 if (!isBuffer(other)) { 11696 return false; 11697 } 11698 objIsArr = true; 11699 objIsObj = false; 11700 } 11701 if (isSameTag && !objIsObj) { 11702 stack || (stack = new Stack); 11703 return (objIsArr || isTypedArray(object)) 11704 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) 11705 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack); 11706 } 11707 if (!(bitmask & COMPARE_PARTIAL_FLAG)) { 11708 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), 11709 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); 11710 11711 if (objIsWrapped || othIsWrapped) { 11712 var objUnwrapped = objIsWrapped ? object.value() : object, 11713 othUnwrapped = othIsWrapped ? other.value() : other; 11714 11715 stack || (stack = new Stack); 11716 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack); 11717 } 11718 } 11719 if (!isSameTag) { 11720 return false; 11721 } 11722 stack || (stack = new Stack); 11723 return equalObjects(object, other, bitmask, customizer, equalFunc, stack); 11724 } 11725 11726 /** 11727 * The base implementation of `_.isMap` without Node.js optimizations. 11728 * 11729 * @private 11730 * @param {*} value The value to check. 11731 * @returns {boolean} Returns `true` if `value` is a map, else `false`. 11732 */ 11733 function baseIsMap(value) { 11734 return isObjectLike(value) && getTag(value) == mapTag; 11735 } 11736 11737 /** 11738 * The base implementation of `_.isMatch` without support for iteratee shorthands. 11739 * 11740 * @private 11741 * @param {Object} object The object to inspect. 11742 * @param {Object} source The object of property values to match. 11743 * @param {Array} matchData The property names, values, and compare flags to match. 11744 * @param {Function} [customizer] The function to customize comparisons. 11745 * @returns {boolean} Returns `true` if `object` is a match, else `false`. 11746 */ 11747 function baseIsMatch(object, source, matchData, customizer) { 11748 var index = matchData.length, 11749 length = index, 11750 noCustomizer = !customizer; 11751 11752 if (object == null) { 11753 return !length; 11754 } 11755 object = Object(object); 11756 while (index--) { 11757 var data = matchData[index]; 11758 if ((noCustomizer && data[2]) 11759 ? data[1] !== object[data[0]] 11760 : !(data[0] in object) 11761 ) { 11762 return false; 11763 } 11764 } 11765 while (++index < length) { 11766 data = matchData[index]; 11767 var key = data[0], 11768 objValue = object[key], 11769 srcValue = data[1]; 11770 11771 if (noCustomizer && data[2]) { 11772 if (objValue === undefined$1 && !(key in object)) { 11773 return false; 11774 } 11775 } else { 11776 var stack = new Stack; 11777 if (customizer) { 11778 var result = customizer(objValue, srcValue, key, object, source, stack); 11779 } 11780 if (!(result === undefined$1 11781 ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) 11782 : result 11783 )) { 11784 return false; 11785 } 11786 } 11787 } 11788 return true; 11789 } 11790 11791 /** 11792 * The base implementation of `_.isNative` without bad shim checks. 11793 * 11794 * @private 11795 * @param {*} value The value to check. 11796 * @returns {boolean} Returns `true` if `value` is a native function, 11797 * else `false`. 11798 */ 11799 function baseIsNative(value) { 11800 if (!isObject(value) || isMasked(value)) { 11801 return false; 11802 } 11803 var pattern = isFunction(value) ? reIsNative : reIsHostCtor; 11804 return pattern.test(toSource(value)); 11805 } 11806 11807 /** 11808 * The base implementation of `_.isRegExp` without Node.js optimizations. 11809 * 11810 * @private 11811 * @param {*} value The value to check. 11812 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. 11813 */ 11814 function baseIsRegExp(value) { 11815 return isObjectLike(value) && baseGetTag(value) == regexpTag; 11816 } 11817 11818 /** 11819 * The base implementation of `_.isSet` without Node.js optimizations. 11820 * 11821 * @private 11822 * @param {*} value The value to check. 11823 * @returns {boolean} Returns `true` if `value` is a set, else `false`. 11824 */ 11825 function baseIsSet(value) { 11826 return isObjectLike(value) && getTag(value) == setTag; 11827 } 11828 11829 /** 11830 * The base implementation of `_.isTypedArray` without Node.js optimizations. 11831 * 11832 * @private 11833 * @param {*} value The value to check. 11834 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. 11835 */ 11836 function baseIsTypedArray(value) { 11837 return isObjectLike(value) && 11838 isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; 11839 } 11840 11841 /** 11842 * The base implementation of `_.iteratee`. 11843 * 11844 * @private 11845 * @param {*} [value=_.identity] The value to convert to an iteratee. 11846 * @returns {Function} Returns the iteratee. 11847 */ 11848 function baseIteratee(value) { 11849 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. 11850 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. 11851 if (typeof value == 'function') { 11852 return value; 11853 } 11854 if (value == null) { 11855 return identity; 11856 } 11857 if (typeof value == 'object') { 11858 return isArray(value) 11859 ? baseMatchesProperty(value[0], value[1]) 11860 : baseMatches(value); 11861 } 11862 return property(value); 11863 } 11864 11865 /** 11866 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. 11867 * 11868 * @private 11869 * @param {Object} object The object to query. 11870 * @returns {Array} Returns the array of property names. 11871 */ 11872 function baseKeys(object) { 11873 if (!isPrototype(object)) { 11874 return nativeKeys(object); 11875 } 11876 var result = []; 11877 for (var key in Object(object)) { 11878 if (hasOwnProperty.call(object, key) && key != 'constructor') { 11879 result.push(key); 11880 } 11881 } 11882 return result; 11883 } 11884 11885 /** 11886 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense. 11887 * 11888 * @private 11889 * @param {Object} object The object to query. 11890 * @returns {Array} Returns the array of property names. 11891 */ 11892 function baseKeysIn(object) { 11893 if (!isObject(object)) { 11894 return nativeKeysIn(object); 11895 } 11896 var isProto = isPrototype(object), 11897 result = []; 11898 11899 for (var key in object) { 11900 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { 11901 result.push(key); 11902 } 11903 } 11904 return result; 11905 } 11906 11907 /** 11908 * The base implementation of `_.lt` which doesn't coerce arguments. 11909 * 11910 * @private 11911 * @param {*} value The value to compare. 11912 * @param {*} other The other value to compare. 11913 * @returns {boolean} Returns `true` if `value` is less than `other`, 11914 * else `false`. 11915 */ 11916 function baseLt(value, other) { 11917 return value < other; 11918 } 11919 11920 /** 11921 * The base implementation of `_.map` without support for iteratee shorthands. 11922 * 11923 * @private 11924 * @param {Array|Object} collection The collection to iterate over. 11925 * @param {Function} iteratee The function invoked per iteration. 11926 * @returns {Array} Returns the new mapped array. 11927 */ 11928 function baseMap(collection, iteratee) { 11929 var index = -1, 11930 result = isArrayLike(collection) ? Array(collection.length) : []; 11931 11932 baseEach(collection, function(value, key, collection) { 11933 result[++index] = iteratee(value, key, collection); 11934 }); 11935 return result; 11936 } 11937 11938 /** 11939 * The base implementation of `_.matches` which doesn't clone `source`. 11940 * 11941 * @private 11942 * @param {Object} source The object of property values to match. 11943 * @returns {Function} Returns the new spec function. 11944 */ 11945 function baseMatches(source) { 11946 var matchData = getMatchData(source); 11947 if (matchData.length == 1 && matchData[0][2]) { 11948 return matchesStrictComparable(matchData[0][0], matchData[0][1]); 11949 } 11950 return function(object) { 11951 return object === source || baseIsMatch(object, source, matchData); 11952 }; 11953 } 11954 11955 /** 11956 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. 11957 * 11958 * @private 11959 * @param {string} path The path of the property to get. 11960 * @param {*} srcValue The value to match. 11961 * @returns {Function} Returns the new spec function. 11962 */ 11963 function baseMatchesProperty(path, srcValue) { 11964 if (isKey(path) && isStrictComparable(srcValue)) { 11965 return matchesStrictComparable(toKey(path), srcValue); 11966 } 11967 return function(object) { 11968 var objValue = get(object, path); 11969 return (objValue === undefined$1 && objValue === srcValue) 11970 ? hasIn(object, path) 11971 : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG); 11972 }; 11973 } 11974 11975 /** 11976 * The base implementation of `_.merge` without support for multiple sources. 11977 * 11978 * @private 11979 * @param {Object} object The destination object. 11980 * @param {Object} source The source object. 11981 * @param {number} srcIndex The index of `source`. 11982 * @param {Function} [customizer] The function to customize merged values. 11983 * @param {Object} [stack] Tracks traversed source values and their merged 11984 * counterparts. 11985 */ 11986 function baseMerge(object, source, srcIndex, customizer, stack) { 11987 if (object === source) { 11988 return; 11989 } 11990 baseFor(source, function(srcValue, key) { 11991 stack || (stack = new Stack); 11992 if (isObject(srcValue)) { 11993 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); 11994 } 11995 else { 11996 var newValue = customizer 11997 ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) 11998 : undefined$1; 11999 12000 if (newValue === undefined$1) { 12001 newValue = srcValue; 12002 } 12003 assignMergeValue(object, key, newValue); 12004 } 12005 }, keysIn); 12006 } 12007 12008 /** 12009 * A specialized version of `baseMerge` for arrays and objects which performs 12010 * deep merges and tracks traversed objects enabling objects with circular 12011 * references to be merged. 12012 * 12013 * @private 12014 * @param {Object} object The destination object. 12015 * @param {Object} source The source object. 12016 * @param {string} key The key of the value to merge. 12017 * @param {number} srcIndex The index of `source`. 12018 * @param {Function} mergeFunc The function to merge values. 12019 * @param {Function} [customizer] The function to customize assigned values. 12020 * @param {Object} [stack] Tracks traversed source values and their merged 12021 * counterparts. 12022 */ 12023 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { 12024 var objValue = safeGet(object, key), 12025 srcValue = safeGet(source, key), 12026 stacked = stack.get(srcValue); 12027 12028 if (stacked) { 12029 assignMergeValue(object, key, stacked); 12030 return; 12031 } 12032 var newValue = customizer 12033 ? customizer(objValue, srcValue, (key + ''), object, source, stack) 12034 : undefined$1; 12035 12036 var isCommon = newValue === undefined$1; 12037 12038 if (isCommon) { 12039 var isArr = isArray(srcValue), 12040 isBuff = !isArr && isBuffer(srcValue), 12041 isTyped = !isArr && !isBuff && isTypedArray(srcValue); 12042 12043 newValue = srcValue; 12044 if (isArr || isBuff || isTyped) { 12045 if (isArray(objValue)) { 12046 newValue = objValue; 12047 } 12048 else if (isArrayLikeObject(objValue)) { 12049 newValue = copyArray(objValue); 12050 } 12051 else if (isBuff) { 12052 isCommon = false; 12053 newValue = cloneBuffer(srcValue, true); 12054 } 12055 else if (isTyped) { 12056 isCommon = false; 12057 newValue = cloneTypedArray(srcValue, true); 12058 } 12059 else { 12060 newValue = []; 12061 } 12062 } 12063 else if (isPlainObject(srcValue) || isArguments(srcValue)) { 12064 newValue = objValue; 12065 if (isArguments(objValue)) { 12066 newValue = toPlainObject(objValue); 12067 } 12068 else if (!isObject(objValue) || isFunction(objValue)) { 12069 newValue = initCloneObject(srcValue); 12070 } 12071 } 12072 else { 12073 isCommon = false; 12074 } 12075 } 12076 if (isCommon) { 12077 // Recursively merge objects and arrays (susceptible to call stack limits). 12078 stack.set(srcValue, newValue); 12079 mergeFunc(newValue, srcValue, srcIndex, customizer, stack); 12080 stack['delete'](srcValue); 12081 } 12082 assignMergeValue(object, key, newValue); 12083 } 12084 12085 /** 12086 * The base implementation of `_.nth` which doesn't coerce arguments. 12087 * 12088 * @private 12089 * @param {Array} array The array to query. 12090 * @param {number} n The index of the element to return. 12091 * @returns {*} Returns the nth element of `array`. 12092 */ 12093 function baseNth(array, n) { 12094 var length = array.length; 12095 if (!length) { 12096 return; 12097 } 12098 n += n < 0 ? length : 0; 12099 return isIndex(n, length) ? array[n] : undefined$1; 12100 } 12101 12102 /** 12103 * The base implementation of `_.orderBy` without param guards. 12104 * 12105 * @private 12106 * @param {Array|Object} collection The collection to iterate over. 12107 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. 12108 * @param {string[]} orders The sort orders of `iteratees`. 12109 * @returns {Array} Returns the new sorted array. 12110 */ 12111 function baseOrderBy(collection, iteratees, orders) { 12112 if (iteratees.length) { 12113 iteratees = arrayMap(iteratees, function(iteratee) { 12114 if (isArray(iteratee)) { 12115 return function(value) { 12116 return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee); 12117 } 12118 } 12119 return iteratee; 12120 }); 12121 } else { 12122 iteratees = [identity]; 12123 } 12124 12125 var index = -1; 12126 iteratees = arrayMap(iteratees, baseUnary(getIteratee())); 12127 12128 var result = baseMap(collection, function(value, key, collection) { 12129 var criteria = arrayMap(iteratees, function(iteratee) { 12130 return iteratee(value); 12131 }); 12132 return { 'criteria': criteria, 'index': ++index, 'value': value }; 12133 }); 12134 12135 return baseSortBy(result, function(object, other) { 12136 return compareMultiple(object, other, orders); 12137 }); 12138 } 12139 12140 /** 12141 * The base implementation of `_.pick` without support for individual 12142 * property identifiers. 12143 * 12144 * @private 12145 * @param {Object} object The source object. 12146 * @param {string[]} paths The property paths to pick. 12147 * @returns {Object} Returns the new object. 12148 */ 12149 function basePick(object, paths) { 12150 return basePickBy(object, paths, function(value, path) { 12151 return hasIn(object, path); 12152 }); 12153 } 12154 12155 /** 12156 * The base implementation of `_.pickBy` without support for iteratee shorthands. 12157 * 12158 * @private 12159 * @param {Object} object The source object. 12160 * @param {string[]} paths The property paths to pick. 12161 * @param {Function} predicate The function invoked per property. 12162 * @returns {Object} Returns the new object. 12163 */ 12164 function basePickBy(object, paths, predicate) { 12165 var index = -1, 12166 length = paths.length, 12167 result = {}; 12168 12169 while (++index < length) { 12170 var path = paths[index], 12171 value = baseGet(object, path); 12172 12173 if (predicate(value, path)) { 12174 baseSet(result, castPath(path, object), value); 12175 } 12176 } 12177 return result; 12178 } 12179 12180 /** 12181 * A specialized version of `baseProperty` which supports deep paths. 12182 * 12183 * @private 12184 * @param {Array|string} path The path of the property to get. 12185 * @returns {Function} Returns the new accessor function. 12186 */ 12187 function basePropertyDeep(path) { 12188 return function(object) { 12189 return baseGet(object, path); 12190 }; 12191 } 12192 12193 /** 12194 * The base implementation of `_.pullAllBy` without support for iteratee 12195 * shorthands. 12196 * 12197 * @private 12198 * @param {Array} array The array to modify. 12199 * @param {Array} values The values to remove. 12200 * @param {Function} [iteratee] The iteratee invoked per element. 12201 * @param {Function} [comparator] The comparator invoked per element. 12202 * @returns {Array} Returns `array`. 12203 */ 12204 function basePullAll(array, values, iteratee, comparator) { 12205 var indexOf = comparator ? baseIndexOfWith : baseIndexOf, 12206 index = -1, 12207 length = values.length, 12208 seen = array; 12209 12210 if (array === values) { 12211 values = copyArray(values); 12212 } 12213 if (iteratee) { 12214 seen = arrayMap(array, baseUnary(iteratee)); 12215 } 12216 while (++index < length) { 12217 var fromIndex = 0, 12218 value = values[index], 12219 computed = iteratee ? iteratee(value) : value; 12220 12221 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { 12222 if (seen !== array) { 12223 splice.call(seen, fromIndex, 1); 12224 } 12225 splice.call(array, fromIndex, 1); 12226 } 12227 } 12228 return array; 12229 } 12230 12231 /** 12232 * The base implementation of `_.pullAt` without support for individual 12233 * indexes or capturing the removed elements. 12234 * 12235 * @private 12236 * @param {Array} array The array to modify. 12237 * @param {number[]} indexes The indexes of elements to remove. 12238 * @returns {Array} Returns `array`. 12239 */ 12240 function basePullAt(array, indexes) { 12241 var length = array ? indexes.length : 0, 12242 lastIndex = length - 1; 12243 12244 while (length--) { 12245 var index = indexes[length]; 12246 if (length == lastIndex || index !== previous) { 12247 var previous = index; 12248 if (isIndex(index)) { 12249 splice.call(array, index, 1); 12250 } else { 12251 baseUnset(array, index); 12252 } 12253 } 12254 } 12255 return array; 12256 } 12257 12258 /** 12259 * The base implementation of `_.random` without support for returning 12260 * floating-point numbers. 12261 * 12262 * @private 12263 * @param {number} lower The lower bound. 12264 * @param {number} upper The upper bound. 12265 * @returns {number} Returns the random number. 12266 */ 12267 function baseRandom(lower, upper) { 12268 return lower + nativeFloor(nativeRandom() * (upper - lower + 1)); 12269 } 12270 12271 /** 12272 * The base implementation of `_.range` and `_.rangeRight` which doesn't 12273 * coerce arguments. 12274 * 12275 * @private 12276 * @param {number} start The start of the range. 12277 * @param {number} end The end of the range. 12278 * @param {number} step The value to increment or decrement by. 12279 * @param {boolean} [fromRight] Specify iterating from right to left. 12280 * @returns {Array} Returns the range of numbers. 12281 */ 12282 function baseRange(start, end, step, fromRight) { 12283 var index = -1, 12284 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), 12285 result = Array(length); 12286 12287 while (length--) { 12288 result[fromRight ? length : ++index] = start; 12289 start += step; 12290 } 12291 return result; 12292 } 12293 12294 /** 12295 * The base implementation of `_.repeat` which doesn't coerce arguments. 12296 * 12297 * @private 12298 * @param {string} string The string to repeat. 12299 * @param {number} n The number of times to repeat the string. 12300 * @returns {string} Returns the repeated string. 12301 */ 12302 function baseRepeat(string, n) { 12303 var result = ''; 12304 if (!string || n < 1 || n > MAX_SAFE_INTEGER) { 12305 return result; 12306 } 12307 // Leverage the exponentiation by squaring algorithm for a faster repeat. 12308 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. 12309 do { 12310 if (n % 2) { 12311 result += string; 12312 } 12313 n = nativeFloor(n / 2); 12314 if (n) { 12315 string += string; 12316 } 12317 } while (n); 12318 12319 return result; 12320 } 12321 12322 /** 12323 * The base implementation of `_.rest` which doesn't validate or coerce arguments. 12324 * 12325 * @private 12326 * @param {Function} func The function to apply a rest parameter to. 12327 * @param {number} [start=func.length-1] The start position of the rest parameter. 12328 * @returns {Function} Returns the new function. 12329 */ 12330 function baseRest(func, start) { 12331 return setToString(overRest(func, start, identity), func + ''); 12332 } 12333 12334 /** 12335 * The base implementation of `_.sample`. 12336 * 12337 * @private 12338 * @param {Array|Object} collection The collection to sample. 12339 * @returns {*} Returns the random element. 12340 */ 12341 function baseSample(collection) { 12342 return arraySample(values(collection)); 12343 } 12344 12345 /** 12346 * The base implementation of `_.sampleSize` without param guards. 12347 * 12348 * @private 12349 * @param {Array|Object} collection The collection to sample. 12350 * @param {number} n The number of elements to sample. 12351 * @returns {Array} Returns the random elements. 12352 */ 12353 function baseSampleSize(collection, n) { 12354 var array = values(collection); 12355 return shuffleSelf(array, baseClamp(n, 0, array.length)); 12356 } 12357 12358 /** 12359 * The base implementation of `_.set`. 12360 * 12361 * @private 12362 * @param {Object} object The object to modify. 12363 * @param {Array|string} path The path of the property to set. 12364 * @param {*} value The value to set. 12365 * @param {Function} [customizer] The function to customize path creation. 12366 * @returns {Object} Returns `object`. 12367 */ 12368 function baseSet(object, path, value, customizer) { 12369 if (!isObject(object)) { 12370 return object; 12371 } 12372 path = castPath(path, object); 12373 12374 var index = -1, 12375 length = path.length, 12376 lastIndex = length - 1, 12377 nested = object; 12378 12379 while (nested != null && ++index < length) { 12380 var key = toKey(path[index]), 12381 newValue = value; 12382 12383 if (key === '__proto__' || key === 'constructor' || key === 'prototype') { 12384 return object; 12385 } 12386 12387 if (index != lastIndex) { 12388 var objValue = nested[key]; 12389 newValue = customizer ? customizer(objValue, key, nested) : undefined$1; 12390 if (newValue === undefined$1) { 12391 newValue = isObject(objValue) 12392 ? objValue 12393 : (isIndex(path[index + 1]) ? [] : {}); 12394 } 12395 } 12396 assignValue(nested, key, newValue); 12397 nested = nested[key]; 12398 } 12399 return object; 12400 } 12401 12402 /** 12403 * The base implementation of `setData` without support for hot loop shorting. 12404 * 12405 * @private 12406 * @param {Function} func The function to associate metadata with. 12407 * @param {*} data The metadata. 12408 * @returns {Function} Returns `func`. 12409 */ 12410 var baseSetData = !metaMap ? identity : function(func, data) { 12411 metaMap.set(func, data); 12412 return func; 12413 }; 12414 12415 /** 12416 * The base implementation of `setToString` without support for hot loop shorting. 12417 * 12418 * @private 12419 * @param {Function} func The function to modify. 12420 * @param {Function} string The `toString` result. 12421 * @returns {Function} Returns `func`. 12422 */ 12423 var baseSetToString = !defineProperty ? identity : function(func, string) { 12424 return defineProperty(func, 'toString', { 12425 'configurable': true, 12426 'enumerable': false, 12427 'value': constant(string), 12428 'writable': true 12429 }); 12430 }; 12431 12432 /** 12433 * The base implementation of `_.shuffle`. 12434 * 12435 * @private 12436 * @param {Array|Object} collection The collection to shuffle. 12437 * @returns {Array} Returns the new shuffled array. 12438 */ 12439 function baseShuffle(collection) { 12440 return shuffleSelf(values(collection)); 12441 } 12442 12443 /** 12444 * The base implementation of `_.slice` without an iteratee call guard. 12445 * 12446 * @private 12447 * @param {Array} array The array to slice. 12448 * @param {number} [start=0] The start position. 12449 * @param {number} [end=array.length] The end position. 12450 * @returns {Array} Returns the slice of `array`. 12451 */ 12452 function baseSlice(array, start, end) { 12453 var index = -1, 12454 length = array.length; 12455 12456 if (start < 0) { 12457 start = -start > length ? 0 : (length + start); 12458 } 12459 end = end > length ? length : end; 12460 if (end < 0) { 12461 end += length; 12462 } 12463 length = start > end ? 0 : ((end - start) >>> 0); 12464 start >>>= 0; 12465 12466 var result = Array(length); 12467 while (++index < length) { 12468 result[index] = array[index + start]; 12469 } 12470 return result; 12471 } 12472 12473 /** 12474 * The base implementation of `_.some` without support for iteratee shorthands. 12475 * 12476 * @private 12477 * @param {Array|Object} collection The collection to iterate over. 12478 * @param {Function} predicate The function invoked per iteration. 12479 * @returns {boolean} Returns `true` if any element passes the predicate check, 12480 * else `false`. 12481 */ 12482 function baseSome(collection, predicate) { 12483 var result; 12484 12485 baseEach(collection, function(value, index, collection) { 12486 result = predicate(value, index, collection); 12487 return !result; 12488 }); 12489 return !!result; 12490 } 12491 12492 /** 12493 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which 12494 * performs a binary search of `array` to determine the index at which `value` 12495 * should be inserted into `array` in order to maintain its sort order. 12496 * 12497 * @private 12498 * @param {Array} array The sorted array to inspect. 12499 * @param {*} value The value to evaluate. 12500 * @param {boolean} [retHighest] Specify returning the highest qualified index. 12501 * @returns {number} Returns the index at which `value` should be inserted 12502 * into `array`. 12503 */ 12504 function baseSortedIndex(array, value, retHighest) { 12505 var low = 0, 12506 high = array == null ? low : array.length; 12507 12508 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { 12509 while (low < high) { 12510 var mid = (low + high) >>> 1, 12511 computed = array[mid]; 12512 12513 if (computed !== null && !isSymbol(computed) && 12514 (retHighest ? (computed <= value) : (computed < value))) { 12515 low = mid + 1; 12516 } else { 12517 high = mid; 12518 } 12519 } 12520 return high; 12521 } 12522 return baseSortedIndexBy(array, value, identity, retHighest); 12523 } 12524 12525 /** 12526 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy` 12527 * which invokes `iteratee` for `value` and each element of `array` to compute 12528 * their sort ranking. The iteratee is invoked with one argument; (value). 12529 * 12530 * @private 12531 * @param {Array} array The sorted array to inspect. 12532 * @param {*} value The value to evaluate. 12533 * @param {Function} iteratee The iteratee invoked per element. 12534 * @param {boolean} [retHighest] Specify returning the highest qualified index. 12535 * @returns {number} Returns the index at which `value` should be inserted 12536 * into `array`. 12537 */ 12538 function baseSortedIndexBy(array, value, iteratee, retHighest) { 12539 var low = 0, 12540 high = array == null ? 0 : array.length; 12541 if (high === 0) { 12542 return 0; 12543 } 12544 12545 value = iteratee(value); 12546 var valIsNaN = value !== value, 12547 valIsNull = value === null, 12548 valIsSymbol = isSymbol(value), 12549 valIsUndefined = value === undefined$1; 12550 12551 while (low < high) { 12552 var mid = nativeFloor((low + high) / 2), 12553 computed = iteratee(array[mid]), 12554 othIsDefined = computed !== undefined$1, 12555 othIsNull = computed === null, 12556 othIsReflexive = computed === computed, 12557 othIsSymbol = isSymbol(computed); 12558 12559 if (valIsNaN) { 12560 var setLow = retHighest || othIsReflexive; 12561 } else if (valIsUndefined) { 12562 setLow = othIsReflexive && (retHighest || othIsDefined); 12563 } else if (valIsNull) { 12564 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull); 12565 } else if (valIsSymbol) { 12566 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol); 12567 } else if (othIsNull || othIsSymbol) { 12568 setLow = false; 12569 } else { 12570 setLow = retHighest ? (computed <= value) : (computed < value); 12571 } 12572 if (setLow) { 12573 low = mid + 1; 12574 } else { 12575 high = mid; 12576 } 12577 } 12578 return nativeMin(high, MAX_ARRAY_INDEX); 12579 } 12580 12581 /** 12582 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without 12583 * support for iteratee shorthands. 12584 * 12585 * @private 12586 * @param {Array} array The array to inspect. 12587 * @param {Function} [iteratee] The iteratee invoked per element. 12588 * @returns {Array} Returns the new duplicate free array. 12589 */ 12590 function baseSortedUniq(array, iteratee) { 12591 var index = -1, 12592 length = array.length, 12593 resIndex = 0, 12594 result = []; 12595 12596 while (++index < length) { 12597 var value = array[index], 12598 computed = iteratee ? iteratee(value) : value; 12599 12600 if (!index || !eq(computed, seen)) { 12601 var seen = computed; 12602 result[resIndex++] = value === 0 ? 0 : value; 12603 } 12604 } 12605 return result; 12606 } 12607 12608 /** 12609 * The base implementation of `_.toNumber` which doesn't ensure correct 12610 * conversions of binary, hexadecimal, or octal string values. 12611 * 12612 * @private 12613 * @param {*} value The value to process. 12614 * @returns {number} Returns the number. 12615 */ 12616 function baseToNumber(value) { 12617 if (typeof value == 'number') { 12618 return value; 12619 } 12620 if (isSymbol(value)) { 12621 return NAN; 12622 } 12623 return +value; 12624 } 12625 12626 /** 12627 * The base implementation of `_.toString` which doesn't convert nullish 12628 * values to empty strings. 12629 * 12630 * @private 12631 * @param {*} value The value to process. 12632 * @returns {string} Returns the string. 12633 */ 12634 function baseToString(value) { 12635 // Exit early for strings to avoid a performance hit in some environments. 12636 if (typeof value == 'string') { 12637 return value; 12638 } 12639 if (isArray(value)) { 12640 // Recursively convert values (susceptible to call stack limits). 12641 return arrayMap(value, baseToString) + ''; 12642 } 12643 if (isSymbol(value)) { 12644 return symbolToString ? symbolToString.call(value) : ''; 12645 } 12646 var result = (value + ''); 12647 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; 12648 } 12649 12650 /** 12651 * The base implementation of `_.uniqBy` without support for iteratee shorthands. 12652 * 12653 * @private 12654 * @param {Array} array The array to inspect. 12655 * @param {Function} [iteratee] The iteratee invoked per element. 12656 * @param {Function} [comparator] The comparator invoked per element. 12657 * @returns {Array} Returns the new duplicate free array. 12658 */ 12659 function baseUniq(array, iteratee, comparator) { 12660 var index = -1, 12661 includes = arrayIncludes, 12662 length = array.length, 12663 isCommon = true, 12664 result = [], 12665 seen = result; 12666 12667 if (comparator) { 12668 isCommon = false; 12669 includes = arrayIncludesWith; 12670 } 12671 else if (length >= LARGE_ARRAY_SIZE) { 12672 var set = iteratee ? null : createSet(array); 12673 if (set) { 12674 return setToArray(set); 12675 } 12676 isCommon = false;
vendor: 3,854 bytes, lines 12677-12778
12677 includes = cacheHas; 12678 seen = new SetCache; 12679 } 12680 else { 12681 seen = iteratee ? [] : result; 12682 } 12683 outer: 12684 while (++index < length) { 12685 var value = array[index], 12686 computed = iteratee ? iteratee(value) : value; 12687 12688 value = (comparator || value !== 0) ? value : 0; 12689 if (isCommon && computed === computed) { 12690 var seenIndex = seen.length; 12691 while (seenIndex--) { 12692 if (seen[seenIndex] === computed) { 12693 continue outer; 12694 } 12695 } 12696 if (iteratee) { 12697 seen.push(computed); 12698 } 12699 result.push(value); 12700 } 12701 else if (!includes(seen, computed, comparator)) { 12702 if (seen !== result) { 12703 seen.push(computed); 12704 } 12705 result.push(value); 12706 } 12707 } 12708 return result; 12709 } 12710 12711 /** 12712 * The base implementation of `_.unset`. 12713 * 12714 * @private 12715 * @param {Object} object The object to modify. 12716 * @param {Array|string} path The property path to unset. 12717 * @returns {boolean} Returns `true` if the property is deleted, else `false`. 12718 */ 12719 function baseUnset(object, path) { 12720 path = castPath(path, object); 12721 object = parent(object, path); 12722 return object == null || delete object[toKey(last(path))]; 12723 } 12724 12725 /** 12726 * The base implementation of `_.update`. 12727 * 12728 * @private 12729 * @param {Object} object The object to modify. 12730 * @param {Array|string} path The path of the property to update. 12731 * @param {Function} updater The function to produce the updated value. 12732 * @param {Function} [customizer] The function to customize path creation. 12733 * @returns {Object} Returns `object`. 12734 */ 12735 function baseUpdate(object, path, updater, customizer) { 12736 return baseSet(object, path, updater(baseGet(object, path)), customizer); 12737 } 12738 12739 /** 12740 * The base implementation of methods like `_.dropWhile` and `_.takeWhile` 12741 * without support for iteratee shorthands. 12742 * 12743 * @private 12744 * @param {Array} array The array to query. 12745 * @param {Function} predicate The function invoked per iteration. 12746 * @param {boolean} [isDrop] Specify dropping elements instead of taking them. 12747 * @param {boolean} [fromRight] Specify iterating from right to left. 12748 * @returns {Array} Returns the slice of `array`. 12749 */ 12750 function baseWhile(array, predicate, isDrop, fromRight) { 12751 var length = array.length, 12752 index = fromRight ? length : -1; 12753 12754 while ((fromRight ? index-- : ++index < length) && 12755 predicate(array[index], index, array)) {} 12756 12757 return isDrop 12758 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) 12759 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)); 12760 } 12761 12762 /** 12763 * The base implementation of `wrapperValue` which returns the result of 12764 * performing a sequence of actions on the unwrapped `value`, where each 12765 * successive action is supplied the return value of the previous. 12766 * 12767 * @private 12768 * @param {*} value The unwrapped value. 12769 * @param {Array} actions Actions to perform to resolve the unwrapped value. 12770 * @returns {*} Returns the resolved value. 12771 */ 12772 function baseWrapperValue(value, actions) { 12773 var result = value; 12774 if (result instanceof LazyWrapper) { 12775 result = result.value(); 12776 } 12777 return arrayReduce(actions, function(result, action) { 12778 return action.func.apply(action.thisArg, arrayPush([result], action.args
vendor: 40,684 bytes, lines 12778-13878
12778)); 12779 }, result); 12780 } 12781 12782 /** 12783 * The base implementation of methods like `_.xor`, without support for 12784 * iteratee shorthands, that accepts an array of arrays to inspect. 12785 * 12786 * @private 12787 * @param {Array} arrays The arrays to inspect. 12788 * @param {Function} [iteratee] The iteratee invoked per element. 12789 * @param {Function} [comparator] The comparator invoked per element. 12790 * @returns {Array} Returns the new array of values. 12791 */ 12792 function baseXor(arrays, iteratee, comparator) { 12793 var length = arrays.length; 12794 if (length < 2) { 12795 return length ? baseUniq(arrays[0]) : []; 12796 } 12797 var index = -1, 12798 result = Array(length); 12799 12800 while (++index < length) { 12801 var array = arrays[index], 12802 othIndex = -1; 12803 12804 while (++othIndex < length) { 12805 if (othIndex != index) { 12806 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator); 12807 } 12808 } 12809 } 12810 return baseUniq(baseFlatten(result, 1), iteratee, comparator); 12811 } 12812 12813 /** 12814 * This base implementation of `_.zipObject` which assigns values using `assignFunc`. 12815 * 12816 * @private 12817 * @param {Array} props The property identifiers. 12818 * @param {Array} values The property values. 12819 * @param {Function} assignFunc The function to assign values. 12820 * @returns {Object} Returns the new object. 12821 */ 12822 function baseZipObject(props, values, assignFunc) { 12823 var index = -1, 12824 length = props.length, 12825 valsLength = values.length, 12826 result = {}; 12827 12828 while (++index < length) { 12829 var value = index < valsLength ? values[index] : undefined$1; 12830 assignFunc(result, props[index], value); 12831 } 12832 return result; 12833 } 12834 12835 /** 12836 * Casts `value` to an empty array if it's not an array like object. 12837 * 12838 * @private 12839 * @param {*} value The value to inspect. 12840 * @returns {Array|Object} Returns the cast array-like object. 12841 */ 12842 function castArrayLikeObject(value) { 12843 return isArrayLikeObject(value) ? value : []; 12844 } 12845 12846 /** 12847 * Casts `value` to `identity` if it's not a function. 12848 * 12849 * @private 12850 * @param {*} value The value to inspect. 12851 * @returns {Function} Returns cast function. 12852 */ 12853 function castFunction(value) { 12854 return typeof value == 'function' ? value : identity; 12855 } 12856 12857 /** 12858 * Casts `value` to a path array if it's not one. 12859 * 12860 * @private 12861 * @param {*} value The value to inspect. 12862 * @param {Object} [object] The object to query keys on. 12863 * @returns {Array} Returns the cast property path array. 12864 */ 12865 function castPath(value, object) { 12866 if (isArray(value)) { 12867 return value; 12868 } 12869 return isKey(value, object) ? [value] : stringToPath(toString(value)); 12870 } 12871 12872 /** 12873 * A `baseRest` alias which can be replaced with `identity` by module 12874 * replacement plugins. 12875 * 12876 * @private 12877 * @type {Function} 12878 * @param {Function} func The function to apply a rest parameter to. 12879 * @returns {Function} Returns the new function. 12880 */ 12881 var castRest = baseRest; 12882 12883 /** 12884 * Casts `array` to a slice if it's needed. 12885 * 12886 * @private 12887 * @param {Array} array The array to inspect. 12888 * @param {number} start The start position. 12889 * @param {number} [end=array.length] The end position. 12890 * @returns {Array} Returns the cast slice. 12891 */ 12892 function castSlice(array, start, end) { 12893 var length = array.length; 12894 end = end === undefined$1 ? length : end; 12895 return (!start && end >= length) ? array : baseSlice(array, start, end); 12896 } 12897 12898 /** 12899 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout). 12900 * 12901 * @private 12902 * @param {number|Object} id The timer id or timeout object of the timer to clear. 12903 */ 12904 var clearTimeout = ctxClearTimeout || function(id) { 12905 return root.clearTimeout(id); 12906 }; 12907 12908 /** 12909 * Creates a clone of `buffer`. 12910 * 12911 * @private 12912 * @param {Buffer} buffer The buffer to clone. 12913 * @param {boolean} [isDeep] Specify a deep clone. 12914 * @returns {Buffer} Returns the cloned buffer. 12915 */ 12916 function cloneBuffer(buffer, isDeep) { 12917 if (isDeep) { 12918 return buffer.slice(); 12919 } 12920 var length = buffer.length, 12921 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); 12922 12923 buffer.copy(result); 12924 return result; 12925 } 12926 12927 /** 12928 * Creates a clone of `arrayBuffer`. 12929 * 12930 * @private 12931 * @param {ArrayBuffer} arrayBuffer The array buffer to clone. 12932 * @returns {ArrayBuffer} Returns the cloned array buffer. 12933 */ 12934 function cloneArrayBuffer(arrayBuffer) { 12935 var result = new arrayBuffer.constructor(arrayBuffer.byteLength); 12936 new Uint8Array(result).set(new Uint8Array(arrayBuffer)); 12937 return result; 12938 } 12939 12940 /** 12941 * Creates a clone of `dataView`. 12942 * 12943 * @private 12944 * @param {Object} dataView The data view to clone. 12945 * @param {boolean} [isDeep] Specify a deep clone. 12946 * @returns {Object} Returns the cloned data view. 12947 */ 12948 function cloneDataView(dataView, isDeep) { 12949 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; 12950 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); 12951 } 12952 12953 /** 12954 * Creates a clone of `regexp`. 12955 * 12956 * @private 12957 * @param {Object} regexp The regexp to clone. 12958 * @returns {Object} Returns the cloned regexp. 12959 */ 12960 function cloneRegExp(regexp) { 12961 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp)); 12962 result.lastIndex = regexp.lastIndex; 12963 return result; 12964 } 12965 12966 /** 12967 * Creates a clone of the `symbol` object. 12968 * 12969 * @private 12970 * @param {Object} symbol The symbol object to clone. 12971 * @returns {Object} Returns the cloned symbol object. 12972 */ 12973 function cloneSymbol(symbol) { 12974 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {}; 12975 } 12976 12977 /** 12978 * Creates a clone of `typedArray`. 12979 * 12980 * @private 12981 * @param {Object} typedArray The typed array to clone. 12982 * @param {boolean} [isDeep] Specify a deep clone. 12983 * @returns {Object} Returns the cloned typed array. 12984 */ 12985 function cloneTypedArray(typedArray, isDeep) { 12986 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer; 12987 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length); 12988 } 12989 12990 /** 12991 * Compares values to sort them in ascending order. 12992 * 12993 * @private 12994 * @param {*} value The value to compare. 12995 * @param {*} other The other value to compare. 12996 * @returns {number} Returns the sort order indicator for `value`. 12997 */ 12998 function compareAscending(value, other) { 12999 if (value !== other) { 13000 var valIsDefined = value !== undefined$1, 13001 valIsNull = value === null, 13002 valIsReflexive = value === value, 13003 valIsSymbol = isSymbol(value); 13004 13005 var othIsDefined = other !== undefined$1, 13006 othIsNull = other === null, 13007 othIsReflexive = other === other, 13008 othIsSymbol = isSymbol(other); 13009 13010 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || 13011 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || 13012 (valIsNull && othIsDefined && othIsReflexive) || 13013 (!valIsDefined && othIsReflexive) || 13014 !valIsReflexive) { 13015 return 1; 13016 } 13017 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || 13018 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || 13019 (othIsNull && valIsDefined && valIsReflexive) || 13020 (!othIsDefined && valIsReflexive) || 13021 !othIsReflexive) { 13022 return -1; 13023 } 13024 } 13025 return 0; 13026 } 13027 13028 /** 13029 * Used by `_.orderBy` to compare multiple properties of a value to another 13030 * and stable sort them. 13031 * 13032 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise, 13033 * specify an order of "desc" for descending or "asc" for ascending sort order 13034 * of corresponding values. 13035 * 13036 * @private 13037 * @param {Object} object The object to compare. 13038 * @param {Object} other The other object to compare. 13039 * @param {boolean[]|string[]} orders The order to sort by for each property. 13040 * @returns {number} Returns the sort order indicator for `object`. 13041 */ 13042 function compareMultiple(object, other, orders) { 13043 var index = -1, 13044 objCriteria = object.criteria, 13045 othCriteria = other.criteria, 13046 length = objCriteria.length, 13047 ordersLength = orders.length; 13048 13049 while (++index < length) { 13050 var result = compareAscending(objCriteria[index], othCriteria[index]); 13051 if (result) { 13052 if (index >= ordersLength) { 13053 return result; 13054 } 13055 var order = orders[index]; 13056 return result * (order == 'desc' ? -1 : 1); 13057 } 13058 } 13059 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications 13060 // that causes it, under certain circumstances, to provide the same value for 13061 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 13062 // for more details. 13063 // 13064 // This also ensures a stable sort in V8 and other engines. 13065 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. 13066 return object.index - other.index; 13067 } 13068 13069 /** 13070 * Creates an array that is the composition of partially applied arguments, 13071 * placeholders, and provided arguments into a single array of arguments. 13072 * 13073 * @private 13074 * @param {Array} args The provided arguments. 13075 * @param {Array} partials The arguments to prepend to those provided. 13076 * @param {Array} holders The `partials` placeholder indexes. 13077 * @params {boolean} [isCurried] Specify composing for a curried function. 13078 * @returns {Array} Returns the new array of composed arguments. 13079 */ 13080 function composeArgs(args, partials, holders, isCurried) { 13081 var argsIndex = -1, 13082 argsLength = args.length, 13083 holdersLength = holders.length, 13084 leftIndex = -1, 13085 leftLength = partials.length, 13086 rangeLength = nativeMax(argsLength - holdersLength, 0), 13087 result = Array(leftLength + rangeLength), 13088 isUncurried = !isCurried; 13089 13090 while (++leftIndex < leftLength) { 13091 result[leftIndex] = partials[leftIndex]; 13092 } 13093 while (++argsIndex < holdersLength) { 13094 if (isUncurried || argsIndex < argsLength) { 13095 result[holders[argsIndex]] = args[argsIndex]; 13096 } 13097 } 13098 while (rangeLength--) { 13099 result[leftIndex++] = args[argsIndex++]; 13100 } 13101 return result; 13102 } 13103 13104 /** 13105 * This function is like `composeArgs` except that the arguments composition 13106 * is tailored for `_.partialRight`. 13107 * 13108 * @private 13109 * @param {Array} args The provided arguments. 13110 * @param {Array} partials The arguments to append to those provided. 13111 * @param {Array} holders The `partials` placeholder indexes. 13112 * @params {boolean} [isCurried] Specify composing for a curried function. 13113 * @returns {Array} Returns the new array of composed arguments. 13114 */ 13115 function composeArgsRight(args, partials, holders, isCurried) { 13116 var argsIndex = -1, 13117 argsLength = args.length, 13118 holdersIndex = -1, 13119 holdersLength = holders.length, 13120 rightIndex = -1, 13121 rightLength = partials.length, 13122 rangeLength = nativeMax(argsLength - holdersLength, 0), 13123 result = Array(rangeLength + rightLength), 13124 isUncurried = !isCurried; 13125 13126 while (++argsIndex < rangeLength) { 13127 result[argsIndex] = args[argsIndex]; 13128 } 13129 var offset = argsIndex; 13130 while (++rightIndex < rightLength) { 13131 result[offset + rightIndex] = partials[rightIndex]; 13132 } 13133 while (++holdersIndex < holdersLength) { 13134 if (isUncurried || argsIndex < argsLength) { 13135 result[offset + holders[holdersIndex]] = args[argsIndex++]; 13136 } 13137 } 13138 return result; 13139 } 13140 13141 /** 13142 * Copies the values of `source` to `array`. 13143 * 13144 * @private 13145 * @param {Array} source The array to copy values from. 13146 * @param {Array} [array=[]] The array to copy values to. 13147 * @returns {Array} Returns `array`. 13148 */ 13149 function copyArray(source, array) { 13150 var index = -1, 13151 length = source.length; 13152 13153 array || (array = Array(length)); 13154 while (++index < length) { 13155 array[index] = source[index]; 13156 } 13157 return array; 13158 } 13159 13160 /** 13161 * Copies properties of `source` to `object`. 13162 * 13163 * @private 13164 * @param {Object} source The object to copy properties from. 13165 * @param {Array} props The property identifiers to copy. 13166 * @param {Object} [object={}] The object to copy properties to. 13167 * @param {Function} [customizer] The function to customize copied values. 13168 * @returns {Object} Returns `object`. 13169 */ 13170 function copyObject(source, props, object, customizer) { 13171 var isNew = !object; 13172 object || (object = {}); 13173 13174 var index = -1, 13175 length = props.length; 13176 13177 while (++index < length) { 13178 var key = props[index]; 13179 13180 var newValue = customizer 13181 ? customizer(object[key], source[key], key, object, source) 13182 : undefined$1; 13183 13184 if (newValue === undefined$1) { 13185 newValue = source[key]; 13186 } 13187 if (isNew) { 13188 baseAssignValue(object, key, newValue); 13189 } else { 13190 assignValue(object, key, newValue); 13191 } 13192 } 13193 return object; 13194 } 13195 13196 /** 13197 * Copies own symbols of `source` to `object`. 13198 * 13199 * @private 13200 * @param {Object} source The object to copy symbols from. 13201 * @param {Object} [object={}] The object to copy symbols to. 13202 * @returns {Object} Returns `object`. 13203 */ 13204 function copySymbols(source, object) { 13205 return copyObject(source, getSymbols(source), object); 13206 } 13207 13208 /** 13209 * Copies own and inherited symbols of `source` to `object`. 13210 * 13211 * @private 13212 * @param {Object} source The object to copy symbols from. 13213 * @param {Object} [object={}] The object to copy symbols to. 13214 * @returns {Object} Returns `object`. 13215 */ 13216 function copySymbolsIn(source, object) { 13217 return copyObject(source, getSymbolsIn(source), object); 13218 } 13219 13220 /** 13221 * Creates a function like `_.groupBy`. 13222 * 13223 * @private 13224 * @param {Function} setter The function to set accumulator values. 13225 * @param {Function} [initializer] The accumulator object initializer. 13226 * @returns {Function} Returns the new aggregator function. 13227 */ 13228 function createAggregator(setter, initializer) { 13229 return function(collection, iteratee) { 13230 var func = isArray(collection) ? arrayAggregator : baseAggregator, 13231 accumulator = initializer ? initializer() : {}; 13232 13233 return func(collection, setter, getIteratee(iteratee, 2), accumulator); 13234 }; 13235 } 13236 13237 /** 13238 * Creates a function like `_.assign`. 13239 * 13240 * @private 13241 * @param {Function} assigner The function to assign values. 13242 * @returns {Function} Returns the new assigner function. 13243 */ 13244 function createAssigner(assigner) { 13245 return baseRest(function(object, sources) { 13246 var index = -1, 13247 length = sources.length, 13248 customizer = length > 1 ? sources[length - 1] : undefined$1, 13249 guard = length > 2 ? sources[2] : undefined$1; 13250 13251 customizer = (assigner.length > 3 && typeof customizer == 'function') 13252 ? (length--, customizer) 13253 : undefined$1; 13254 13255 if (guard && isIterateeCall(sources[0], sources[1], guard)) { 13256 customizer = length < 3 ? undefined$1 : customizer; 13257 length = 1; 13258 } 13259 object = Object(object); 13260 while (++index < length) { 13261 var source = sources[index]; 13262 if (source) { 13263 assigner(object, source, index, customizer); 13264 } 13265 } 13266 return object; 13267 }); 13268 } 13269 13270 /** 13271 * Creates a `baseEach` or `baseEachRight` function. 13272 * 13273 * @private 13274 * @param {Function} eachFunc The function to iterate over a collection. 13275 * @param {boolean} [fromRight] Specify iterating from right to left. 13276 * @returns {Function} Returns the new base function. 13277 */ 13278 function createBaseEach(eachFunc, fromRight) { 13279 return function(collection, iteratee) { 13280 if (collection == null) { 13281 return collection; 13282 } 13283 if (!isArrayLike(collection)) { 13284 return eachFunc(collection, iteratee); 13285 } 13286 var length = collection.length, 13287 index = fromRight ? length : -1, 13288 iterable = Object(collection); 13289 13290 while ((fromRight ? index-- : ++index < length)) { 13291 if (iteratee(iterable[index], index, iterable) === false) { 13292 break; 13293 } 13294 } 13295 return collection; 13296 }; 13297 } 13298 13299 /** 13300 * Creates a base function for methods like `_.forIn` and `_.forOwn`. 13301 * 13302 * @private 13303 * @param {boolean} [fromRight] Specify iterating from right to left. 13304 * @returns {Function} Returns the new base function. 13305 */ 13306 function createBaseFor(fromRight) { 13307 return function(object, iteratee, keysFunc) { 13308 var index = -1, 13309 iterable = Object(object), 13310 props = keysFunc(object), 13311 length = props.length; 13312 13313 while (length--) { 13314 var key = props[fromRight ? length : ++index]; 13315 if (iteratee(iterable[key], key, iterable) === false) { 13316 break; 13317 } 13318 } 13319 return object; 13320 }; 13321 } 13322 13323 /** 13324 * Creates a function that wraps `func` to invoke it with the optional `this` 13325 * binding of `thisArg`. 13326 * 13327 * @private 13328 * @param {Function} func The function to wrap. 13329 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 13330 * @param {*} [thisArg] The `this` binding of `func`. 13331 * @returns {Function} Returns the new wrapped function. 13332 */ 13333 function createBind(func, bitmask, thisArg) { 13334 var isBind = bitmask & WRAP_BIND_FLAG, 13335 Ctor = createCtor(func); 13336 13337 function wrapper() { 13338 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; 13339 return fn.apply(isBind ? thisArg : this, arguments); 13340 } 13341 return wrapper; 13342 } 13343 13344 /** 13345 * Creates a function like `_.lowerFirst`. 13346 * 13347 * @private 13348 * @param {string} methodName The name of the `String` case method to use. 13349 * @returns {Function} Returns the new case function. 13350 */ 13351 function createCaseFirst(methodName) { 13352 return function(string) { 13353 string = toString(string); 13354 13355 var strSymbols = hasUnicode(string) 13356 ? stringToArray(string) 13357 : undefined$1; 13358 13359 var chr = strSymbols 13360 ? strSymbols[0] 13361 : string.charAt(0); 13362 13363 var trailing = strSymbols 13364 ? castSlice(strSymbols, 1).join('') 13365 : string.slice(1); 13366 13367 return chr[methodName]() + trailing; 13368 }; 13369 } 13370 13371 /** 13372 * Creates a function like `_.camelCase`. 13373 * 13374 * @private 13375 * @param {Function} callback The function to combine each word. 13376 * @returns {Function} Returns the new compounder function. 13377 */ 13378 function createCompounder(callback) { 13379 return function(string) { 13380 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); 13381 }; 13382 } 13383 13384 /** 13385 * Creates a function that produces an instance of `Ctor` regardless of 13386 * whether it was invoked as part of a `new` expression or by `call` or `apply`. 13387 * 13388 * @private 13389 * @param {Function} Ctor The constructor to wrap. 13390 * @returns {Function} Returns the new wrapped function. 13391 */ 13392 function createCtor(Ctor) { 13393 return function() { 13394 // Use a `switch` statement to work with class constructors. See 13395 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist 13396 // for more details. 13397 var args = arguments; 13398 switch (args.length) { 13399 case 0: return new Ctor; 13400 case 1: return new Ctor(args[0]); 13401 case 2: return new Ctor(args[0], args[1]); 13402 case 3: return new Ctor(args[0], args[1], args[2]); 13403 case 4: return new Ctor(args[0], args[1], args[2], args[3]); 13404 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); 13405 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); 13406 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); 13407 } 13408 var thisBinding = baseCreate(Ctor.prototype), 13409 result = Ctor.apply(thisBinding, args); 13410 13411 // Mimic the constructor's `return` behavior. 13412 // See https://es5.github.io/#x13.2.2 for more details. 13413 return isObject(result) ? result : thisBinding; 13414 }; 13415 } 13416 13417 /** 13418 * Creates a function that wraps `func` to enable currying. 13419 * 13420 * @private 13421 * @param {Function} func The function to wrap. 13422 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 13423 * @param {number} arity The arity of `func`. 13424 * @returns {Function} Returns the new wrapped function. 13425 */ 13426 function createCurry(func, bitmask, arity) { 13427 var Ctor = createCtor(func); 13428 13429 function wrapper() { 13430 var length = arguments.length, 13431 args = Array(length), 13432 index = length, 13433 placeholder = getHolder(wrapper); 13434 13435 while (index--) { 13436 args[index] = arguments[index]; 13437 } 13438 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) 13439 ? [] 13440 : replaceHolders(args, placeholder); 13441 13442 length -= holders.length; 13443 if (length < arity) { 13444 return createRecurry( 13445 func, bitmask, createHybrid, wrapper.placeholder, undefined$1, 13446 args, holders, undefined$1, undefined$1, arity - length); 13447 } 13448 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; 13449 return apply(fn, this, args); 13450 } 13451 return wrapper; 13452 } 13453 13454 /** 13455 * Creates a `_.find` or `_.findLast` function. 13456 * 13457 * @private 13458 * @param {Function} findIndexFunc The function to find the collection index. 13459 * @returns {Function} Returns the new find function. 13460 */ 13461 function createFind(findIndexFunc) { 13462 return function(collection, predicate, fromIndex) { 13463 var iterable = Object(collection); 13464 if (!isArrayLike(collection)) { 13465 var iteratee = getIteratee(predicate, 3); 13466 collection = keys(collection); 13467 predicate = function(key) { return iteratee(iterable[key], key, iterable); }; 13468 } 13469 var index = findIndexFunc(collection, predicate, fromIndex); 13470 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined$1; 13471 }; 13472 } 13473 13474 /** 13475 * Creates a `_.flow` or `_.flowRight` function. 13476 * 13477 * @private 13478 * @param {boolean} [fromRight] Specify iterating from right to left. 13479 * @returns {Function} Returns the new flow function. 13480 */ 13481 function createFlow(fromRight) { 13482 return flatRest(function(funcs) { 13483 var length = funcs.length, 13484 index = length, 13485 prereq = LodashWrapper.prototype.thru; 13486 13487 if (fromRight) { 13488 funcs.reverse(); 13489 } 13490 while (index--) { 13491 var func = funcs[index]; 13492 if (typeof func != 'function') { 13493 throw new TypeError(FUNC_ERROR_TEXT); 13494 } 13495 if (prereq && !wrapper && getFuncName(func) == 'wrapper') { 13496 var wrapper = new LodashWrapper([], true); 13497 } 13498 } 13499 index = wrapper ? index : length; 13500 while (++index < length) { 13501 func = funcs[index]; 13502 13503 var funcName = getFuncName(func), 13504 data = funcName == 'wrapper' ? getData(func) : undefined$1; 13505 13506 if (data && isLaziable(data[0]) && 13507 data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) && 13508 !data[4].length && data[9] == 1 13509 ) { 13510 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); 13511 } else { 13512 wrapper = (func.length == 1 && isLaziable(func)) 13513 ? wrapper[funcName]() 13514 : wrapper.thru(func); 13515 } 13516 } 13517 return function() { 13518 var args = arguments, 13519 value = args[0]; 13520 13521 if (wrapper && args.length == 1 && isArray(value)) { 13522 return wrapper.plant(value).value(); 13523 } 13524 var index = 0, 13525 result = length ? funcs[index].apply(this, args) : value; 13526 13527 while (++index < length) { 13528 result = funcs[index].call(this, result); 13529 } 13530 return result; 13531 }; 13532 }); 13533 } 13534 13535 /** 13536 * Creates a function that wraps `func` to invoke it with optional `this` 13537 * binding of `thisArg`, partial application, and currying. 13538 * 13539 * @private 13540 * @param {Function|string} func The function or method name to wrap. 13541 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 13542 * @param {*} [thisArg] The `this` binding of `func`. 13543 * @param {Array} [partials] The arguments to prepend to those provided to 13544 * the new function. 13545 * @param {Array} [holders] The `partials` placeholder indexes. 13546 * @param {Array} [partialsRight] The arguments to append to those provided 13547 * to the new function. 13548 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes. 13549 * @param {Array} [argPos] The argument positions of the new function. 13550 * @param {number} [ary] The arity cap of `func`. 13551 * @param {number} [arity] The arity of `func`. 13552 * @returns {Function} Returns the new wrapped function. 13553 */ 13554 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { 13555 var isAry = bitmask & WRAP_ARY_FLAG, 13556 isBind = bitmask & WRAP_BIND_FLAG, 13557 isBindKey = bitmask & WRAP_BIND_KEY_FLAG, 13558 isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), 13559 isFlip = bitmask & WRAP_FLIP_FLAG, 13560 Ctor = isBindKey ? undefined$1 : createCtor(func); 13561 13562 function wrapper() { 13563 var length = arguments.length, 13564 args = Array(length), 13565 index = length; 13566 13567 while (index--) { 13568 args[index] = arguments[index]; 13569 } 13570 if (isCurried) { 13571 var placeholder = getHolder(wrapper), 13572 holdersCount = countHolders(args, placeholder); 13573 } 13574 if (partials) { 13575 args = composeArgs(args, partials, holders, isCurried); 13576 } 13577 if (partialsRight) { 13578 args = composeArgsRight(args, partialsRight, holdersRight, isCurried); 13579 } 13580 length -= holdersCount; 13581 if (isCurried && length < arity) { 13582 var newHolders = replaceHolders(args, placeholder); 13583 return createRecurry( 13584 func, bitmask, createHybrid, wrapper.placeholder, thisArg, 13585 args, newHolders, argPos, ary, arity - length 13586 ); 13587 } 13588 var thisBinding = isBind ? thisArg : this, 13589 fn = isBindKey ? thisBinding[func] : func; 13590 13591 length = args.length; 13592 if (argPos) { 13593 args = reorder(args, argPos); 13594 } else if (isFlip && length > 1) { 13595 args.reverse(); 13596 } 13597 if (isAry && ary < length) { 13598 args.length = ary; 13599 } 13600 if (this && this !== root && this instanceof wrapper) { 13601 fn = Ctor || createCtor(fn); 13602 } 13603 return fn.apply(thisBinding, args); 13604 } 13605 return wrapper; 13606 } 13607 13608 /** 13609 * Creates a function like `_.invertBy`. 13610 * 13611 * @private 13612 * @param {Function} setter The function to set accumulator values. 13613 * @param {Function} toIteratee The function to resolve iteratees. 13614 * @returns {Function} Returns the new inverter function. 13615 */ 13616 function createInverter(setter, toIteratee) { 13617 return function(object, iteratee) { 13618 return baseInverter(object, setter, toIteratee(iteratee), {}); 13619 }; 13620 } 13621 13622 /** 13623 * Creates a function that performs a mathematical operation on two values. 13624 * 13625 * @private 13626 * @param {Function} operator The function to perform the operation. 13627 * @param {number} [defaultValue] The value used for `undefined` arguments. 13628 * @returns {Function} Returns the new mathematical operation function. 13629 */ 13630 function createMathOperation(operator, defaultValue) { 13631 return function(value, other) { 13632 var result; 13633 if (value === undefined$1 && other === undefined$1) { 13634 return defaultValue; 13635 } 13636 if (value !== undefined$1) { 13637 result = value; 13638 } 13639 if (other !== undefined$1) { 13640 if (result === undefined$1) { 13641 return other; 13642 } 13643 if (typeof value == 'string' || typeof other == 'string') { 13644 value = baseToString(value); 13645 other = baseToString(other); 13646 } else { 13647 value = baseToNumber(value); 13648 other = baseToNumber(other); 13649 } 13650 result = operator(value, other); 13651 } 13652 return result; 13653 }; 13654 } 13655 13656 /** 13657 * Creates a function like `_.over`. 13658 * 13659 * @private 13660 * @param {Function} arrayFunc The function to iterate over iteratees. 13661 * @returns {Function} Returns the new over function. 13662 */ 13663 function createOver(arrayFunc) { 13664 return flatRest(function(iteratees) { 13665 iteratees = arrayMap(iteratees, baseUnary(getIteratee())); 13666 return baseRest(function(args) { 13667 var thisArg = this; 13668 return arrayFunc(iteratees, function(iteratee) { 13669 return apply(iteratee, thisArg, args); 13670 }); 13671 }); 13672 }); 13673 } 13674 13675 /** 13676 * Creates the padding for `string` based on `length`. The `chars` string 13677 * is truncated if the number of characters exceeds `length`. 13678 * 13679 * @private 13680 * @param {number} length The padding length. 13681 * @param {string} [chars=' '] The string used as padding. 13682 * @returns {string} Returns the padding for `string`. 13683 */ 13684 function createPadding(length, chars) { 13685 chars = chars === undefined$1 ? ' ' : baseToString(chars); 13686 13687 var charsLength = chars.length; 13688 if (charsLength < 2) { 13689 return charsLength ? baseRepeat(chars, length) : chars; 13690 } 13691 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); 13692 return hasUnicode(chars) 13693 ? castSlice(stringToArray(result), 0, length).join('') 13694 : result.slice(0, length); 13695 } 13696 13697 /** 13698 * Creates a function that wraps `func` to invoke it with the `this` binding 13699 * of `thisArg` and `partials` prepended to the arguments it receives. 13700 * 13701 * @private 13702 * @param {Function} func The function to wrap. 13703 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 13704 * @param {*} thisArg The `this` binding of `func`. 13705 * @param {Array} partials The arguments to prepend to those provided to 13706 * the new function. 13707 * @returns {Function} Returns the new wrapped function. 13708 */ 13709 function createPartial(func, bitmask, thisArg, partials) { 13710 var isBind = bitmask & WRAP_BIND_FLAG, 13711 Ctor = createCtor(func); 13712 13713 function wrapper() { 13714 var argsIndex = -1, 13715 argsLength = arguments.length, 13716 leftIndex = -1, 13717 leftLength = partials.length, 13718 args = Array(leftLength + argsLength), 13719 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; 13720 13721 while (++leftIndex < leftLength) { 13722 args[leftIndex] = partials[leftIndex]; 13723 } 13724 while (argsLength--) { 13725 args[leftIndex++] = arguments[++argsIndex]; 13726 } 13727 return apply(fn, isBind ? thisArg : this, args); 13728 } 13729 return wrapper; 13730 } 13731 13732 /** 13733 * Creates a `_.range` or `_.rangeRight` function. 13734 * 13735 * @private 13736 * @param {boolean} [fromRight] Specify iterating from right to left. 13737 * @returns {Function} Returns the new range function. 13738 */ 13739 function createRange(fromRight) { 13740 return function(start, end, step) { 13741 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) { 13742 end = step = undefined$1; 13743 } 13744 // Ensure the sign of `-0` is preserved. 13745 start = toFinite(start); 13746 if (end === undefined$1) { 13747 end = start; 13748 start = 0; 13749 } else { 13750 end = toFinite(end); 13751 } 13752 step = step === undefined$1 ? (start < end ? 1 : -1) : toFinite(step); 13753 return baseRange(start, end, step, fromRight); 13754 }; 13755 } 13756 13757 /** 13758 * Creates a function that performs a relational operation on two values. 13759 * 13760 * @private 13761 * @param {Function} operator The function to perform the operation. 13762 * @returns {Function} Returns the new relational operation function. 13763 */ 13764 function createRelationalOperation(operator) { 13765 return function(value, other) { 13766 if (!(typeof value == 'string' && typeof other == 'string')) { 13767 value = toNumber(value); 13768 other = toNumber(other); 13769 } 13770 return operator(value, other); 13771 }; 13772 } 13773 13774 /** 13775 * Creates a function that wraps `func` to continue currying. 13776 * 13777 * @private 13778 * @param {Function} func The function to wrap. 13779 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 13780 * @param {Function} wrapFunc The function to create the `func` wrapper. 13781 * @param {*} placeholder The placeholder value. 13782 * @param {*} [thisArg] The `this` binding of `func`. 13783 * @param {Array} [partials] The arguments to prepend to those provided to 13784 * the new function. 13785 * @param {Array} [holders] The `partials` placeholder indexes. 13786 * @param {Array} [argPos] The argument positions of the new function. 13787 * @param {number} [ary] The arity cap of `func`. 13788 * @param {number} [arity] The arity of `func`. 13789 * @returns {Function} Returns the new wrapped function. 13790 */ 13791 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { 13792 var isCurry = bitmask & WRAP_CURRY_FLAG, 13793 newHolders = isCurry ? holders : undefined$1, 13794 newHoldersRight = isCurry ? undefined$1 : holders, 13795 newPartials = isCurry ? partials : undefined$1, 13796 newPartialsRight = isCurry ? undefined$1 : partials; 13797 13798 bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); 13799 bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); 13800 13801 if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) { 13802 bitmask &= -4; 13803 } 13804 var newData = [ 13805 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, 13806 newHoldersRight, argPos, ary, arity 13807 ]; 13808 13809 var result = wrapFunc.apply(undefined$1, newData); 13810 if (isLaziable(func)) { 13811 setData(result, newData); 13812 } 13813 result.placeholder = placeholder; 13814 return setWrapToString(result, func, bitmask); 13815 } 13816 13817 /** 13818 * Creates a function like `_.round`. 13819 * 13820 * @private 13821 * @param {string} methodName The name of the `Math` method to use when rounding. 13822 * @returns {Function} Returns the new round function. 13823 */ 13824 function createRound(methodName) { 13825 var func = Math[methodName]; 13826 return function(number, precision) { 13827 number = toNumber(number); 13828 precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); 13829 if (precision && nativeIsFinite(number)) { 13830 // Shift with exponential notation to avoid floating-point issues. 13831 // See [MDN](https://mdn.io/round#Examples) for more details. 13832 var pair = (toString(number) + 'e').split('e'), 13833 value = func(pair[0] + 'e' + (+pair[1] + precision)); 13834 13835 pair = (toString(value) + 'e').split('e'); 13836 return +(pair[0] + 'e' + (+pair[1] - precision)); 13837 } 13838 return func(number); 13839 }; 13840 } 13841 13842 /** 13843 * Creates a set object of `values`. 13844 * 13845 * @private 13846 * @param {Array} values The values to add to the set. 13847 * @returns {Object} Returns the new set. 13848 */ 13849 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { 13850 return new Set(values); 13851 }; 13852 13853 /** 13854 * Creates a `_.toPairs` or `_.toPairsIn` function. 13855 * 13856 * @private 13857 * @param {Function} keysFunc The function to get the keys of a given object. 13858 * @returns {Function} Returns the new pairs function. 13859 */ 13860 function createToPairs(keysFunc) { 13861 return function(object) { 13862 var tag = getTag(object); 13863 if (tag == mapTag) { 13864 return mapToArray(object); 13865 } 13866 if (tag == setTag) { 13867 return setToPairs(object); 13868 } 13869 return baseToPairs(object, keysFunc(object)); 13870 }; 13871 } 13872 13873 /** 13874 * Creates a function that either curries or invokes `func` with optional 13875 * `this` binding and partially applied arguments. 13876 * 13877 * @private 13878 * @param {Function|string}
13878 func The function or method name to wrap. 13879 * @param {number} bitmask The bitmask flags. 13880 * 1 - `_.bind` 13881 * 2 - `_.bindKey` 13882 * 4 - `_.curry` or `_.curryRight` of a bound function 13883 * 8 - `_.curry` 13884 * 16 - `_.curryRight` 13885 * 32 - `_.partial` 13886 * 64 - `_.partialRight` 13887 * 128 - `_.rearg` 13888 * 256 - `_.ary` 13889 * 512 - `_.flip` 13890 * @param {*} [thisArg] The `this` binding of `func`. 13891 * @param {Array} [partials] The arguments to be partially applied. 13892 * @param {Array} [holders] The `partials` placeholder indexes. 13893 * @param {Array} [argPos] The argument positions of the new function. 13894 * @param {number} [ary] The arity cap of `func`. 13895 * @param {number} [arity] The arity of `func`. 13896 * @returns {Function} Returns the new wrapped function. 13897 */ 13898 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { 13899 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG; 13900 if (!isBindKey && typeof func != 'function') { 13901 throw new TypeError(FUNC_ERROR_TEXT); 13902 } 13903 var length = partials ? partials.length : 0; 13904 if (!length) { 13905 bitmask &= -97; 13906 partials = holders = undefined$1; 13907 } 13908 ary = ary === undefined$1 ? ary : nativeMax(toInteger(ary), 0); 13909 arity = arity === undefined$1 ? arity : toInteger(arity); 13910 length -= holders ? holders.length : 0; 13911 13912 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) { 13913 var partialsRight = partials, 13914 holdersRight = holders; 13915 13916 partials = holders = undefined$1; 13917 } 13918 var data = isBindKey ? undefined$1 : getData(func); 13919 13920 var newData = [ 13921 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, 13922 argPos, ary, arity 13923 ]; 13924 13925 if (data) { 13926 mergeData(newData, data); 13927 } 13928 func = newData[0]; 13929 bitmask = newData[1]; 13930 thisArg = newData[2]; 13931 partials = newData[3]; 13932 holders = newData[4]; 13933 arity = newData[9] = newData[9] === undefined$1 13934 ? (isBindKey ? 0 : func.length) 13935 : nativeMax(newData[9] - length, 0); 13936 13937 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) { 13938 bitmask &= -25; 13939 } 13940 if (!bitmask || bitmask == WRAP_BIND_FLAG) { 13941 var result = createBind(func, bitmask, thisArg); 13942 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) { 13943 result = createCurry(func, bitmask, arity); 13944 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) { 13945 result = createPartial(func, bitmask, thisArg, partials); 13946 } else { 13947 result = createHybrid.apply(undefined$1, newData); 13948 } 13949 var setter = data ? baseSetData : setData; 13950 return setWrapToString(setter(result, newData), func, bitmask); 13951 } 13952 13953 /** 13954 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties 13955 * of source objects to the destination object for all destination properties 13956 * that resolve to `undefined`. 13957 * 13958 * @private 13959 * @param {*} objValue The destination value. 13960 * @param {*} srcValue The source value. 13961 * @param {string} key The key of the property to assign. 13962 * @param {Object} object The parent object of `objValue`. 13963 * @returns {*} Returns the value to assign. 13964 */ 13965 function customDefaultsAssignIn(objValue, srcValue, key, object) { 13966 if (objValue === undefined$1 || 13967 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { 13968 return srcValue; 13969 } 13970 return objValue; 13971 } 13972 13973 /** 13974 * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source 13975 * objects into destination objects that are passed thru. 13976 * 13977 * @private 13978 * @param {*} objValue The destination value. 13979 * @param {*} srcValue The source value. 13980 * @param {string} key The key of the property to merge. 13981 * @param {Object} object The parent object of `objValue`. 13982 * @param {Object} source The parent object of `srcValue`. 13983 * @param {Object} [stack] Tracks traversed source values and their merged 13984 * counterparts. 13985 * @returns {*} Returns the value to assign. 13986 */ 13987 function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { 13988 if (isObject(objValue) && isObject(srcValue)) { 13989 // Recursively merge objects and arrays (susceptible to call stack limits). 13990 stack.set(srcValue, objValue); 13991 baseMerge(objValue, srcValue, undefined$1, customDefaultsMerge, stack); 13992 stack['delete'](srcValue); 13993 } 13994 return objValue; 13995 } 13996 13997 /** 13998 * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain 13999 * objects. 14000 * 14001 * @private 14002 * @param {*} value The value to inspect. 14003 * @param {string} key The key of the property to inspect. 14004 * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`. 14005 */ 14006 function customOmitClone(value) { 14007 return isPlainObject(value) ? undefined$1 : value; 14008 } 14009 14010 /** 14011 * A specialized version of `baseIsEqualDeep` for arrays with support for 14012 * partial deep comparisons. 14013 * 14014 * @private 14015 * @param {Array} array The array to compare. 14016 * @param {Array} other The other array to compare. 14017 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 14018 * @param {Function} customizer The function to customize comparisons. 14019 * @param {Function} equalFunc The function to determine equivalents of values. 14020 * @param {Object} stack Tracks traversed `array` and `other` objects. 14021 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. 14022 */ 14023 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { 14024 var isPartial = bitmask & COMPARE_PARTIAL_FLAG, 14025 arrLength = array.length, 14026 othLength = other.length; 14027 14028 if (arrLength != othLength && !(isPartial && othLength > arrLength)) { 14029 return false;
vendor: 1,490 bytes, lines 14030-14069
14030 } 14031 // Check that cyclic values are equal. 14032 var arrStacked = stack.get(array); 14033 var othStacked = stack.get(other); 14034 if (arrStacked && othStacked) { 14035 return arrStacked == other && othStacked == array; 14036 } 14037 var index = -1, 14038 result = true, 14039 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined$1; 14040 14041 stack.set(array, other); 14042 stack.set(other, array); 14043 14044 // Ignore non-index properties. 14045 while (++index < arrLength) { 14046 var arrValue = array[index], 14047 othValue = other[index]; 14048 14049 if (customizer) { 14050 var compared = isPartial 14051 ? customizer(othValue, arrValue, index, other, array, stack) 14052 : customizer(arrValue, othValue, index, array, other, stack); 14053 } 14054 if (compared !== undefined$1) { 14055 if (compared) { 14056 continue; 14057 } 14058 result = false; 14059 break; 14060 } 14061 // Recursively compare arrays (susceptible to call stack limits). 14062 if (seen) { 14063 if (!arraySome(other, function(othValue, othIndex) { 14064 if (!cacheHas(seen, othIndex) && 14065 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { 14066 return seen.push(othIndex); 14067 } 14068 })) { 14069 result = false;
vendor: 4,482 bytes, lines 14070-14181
14070 break; 14071 } 14072 } else if (!( 14073 arrValue === othValue || 14074 equalFunc(arrValue, othValue, bitmask, customizer, stack) 14075 )) { 14076 result = false; 14077 break; 14078 } 14079 } 14080 stack['delete'](array); 14081 stack['delete'](other); 14082 return result; 14083 } 14084 14085 /** 14086 * A specialized version of `baseIsEqualDeep` for comparing objects of 14087 * the same `toStringTag`. 14088 * 14089 * **Note:** This function only supports comparing values with tags of 14090 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. 14091 * 14092 * @private 14093 * @param {Object} object The object to compare. 14094 * @param {Object} other The other object to compare. 14095 * @param {string} tag The `toStringTag` of the objects to compare. 14096 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 14097 * @param {Function} customizer The function to customize comparisons. 14098 * @param {Function} equalFunc The function to determine equivalents of values. 14099 * @param {Object} stack Tracks traversed `object` and `other` objects. 14100 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. 14101 */ 14102 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { 14103 switch (tag) { 14104 case dataViewTag: 14105 if ((object.byteLength != other.byteLength) || 14106 (object.byteOffset != other.byteOffset)) { 14107 return false; 14108 } 14109 object = object.buffer; 14110 other = other.buffer; 14111 14112 case arrayBufferTag: 14113 if ((object.byteLength != other.byteLength) || 14114 !equalFunc(new Uint8Array(object), new Uint8Array(other))) { 14115 return false; 14116 } 14117 return true; 14118 14119 case boolTag: 14120 case dateTag: 14121 case numberTag: 14122 // Coerce booleans to `1` or `0` and dates to milliseconds. 14123 // Invalid dates are coerced to `NaN`. 14124 return eq(+object, +other); 14125 14126 case errorTag: 14127 return object.name == other.name && object.message == other.message; 14128 14129 case regexpTag: 14130 case stringTag: 14131 // Coerce regexes to strings and treat strings, primitives and objects, 14132 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring 14133 // for more details. 14134 return object == (other + ''); 14135 14136 case mapTag: 14137 var convert = mapToArray; 14138 14139 case setTag: 14140 var isPartial = bitmask & COMPARE_PARTIAL_FLAG; 14141 convert || (convert = setToArray); 14142 14143 if (object.size != other.size && !isPartial) { 14144 return false; 14145 } 14146 // Assume cyclic values are equal. 14147 var stacked = stack.get(object); 14148 if (stacked) { 14149 return stacked == other; 14150 } 14151 bitmask |= COMPARE_UNORDERED_FLAG; 14152 14153 // Recursively compare objects (susceptible to call stack limits). 14154 stack.set(object, other); 14155 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack); 14156 stack['delete'](object); 14157 return result; 14158 14159 case symbolTag: 14160 if (symbolValueOf) { 14161 return symbolValueOf.call(object) == symbolValueOf.call(other); 14162 } 14163 } 14164 return false; 14165 } 14166 14167 /** 14168 * A specialized version of `baseIsEqualDeep` for objects with support for 14169 * partial deep comparisons. 14170 * 14171 * @private 14172 * @param {Object} object The object to compare. 14173 * @param {Object} other The other object to compare. 14174 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 14175 * @param {Function} customizer The function to customize comparisons. 14176 * @param {Function} equalFunc The function to determine equivalents of values. 14177 * @param {Object} stack Tracks traversed `object` and `other` objects. 14178 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. 14179 */ 14180 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { 14181 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
vendor: 1,558 bytes, lines 14182-14223
14182 objProps = getAllKeys(object), 14183 objLength = objProps.length, 14184 othProps = getAllKeys(other), 14185 othLength = othProps.length; 14186 14187 if (objLength != othLength && !isPartial) { 14188 return false; 14189 } 14190 var index = objLength; 14191 while (index--) { 14192 var key = objProps[index]; 14193 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { 14194 return false; 14195 } 14196 } 14197 // Check that cyclic values are equal. 14198 var objStacked = stack.get(object); 14199 var othStacked = stack.get(other); 14200 if (objStacked && othStacked) { 14201 return objStacked == other && othStacked == object; 14202 } 14203 var result = true; 14204 stack.set(object, other); 14205 stack.set(other, object); 14206 14207 var skipCtor = isPartial; 14208 while (++index < objLength) { 14209 key = objProps[index]; 14210 var objValue = object[key], 14211 othValue = other[key]; 14212 14213 if (customizer) { 14214 var compared = isPartial 14215 ? customizer(othValue, objValue, key, other, object, stack) 14216 : customizer(objValue, othValue, key, object, other, stack); 14217 } 14218 // Recursively compare objects (susceptible to call stack limits). 14219 if (!(compared === undefined$1 14220 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) 14221 : compared 14222 )) { 14223 result = false;
vendor: 4,299 bytes, lines 14224-14350
14224 break; 14225 } 14226 skipCtor || (skipCtor = key == 'constructor'); 14227 } 14228 if (result && !skipCtor) { 14229 var objCtor = object.constructor, 14230 othCtor = other.constructor; 14231 14232 // Non `Object` object instances with different constructors are not equal. 14233 if (objCtor != othCtor && 14234 ('constructor' in object && 'constructor' in other) && 14235 !(typeof objCtor == 'function' && objCtor instanceof objCtor && 14236 typeof othCtor == 'function' && othCtor instanceof othCtor)) { 14237 result = false; 14238 } 14239 } 14240 stack['delete'](object); 14241 stack['delete'](other); 14242 return result; 14243 } 14244 14245 /** 14246 * A specialized version of `baseRest` which flattens the rest array. 14247 * 14248 * @private 14249 * @param {Function} func The function to apply a rest parameter to. 14250 * @returns {Function} Returns the new function. 14251 */ 14252 function flatRest(func) { 14253 return setToString(overRest(func, undefined$1, flatten), func + ''); 14254 } 14255 14256 /** 14257 * Creates an array of own enumerable property names and symbols of `object`. 14258 * 14259 * @private 14260 * @param {Object} object The object to query. 14261 * @returns {Array} Returns the array of property names and symbols. 14262 */ 14263 function getAllKeys(object) { 14264 return baseGetAllKeys(object, keys, getSymbols); 14265 } 14266 14267 /** 14268 * Creates an array of own and inherited enumerable property names and 14269 * symbols of `object`. 14270 * 14271 * @private 14272 * @param {Object} object The object to query. 14273 * @returns {Array} Returns the array of property names and symbols. 14274 */ 14275 function getAllKeysIn(object) { 14276 return baseGetAllKeys(object, keysIn, getSymbolsIn); 14277 } 14278 14279 /** 14280 * Gets metadata for `func`. 14281 * 14282 * @private 14283 * @param {Function} func The function to query. 14284 * @returns {*} Returns the metadata for `func`. 14285 */ 14286 var getData = !metaMap ? noop : function(func) { 14287 return metaMap.get(func); 14288 }; 14289 14290 /** 14291 * Gets the name of `func`. 14292 * 14293 * @private 14294 * @param {Function} func The function to query. 14295 * @returns {string} Returns the function name. 14296 */ 14297 function getFuncName(func) { 14298 var result = (func.name + ''), 14299 array = realNames[result], 14300 length = hasOwnProperty.call(realNames, result) ? array.length : 0; 14301 14302 while (length--) { 14303 var data = array[length], 14304 otherFunc = data.func; 14305 if (otherFunc == null || otherFunc == func) { 14306 return data.name; 14307 } 14308 } 14309 return result; 14310 } 14311 14312 /** 14313 * Gets the argument placeholder value for `func`. 14314 * 14315 * @private 14316 * @param {Function} func The function to inspect. 14317 * @returns {*} Returns the placeholder value. 14318 */ 14319 function getHolder(func) { 14320 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func; 14321 return object.placeholder; 14322 } 14323 14324 /** 14325 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized, 14326 * this function returns the custom method, otherwise it returns `baseIteratee`. 14327 * If arguments are provided, the chosen function is invoked with them and 14328 * its result is returned. 14329 * 14330 * @private 14331 * @param {*} [value] The value to convert to an iteratee. 14332 * @param {number} [arity] The arity of the created iteratee. 14333 * @returns {Function} Returns the chosen function or its result. 14334 */ 14335 function getIteratee() { 14336 var result = lodash.iteratee || iteratee; 14337 result = result === iteratee ? baseIteratee : result; 14338 return arguments.length ? result(arguments[0], arguments[1]) : result; 14339 } 14340 14341 /** 14342 * Gets the data for `map`. 14343 * 14344 * @private 14345 * @param {Object} map The map to query. 14346 * @param {string} key The reference key. 14347 * @returns {*} Returns the map data. 14348 */ 14349 function getMapData(map, key) { 14350 var data = map.__data__;
vendor: 4,613 bytes, lines 14351-14489
14351 return isKeyable(key) 14352 ? data[typeof key == 'string' ? 'string' : 'hash'] 14353 : data.map; 14354 } 14355 14356 /** 14357 * Gets the property names, values, and compare flags of `object`. 14358 * 14359 * @private 14360 * @param {Object} object The object to query. 14361 * @returns {Array} Returns the match data of `object`. 14362 */ 14363 function getMatchData(object) { 14364 var result = keys(object), 14365 length = result.length; 14366 14367 while (length--) { 14368 var key = result[length], 14369 value = object[key]; 14370 14371 result[length] = [key, value, isStrictComparable(value)]; 14372 } 14373 return result; 14374 } 14375 14376 /** 14377 * Gets the native function at `key` of `object`. 14378 * 14379 * @private 14380 * @param {Object} object The object to query. 14381 * @param {string} key The key of the method to get. 14382 * @returns {*} Returns the function if it's native, else `undefined`. 14383 */ 14384 function getNative(object, key) { 14385 var value = getValue(object, key); 14386 return baseIsNative(value) ? value : undefined$1; 14387 } 14388 14389 /** 14390 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. 14391 * 14392 * @private 14393 * @param {*} value The value to query. 14394 * @returns {string} Returns the raw `toStringTag`. 14395 */ 14396 function getRawTag(value) { 14397 var isOwn = hasOwnProperty.call(value, symToStringTag), 14398 tag = value[symToStringTag]; 14399 14400 try { 14401 value[symToStringTag] = undefined$1; 14402 var unmasked = true; 14403 } catch (e) {} 14404 14405 var result = nativeObjectToString.call(value); 14406 if (unmasked) { 14407 if (isOwn) { 14408 value[symToStringTag] = tag; 14409 } else { 14410 delete value[symToStringTag]; 14411 } 14412 } 14413 return result; 14414 } 14415 14416 /** 14417 * Creates an array of the own enumerable symbols of `object`. 14418 * 14419 * @private 14420 * @param {Object} object The object to query. 14421 * @returns {Array} Returns the array of symbols. 14422 */ 14423 var getSymbols = !nativeGetSymbols ? stubArray : function(object) { 14424 if (object == null) { 14425 return []; 14426 } 14427 object = Object(object); 14428 return arrayFilter(nativeGetSymbols(object), function(symbol) { 14429 return propertyIsEnumerable.call(object, symbol); 14430 }); 14431 }; 14432 14433 /** 14434 * Creates an array of the own and inherited enumerable symbols of `object`. 14435 * 14436 * @private 14437 * @param {Object} object The object to query. 14438 * @returns {Array} Returns the array of symbols. 14439 */ 14440 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) { 14441 var result = []; 14442 while (object) { 14443 arrayPush(result, getSymbols(object)); 14444 object = getPrototype(object); 14445 } 14446 return result; 14447 }; 14448 14449 /** 14450 * Gets the `toStringTag` of `value`. 14451 * 14452 * @private 14453 * @param {*} value The value to query. 14454 * @returns {string} Returns the `toStringTag`. 14455 */ 14456 var getTag = baseGetTag; 14457 14458 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. 14459 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || 14460 (Map && getTag(new Map) != mapTag) || 14461 (Promise && getTag(Promise.resolve()) != promiseTag) || 14462 (Set && getTag(new Set) != setTag) || 14463 (WeakMap && getTag(new WeakMap) != weakMapTag)) { 14464 getTag = function(value) { 14465 var result = baseGetTag(value), 14466 Ctor = result == objectTag ? value.constructor : undefined$1, 14467 ctorString = Ctor ? toSource(Ctor) : ''; 14468 14469 if (ctorString) { 14470 switch (ctorString) { 14471 case dataViewCtorString: return dataViewTag; 14472 case mapCtorString: return mapTag; 14473 case promiseCtorString: return promiseTag; 14474 case setCtorString: return setTag; 14475 case weakMapCtorString: return weakMapTag; 14476 } 14477 } 14478 return result; 14479 }; 14480 } 14481 14482 /** 14483 * Gets the view, applying any `transforms` to the `start` and `end` positions. 14484 * 14485 * @private 14486 * @param {number} start The start of the view. 14487 * @param {number} end The end of the view. 14488 * @param {Array} transforms The transformations to apply to the view. 14489 * @returns {Object}
vendor: 11,201 bytes, lines 14489-14821
14489 Returns an object containing the `start` and `end` 14490 * positions of the view. 14491 */ 14492 function getView(start, end, transforms) { 14493 var index = -1, 14494 length = transforms.length; 14495 14496 while (++index < length) { 14497 var data = transforms[index], 14498 size = data.size; 14499 14500 switch (data.type) { 14501 case 'drop': start += size; break; 14502 case 'dropRight': end -= size; break; 14503 case 'take': end = nativeMin(end, start + size); break; 14504 case 'takeRight': start = nativeMax(start, end - size); break; 14505 } 14506 } 14507 return { 'start': start, 'end': end }; 14508 } 14509 14510 /** 14511 * Extracts wrapper details from the `source` body comment. 14512 * 14513 * @private 14514 * @param {string} source The source to inspect. 14515 * @returns {Array} Returns the wrapper details. 14516 */ 14517 function getWrapDetails(source) { 14518 var match = source.match(reWrapDetails); 14519 return match ? match[1].split(reSplitDetails) : []; 14520 } 14521 14522 /** 14523 * Checks if `path` exists on `object`. 14524 * 14525 * @private 14526 * @param {Object} object The object to query. 14527 * @param {Array|string} path The path to check. 14528 * @param {Function} hasFunc The function to check properties. 14529 * @returns {boolean} Returns `true` if `path` exists, else `false`. 14530 */ 14531 function hasPath(object, path, hasFunc) { 14532 path = castPath(path, object); 14533 14534 var index = -1, 14535 length = path.length, 14536 result = false; 14537 14538 while (++index < length) { 14539 var key = toKey(path[index]); 14540 if (!(result = object != null && hasFunc(object, key))) { 14541 break; 14542 } 14543 object = object[key]; 14544 } 14545 if (result || ++index != length) { 14546 return result; 14547 } 14548 length = object == null ? 0 : object.length; 14549 return !!length && isLength(length) && isIndex(key, length) && 14550 (isArray(object) || isArguments(object)); 14551 } 14552 14553 /** 14554 * Initializes an array clone. 14555 * 14556 * @private 14557 * @param {Array} array The array to clone. 14558 * @returns {Array} Returns the initialized clone. 14559 */ 14560 function initCloneArray(array) { 14561 var length = array.length, 14562 result = new array.constructor(length); 14563 14564 // Add properties assigned by `RegExp#exec`. 14565 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { 14566 result.index = array.index; 14567 result.input = array.input; 14568 } 14569 return result; 14570 } 14571 14572 /** 14573 * Initializes an object clone. 14574 * 14575 * @private 14576 * @param {Object} object The object to clone. 14577 * @returns {Object} Returns the initialized clone. 14578 */ 14579 function initCloneObject(object) { 14580 return (typeof object.constructor == 'function' && !isPrototype(object)) 14581 ? baseCreate(getPrototype(object)) 14582 : {}; 14583 } 14584 14585 /** 14586 * Initializes an object clone based on its `toStringTag`. 14587 * 14588 * **Note:** This function only supports cloning values with tags of 14589 * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. 14590 * 14591 * @private 14592 * @param {Object} object The object to clone. 14593 * @param {string} tag The `toStringTag` of the object to clone. 14594 * @param {boolean} [isDeep] Specify a deep clone. 14595 * @returns {Object} Returns the initialized clone. 14596 */ 14597 function initCloneByTag(object, tag, isDeep) { 14598 var Ctor = object.constructor; 14599 switch (tag) { 14600 case arrayBufferTag: 14601 return cloneArrayBuffer(object); 14602 14603 case boolTag: 14604 case dateTag: 14605 return new Ctor(+object); 14606 14607 case dataViewTag: 14608 return cloneDataView(object, isDeep); 14609 14610 case float32Tag: case float64Tag: 14611 case int8Tag: case int16Tag: case int32Tag: 14612 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: 14613 return cloneTypedArray(object, isDeep); 14614 14615 case mapTag: 14616 return new Ctor; 14617 14618 case numberTag: 14619 case stringTag: 14620 return new Ctor(object); 14621 14622 case regexpTag: 14623 return cloneRegExp(object); 14624 14625 case setTag: 14626 return new Ctor; 14627 14628 case symbolTag: 14629 return cloneSymbol(object); 14630 } 14631 } 14632 14633 /** 14634 * Inserts wrapper `details` in a comment at the top of the `source` body. 14635 * 14636 * @private 14637 * @param {string} source The source to modify. 14638 * @returns {Array} details The details to insert. 14639 * @returns {string} Returns the modified source. 14640 */ 14641 function insertWrapDetails(source, details) { 14642 var length = details.length; 14643 if (!length) { 14644 return source; 14645 } 14646 var lastIndex = length - 1; 14647 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; 14648 details = details.join(length > 2 ? ', ' : ' '); 14649 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); 14650 } 14651 14652 /** 14653 * Checks if `value` is a flattenable `arguments` object or array. 14654 * 14655 * @private 14656 * @param {*} value The value to check. 14657 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. 14658 */ 14659 function isFlattenable(value) { 14660 return isArray(value) || isArguments(value) || 14661 !!(spreadableSymbol && value && value[spreadableSymbol]); 14662 } 14663 14664 /** 14665 * Checks if `value` is a valid array-like index. 14666 * 14667 * @private 14668 * @param {*} value The value to check. 14669 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. 14670 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. 14671 */ 14672 function isIndex(value, length) { 14673 var type = typeof value; 14674 length = length == null ? MAX_SAFE_INTEGER : length; 14675 14676 return !!length && 14677 (type == 'number' || 14678 (type != 'symbol' && reIsUint.test(value))) && 14679 (value > -1 && value % 1 == 0 && value < length); 14680 } 14681 14682 /** 14683 * Checks if the given arguments are from an iteratee call. 14684 * 14685 * @private 14686 * @param {*} value The potential iteratee value argument. 14687 * @param {*} index The potential iteratee index or key argument. 14688 * @param {*} object The potential iteratee object argument. 14689 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, 14690 * else `false`. 14691 */ 14692 function isIterateeCall(value, index, object) { 14693 if (!isObject(object)) { 14694 return false; 14695 } 14696 var type = typeof index; 14697 if (type == 'number' 14698 ? (isArrayLike(object) && isIndex(index, object.length)) 14699 : (type == 'string' && index in object) 14700 ) { 14701 return eq(object[index], value); 14702 } 14703 return false; 14704 } 14705 14706 /** 14707 * Checks if `value` is a property name and not a property path. 14708 * 14709 * @private 14710 * @param {*} value The value to check. 14711 * @param {Object} [object] The object to query keys on. 14712 * @returns {boolean} Returns `true` if `value` is a property name, else `false`. 14713 */ 14714 function isKey(value, object) { 14715 if (isArray(value)) { 14716 return false; 14717 } 14718 var type = typeof value; 14719 if (type == 'number' || type == 'symbol' || type == 'boolean' || 14720 value == null || isSymbol(value)) { 14721 return true; 14722 } 14723 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || 14724 (object != null && value in Object(object)); 14725 } 14726 14727 /** 14728 * Checks if `value` is suitable for use as unique object key. 14729 * 14730 * @private 14731 * @param {*} value The value to check. 14732 * @returns {boolean} Returns `true` if `value` is suitable, else `false`. 14733 */ 14734 function isKeyable(value) { 14735 var type = typeof value; 14736 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') 14737 ? (value !== '__proto__') 14738 : (value === null); 14739 } 14740 14741 /** 14742 * Checks if `func` has a lazy counterpart. 14743 * 14744 * @private 14745 * @param {Function} func The function to check. 14746 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, 14747 * else `false`. 14748 */ 14749 function isLaziable(func) { 14750 var funcName = getFuncName(func), 14751 other = lodash[funcName]; 14752 14753 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) { 14754 return false; 14755 } 14756 if (func === other) { 14757 return true; 14758 } 14759 var data = getData(other); 14760 return !!data && func === data[0]; 14761 } 14762 14763 /** 14764 * Checks if `func` has its source masked. 14765 * 14766 * @private 14767 * @param {Function} func The function to check. 14768 * @returns {boolean} Returns `true` if `func` is masked, else `false`. 14769 */ 14770 function isMasked(func) { 14771 return !!maskSrcKey && (maskSrcKey in func); 14772 } 14773 14774 /** 14775 * Checks if `func` is capable of being masked. 14776 * 14777 * @private 14778 * @param {*} value The value to check. 14779 * @returns {boolean} Returns `true` if `func` is maskable, else `false`. 14780 */ 14781 var isMaskable = coreJsData ? isFunction : stubFalse; 14782 14783 /** 14784 * Checks if `value` is likely a prototype object. 14785 * 14786 * @private 14787 * @param {*} value The value to check. 14788 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. 14789 */ 14790 function isPrototype(value) { 14791 var Ctor = value && value.constructor, 14792 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; 14793 14794 return value === proto; 14795 } 14796 14797 /** 14798 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. 14799 * 14800 * @private 14801 * @param {*} value The value to check. 14802 * @returns {boolean} Returns `true` if `value` if suitable for strict 14803 * equality comparisons, else `false`. 14804 */ 14805 function isStrictComparable(value) { 14806 return value === value && !isObject(value); 14807 } 14808 14809 /** 14810 * A specialized version of `matchesProperty` for source values suitable 14811 * for strict equality comparisons, i.e. `===`. 14812 * 14813 * @private 14814 * @param {string} key The key of the property to get. 14815 * @param {*} srcValue The value to match. 14816 * @returns {Function} Returns the new spec function. 14817 */ 14818 function matchesStrictComparable(key, srcValue) { 14819 return function(object) { 14820 if (object == null) { 14821 return false;
vendor: 11,404 bytes, lines 14822-15141
14822 } 14823 return object[key] === srcValue && 14824 (srcValue !== undefined$1 || (key in Object(object))); 14825 }; 14826 } 14827 14828 /** 14829 * A specialized version of `_.memoize` which clears the memoized function's 14830 * cache when it exceeds `MAX_MEMOIZE_SIZE`. 14831 * 14832 * @private 14833 * @param {Function} func The function to have its output memoized. 14834 * @returns {Function} Returns the new memoized function. 14835 */ 14836 function memoizeCapped(func) { 14837 var result = memoize(func, function(key) { 14838 if (cache.size === MAX_MEMOIZE_SIZE) { 14839 cache.clear(); 14840 } 14841 return key; 14842 }); 14843 14844 var cache = result.cache; 14845 return result; 14846 } 14847 14848 /** 14849 * Merges the function metadata of `source` into `data`. 14850 * 14851 * Merging metadata reduces the number of wrappers used to invoke a function. 14852 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` 14853 * may be applied regardless of execution order. Methods like `_.ary` and 14854 * `_.rearg` modify function arguments, making the order in which they are 14855 * executed important, preventing the merging of metadata. However, we make 14856 * an exception for a safe combined case where curried functions have `_.ary` 14857 * and or `_.rearg` applied. 14858 * 14859 * @private 14860 * @param {Array} data The destination metadata. 14861 * @param {Array} source The source metadata. 14862 * @returns {Array} Returns `data`. 14863 */ 14864 function mergeData(data, source) { 14865 var bitmask = data[1], 14866 srcBitmask = source[1], 14867 newBitmask = bitmask | srcBitmask, 14868 isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG); 14869 14870 var isCombo = 14871 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) || 14872 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) || 14873 ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG)); 14874 14875 // Exit early if metadata can't be merged. 14876 if (!(isCommon || isCombo)) { 14877 return data; 14878 } 14879 // Use source `thisArg` if available. 14880 if (srcBitmask & WRAP_BIND_FLAG) { 14881 data[2] = source[2]; 14882 // Set when currying a bound function. 14883 newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG; 14884 } 14885 // Compose partial arguments. 14886 var value = source[3]; 14887 if (value) { 14888 var partials = data[3]; 14889 data[3] = partials ? composeArgs(partials, value, source[4]) : value; 14890 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; 14891 } 14892 // Compose partial right arguments. 14893 value = source[5]; 14894 if (value) { 14895 partials = data[5]; 14896 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; 14897 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; 14898 } 14899 // Use source `argPos` if available. 14900 value = source[7]; 14901 if (value) { 14902 data[7] = value; 14903 } 14904 // Use source `ary` if it's smaller. 14905 if (srcBitmask & WRAP_ARY_FLAG) { 14906 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); 14907 } 14908 // Use source `arity` if one is not provided. 14909 if (data[9] == null) { 14910 data[9] = source[9]; 14911 } 14912 // Use source `func` and merge bitmasks. 14913 data[0] = source[0]; 14914 data[1] = newBitmask; 14915 14916 return data; 14917 } 14918 14919 /** 14920 * This function is like 14921 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) 14922 * except that it includes inherited enumerable properties. 14923 * 14924 * @private 14925 * @param {Object} object The object to query. 14926 * @returns {Array} Returns the array of property names. 14927 */ 14928 function nativeKeysIn(object) { 14929 var result = []; 14930 if (object != null) { 14931 for (var key in Object(object)) { 14932 result.push(key); 14933 } 14934 } 14935 return result; 14936 } 14937 14938 /** 14939 * Converts `value` to a string using `Object.prototype.toString`. 14940 * 14941 * @private 14942 * @param {*} value The value to convert. 14943 * @returns {string} Returns the converted string. 14944 */ 14945 function objectToString(value) { 14946 return nativeObjectToString.call(value); 14947 } 14948 14949 /** 14950 * A specialized version of `baseRest` which transforms the rest array. 14951 * 14952 * @private 14953 * @param {Function} func The function to apply a rest parameter to. 14954 * @param {number} [start=func.length-1] The start position of the rest parameter. 14955 * @param {Function} transform The rest array transform. 14956 * @returns {Function} Returns the new function. 14957 */ 14958 function overRest(func, start, transform) { 14959 start = nativeMax(start === undefined$1 ? (func.length - 1) : start, 0); 14960 return function() { 14961 var args = arguments, 14962 index = -1, 14963 length = nativeMax(args.length - start, 0), 14964 array = Array(length); 14965 14966 while (++index < length) { 14967 array[index] = args[start + index]; 14968 } 14969 index = -1; 14970 var otherArgs = Array(start + 1); 14971 while (++index < start) { 14972 otherArgs[index] = args[index]; 14973 } 14974 otherArgs[start] = transform(array); 14975 return apply(func, this, otherArgs); 14976 }; 14977 } 14978 14979 /** 14980 * Gets the parent value at `path` of `object`. 14981 * 14982 * @private 14983 * @param {Object} object The object to query. 14984 * @param {Array} path The path to get the parent value of. 14985 * @returns {*} Returns the parent value. 14986 */ 14987 function parent(object, path) { 14988 return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1)); 14989 } 14990 14991 /** 14992 * Reorder `array` according to the specified indexes where the element at 14993 * the first index is assigned as the first element, the element at 14994 * the second index is assigned as the second element, and so on. 14995 * 14996 * @private 14997 * @param {Array} array The array to reorder. 14998 * @param {Array} indexes The arranged array indexes. 14999 * @returns {Array} Returns `array`. 15000 */ 15001 function reorder(array, indexes) { 15002 var arrLength = array.length, 15003 length = nativeMin(indexes.length, arrLength), 15004 oldArray = copyArray(array); 15005 15006 while (length--) { 15007 var index = indexes[length]; 15008 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined$1; 15009 } 15010 return array; 15011 } 15012 15013 /** 15014 * Gets the value at `key`, unless `key` is "__proto__" or "constructor". 15015 * 15016 * @private 15017 * @param {Object} object The object to query. 15018 * @param {string} key The key of the property to get. 15019 * @returns {*} Returns the property value. 15020 */ 15021 function safeGet(object, key) { 15022 if (key === 'constructor' && typeof object[key] === 'function') { 15023 return; 15024 } 15025 15026 if (key == '__proto__') { 15027 return; 15028 } 15029 15030 return object[key]; 15031 } 15032 15033 /** 15034 * Sets metadata for `func`. 15035 * 15036 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short 15037 * period of time, it will trip its breaker and transition to an identity 15038 * function to avoid garbage collection pauses in V8. See 15039 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070) 15040 * for more details. 15041 * 15042 * @private 15043 * @param {Function} func The function to associate metadata with. 15044 * @param {*} data The metadata. 15045 * @returns {Function} Returns `func`. 15046 */ 15047 var setData = shortOut(baseSetData); 15048 15049 /** 15050 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout). 15051 * 15052 * @private 15053 * @param {Function} func The function to delay. 15054 * @param {number} wait The number of milliseconds to delay invocation. 15055 * @returns {number|Object} Returns the timer id or timeout object. 15056 */ 15057 var setTimeout = ctxSetTimeout || function(func, wait) { 15058 return root.setTimeout(func, wait); 15059 }; 15060 15061 /** 15062 * Sets the `toString` method of `func` to return `string`. 15063 * 15064 * @private 15065 * @param {Function} func The function to modify. 15066 * @param {Function} string The `toString` result. 15067 * @returns {Function} Returns `func`. 15068 */ 15069 var setToString = shortOut(baseSetToString); 15070 15071 /** 15072 * Sets the `toString` method of `wrapper` to mimic the source of `reference` 15073 * with wrapper details in a comment at the top of the source body. 15074 * 15075 * @private 15076 * @param {Function} wrapper The function to modify. 15077 * @param {Function} reference The reference function. 15078 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 15079 * @returns {Function} Returns `wrapper`. 15080 */ 15081 function setWrapToString(wrapper, reference, bitmask) { 15082 var source = (reference + ''); 15083 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask))); 15084 } 15085 15086 /** 15087 * Creates a function that'll short out and invoke `identity` instead 15088 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` 15089 * milliseconds. 15090 * 15091 * @private 15092 * @param {Function} func The function to restrict. 15093 * @returns {Function} Returns the new shortable function. 15094 */ 15095 function shortOut(func) { 15096 var count = 0, 15097 lastCalled = 0; 15098 15099 return function() { 15100 var stamp = nativeNow(), 15101 remaining = HOT_SPAN - (stamp - lastCalled); 15102 15103 lastCalled = stamp; 15104 if (remaining > 0) { 15105 if (++count >= HOT_COUNT) { 15106 return arguments[0]; 15107 } 15108 } else { 15109 count = 0; 15110 } 15111 return func.apply(undefined$1, arguments); 15112 }; 15113 } 15114 15115 /** 15116 * A specialized version of `_.shuffle` which mutates and sets the size of `array`. 15117 * 15118 * @private 15119 * @param {Array} array The array to shuffle. 15120 * @param {number} [size=array.length] The size of `array`. 15121 * @returns {Array} Returns `array`. 15122 */ 15123 function shuffleSelf(array, size) { 15124 var index = -1, 15125 length = array.length, 15126 lastIndex = length - 1; 15127 15128 size = size === undefined$1 ? length : size; 15129 while (++index < size) { 15130 var rand = baseRandom(index, lastIndex), 15131 value = array[rand]; 15132 15133 array[rand] = array[index]; 15134 array[index] = value; 15135 } 15136 array.length = size; 15137 return array; 15138 } 15139 15140 /** 15141 * Converts `string` to a property path array.
15142 * 15143 * @private 15144 * @param {string} string The string to convert. 15145 * @returns {Array} Returns the property path array. 15146 */ 15147 var stringToPath = memoizeCapped(function(string) { 15148 var result = []; 15149 if (string.charCodeAt(0) === 46 /* . */) { 15150 result.push(''); 15151 } 15152 string.replace(rePropName, function(match, number, quote, subString) { 15153 result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); 15154 }); 15155 return result; 15156 }); 15157 15158 /** 15159 * Converts `value` to a string key if it's not a string or symbol. 15160 * 15161 * @private 15162 * @param {*} value The value to inspect. 15163 * @returns {string|symbol} Returns the key. 15164 */ 15165 function toKey(value) { 15166 if (typeof value == 'string' || isSymbol(value)) { 15167 return value; 15168 } 15169 var result = (value + ''); 15170 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; 15171 } 15172 15173 /** 15174 * Converts `func` to its source code. 15175 * 15176 * @private 15177 * @param {Function} func The function to convert. 15178 * @returns {string} Returns the source code. 15179 */ 15180 function toSource(func) { 15181 if (func != null) { 15182 try { 15183 return funcToString.call(func); 15184 } catch (e) {} 15185 try { 15186 return (func + ''); 15187 } catch (e) {} 15188 } 15189 return ''; 15190 } 15191 15192 /** 15193 * Updates wrapper `details` based on `bitmask` flags. 15194 * 15195 * @private 15196 * @returns {Array} details The details to modify. 15197 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 15198 * @returns {Array} Returns `details`. 15199 */ 15200 function updateWrapDetails(details, bitmask) { 15201 arrayEach(wrapFlags, function(pair) { 15202 var value = '_.' + pair[0];
vendor: 4,179 bytes, lines 15203-15338
15203 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { 15204 details.push(value); 15205 } 15206 }); 15207 return details.sort(); 15208 } 15209 15210 /** 15211 * Creates a clone of `wrapper`. 15212 * 15213 * @private 15214 * @param {Object} wrapper The wrapper to clone. 15215 * @returns {Object} Returns the cloned wrapper. 15216 */ 15217 function wrapperClone(wrapper) { 15218 if (wrapper instanceof LazyWrapper) { 15219 return wrapper.clone(); 15220 } 15221 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); 15222 result.__actions__ = copyArray(wrapper.__actions__); 15223 result.__index__ = wrapper.__index__; 15224 result.__values__ = wrapper.__values__; 15225 return result; 15226 } 15227 15228 /*------------------------------------------------------------------------*/ 15229 15230 /** 15231 * Creates an array of elements split into groups the length of `size`. 15232 * If `array` can't be split evenly, the final chunk will be the remaining 15233 * elements. 15234 * 15235 * @static 15236 * @memberOf _ 15237 * @since 3.0.0 15238 * @category Array 15239 * @param {Array} array The array to process. 15240 * @param {number} [size=1] The length of each chunk 15241 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 15242 * @returns {Array} Returns the new array of chunks. 15243 * @example 15244 * 15245 * _.chunk(['a', 'b', 'c', 'd'], 2); 15246 * // => [['a', 'b'], ['c', 'd']] 15247 * 15248 * _.chunk(['a', 'b', 'c', 'd'], 3); 15249 * // => [['a', 'b', 'c'], ['d']] 15250 */ 15251 function chunk(array, size, guard) { 15252 if ((guard ? isIterateeCall(array, size, guard) : size === undefined$1)) { 15253 size = 1; 15254 } else { 15255 size = nativeMax(toInteger(size), 0); 15256 } 15257 var length = array == null ? 0 : array.length; 15258 if (!length || size < 1) { 15259 return []; 15260 } 15261 var index = 0, 15262 resIndex = 0, 15263 result = Array(nativeCeil(length / size)); 15264 15265 while (index < length) { 15266 result[resIndex++] = baseSlice(array, index, (index += size)); 15267 } 15268 return result; 15269 } 15270 15271 /** 15272 * Creates an array with all falsey values removed. The values `false`, `null`, 15273 * `0`, `""`, `undefined`, and `NaN` are falsey. 15274 * 15275 * @static 15276 * @memberOf _ 15277 * @since 0.1.0 15278 * @category Array 15279 * @param {Array} array The array to compact. 15280 * @returns {Array} Returns the new array of filtered values. 15281 * @example 15282 * 15283 * _.compact([0, 1, false, 2, '', 3]); 15284 * // => [1, 2, 3] 15285 */ 15286 function compact(array) { 15287 var index = -1, 15288 length = array == null ? 0 : array.length, 15289 resIndex = 0, 15290 result = []; 15291 15292 while (++index < length) { 15293 var value = array[index]; 15294 if (value) { 15295 result[resIndex++] = value; 15296 } 15297 } 15298 return result; 15299 } 15300 15301 /** 15302 * Creates a new array concatenating `array` with any additional arrays 15303 * and/or values. 15304 * 15305 * @static 15306 * @memberOf _ 15307 * @since 4.0.0 15308 * @category Array 15309 * @param {Array} array The array to concatenate. 15310 * @param {...*} [values] The values to concatenate. 15311 * @returns {Array} Returns the new concatenated array. 15312 * @example 15313 * 15314 * var array = [1]; 15315 * var other = _.concat(array, 2, [3], [[4]]); 15316 * 15317 * console.log(other); 15318 * // => [1, 2, 3, [4]] 15319 * 15320 * console.log(array); 15321 * // => [1] 15322 */ 15323 function concat() { 15324 var length = arguments.length; 15325 if (!length) { 15326 return []; 15327 } 15328 var args = Array(length - 1), 15329 array = arguments[0], 15330 index = length; 15331 15332 while (index--) { 15333 args[index - 1] = arguments[index]; 15334 } 15335 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); 15336 } 15337 15338 /**
15339 * Creates an array of `array` values not included in the other given arrays 15340 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 15341 * for equality comparisons. The order and references of result values are 15342 * determined by the first array. 15343 * 15344 * **Note:** Unlike `_.pullAll`, this method returns a new array. 15345 * 15346 * @static 15347 * @memberOf _ 15348 * @since 0.1.0 15349 * @category Array 15350 * @param {Array} array The array to inspect. 15351 * @param {...Array} [values] The values to exclude. 15352 * @returns {Array} Returns the new array of filtered values. 15353 * @see _.without, _.xor 15354 * @example 15355 * 15356 * _.difference([2, 1], [2, 3]); 15357 * // => [1] 15358 */ 15359 var difference = baseRest(function(array, values) { 15360 return isArrayLikeObject(array) 15361 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) 15362 : []; 15363 }); 15364 15365 /** 15366 * This method is like `_.difference` except that it accepts `iteratee` which 15367 * is invoked for each element of `array` and `values` to generate the criterion 15368 * by which they're compared. The order and references of result values are 15369 * determined by the first array. The iteratee is invoked with one argument: 15370 * (value). 15371 * 15372 * **Note:** Unlike `_.pullAllBy`, this method returns a new array. 15373 * 15374 * @static 15375 * @memberOf _ 15376 * @since 4.0.0 15377 * @category Array 15378 * @param {Array} array The array to inspect. 15379 * @param {...Array} [values] The values to exclude. 15380 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 15381 * @returns {Array} Returns the new array of filtered values. 15382 * @example 15383 * 15384 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); 15385 * // => [1.2] 15386 * 15387 * // The `_.property` iteratee shorthand. 15388 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); 15389 * // => [{ 'x': 2 }] 15390 */ 15391 var differenceBy = baseRest(function(array, values) { 15392 var iteratee = last(values); 15393 if (isArrayLikeObject(iteratee)) { 15394 iteratee = undefined$1; 15395 } 15396 return isArrayLikeObject(array) 15397 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) 15398 : []; 15399 }); 15400 15401 /** 15402 * This method is like `_.difference` except that it accepts `comparator` 15403 * which is invoked to compare elements of `array` to `values`. The order and 15404 * references of result values are determined by the first array. The comparator 15405 * is invoked with two arguments: (arrVal, othVal). 15406 * 15407 * **Note:** Unlike `_.pullAllWith`, this method returns a new array. 15408 * 15409 * @static 15410 * @memberOf _ 15411 * @since 4.0.0 15412 * @category Array 15413 * @param {Array} array The array to inspect. 15414 * @param {...Array} [values] The values to exclude. 15415 * @param {Function} [comparator] The comparator invoked per element. 15416 * @returns {Array} Returns the new array of filtered values. 15417 * @example 15418 * 15419 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 15420 * 15421 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); 15422 * // => [{ 'x': 2, 'y': 1 }] 15423 */ 15424 var differenceWith = baseRest(function(array, values) { 15425 var comparator = last(values); 15426 if (isArrayLikeObject(comparator)) { 15427 comparator = undefined$1; 15428 } 15429 return isArrayLikeObject(array) 15430 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined$1, comparator) 15431 : []; 15432 }); 15433 15434 /** 15435 * Creates a slice of `array` with `n` elements dropped from the beginning. 15436 * 15437 * @static 15438 * @memberOf _ 15439 * @since 0.5.0 15440 * @category Array 15441 * @param {Array} array The array to query. 15442 * @param {number} [n=1] The number of elements to drop. 15443 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 15444 * @returns {Array} Returns the slice of `array`. 15445 * @example 15446 * 15447 * _.drop([1, 2, 3]); 15448 * // => [2, 3] 15449 * 15450 * _.drop([1, 2, 3], 2); 15451 * // => [3] 15452 * 15453 * _.drop([1, 2, 3], 5); 15454 * // => [] 15455 * 15456 * _.drop([1, 2, 3], 0); 15457 * // => [1, 2, 3] 15458 */ 15459 function drop(array, n, guard) { 15460 var length = array == null ? 0 : array.length; 15461 if (!length) { 15462 return []; 15463 } 15464 n = (guard || n === undefined$1) ? 1 : toInteger(n); 15465 return baseSlice(array, n < 0 ? 0 : n, length); 15466 } 15467 15468 /** 15469 * Creates a slice of `array` with `n` elements dropped from the end. 15470 * 15471 * @static 15472 * @memberOf _ 15473 * @since 3.0.0 15474 * @category Array 15475 * @param {Array} array The array to query. 15476 * @param {number} [n=1] The number of elements to drop. 15477 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 15478 * @returns {Array} Returns the slice of `array`. 15479 * @example 15480 * 15481 * _.dropRight([1, 2, 3]); 15482 * // => [1, 2] 15483 * 15484 * _.dropRight([1, 2, 3], 2); 15485 * // => [1] 15486 * 15487 * _.dropRight([1, 2, 3], 5); 15488 * // => [] 15489 * 15490 * _.dropRight([1, 2, 3], 0); 15491 * // => [1, 2, 3] 15492 */ 15493 function dropRight(array, n, guard) { 15494 var length = array == null ? 0 : array.length; 15495 if (!length) { 15496 return []; 15497 } 15498 n = (guard || n === undefined$1) ? 1 : toInteger(n); 15499 n = length - n; 15500 return baseSlice(array, 0, n < 0 ? 0 : n); 15501 } 15502 15503 /** 15504 * Creates a slice of `array` excluding elements dropped from the end. 15505 * Elements are dropped until `predicate` returns falsey. The predicate is 15506 * invoked with three arguments: (value, index, array). 15507 * 15508 * @static 15509 * @memberOf _ 15510 * @since 3.0.0 15511 * @category Array 15512 * @param {Array} array The array to query. 15513 * @param {Function} [predicate=_.identity] The function invoked per iteration. 15514 * @returns {Array} Returns the slice of `array`. 15515 * @example 15516 * 15517 * var users = [ 15518 * { 'user': 'barney', 'active': true }, 15519 * { 'user': 'fred', 'active': false }, 15520 * { 'user': 'pebbles', 'active': false } 15521 * ]; 15522 * 15523 * _.dropRightWhile(users, function(o) { return !o.active; }); 15524 * // => objects for ['barney'] 15525 * 15526 * // The `_.matches` iteratee shorthand. 15527 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); 15528 * // => objects for ['barney', 'fred'] 15529 * 15530 * // The `_.matchesProperty` iteratee shorthand. 15531 * _.dropRightWhile(users, ['active', false]); 15532 * // => objects for ['barney'] 15533 * 15534 * // The `_.property` iteratee shorthand. 15535 * _.dropRightWhile(users, 'active'); 15536 * // => objects for ['barney', 'fred', 'pebbles'] 15537 */ 15538 function dropRightWhile(array, predicate) { 15539 return (array && array.length) 15540 ? baseWhile(array, getIteratee(predicate, 3), true, true) 15541 : []; 15542 } 15543 15544 /** 15545 * Creates a slice of `array` excluding elements dropped from the beginning. 15546 * Elements are dropped until `predicate` returns falsey. The predicate is 15547 * invoked with three arguments: (value, index, array). 15548 * 15549 * @static 15550 * @memberOf _ 15551 * @since 3.0.0 15552 * @category Array 15553 * @param {Array} array The array to query. 15554 * @param {Function} [predicate=_.identity] The function invoked per iteration. 15555 * @returns {Array} Returns the slice of `array`. 15556 * @example 15557 * 15558 * var users = [ 15559 * { 'user': 'barney', 'active': false }, 15560 * { 'user': 'fred', 'active': false }, 15561 * { 'user': 'pebbles', 'active': true } 15562 * ]; 15563 * 15564 * _.dropWhile(users, function(o) { return !o.active; }); 15565 * // => objects for ['pebbles'] 15566 * 15567 * // The `_.matches` iteratee shorthand. 15568 * _.dropWhile(users, { 'user': 'barney', 'active': false }); 15569 * // => objects for ['fred', 'pebbles'] 15570 * 15571 * // The `_.matchesProperty` iteratee shorthand. 15572 * _.dropWhile(users, ['active', false]); 15573 * // => objects for ['pebbles'] 15574 * 15575 * // The `_.property` iteratee shorthand. 15576 * _.dropWhile(users, 'active'); 15577 * // => objects for ['barney', 'fred', 'pebbles'] 15578 */ 15579 function dropWhile(array, predicate) { 15580 return (array && array.length) 15581 ? baseWhile(array, getIteratee(predicate, 3), true) 15582 : []; 15583 } 15584 15585 /** 15586 * Fills elements of `array` with `value` from `start` up to, but not 15587 * including, `end`. 15588 * 15589 * **Note:** This method mutates `array`. 15590 * 15591 * @static 15592 * @memberOf _ 15593 * @since 3.2.0 15594 * @category Array 15595 * @param {Array} array The array to fill. 15596 * @param {*} value The value to fill `array` with. 15597 * @param {number} [start=0] The start position. 15598 * @param {number} [end=array.length] The end position. 15599 * @returns {Array} Returns `array`. 15600 * @example 15601 * 15602 * var array = [1, 2, 3]; 15603 * 15604 * _.fill(array, 'a'); 15605 * console.log(array); 15606 * // => ['a', 'a', 'a'] 15607 * 15608 * _.fill(Array(3), 2); 15609 * // => [2, 2, 2] 15610 * 15611 * _.fill([4, 6, 8, 10], '*', 1, 3); 15612 * // => [4, '*', '*', 10] 15613 */ 15614 function fill(array, value, start, end) { 15615 var length = array == null ? 0 : array.length; 15616 if (!length) { 15617 return []; 15618 } 15619 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { 15620 start = 0; 15621 end = length; 15622 } 15623 return baseFill(array, value, start, end); 15624 } 15625 15626 /** 15627 * This method is like `_.find` except that it returns the index of the first 15628 * element `predicate` returns truthy for instead of the element itself. 15629 * 15630 * @static 15631 * @memberOf _ 15632 * @since 1.1.0 15633 * @category Array 15634 * @param {Array} array The array to inspect. 15635 * @param {Function} [predicate=_.identity] The function invoked per iteration. 15636 * @param {number} [fromIndex=0] The index to search from. 15637 * @returns {number} Returns the index of the found element, else `-1`. 15638 * @example 15639 * 15640 * var users = [ 15641 * { 'user': 'barney', 'active': false }, 15642 * { 'user': 'fred', 'active': false }, 15643 * { 'user': 'pebbles', 'active': true } 15644 * ]; 15645 * 15646 * _.findIndex(users, function(o) { return o.user == 'barney'; }); 15647 * // => 0 15648 * 15649 * // The `_.matches` iteratee shorthand. 15650 * _.findIndex(users, { 'user': 'fred', 'active': false }); 15651 * // => 1 15652 * 15653 * // The `_.matchesProperty` iteratee shorthand. 15654 * _.findIndex(users, ['active', false]); 15655 * // => 0 15656 * 15657 * // The `_.property` iteratee shorthand. 15658 * _.findIndex(users, 'active'); 15659 * // => 2 15660 */ 15661 function findIndex(array, predicate, fromIndex) { 15662 var length = array == null ? 0 : array.length; 15663 if (!length) { 15664 return -1; 15665 } 15666 var index = fromIndex == null ? 0 : toInteger(fromIndex); 15667 if (index < 0) { 15668 index = nativeMax(length + index, 0); 15669 } 15670 return baseFindIndex(array, getIteratee(predicate, 3), index); 15671 } 15672 15673 /** 15674 * This method is like `_.findIndex` except that it iterates over elements 15675 * of `collection` from right to left. 15676 * 15677 * @static 15678 * @memberOf _ 15679 * @since 2.0.0 15680 * @category Array 15681 * @param {Array} array The array to inspect. 15682 * @param {Function} [predicate=_.identity] The function invoked per iteration. 15683 * @param {number} [fromIndex=array.length-1] The index to search from. 15684 * @returns {number} Returns the index of the found element, else `-1`. 15685 * @example 15686 * 15687 * var users = [ 15688 * { 'user': 'barney', 'active': true }, 15689 * { 'user': 'fred', 'active': false }, 15690 * { 'user': 'pebbles', 'active': false } 15691 * ]; 15692 * 15693 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); 15694 * // => 2 15695 * 15696 * // The `_.matches` iteratee shorthand. 15697 * _.findLastIndex(users, { 'user': 'barney', 'active': true }); 15698 * // => 0 15699 * 15700 * // The `_.matchesProperty` iteratee shorthand. 15701 * _.findLastIndex(users, ['active', false]); 15702 * // => 2 15703 * 15704 * // The `_.property` iteratee shorthand. 15705 * _.findLastIndex(users, 'active'); 15706 * // => 0 15707 */ 15708 function findLastIndex(array, predicate, fromIndex) { 15709 var length = array == null ? 0 : array.length; 15710 if (!length) { 15711 return -1; 15712 } 15713 var index = length - 1; 15714 if (fromIndex !== undefined$1) { 15715 index = toInteger(fromIndex); 15716 index = fromIndex < 0 15717 ? nativeMax(length + index, 0) 15718 : nativeMin(index, length - 1); 15719 } 15720 return baseFindIndex(array, getIteratee(predicate, 3), index, true); 15721 } 15722 15723 /** 15724 * Flattens `array` a single level deep. 15725 * 15726 * @static 15727 * @memberOf _ 15728 * @since 0.1.0 15729 * @category Array 15730 * @param {Array} array The array to flatten. 15731 * @returns {Array} Returns the new flattened array.
15732 * @example 15733 * 15734 * _.flatten([1, [2, [3, [4]], 5]]); 15735 * // => [1, 2, [3, [4]], 5] 15736 */ 15737 function flatten(array) { 15738 var length = array == null ? 0 : array.length; 15739 return length ? baseFlatten(array, 1) : []; 15740 } 15741 15742 /** 15743 * Recursively flattens `array`. 15744 * 15745 * @static 15746 * @memberOf _ 15747 * @since 3.0.0 15748 * @category Array 15749 * @param {Array} array The array to flatten. 15750 * @returns {Array} Returns the new flattened array. 15751 * @example 15752 * 15753 * _.flattenDeep([1, [2, [3, [4]], 5]]); 15754 * // => [1, 2, 3, 4, 5] 15755 */ 15756 function flattenDeep(array) { 15757 var length = array == null ? 0 : array.length; 15758 return length ? baseFlatten(array, INFINITY) : []; 15759 } 15760 15761 /** 15762 * Recursively flatten `array` up to `depth` times. 15763 * 15764 * @static 15765 * @memberOf _ 15766 * @since 4.4.0 15767 * @category Array 15768 * @param {Array} array The array to flatten. 15769 * @param {number} [depth=1] The maximum recursion depth. 15770 * @returns {Array} Returns the new flattened array. 15771 * @example 15772 * 15773 * var array = [1, [2, [3, [4]], 5]]; 15774 * 15775 * _.flattenDepth(array, 1); 15776 * // => [1, 2, [3, [4]], 5] 15777 * 15778 * _.flattenDepth(array, 2); 15779 * // => [1, 2, 3, [4], 5] 15780 */ 15781 function flattenDepth(array, depth) { 15782 var length = array == null ? 0 : array.length; 15783 if (!length) { 15784 return []; 15785 } 15786 depth = depth === undefined$1 ? 1 : toInteger(depth); 15787 return baseFlatten(array, depth); 15788 } 15789 15790 /** 15791 * The inverse of `_.toPairs`;
15791 this method returns an object composed 15792 * from key-value `pairs`. 15793 * 15794 * @static 15795 * @memberOf _ 15796 * @since 4.0.0 15797 * @category Array 15798 * @param {Array} pairs The key-value pairs. 15799 * @returns {Object} Returns the new object. 15800 * @example 15801 * 15802 * _.fromPairs([['a', 1], ['b', 2]]); 15803 * // => { 'a': 1, 'b': 2 } 15804 */ 15805 function fromPairs(pairs) { 15806 var index = -1, 15807 length = pairs == null ? 0 : pairs.length, 15808 result = {}; 15809 15810 while (++index < length) { 15811 var pair = pairs[index]; 15812 result[pair[0]] = pair[1]; 15813 } 15814 return result; 15815 } 15816 15817 /** 15818 * Gets the first element of `array`. 15819 * 15820 * @static 15821 * @memberOf _ 15822 * @since 0.1.0 15823 * @alias first 15824 * @category Array 15825 * @param {Array} array The array to query. 15826 * @returns {*} Returns the first element of `array`. 15827 * @example 15828 * 15829 * _.head([1, 2, 3]); 15830 * // => 1 15831 * 15832 * _.head([]); 15833 * // => undefined 15834 */ 15835 function head(array) { 15836 return (array && array.length) ? array[0] : undefined$1; 15837 } 15838 15839 /** 15840 * Gets the index at which the first occurrence of `value` is found in `array` 15841 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 15842 * for equality comparisons. If `fromIndex` is negative, it's used as the 15843 * offset from the end of `array`. 15844 * 15845 * @static 15846 * @memberOf _ 15847 * @since 0.1.0 15848 * @category Array 15849 * @param {Array} array The array to inspect. 15850 * @param {*} value The value to search for. 15851 * @param {number} [fromIndex=0] The index to search from. 15852 * @returns {number} Returns the index of the matched value, else `-1`. 15853 * @example 15854 * 15855 * _.indexOf([1, 2, 1, 2], 2); 15856 * // => 1 15857 * 15858 * // Search from the `fromIndex`. 15859 * _.indexOf([1, 2, 1, 2], 2, 2); 15860 * // => 3 15861 */ 15862 function indexOf(array, value, fromIndex) { 15863 var length = array == null ? 0 : array.length; 15864 if (!length) { 15865 return -1; 15866 } 15867 var index = fromIndex == null ? 0 : toInteger(fromIndex); 15868 if (index < 0) { 15869 index = nativeMax(length + index, 0); 15870 } 15871 return baseIndexOf(array, value, index); 15872 } 15873 15874 /** 15875 * Gets all but the last element of `array`. 15876 * 15877 * @static 15878 * @memberOf _ 15879 * @since 0.1.0 15880 * @category Array 15881 * @param {Array} array The array to query. 15882 * @returns {Array} Returns the slice of `array`. 15883 * @example 15884 * 15885 * _.initial([1, 2, 3]); 15886 * // => [1, 2] 15887 */ 15888 function initial(array) { 15889 var length = array == null ? 0 : array.length; 15890 return length ? baseSlice(array, 0, -1) : []; 15891 } 15892 15893 /** 15894 * Creates an array of unique values that are included in all given arrays 15895 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 15896 * for equality comparisons. The order and references of result values are 15897 * determined by the first array. 15898 * 15899 * @static 15900 * @memberOf _ 15901 * @since 0.1.0 15902 * @category Array 15903 * @param {...Array} [arrays] The arrays to inspect. 15904 * @returns {Array} Returns the new array of intersecting values. 15905 * @example 15906 * 15907 * _.intersection([2, 1], [2, 3]); 15908 * // => [2] 15909 */ 15910 var intersection = baseRest(function(arrays) { 15911 var mapped = arrayMap(arrays, castArrayLikeObject); 15912 return (mapped.length && mapped[0] === arrays[0]) 15913 ? baseIntersection(mapped) 15914 : []; 15915 }); 15916 15917 /** 15918 * This method is like `_.intersection` except that it accepts `iteratee` 15919 * which is invoked for each element of each `arrays` to generate the criterion 15920 * by which they're compared. The order and references of result values are 15921 * determined by the first array. The iteratee is invoked with one argument: 15922 * (value). 15923 * 15924 * @static 15925 * @memberOf _ 15926 * @since 4.0.0 15927 * @category Array 15928 * @param {...Array} [arrays] The arrays to inspect. 15929 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 15930 * @returns {Array} Returns the new array of intersecting values. 15931 * @example 15932 * 15933 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); 15934 * // => [2.1] 15935 * 15936 * // The `_.property` iteratee shorthand. 15937 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); 15938 * // => [{ 'x': 1 }] 15939 */ 15940 var intersectionBy = baseRest(function(arrays) { 15941 var iteratee = last(arrays), 15942 mapped = arrayMap(arrays, castArrayLikeObject); 15943 15944 if (iteratee === last(mapped)) { 15945 iteratee = undefined$1; 15946 } else { 15947 mapped.pop(); 15948 } 15949 return (mapped.length && mapped[0] === arrays[0]) 15950 ? baseIntersection(mapped, getIteratee(iteratee, 2)) 15951 : []; 15952 }); 15953 15954 /** 15955 * This method is like `_.intersection` except that it accepts `comparator` 15956 * which is invoked to compare elements of `arrays`. The order and references 15957 * of result values are determined by the first array. The comparator is 15958 * invoked with two arguments: (arrVal, othVal). 15959 * 15960 * @static 15961 * @memberOf _ 15962 * @since 4.0.0 15963 * @category Array 15964 * @param {...Array} [arrays] The arrays to inspect. 15965 * @param {Function} [comparator] The comparator invoked per element. 15966 * @returns {Array} Returns the new array of intersecting values. 15967 * @example 15968 * 15969 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 15970 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 15971 * 15972 * _.intersectionWith(objects, others, _.isEqual); 15973 * // => [{ 'x': 1, 'y': 2 }] 15974 */ 15975 var intersectionWith = baseRest(function(arrays) { 15976 var comparator = last(arrays), 15977 mapped = arrayMap(arrays, castArrayLikeObject); 15978 15979 comparator = typeof comparator == 'function' ? comparator : undefined$1; 15980 if (comparator) { 15981 mapped.pop(); 15982 } 15983 return (mapped.length && mapped[0] === arrays[0]) 15984 ? baseIntersection(mapped, undefined$1, comparator) 15985 : []; 15986 }); 15987 15988 /** 15989 * Converts all elements in `array` into a string separated by `separator`. 15990 * 15991 * @static 15992 * @memberOf _ 15993 * @since 4.0.0 15994 * @category Array 15995 * @param {Array} array The array to convert. 15996 * @param {string} [separator=','] The element separator. 15997 * @returns {string} Returns the joined string. 15998 * @example 15999 * 16000 * _.join(['a', 'b', 'c'], '~'); 16001 * // => 'a~b~c' 16002 */ 16003 function join(array, separator) { 16004 return array == null ? '' : nativeJoin.call(array, separator); 16005 } 16006 16007 /** 16008 * Gets the last element of `array`. 16009 * 16010 * @static 16011 * @memberOf _ 16012 * @since 0.1.0 16013 * @category Array 16014 * @param {Array} array The array to query. 16015 * @returns {*} Returns the last element of `array`. 16016 * @example 16017 * 16018 * _.last([1, 2, 3]); 16019 * // => 3 16020 */
vendor: 46,818 bytes, lines 16021-17412
16021 function last(array) { 16022 var length = array == null ? 0 : array.length; 16023 return length ? array[length - 1] : undefined$1; 16024 } 16025 16026 /** 16027 * This method is like `_.indexOf` except that it iterates over elements of 16028 * `array` from right to left. 16029 * 16030 * @static 16031 * @memberOf _ 16032 * @since 0.1.0 16033 * @category Array 16034 * @param {Array} array The array to inspect. 16035 * @param {*} value The value to search for. 16036 * @param {number} [fromIndex=array.length-1] The index to search from. 16037 * @returns {number} Returns the index of the matched value, else `-1`. 16038 * @example 16039 * 16040 * _.lastIndexOf([1, 2, 1, 2], 2); 16041 * // => 3 16042 * 16043 * // Search from the `fromIndex`. 16044 * _.lastIndexOf([1, 2, 1, 2], 2, 2); 16045 * // => 1 16046 */ 16047 function lastIndexOf(array, value, fromIndex) { 16048 var length = array == null ? 0 : array.length; 16049 if (!length) { 16050 return -1; 16051 } 16052 var index = length; 16053 if (fromIndex !== undefined$1) { 16054 index = toInteger(fromIndex); 16055 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1); 16056 } 16057 return value === value 16058 ? strictLastIndexOf(array, value, index) 16059 : baseFindIndex(array, baseIsNaN, index, true); 16060 } 16061 16062 /** 16063 * Gets the element at index `n` of `array`. If `n` is negative, the nth 16064 * element from the end is returned. 16065 * 16066 * @static 16067 * @memberOf _ 16068 * @since 4.11.0 16069 * @category Array 16070 * @param {Array} array The array to query. 16071 * @param {number} [n=0] The index of the element to return. 16072 * @returns {*} Returns the nth element of `array`. 16073 * @example 16074 * 16075 * var array = ['a', 'b', 'c', 'd']; 16076 * 16077 * _.nth(array, 1); 16078 * // => 'b' 16079 * 16080 * _.nth(array, -2); 16081 * // => 'c'; 16082 */ 16083 function nth(array, n) { 16084 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined$1; 16085 } 16086 16087 /** 16088 * Removes all given values from `array` using 16089 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 16090 * for equality comparisons. 16091 * 16092 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove` 16093 * to remove elements from an array by predicate. 16094 * 16095 * @static 16096 * @memberOf _ 16097 * @since 2.0.0 16098 * @category Array 16099 * @param {Array} array The array to modify. 16100 * @param {...*} [values] The values to remove. 16101 * @returns {Array} Returns `array`. 16102 * @example 16103 * 16104 * var array = ['a', 'b', 'c', 'a', 'b', 'c']; 16105 * 16106 * _.pull(array, 'a', 'c'); 16107 * console.log(array); 16108 * // => ['b', 'b'] 16109 */ 16110 var pull = baseRest(pullAll); 16111 16112 /** 16113 * This method is like `_.pull` except that it accepts an array of values to remove. 16114 * 16115 * **Note:** Unlike `_.difference`, this method mutates `array`. 16116 * 16117 * @static 16118 * @memberOf _ 16119 * @since 4.0.0 16120 * @category Array 16121 * @param {Array} array The array to modify. 16122 * @param {Array} values The values to remove. 16123 * @returns {Array} Returns `array`. 16124 * @example 16125 * 16126 * var array = ['a', 'b', 'c', 'a', 'b', 'c']; 16127 * 16128 * _.pullAll(array, ['a', 'c']); 16129 * console.log(array); 16130 * // => ['b', 'b'] 16131 */ 16132 function pullAll(array, values) { 16133 return (array && array.length && values && values.length) 16134 ? basePullAll(array, values) 16135 : array; 16136 } 16137 16138 /** 16139 * This method is like `_.pullAll` except that it accepts `iteratee` which is 16140 * invoked for each element of `array` and `values` to generate the criterion 16141 * by which they're compared. The iteratee is invoked with one argument: (value). 16142 * 16143 * **Note:** Unlike `_.differenceBy`, this method mutates `array`. 16144 * 16145 * @static 16146 * @memberOf _ 16147 * @since 4.0.0 16148 * @category Array 16149 * @param {Array} array The array to modify. 16150 * @param {Array} values The values to remove. 16151 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16152 * @returns {Array} Returns `array`. 16153 * @example 16154 * 16155 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; 16156 * 16157 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x'); 16158 * console.log(array); 16159 * // => [{ 'x': 2 }] 16160 */ 16161 function pullAllBy(array, values, iteratee) { 16162 return (array && array.length && values && values.length) 16163 ? basePullAll(array, values, getIteratee(iteratee, 2)) 16164 : array; 16165 } 16166 16167 /** 16168 * This method is like `_.pullAll` except that it accepts `comparator` which 16169 * is invoked to compare elements of `array` to `values`. The comparator is 16170 * invoked with two arguments: (arrVal, othVal). 16171 * 16172 * **Note:** Unlike `_.differenceWith`, this method mutates `array`. 16173 * 16174 * @static 16175 * @memberOf _ 16176 * @since 4.6.0 16177 * @category Array 16178 * @param {Array} array The array to modify. 16179 * @param {Array} values The values to remove. 16180 * @param {Function} [comparator] The comparator invoked per element. 16181 * @returns {Array} Returns `array`. 16182 * @example 16183 * 16184 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }]; 16185 * 16186 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual); 16187 * console.log(array); 16188 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] 16189 */ 16190 function pullAllWith(array, values, comparator) { 16191 return (array && array.length && values && values.length) 16192 ? basePullAll(array, values, undefined$1, comparator) 16193 : array; 16194 } 16195 16196 /** 16197 * Removes elements from `array` corresponding to `indexes` and returns an 16198 * array of removed elements. 16199 * 16200 * **Note:** Unlike `_.at`, this method mutates `array`. 16201 * 16202 * @static 16203 * @memberOf _ 16204 * @since 3.0.0 16205 * @category Array 16206 * @param {Array} array The array to modify. 16207 * @param {...(number|number[])} [indexes] The indexes of elements to remove. 16208 * @returns {Array} Returns the new array of removed elements. 16209 * @example 16210 * 16211 * var array = ['a', 'b', 'c', 'd']; 16212 * var pulled = _.pullAt(array, [1, 3]); 16213 * 16214 * console.log(array); 16215 * // => ['a', 'c'] 16216 * 16217 * console.log(pulled); 16218 * // => ['b', 'd'] 16219 */ 16220 var pullAt = flatRest(function(array, indexes) { 16221 var length = array == null ? 0 : array.length, 16222 result = baseAt(array, indexes); 16223 16224 basePullAt(array, arrayMap(indexes, function(index) { 16225 return isIndex(index, length) ? +index : index; 16226 }).sort(compareAscending)); 16227 16228 return result; 16229 }); 16230 16231 /** 16232 * Removes all elements from `array` that `predicate` returns truthy for 16233 * and returns an array of the removed elements. The predicate is invoked 16234 * with three arguments: (value, index, array). 16235 * 16236 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull` 16237 * to pull elements from an array by value. 16238 * 16239 * @static 16240 * @memberOf _ 16241 * @since 2.0.0 16242 * @category Array 16243 * @param {Array} array The array to modify. 16244 * @param {Function} [predicate=_.identity] The function invoked per iteration. 16245 * @returns {Array} Returns the new array of removed elements. 16246 * @example 16247 * 16248 * var array = [1, 2, 3, 4]; 16249 * var evens = _.remove(array, function(n) { 16250 * return n % 2 == 0; 16251 * }); 16252 * 16253 * console.log(array); 16254 * // => [1, 3] 16255 * 16256 * console.log(evens); 16257 * // => [2, 4] 16258 */ 16259 function remove(array, predicate) { 16260 var result = []; 16261 if (!(array && array.length)) { 16262 return result; 16263 } 16264 var index = -1, 16265 indexes = [], 16266 length = array.length; 16267 16268 predicate = getIteratee(predicate, 3); 16269 while (++index < length) { 16270 var value = array[index]; 16271 if (predicate(value, index, array)) { 16272 result.push(value); 16273 indexes.push(index); 16274 } 16275 } 16276 basePullAt(array, indexes); 16277 return result; 16278 } 16279 16280 /** 16281 * Reverses `array` so that the first element becomes the last, the second 16282 * element becomes the second to last, and so on. 16283 * 16284 * **Note:** This method mutates `array` and is based on 16285 * [`Array#reverse`](https://mdn.io/Array/reverse). 16286 * 16287 * @static 16288 * @memberOf _ 16289 * @since 4.0.0 16290 * @category Array 16291 * @param {Array} array The array to modify. 16292 * @returns {Array} Returns `array`. 16293 * @example 16294 * 16295 * var array = [1, 2, 3]; 16296 * 16297 * _.reverse(array); 16298 * // => [3, 2, 1] 16299 * 16300 * console.log(array); 16301 * // => [3, 2, 1] 16302 */ 16303 function reverse(array) { 16304 return array == null ? array : nativeReverse.call(array); 16305 } 16306 16307 /** 16308 * Creates a slice of `array` from `start` up to, but not including, `end`. 16309 * 16310 * **Note:** This method is used instead of 16311 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are 16312 * returned. 16313 * 16314 * @static 16315 * @memberOf _ 16316 * @since 3.0.0 16317 * @category Array 16318 * @param {Array} array The array to slice. 16319 * @param {number} [start=0] The start position. 16320 * @param {number} [end=array.length] The end position. 16321 * @returns {Array} Returns the slice of `array`. 16322 */ 16323 function slice(array, start, end) { 16324 var length = array == null ? 0 : array.length; 16325 if (!length) { 16326 return []; 16327 } 16328 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) { 16329 start = 0; 16330 end = length; 16331 } 16332 else { 16333 start = start == null ? 0 : toInteger(start); 16334 end = end === undefined$1 ? length : toInteger(end); 16335 } 16336 return baseSlice(array, start, end); 16337 } 16338 16339 /** 16340 * Uses a binary search to determine the lowest index at which `value` 16341 * should be inserted into `array` in order to maintain its sort order. 16342 * 16343 * @static 16344 * @memberOf _ 16345 * @since 0.1.0 16346 * @category Array 16347 * @param {Array} array The sorted array to inspect. 16348 * @param {*} value The value to evaluate. 16349 * @returns {number} Returns the index at which `value` should be inserted 16350 * into `array`. 16351 * @example 16352 * 16353 * _.sortedIndex([30, 50], 40); 16354 * // => 1 16355 */ 16356 function sortedIndex(array, value) { 16357 return baseSortedIndex(array, value); 16358 } 16359 16360 /** 16361 * This method is like `_.sortedIndex` except that it accepts `iteratee` 16362 * which is invoked for `value` and each element of `array` to compute their 16363 * sort ranking. The iteratee is invoked with one argument: (value). 16364 * 16365 * @static 16366 * @memberOf _ 16367 * @since 4.0.0 16368 * @category Array 16369 * @param {Array} array The sorted array to inspect. 16370 * @param {*} value The value to evaluate. 16371 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16372 * @returns {number} Returns the index at which `value` should be inserted 16373 * into `array`. 16374 * @example 16375 * 16376 * var objects = [{ 'x': 4 }, { 'x': 5 }]; 16377 * 16378 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); 16379 * // => 0 16380 * 16381 * // The `_.property` iteratee shorthand. 16382 * _.sortedIndexBy(objects, { 'x': 4 }, 'x'); 16383 * // => 0 16384 */ 16385 function sortedIndexBy(array, value, iteratee) { 16386 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2)); 16387 } 16388 16389 /** 16390 * This method is like `_.indexOf` except that it performs a binary 16391 * search on a sorted `array`. 16392 * 16393 * @static 16394 * @memberOf _ 16395 * @since 4.0.0 16396 * @category Array 16397 * @param {Array} array The array to inspect. 16398 * @param {*} value The value to search for. 16399 * @returns {number} Returns the index of the matched value, else `-1`. 16400 * @example 16401 * 16402 * _.sortedIndexOf([4, 5, 5, 5, 6], 5); 16403 * // => 1 16404 */ 16405 function sortedIndexOf(array, value) { 16406 var length = array == null ? 0 : array.length; 16407 if (length) { 16408 var index = baseSortedIndex(array, value); 16409 if (index < length && eq(array[index], value)) { 16410 return index; 16411 } 16412 } 16413 return -1; 16414 } 16415 16416 /** 16417 * This method is like `_.sortedIndex` except that it returns the highest 16418 * index at which `value` should be inserted into `array` in order to 16419 * maintain its sort order. 16420 * 16421 * @static 16422 * @memberOf _ 16423 * @since 3.0.0 16424 * @category Array 16425 * @param {Array} array The sorted array to inspect. 16426 * @param {*} value The value to evaluate. 16427 * @returns {number} Returns the index at which `value` should be inserted 16428 * into `array`. 16429 * @example 16430 * 16431 * _.sortedLastIndex([4, 5, 5, 5, 6], 5); 16432 * // => 4 16433 */ 16434 function sortedLastIndex(array, value) { 16435 return baseSortedIndex(array, value, true); 16436 } 16437 16438 /** 16439 * This method is like `_.sortedLastIndex` except that it accepts `iteratee` 16440 * which is invoked for `value` and each element of `array` to compute their 16441 * sort ranking. The iteratee is invoked with one argument: (value). 16442 * 16443 * @static 16444 * @memberOf _ 16445 * @since 4.0.0 16446 * @category Array 16447 * @param {Array} array The sorted array to inspect. 16448 * @param {*} value The value to evaluate. 16449 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16450 * @returns {number} Returns the index at which `value` should be inserted 16451 * into `array`. 16452 * @example 16453 * 16454 * var objects = [{ 'x': 4 }, { 'x': 5 }]; 16455 * 16456 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); 16457 * // => 1 16458 * 16459 * // The `_.property` iteratee shorthand. 16460 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x'); 16461 * // => 1 16462 */ 16463 function sortedLastIndexBy(array, value, iteratee) { 16464 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true); 16465 } 16466 16467 /** 16468 * This method is like `_.lastIndexOf` except that it performs a binary 16469 * search on a sorted `array`. 16470 * 16471 * @static 16472 * @memberOf _ 16473 * @since 4.0.0 16474 * @category Array 16475 * @param {Array} array The array to inspect. 16476 * @param {*} value The value to search for. 16477 * @returns {number} Returns the index of the matched value, else `-1`. 16478 * @example 16479 * 16480 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5); 16481 * // => 3 16482 */ 16483 function sortedLastIndexOf(array, value) { 16484 var length = array == null ? 0 : array.length; 16485 if (length) { 16486 var index = baseSortedIndex(array, value, true) - 1; 16487 if (eq(array[index], value)) { 16488 return index; 16489 } 16490 } 16491 return -1; 16492 } 16493 16494 /** 16495 * This method is like `_.uniq` except that it's designed and optimized 16496 * for sorted arrays. 16497 * 16498 * @static 16499 * @memberOf _ 16500 * @since 4.0.0 16501 * @category Array 16502 * @param {Array} array The array to inspect. 16503 * @returns {Array} Returns the new duplicate free array. 16504 * @example 16505 * 16506 * _.sortedUniq([1, 1, 2]); 16507 * // => [1, 2] 16508 */ 16509 function sortedUniq(array) { 16510 return (array && array.length) 16511 ? baseSortedUniq(array) 16512 : []; 16513 } 16514 16515 /** 16516 * This method is like `_.uniqBy` except that it's designed and optimized 16517 * for sorted arrays. 16518 * 16519 * @static 16520 * @memberOf _ 16521 * @since 4.0.0 16522 * @category Array 16523 * @param {Array} array The array to inspect. 16524 * @param {Function} [iteratee] The iteratee invoked per element. 16525 * @returns {Array} Returns the new duplicate free array. 16526 * @example 16527 * 16528 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); 16529 * // => [1.1, 2.3] 16530 */ 16531 function sortedUniqBy(array, iteratee) { 16532 return (array && array.length) 16533 ? baseSortedUniq(array, getIteratee(iteratee, 2)) 16534 : []; 16535 } 16536 16537 /** 16538 * Gets all but the first element of `array`. 16539 * 16540 * @static 16541 * @memberOf _ 16542 * @since 4.0.0 16543 * @category Array 16544 * @param {Array} array The array to query. 16545 * @returns {Array} Returns the slice of `array`. 16546 * @example 16547 * 16548 * _.tail([1, 2, 3]); 16549 * // => [2, 3] 16550 */ 16551 function tail(array) { 16552 var length = array == null ? 0 : array.length; 16553 return length ? baseSlice(array, 1, length) : []; 16554 } 16555 16556 /** 16557 * Creates a slice of `array` with `n` elements taken from the beginning. 16558 * 16559 * @static 16560 * @memberOf _ 16561 * @since 0.1.0 16562 * @category Array 16563 * @param {Array} array The array to query. 16564 * @param {number} [n=1] The number of elements to take. 16565 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 16566 * @returns {Array} Returns the slice of `array`. 16567 * @example 16568 * 16569 * _.take([1, 2, 3]); 16570 * // => [1] 16571 * 16572 * _.take([1, 2, 3], 2); 16573 * // => [1, 2] 16574 * 16575 * _.take([1, 2, 3], 5); 16576 * // => [1, 2, 3] 16577 * 16578 * _.take([1, 2, 3], 0); 16579 * // => [] 16580 */ 16581 function take(array, n, guard) { 16582 if (!(array && array.length)) { 16583 return []; 16584 } 16585 n = (guard || n === undefined$1) ? 1 : toInteger(n); 16586 return baseSlice(array, 0, n < 0 ? 0 : n); 16587 } 16588 16589 /** 16590 * Creates a slice of `array` with `n` elements taken from the end. 16591 * 16592 * @static 16593 * @memberOf _ 16594 * @since 3.0.0 16595 * @category Array 16596 * @param {Array} array The array to query. 16597 * @param {number} [n=1] The number of elements to take. 16598 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 16599 * @returns {Array} Returns the slice of `array`. 16600 * @example 16601 * 16602 * _.takeRight([1, 2, 3]); 16603 * // => [3] 16604 * 16605 * _.takeRight([1, 2, 3], 2); 16606 * // => [2, 3] 16607 * 16608 * _.takeRight([1, 2, 3], 5); 16609 * // => [1, 2, 3] 16610 * 16611 * _.takeRight([1, 2, 3], 0); 16612 * // => [] 16613 */ 16614 function takeRight(array, n, guard) { 16615 var length = array == null ? 0 : array.length; 16616 if (!length) { 16617 return []; 16618 } 16619 n = (guard || n === undefined$1) ? 1 : toInteger(n); 16620 n = length - n; 16621 return baseSlice(array, n < 0 ? 0 : n, length); 16622 } 16623 16624 /** 16625 * Creates a slice of `array` with elements taken from the end. Elements are 16626 * taken until `predicate` returns falsey. The predicate is invoked with 16627 * three arguments: (value, index, array). 16628 * 16629 * @static 16630 * @memberOf _ 16631 * @since 3.0.0 16632 * @category Array 16633 * @param {Array} array The array to query. 16634 * @param {Function} [predicate=_.identity] The function invoked per iteration. 16635 * @returns {Array} Returns the slice of `array`. 16636 * @example 16637 * 16638 * var users = [ 16639 * { 'user': 'barney', 'active': true }, 16640 * { 'user': 'fred', 'active': false }, 16641 * { 'user': 'pebbles', 'active': false } 16642 * ]; 16643 * 16644 * _.takeRightWhile(users, function(o) { return !o.active; }); 16645 * // => objects for ['fred', 'pebbles'] 16646 * 16647 * // The `_.matches` iteratee shorthand. 16648 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); 16649 * // => objects for ['pebbles'] 16650 * 16651 * // The `_.matchesProperty` iteratee shorthand. 16652 * _.takeRightWhile(users, ['active', false]); 16653 * // => objects for ['fred', 'pebbles'] 16654 * 16655 * // The `_.property` iteratee shorthand. 16656 * _.takeRightWhile(users, 'active'); 16657 * // => [] 16658 */ 16659 function takeRightWhile(array, predicate) { 16660 return (array && array.length) 16661 ? baseWhile(array, getIteratee(predicate, 3), false, true) 16662 : []; 16663 } 16664 16665 /** 16666 * Creates a slice of `array` with elements taken from the beginning. Elements 16667 * are taken until `predicate` returns falsey. The predicate is invoked with 16668 * three arguments: (value, index, array). 16669 * 16670 * @static 16671 * @memberOf _ 16672 * @since 3.0.0 16673 * @category Array 16674 * @param {Array} array The array to query. 16675 * @param {Function} [predicate=_.identity] The function invoked per iteration. 16676 * @returns {Array} Returns the slice of `array`. 16677 * @example 16678 * 16679 * var users = [ 16680 * { 'user': 'barney', 'active': false }, 16681 * { 'user': 'fred', 'active': false }, 16682 * { 'user': 'pebbles', 'active': true } 16683 * ]; 16684 * 16685 * _.takeWhile(users, function(o) { return !o.active; }); 16686 * // => objects for ['barney', 'fred'] 16687 * 16688 * // The `_.matches` iteratee shorthand. 16689 * _.takeWhile(users, { 'user': 'barney', 'active': false }); 16690 * // => objects for ['barney'] 16691 * 16692 * // The `_.matchesProperty` iteratee shorthand. 16693 * _.takeWhile(users, ['active', false]); 16694 * // => objects for ['barney', 'fred'] 16695 * 16696 * // The `_.property` iteratee shorthand. 16697 * _.takeWhile(users, 'active'); 16698 * // => [] 16699 */ 16700 function takeWhile(array, predicate) { 16701 return (array && array.length) 16702 ? baseWhile(array, getIteratee(predicate, 3)) 16703 : []; 16704 } 16705 16706 /** 16707 * Creates an array of unique values, in order, from all given arrays using 16708 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 16709 * for equality comparisons. 16710 * 16711 * @static 16712 * @memberOf _ 16713 * @since 0.1.0 16714 * @category Array 16715 * @param {...Array} [arrays] The arrays to inspect. 16716 * @returns {Array} Returns the new array of combined values. 16717 * @example 16718 * 16719 * _.union([2], [1, 2]); 16720 * // => [2, 1] 16721 */ 16722 var union = baseRest(function(arrays) { 16723 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); 16724 }); 16725 16726 /** 16727 * This method is like `_.union` except that it accepts `iteratee` which is 16728 * invoked for each element of each `arrays` to generate the criterion by 16729 * which uniqueness is computed. Result values are chosen from the first 16730 * array in which the value occurs. The iteratee is invoked with one argument: 16731 * (value). 16732 * 16733 * @static 16734 * @memberOf _ 16735 * @since 4.0.0 16736 * @category Array 16737 * @param {...Array} [arrays] The arrays to inspect. 16738 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16739 * @returns {Array} Returns the new array of combined values. 16740 * @example 16741 * 16742 * _.unionBy([2.1], [1.2, 2.3], Math.floor); 16743 * // => [2.1, 1.2] 16744 * 16745 * // The `_.property` iteratee shorthand. 16746 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); 16747 * // => [{ 'x': 1 }, { 'x': 2 }] 16748 */ 16749 var unionBy = baseRest(function(arrays) { 16750 var iteratee = last(arrays); 16751 if (isArrayLikeObject(iteratee)) { 16752 iteratee = undefined$1; 16753 } 16754 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)); 16755 }); 16756 16757 /** 16758 * This method is like `_.union` except that it accepts `comparator` which 16759 * is invoked to compare elements of `arrays`. Result values are chosen from 16760 * the first array in which the value occurs. The comparator is invoked 16761 * with two arguments: (arrVal, othVal). 16762 * 16763 * @static 16764 * @memberOf _ 16765 * @since 4.0.0 16766 * @category Array 16767 * @param {...Array} [arrays] The arrays to inspect. 16768 * @param {Function} [comparator] The comparator invoked per element. 16769 * @returns {Array} Returns the new array of combined values. 16770 * @example 16771 * 16772 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 16773 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 16774 * 16775 * _.unionWith(objects, others, _.isEqual); 16776 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] 16777 */ 16778 var unionWith = baseRest(function(arrays) { 16779 var comparator = last(arrays); 16780 comparator = typeof comparator == 'function' ? comparator : undefined$1; 16781 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined$1, comparator); 16782 }); 16783 16784 /** 16785 * Creates a duplicate-free version of an array, using 16786 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 16787 * for equality comparisons, in which only the first occurrence of each element 16788 * is kept. The order of result values is determined by the order they occur 16789 * in the array. 16790 * 16791 * @static 16792 * @memberOf _ 16793 * @since 0.1.0 16794 * @category Array 16795 * @param {Array} array The array to inspect. 16796 * @returns {Array} Returns the new duplicate free array. 16797 * @example 16798 * 16799 * _.uniq([2, 1, 2]); 16800 * // => [2, 1] 16801 */ 16802 function uniq(array) { 16803 return (array && array.length) ? baseUniq(array) : []; 16804 } 16805 16806 /** 16807 * This method is like `_.uniq` except that it accepts `iteratee` which is 16808 * invoked for each element in `array` to generate the criterion by which 16809 * uniqueness is computed. The order of result values is determined by the 16810 * order they occur in the array. The iteratee is invoked with one argument: 16811 * (value). 16812 * 16813 * @static 16814 * @memberOf _ 16815 * @since 4.0.0 16816 * @category Array 16817 * @param {Array} array The array to inspect. 16818 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16819 * @returns {Array} Returns the new duplicate free array. 16820 * @example 16821 * 16822 * _.uniqBy([2.1, 1.2, 2.3], Math.floor); 16823 * // => [2.1, 1.2] 16824 * 16825 * // The `_.property` iteratee shorthand. 16826 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); 16827 * // => [{ 'x': 1 }, { 'x': 2 }] 16828 */ 16829 function uniqBy(array, iteratee) { 16830 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : []; 16831 } 16832 16833 /** 16834 * This method is like `_.uniq` except that it accepts `comparator` which 16835 * is invoked to compare elements of `array`. The order of result values is 16836 * determined by the order they occur in the array.The comparator is invoked 16837 * with two arguments: (arrVal, othVal). 16838 * 16839 * @static 16840 * @memberOf _ 16841 * @since 4.0.0 16842 * @category Array 16843 * @param {Array} array The array to inspect. 16844 * @param {Function} [comparator] The comparator invoked per element. 16845 * @returns {Array} Returns the new duplicate free array. 16846 * @example 16847 * 16848 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; 16849 * 16850 * _.uniqWith(objects, _.isEqual); 16851 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] 16852 */ 16853 function uniqWith(array, comparator) { 16854 comparator = typeof comparator == 'function' ? comparator : undefined$1; 16855 return (array && array.length) ? baseUniq(array, undefined$1, comparator) : []; 16856 } 16857 16858 /** 16859 * This method is like `_.zip` except that it accepts an array of grouped 16860 * elements and creates an array regrouping the elements to their pre-zip 16861 * configuration. 16862 * 16863 * @static 16864 * @memberOf _ 16865 * @since 1.2.0 16866 * @category Array 16867 * @param {Array} array The array of grouped elements to process. 16868 * @returns {Array} Returns the new array of regrouped elements. 16869 * @example 16870 * 16871 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); 16872 * // => [['a', 1, true], ['b', 2, false]] 16873 * 16874 * _.unzip(zipped); 16875 * // => [['a', 'b'], [1, 2], [true, false]] 16876 */ 16877 function unzip(array) { 16878 if (!(array && array.length)) { 16879 return []; 16880 } 16881 var length = 0; 16882 array = arrayFilter(array, function(group) { 16883 if (isArrayLikeObject(group)) { 16884 length = nativeMax(group.length, length); 16885 return true; 16886 } 16887 }); 16888 return baseTimes(length, function(index) { 16889 return arrayMap(array, baseProperty(index)); 16890 }); 16891 } 16892 16893 /** 16894 * This method is like `_.unzip` except that it accepts `iteratee` to specify 16895 * how regrouped values should be combined. The iteratee is invoked with the 16896 * elements of each group: (...group). 16897 * 16898 * @static 16899 * @memberOf _ 16900 * @since 3.8.0 16901 * @category Array 16902 * @param {Array} array The array of grouped elements to process. 16903 * @param {Function} [iteratee=_.identity] The function to combine 16904 * regrouped values. 16905 * @returns {Array} Returns the new array of regrouped elements. 16906 * @example 16907 * 16908 * var zipped = _.zip([1, 2], [10, 20], [100, 200]); 16909 * // => [[1, 10, 100], [2, 20, 200]] 16910 * 16911 * _.unzipWith(zipped, _.add); 16912 * // => [3, 30, 300] 16913 */ 16914 function unzipWith(array, iteratee) { 16915 if (!(array && array.length)) { 16916 return []; 16917 } 16918 var result = unzip(array); 16919 if (iteratee == null) { 16920 return result; 16921 } 16922 return arrayMap(result, function(group) { 16923 return apply(iteratee, undefined$1, group); 16924 }); 16925 } 16926 16927 /** 16928 * Creates an array excluding all given values using 16929 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 16930 * for equality comparisons. 16931 * 16932 * **Note:** Unlike `_.pull`, this method returns a new array. 16933 * 16934 * @static 16935 * @memberOf _ 16936 * @since 0.1.0 16937 * @category Array 16938 * @param {Array} array The array to inspect. 16939 * @param {...*} [values] The values to exclude. 16940 * @returns {Array} Returns the new array of filtered values. 16941 * @see _.difference, _.xor 16942 * @example 16943 * 16944 * _.without([2, 1, 2, 3], 1, 2); 16945 * // => [3] 16946 */ 16947 var without = baseRest(function(array, values) { 16948 return isArrayLikeObject(array) 16949 ? baseDifference(array, values) 16950 : []; 16951 }); 16952 16953 /** 16954 * Creates an array of unique values that is the 16955 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) 16956 * of the given arrays. The order of result values is determined by the order 16957 * they occur in the arrays. 16958 * 16959 * @static 16960 * @memberOf _ 16961 * @since 2.4.0 16962 * @category Array 16963 * @param {...Array} [arrays] The arrays to inspect. 16964 * @returns {Array} Returns the new array of filtered values. 16965 * @see _.difference, _.without 16966 * @example 16967 * 16968 * _.xor([2, 1], [2, 3]); 16969 * // => [1, 3] 16970 */ 16971 var xor = baseRest(function(arrays) { 16972 return baseXor(arrayFilter(arrays, isArrayLikeObject)); 16973 }); 16974 16975 /** 16976 * This method is like `_.xor` except that it accepts `iteratee` which is 16977 * invoked for each element of each `arrays` to generate the criterion by 16978 * which by which they're compared. The order of result values is determined 16979 * by the order they occur in the arrays. The iteratee is invoked with one 16980 * argument: (value). 16981 * 16982 * @static 16983 * @memberOf _ 16984 * @since 4.0.0 16985 * @category Array 16986 * @param {...Array} [arrays] The arrays to inspect. 16987 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16988 * @returns {Array} Returns the new array of filtered values. 16989 * @example 16990 * 16991 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor); 16992 * // => [1.2, 3.4] 16993 * 16994 * // The `_.property` iteratee shorthand. 16995 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); 16996 * // => [{ 'x': 2 }] 16997 */ 16998 var xorBy = baseRest(function(arrays) { 16999 var iteratee = last(arrays); 17000 if (isArrayLikeObject(iteratee)) { 17001 iteratee = undefined$1; 17002 } 17003 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2)); 17004 }); 17005 17006 /** 17007 * This method is like `_.xor` except that it accepts `comparator` which is 17008 * invoked to compare elements of `arrays`. The order of result values is 17009 * determined by the order they occur in the arrays. The comparator is invoked 17010 * with two arguments: (arrVal, othVal). 17011 * 17012 * @static 17013 * @memberOf _ 17014 * @since 4.0.0 17015 * @category Array 17016 * @param {...Array} [arrays] The arrays to inspect. 17017 * @param {Function} [comparator] The comparator invoked per element. 17018 * @returns {Array} Returns the new array of filtered values. 17019 * @example 17020 * 17021 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 17022 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 17023 * 17024 * _.xorWith(objects, others, _.isEqual); 17025 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] 17026 */ 17027 var xorWith = baseRest(function(arrays) { 17028 var comparator = last(arrays); 17029 comparator = typeof comparator == 'function' ? comparator : undefined$1; 17030 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined$1, comparator); 17031 }); 17032 17033 /** 17034 * Creates an array of grouped elements, the first of which contains the 17035 * first elements of the given arrays, the second of which contains the 17036 * second elements of the given arrays, and so on. 17037 * 17038 * @static 17039 * @memberOf _ 17040 * @since 0.1.0 17041 * @category Array 17042 * @param {...Array} [arrays] The arrays to process. 17043 * @returns {Array} Returns the new array of grouped elements. 17044 * @example 17045 * 17046 * _.zip(['a', 'b'], [1, 2], [true, false]); 17047 * // => [['a', 1, true], ['b', 2, false]] 17048 */ 17049 var zip = baseRest(unzip); 17050 17051 /** 17052 * This method is like `_.fromPairs` except that it accepts two arrays, 17053 * one of property identifiers and one of corresponding values. 17054 * 17055 * @static 17056 * @memberOf _ 17057 * @since 0.4.0 17058 * @category Array 17059 * @param {Array} [props=[]] The property identifiers. 17060 * @param {Array} [values=[]] The property values. 17061 * @returns {Object} Returns the new object. 17062 * @example 17063 * 17064 * _.zipObject(['a', 'b'], [1, 2]); 17065 * // => { 'a': 1, 'b': 2 } 17066 */ 17067 function zipObject(props, values) { 17068 return baseZipObject(props || [], values || [], assignValue); 17069 } 17070 17071 /** 17072 * This method is like `_.zipObject` except that it supports property paths. 17073 * 17074 * @static 17075 * @memberOf _ 17076 * @since 4.1.0 17077 * @category Array 17078 * @param {Array} [props=[]] The property identifiers. 17079 * @param {Array} [values=[]] The property values. 17080 * @returns {Object} Returns the new object. 17081 * @example 17082 * 17083 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]); 17084 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } 17085 */ 17086 function zipObjectDeep(props, values) { 17087 return baseZipObject(props || [], values || [], baseSet); 17088 } 17089 17090 /** 17091 * This method is like `_.zip` except that it accepts `iteratee` to specify 17092 * how grouped values should be combined. The iteratee is invoked with the 17093 * elements of each group: (...group). 17094 * 17095 * @static 17096 * @memberOf _ 17097 * @since 3.8.0 17098 * @category Array 17099 * @param {...Array} [arrays] The arrays to process. 17100 * @param {Function} [iteratee=_.identity] The function to combine 17101 * grouped values. 17102 * @returns {Array} Returns the new array of grouped elements. 17103 * @example 17104 * 17105 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) { 17106 * return a + b + c; 17107 * }); 17108 * // => [111, 222] 17109 */ 17110 var zipWith = baseRest(function(arrays) { 17111 var length = arrays.length, 17112 iteratee = length > 1 ? arrays[length - 1] : undefined$1; 17113 17114 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined$1; 17115 return unzipWith(arrays, iteratee); 17116 }); 17117 17118 /*------------------------------------------------------------------------*/ 17119 17120 /** 17121 * Creates a `lodash` wrapper instance that wraps `value` with explicit method 17122 * chain sequences enabled. The result of such sequences must be unwrapped 17123 * with `_#value`. 17124 * 17125 * @static 17126 * @memberOf _ 17127 * @since 1.3.0 17128 * @category Seq 17129 * @param {*} value The value to wrap. 17130 * @returns {Object} Returns the new `lodash` wrapper instance. 17131 * @example 17132 * 17133 * var users = [ 17134 * { 'user': 'barney', 'age': 36 }, 17135 * { 'user': 'fred', 'age': 40 }, 17136 * { 'user': 'pebbles', 'age': 1 } 17137 * ]; 17138 * 17139 * var youngest = _ 17140 * .chain(users) 17141 * .sortBy('age') 17142 * .map(function(o) { 17143 * return o.user + ' is ' + o.age; 17144 * }) 17145 * .head() 17146 * .value(); 17147 * // => 'pebbles is 1' 17148 */ 17149 function chain(value) { 17150 var result = lodash(value); 17151 result.__chain__ = true; 17152 return result; 17153 } 17154 17155 /** 17156 * This method invokes `interceptor` and returns `value`. The interceptor 17157 * is invoked with one argument; (value). The purpose of this method is to 17158 * "tap into" a method chain sequence in order to modify intermediate results. 17159 * 17160 * @static 17161 * @memberOf _ 17162 * @since 0.1.0 17163 * @category Seq 17164 * @param {*} value The value to provide to `interceptor`. 17165 * @param {Function} interceptor The function to invoke. 17166 * @returns {*} Returns `value`. 17167 * @example 17168 * 17169 * _([1, 2, 3]) 17170 * .tap(function(array) { 17171 * // Mutate input array. 17172 * array.pop(); 17173 * }) 17174 * .reverse() 17175 * .value(); 17176 * // => [2, 1] 17177 */ 17178 function tap(value, interceptor) { 17179 interceptor(value); 17180 return value; 17181 } 17182 17183 /** 17184 * This method is like `_.tap` except that it returns the result of `interceptor`. 17185 * The purpose of this method is to "pass thru" values replacing intermediate 17186 * results in a method chain sequence. 17187 * 17188 * @static 17189 * @memberOf _ 17190 * @since 3.0.0 17191 * @category Seq 17192 * @param {*} value The value to provide to `interceptor`. 17193 * @param {Function} interceptor The function to invoke. 17194 * @returns {*} Returns the result of `interceptor`. 17195 * @example 17196 * 17197 * _(' abc ') 17198 * .chain() 17199 * .trim() 17200 * .thru(function(value) { 17201 * return [value]; 17202 * }) 17203 * .value(); 17204 * // => ['abc'] 17205 */ 17206 function thru(value, interceptor) { 17207 return interceptor(value); 17208 } 17209 17210 /** 17211 * This method is the wrapper version of `_.at`. 17212 * 17213 * @name at 17214 * @memberOf _ 17215 * @since 1.0.0 17216 * @category Seq 17217 * @param {...(string|string[])} [paths] The property paths to pick. 17218 * @returns {Object} Returns the new `lodash` wrapper instance. 17219 * @example 17220 * 17221 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; 17222 * 17223 * _(object).at(['a[0].b.c', 'a[1]']).value(); 17224 * // => [3, 4] 17225 */ 17226 var wrapperAt = flatRest(function(paths) { 17227 var length = paths.length, 17228 start = length ? paths[0] : 0, 17229 value = this.__wrapped__, 17230 interceptor = function(object) { return baseAt(object, paths); }; 17231 17232 if (length > 1 || this.__actions__.length || 17233 !(value instanceof LazyWrapper) || !isIndex(start)) { 17234 return this.thru(interceptor); 17235 } 17236 value = value.slice(start, +start + (length ? 1 : 0)); 17237 value.__actions__.push({ 17238 'func': thru, 17239 'args': [interceptor], 17240 'thisArg': undefined$1 17241 }); 17242 return new LodashWrapper(value, this.__chain__).thru(function(array) { 17243 if (length && !array.length) { 17244 array.push(undefined$1); 17245 } 17246 return array; 17247 }); 17248 }); 17249 17250 /** 17251 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled. 17252 * 17253 * @name chain 17254 * @memberOf _ 17255 * @since 0.1.0 17256 * @category Seq 17257 * @returns {Object} Returns the new `lodash` wrapper instance. 17258 * @example 17259 * 17260 * var users = [ 17261 * { 'user': 'barney', 'age': 36 }, 17262 * { 'user': 'fred', 'age': 40 } 17263 * ]; 17264 * 17265 * // A sequence without explicit chaining. 17266 * _(users).head(); 17267 * // => { 'user': 'barney', 'age': 36 } 17268 * 17269 * // A sequence with explicit chaining. 17270 * _(users) 17271 * .chain() 17272 * .head() 17273 * .pick('user') 17274 * .value(); 17275 * // => { 'user': 'barney' } 17276 */ 17277 function wrapperChain() { 17278 return chain(this); 17279 } 17280 17281 /** 17282 * Executes the chain sequence and returns the wrapped result. 17283 * 17284 * @name commit 17285 * @memberOf _ 17286 * @since 3.2.0 17287 * @category Seq 17288 * @returns {Object} Returns the new `lodash` wrapper instance. 17289 * @example 17290 * 17291 * var array = [1, 2]; 17292 * var wrapped = _(array).push(3); 17293 * 17294 * console.log(array); 17295 * // => [1, 2] 17296 * 17297 * wrapped = wrapped.commit(); 17298 * console.log(array); 17299 * // => [1, 2, 3] 17300 * 17301 * wrapped.last(); 17302 * // => 3 17303 * 17304 * console.log(array); 17305 * // => [1, 2, 3] 17306 */ 17307 function wrapperCommit() { 17308 return new LodashWrapper(this.value(), this.__chain__); 17309 } 17310 17311 /** 17312 * Gets the next value on a wrapped object following the 17313 * [iterator protocol](https://mdn.io/iteration_protocols#iterator). 17314 * 17315 * @name next 17316 * @memberOf _ 17317 * @since 4.0.0 17318 * @category Seq 17319 * @returns {Object} Returns the next iterator value. 17320 * @example 17321 * 17322 * var wrapped = _([1, 2]); 17323 * 17324 * wrapped.next(); 17325 * // => { 'done': false, 'value': 1 } 17326 * 17327 * wrapped.next(); 17328 * // => { 'done': false, 'value': 2 } 17329 * 17330 * wrapped.next(); 17331 * // => { 'done': true, 'value': undefined } 17332 */ 17333 function wrapperNext() { 17334 if (this.__values__ === undefined$1) { 17335 this.__values__ = toArray(this.value()); 17336 } 17337 var done = this.__index__ >= this.__values__.length, 17338 value = done ? undefined$1 : this.__values__[this.__index__++]; 17339 17340 return { 'done': done, 'value': value }; 17341 } 17342 17343 /** 17344 * Enables the wrapper to be iterable. 17345 * 17346 * @name Symbol.iterator 17347 * @memberOf _ 17348 * @since 4.0.0 17349 * @category Seq 17350 * @returns {Object} Returns the wrapper object. 17351 * @example 17352 * 17353 * var wrapped = _([1, 2]); 17354 * 17355 * wrapped[Symbol.iterator]() === wrapped; 17356 * // => true 17357 * 17358 * Array.from(wrapped); 17359 * // => [1, 2] 17360 */ 17361 function wrapperToIterator() { 17362 return this; 17363 } 17364 17365 /** 17366 * Creates a clone of the chain sequence planting `value` as the wrapped value. 17367 * 17368 * @name plant 17369 * @memberOf _ 17370 * @since 3.2.0 17371 * @category Seq 17372 * @param {*} value The value to plant. 17373 * @returns {Object} Returns the new `lodash` wrapper instance. 17374 * @example 17375 * 17376 * function square(n) { 17377 * return n * n; 17378 * } 17379 * 17380 * var wrapped = _([1, 2]).map(square); 17381 * var other = wrapped.plant([3, 4]); 17382 * 17383 * other.value(); 17384 * // => [9, 16] 17385 * 17386 * wrapped.value(); 17387 * // => [1, 4] 17388 */ 17389 function wrapperPlant(value) { 17390 var result, 17391 parent = this; 17392 17393 while (parent instanceof baseLodash) { 17394 var clone = wrapperClone(parent); 17395 clone.__index__ = 0; 17396 clone.__values__ = undefined$1; 17397 if (result) { 17398 previous.__wrapped__ = clone; 17399 } else { 17400 result = clone; 17401 } 17402 var previous = clone; 17403 parent = parent.__wrapped__; 17404 } 17405 previous.__wrapped__ = value; 17406 return result; 17407 } 17408 17409 /** 17410 * This method is the wrapper version of `_.reverse`. 17411 * 17412 * **Note:** This method mutates the wrapped array.
17413 * 17414 * @name reverse 17415 * @memberOf _ 17416 * @since 0.1.0 17417 * @category Seq 17418 * @returns {Object} Returns the new `lodash` wrapper instance. 17419 * @example 17420 * 17421 * var array = [1, 2, 3]; 17422 * 17423 * _(array).reverse().value() 17424 * // => [3, 2, 1] 17425 * 17426 * console.log(array); 17427 * // => [3, 2, 1] 17428 */ 17429 function wrapperReverse() { 17430 var value = this.__wrapped__; 17431 if (value instanceof LazyWrapper) { 17432 var wrapped = value; 17433 if (this.__actions__.length) { 17434 wrapped = new LazyWrapper(this); 17435 } 17436 wrapped = wrapped.reverse(); 17437 wrapped.__actions__.push({ 17438 'func': thru, 17439 'args': [reverse], 17440 'thisArg': undefined$1 17441 }); 17442 return new LodashWrapper(wrapped, this.__chain__); 17443 } 17444 return this.thru(reverse); 17445 } 17446 17447 /** 17448 * Executes the chain sequence to resolve the unwrapped value. 17449 * 17450 * @name value 17451 * @memberOf _ 17452 * @since 0.1.0 17453 * @alias toJSON, valueOf 17454 * @category Seq 17455 * @returns {*} Returns the resolved unwrapped value. 17456 * @example 17457 * 17458 * _([1, 2, 3]).value(); 17459 * // => [1, 2, 3] 17460 */ 17461 function wrapperValue() { 17462 return baseWrapperValue(this.__wrapped__, this.__actions__); 17463 } 17464 17465 /*------------------------------------------------------------------------*/ 17466 17467 /**
17468 * Creates an object composed of keys generated from the results of running 17469 * each element of `collection` thru `iteratee`. The corresponding value of 17470 * each key is the number of times the key was returned by `iteratee`. The 17471 * iteratee is invoked with one argument: (value). 17472 * 17473 * @static 17474 * @memberOf _ 17475 * @since 0.5.0 17476 * @category Collection 17477 * @param {Array|Object} collection The collection to iterate over. 17478 * @param {Function} [iteratee=_.identity] The iteratee to transform keys. 17479 * @returns {Object} Returns the composed aggregate object. 17480 * @example 17481 * 17482 * _.countBy([6.1, 4.2, 6.3], Math.floor); 17483 * // => { '4': 1, '6': 2 } 17484 * 17485 * // The `_.property` iteratee shorthand. 17486 * _.countBy(['one', 'two', 'three'], 'length'); 17487 * // => { '3': 2, '5': 1 } 17488 */ 17489 var countBy = createAggregator(function(result, value, key) { 17490 if (hasOwnProperty.call(result, key)) { 17491 ++result[key]; 17492 } else { 17493 baseAssignValue(result, key, 1); 17494 } 17495 }); 17496 17497 /** 17498 * Checks if `predicate` returns truthy for **all** elements of `collection`. 17499 * Iteration is stopped once `predicate` returns falsey. The predicate is 17500 * invoked with three arguments: (value, index|key, collection). 17501 * 17502 * **Note:** This method returns `true` for 17503 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because 17504 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of 17505 * elements of empty collections. 17506 * 17507 * @static 17508 * @memberOf _ 17509 * @since 0.1.0 17510 * @category Collection 17511 * @param {Array|Object} collection The collection to iterate over. 17512 * @param {Function} [predicate=_.identity] The function invoked per iteration. 17513 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 17514 * @returns {boolean} Returns `true` if all elements pass the predicate check, 17515 * else `false`. 17516 * @example 17517 * 17518 * _.every([true, 1, null, 'yes'], Boolean); 17519 * // => false 17520 * 17521 * var users = [ 17522 * { 'user': 'barney', 'age': 36, 'active': false }, 17523 * { 'user': 'fred', 'age': 40, 'active': false } 17524 * ]; 17525 * 17526 * // The `_.matches` iteratee shorthand. 17527 * _.every(users, { 'user': 'barney', 'active': false }); 17528 * // => false 17529 * 17530 * // The `_.matchesProperty` iteratee shorthand. 17531 * _.every(users, ['active', false]); 17532 * // => true 17533 * 17534 * // The `_.property` iteratee shorthand. 17535 * _.every(users, 'active'); 17536 * // => false 17537 */ 17538 function every(collection, predicate, guard) { 17539 var func = isArray(collection) ? arrayEvery : baseEvery; 17540 if (guard && isIterateeCall(collection, predicate, guard)) { 17541 predicate = undefined$1; 17542 } 17543 return func(collection, getIteratee(predicate, 3)); 17544 } 17545 17546 /** 17547 * Iterates over elements of `collection`, returning an array of all elements 17548 * `predicate` returns truthy for. The predicate is invoked with three 17549 * arguments: (value, index|key, collection). 17550 * 17551 * **Note:** Unlike `_.remove`, this method returns a new array. 17552 * 17553 * @static 17554 * @memberOf _ 17555 * @since 0.1.0 17556 * @category Collection 17557 * @param {Array|Object} collection The collection to iterate over. 17558 * @param {Function} [predicate=_.identity] The function invoked per iteration. 17559 * @returns {Array} Returns the new filtered array. 17560 * @see _.reject 17561 * @example 17562 * 17563 * var users = [ 17564 * { 'user': 'barney', 'age': 36, 'active': true }, 17565 * { 'user': 'fred', 'age': 40, 'active': false } 17566 * ]; 17567 * 17568 * _.filter(users, function(o) { return !o.active; }); 17569 * // => objects for ['fred'] 17570 * 17571 * // The `_.matches` iteratee shorthand. 17572 * _.filter(users, { 'age': 36, 'active': true }); 17573 * // => objects for ['barney'] 17574 * 17575 * // The `_.matchesProperty` iteratee shorthand. 17576 * _.filter(users, ['active', false]); 17577 * // => objects for ['fred'] 17578 * 17579 * // The `_.property` iteratee shorthand. 17580 * _.filter(users, 'active'); 17581 * // => objects for ['barney'] 17582 * 17583 * // Combining several predicates using `_.overEvery` or `_.overSome`. 17584 * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]])); 17585 * // => objects for ['fred', 'barney'] 17586 */ 17587 function filter(collection, predicate) { 17588 var func = isArray(collection) ? arrayFilter : baseFilter; 17589 return func(collection, getIteratee(predicate, 3)); 17590 } 17591 17592 /** 17593 * Iterates over elements of `collection`, returning the first element 17594 * `predicate` returns truthy for. The predicate is invoked with three 17595 * arguments: (value, index|key, collection). 17596 * 17597 * @static 17598 * @memberOf _ 17599 * @since 0.1.0 17600 * @category Collection 17601 * @param {Array|Object} collection The collection to inspect. 17602 * @param {Function} [predicate=_.identity] The function invoked per iteration. 17603 * @param {number} [fromIndex=0] The index to search from. 17604 * @returns {*} Returns the matched element, else `undefined`. 17605 * @example 17606 * 17607 * var users = [ 17608 * { 'user': 'barney', 'age': 36, 'active': true }, 17609 * { 'user': 'fred', 'age': 40, 'active': false }, 17610 * { 'user': 'pebbles', 'age': 1, 'active': true } 17611 * ]; 17612 * 17613 * _.find(users, function(o) { return o.age < 40; }); 17614 * // => object for 'barney' 17615 * 17616 * // The `_.matches` iteratee shorthand. 17617 * _.find(users, { 'age': 1, 'active': true }); 17618 * // => object for 'pebbles' 17619 * 17620 * // The `_.matchesProperty` iteratee shorthand. 17621 * _.find(users, ['active', false]); 17622 * // => object for 'fred' 17623 * 17624 * // The `_.property` iteratee shorthand. 17625 * _.find(users, 'active'); 17626 * // => object for 'barney' 17627 */ 17628 var find = createFind(findIndex); 17629 17630 /** 17631 * This method is like `_.find` except that it iterates over elements of 17632 * `collection` from right to left. 17633 * 17634 * @static 17635 * @memberOf _ 17636 * @since 2.0.0 17637 * @category Collection 17638 * @param {Array|Object} collection The collection to inspect. 17639 * @param {Function} [predicate=_.identity] The function invoked per iteration. 17640 * @param {number} [fromIndex=collection.length-1] The index to search from. 17641 * @returns {*} Returns the matched element, else `undefined`. 17642 * @example 17643 * 17644 * _.findLast([1, 2, 3, 4], function(n) { 17645 * return n % 2 == 1; 17646 * }); 17647 * // => 3 17648 */ 17649 var findLast = createFind(findLastIndex); 17650 17651 /** 17652 * Creates a flattened array of values by running each element in `collection` 17653 * thru `iteratee` and flattening the mapped results. The iteratee is invoked 17654 * with three arguments: (value, index|key, collection). 17655 * 17656 * @static 17657 * @memberOf _ 17658 * @since 4.0.0 17659 * @category Collection 17660 * @param {Array|Object} collection The collection to iterate over. 17661 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 17662 * @returns {Array} Returns the new flattened array.
17663 * @example 17664 * 17665 * function duplicate(n) { 17666 * return [n, n]; 17667 * } 17668 * 17669 * _.flatMap([1, 2], duplicate); 17670 * // => [1, 1, 2, 2] 17671 */ 17672 function flatMap(collection, iteratee) { 17673 return baseFlatten(map(collection, iteratee), 1); 17674 } 17675 17676 /** 17677 * This method is like `_.flatMap` except that it recursively flattens the 17678 * mapped results. 17679 * 17680 * @static 17681 * @memberOf _ 17682 * @since 4.7.0 17683 * @category Collection 17684 * @param {Array|Object} collection The collection to iterate over. 17685 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 17686 * @returns {Array} Returns the new flattened array. 17687 * @example 17688 * 17689 * function duplicate(n) { 17690 * return [[[n, n]]]; 17691 * } 17692 * 17693 * _.flatMapDeep([1, 2], duplicate); 17694 * // => [1, 1, 2, 2] 17695 */ 17696 function flatMapDeep(collection, iteratee) { 17697 return baseFlatten(map(collection, iteratee), INFINITY); 17698 } 17699 17700 /** 17701 * This method is like `_.flatMap` except that it recursively flattens the 17702 * mapped results up to `depth` times. 17703 * 17704 * @static 17705 * @memberOf _ 17706 * @since 4.7.0 17707 * @category Collection 17708 * @param {Array|Object} collection The collection to iterate over. 17709 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 17710 * @param {number} [depth=1] The maximum recursion depth. 17711 * @returns {Array} Returns the new flattened array. 17712 * @example 17713 * 17714 * function duplicate(n) { 17715 * return [[[n, n]]]; 17716 * } 17717 * 17718 * _.flatMapDepth([1, 2], duplicate, 2); 17719 * // => [[1, 1], [2, 2]] 17720 */ 17721 function flatMapDepth(collection, iteratee, depth) { 17722 depth = depth === undefined$1 ? 1 : toInteger(depth); 17723 return baseFlatten(map(collection, iteratee), depth); 17724 } 17725 17726 /** 17727 * Iterates over elements of `collection` and invokes `iteratee` for each element. 17728 * The iteratee is invoked with three arguments: (value, index|key, collection). 17729 * Iteratee functions may exit iteration early by explicitly returning `false`. 17730 * 17731 * **Note:** As with other "Collections" methods, objects with a "length" 17732 * property are iterated like arrays. To avoid this behavior use `_.forIn` 17733 * or `_.forOwn` for object iteration. 17734 * 17735 * @static 17736 * @memberOf _ 17737 * @since 0.1.0 17738 * @alias each 17739 * @category Collection 17740 * @param {Array|Object} collection The collection to iterate over. 17741 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 17742 * @returns {Array|Object} Returns `collection`. 17743 * @see _.forEachRight 17744 * @example 17745 * 17746 * _.forEach([1, 2], function(value) { 17747 * console.log(value); 17748 * }); 17749 * // => Logs `1` then `2`. 17750 * 17751 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { 17752 * console.log(key); 17753 * }); 17754 * // => Logs 'a' then 'b' (iteration order is not guaranteed). 17755 */ 17756 function forEach(collection, iteratee) { 17757 var func = isArray(collection) ? arrayEach : baseEach; 17758 return func(collection, getIteratee(iteratee, 3)); 17759 } 17760 17761 /** 17762 * This method is like `_.forEach` except that it iterates over elements of 17763 * `collection` from right to left. 17764 * 17765 * @static 17766 * @memberOf _ 17767 * @since 2.0.0 17768 * @alias eachRight 17769 * @category Collection 17770 * @param {Array|Object} collection The collection to iterate over. 17771 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 17772 * @returns {Array|Object} Returns `collection`. 17773 * @see _.forEach 17774 * @example 17775 * 17776 * _.forEachRight([1, 2], function(value) { 17777 * console.log(value); 17778 * }); 17779 * // => Logs `2` then `1`. 17780 */ 17781 function forEachRight(collection, iteratee) { 17782 var func = isArray(collection) ? arrayEachRight : baseEachRight; 17783 return func(collection, getIteratee(iteratee, 3)); 17784 } 17785 17786 /**
17787 * Creates an object composed of keys generated from the results of running 17788 * each element of `collection` thru `iteratee`. The order of grouped values 17789 * is determined by the order they occur in `collection`. The corresponding 17790 * value of each key is an array of elements responsible for generating the 17791 * key. The iteratee is invoked with one argument: (value). 17792 * 17793 * @static 17794 * @memberOf _ 17795 * @since 0.1.0 17796 * @category Collection 17797 * @param {Array|Object} collection The collection to iterate over. 17798 * @param {Function} [iteratee=_.identity] The iteratee to transform keys. 17799 * @returns {Object} Returns the composed aggregate object. 17800 * @example 17801 * 17802 * _.groupBy([6.1, 4.2, 6.3], Math.floor); 17803 * // => { '4': [4.2], '6': [6.1, 6.3] } 17804 * 17805 * // The `_.property` iteratee shorthand. 17806 * _.groupBy(['one', 'two', 'three'], 'length'); 17807 * // => { '3': ['one', 'two'], '5': ['three'] } 17808 */ 17809 var groupBy = createAggregator(function(result, value, key) { 17810 if (hasOwnProperty.call(result, key)) { 17811 result[key].push(value); 17812 } else { 17813 baseAssignValue(result, key, [value]); 17814 } 17815 }); 17816 17817 /** 17818 * Checks if `value` is in `collection`. If `collection` is a string, it's 17819 * checked for a substring of `value`, otherwise 17820 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 17821 * is used for equality comparisons. If `fromIndex` is negative, it's used as 17822 * the offset from the end of `collection`. 17823 * 17824 * @static 17825 * @memberOf _ 17826 * @since 0.1.0 17827 * @category Collection 17828 * @param {Array|Object|string} collection The collection to inspect. 17829 * @param {*} value The value to search for. 17830 * @param {number} [fromIndex=0] The index to search from. 17831 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. 17832 * @returns {boolean} Returns `true` if `value` is found, else `false`. 17833 * @example 17834 * 17835 * _.includes([1, 2, 3], 1); 17836 * // => true 17837 * 17838 * _.includes([1, 2, 3], 1, 2); 17839 * // => false 17840 * 17841 * _.includes({ 'a': 1, 'b': 2 }, 1); 17842 * // => true 17843 * 17844 * _.includes('abcd', 'bc'); 17845 * // => true 17846 */ 17847 function includes(collection, value, fromIndex, guard) { 17848 collection = isArrayLike(collection) ? collection : values(collection); 17849 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0; 17850 17851 var length = collection.length; 17852 if (fromIndex < 0) { 17853 fromIndex = nativeMax(length + fromIndex, 0); 17854 } 17855 return isString(collection) 17856 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1) 17857 : (!!length && baseIndexOf(collection, value, fromIndex) > -1); 17858 } 17859 17860 /** 17861 * Invokes the method at `path` of each element in `collection`, returning 17862 * an array of the results of each invoked method. Any additional arguments 17863 * are provided to each invoked method. If `path` is a function, it's invoked 17864 * for, and `this` bound to, each element in `collection`. 17865 * 17866 * @static 17867 * @memberOf _ 17868 * @since 4.0.0 17869 * @category Collection 17870 * @param {Array|Object} collection The collection to iterate over. 17871 * @param {Array|Function|string} path The path of the method to invoke or 17872 * the function invoked per iteration. 17873 * @param {...*} [args] The arguments to invoke each method with. 17874 * @returns {Array} Returns the array of results. 17875 * @example 17876 * 17877 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); 17878 * // => [[1, 5, 7], [1, 2, 3]] 17879 * 17880 * _.invokeMap([123, 456], String.prototype.split, ''); 17881 * // => [['1', '2', '3'], ['4', '5', '6']] 17882 */ 17883 var invokeMap = baseRest(function(collection, path, args) { 17884 var index = -1, 17885 isFunc = typeof path == 'function', 17886 result = isArrayLike(collection) ? Array(collection.length) : []; 17887 17888 baseEach(collection, function(value) {
vendor: 10,126 bytes, lines 17889-18139
17889 result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args); 17890 }); 17891 return result; 17892 }); 17893 17894 /** 17895 * Creates an object composed of keys generated from the results of running 17896 * each element of `collection` thru `iteratee`. The corresponding value of 17897 * each key is the last element responsible for generating the key. The 17898 * iteratee is invoked with one argument: (value). 17899 * 17900 * @static 17901 * @memberOf _ 17902 * @since 4.0.0 17903 * @category Collection 17904 * @param {Array|Object} collection The collection to iterate over. 17905 * @param {Function} [iteratee=_.identity] The iteratee to transform keys. 17906 * @returns {Object} Returns the composed aggregate object. 17907 * @example 17908 * 17909 * var array = [ 17910 * { 'dir': 'left', 'code': 97 }, 17911 * { 'dir': 'right', 'code': 100 } 17912 * ]; 17913 * 17914 * _.keyBy(array, function(o) { 17915 * return String.fromCharCode(o.code); 17916 * }); 17917 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } 17918 * 17919 * _.keyBy(array, 'dir'); 17920 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } 17921 */ 17922 var keyBy = createAggregator(function(result, value, key) { 17923 baseAssignValue(result, key, value); 17924 }); 17925 17926 /** 17927 * Creates an array of values by running each element in `collection` thru 17928 * `iteratee`. The iteratee is invoked with three arguments: 17929 * (value, index|key, collection). 17930 * 17931 * Many lodash methods are guarded to work as iteratees for methods like 17932 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. 17933 * 17934 * The guarded methods are: 17935 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, 17936 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, 17937 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, 17938 * `template`, `trim`, `trimEnd`, `trimStart`, and `words` 17939 * 17940 * @static 17941 * @memberOf _ 17942 * @since 0.1.0 17943 * @category Collection 17944 * @param {Array|Object} collection The collection to iterate over. 17945 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 17946 * @returns {Array} Returns the new mapped array. 17947 * @example 17948 * 17949 * function square(n) { 17950 * return n * n; 17951 * } 17952 * 17953 * _.map([4, 8], square); 17954 * // => [16, 64] 17955 * 17956 * _.map({ 'a': 4, 'b': 8 }, square); 17957 * // => [16, 64] (iteration order is not guaranteed) 17958 * 17959 * var users = [ 17960 * { 'user': 'barney' }, 17961 * { 'user': 'fred' } 17962 * ]; 17963 * 17964 * // The `_.property` iteratee shorthand. 17965 * _.map(users, 'user'); 17966 * // => ['barney', 'fred'] 17967 */ 17968 function map(collection, iteratee) { 17969 var func = isArray(collection) ? arrayMap : baseMap; 17970 return func(collection, getIteratee(iteratee, 3)); 17971 } 17972 17973 /** 17974 * This method is like `_.sortBy` except that it allows specifying the sort 17975 * orders of the iteratees to sort by. If `orders` is unspecified, all values 17976 * are sorted in ascending order. Otherwise, specify an order of "desc" for 17977 * descending or "asc" for ascending sort order of corresponding values. 17978 * 17979 * @static 17980 * @memberOf _ 17981 * @since 4.0.0 17982 * @category Collection 17983 * @param {Array|Object} collection The collection to iterate over. 17984 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]] 17985 * The iteratees to sort by. 17986 * @param {string[]} [orders] The sort orders of `iteratees`. 17987 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. 17988 * @returns {Array} Returns the new sorted array. 17989 * @example 17990 * 17991 * var users = [ 17992 * { 'user': 'fred', 'age': 48 }, 17993 * { 'user': 'barney', 'age': 34 }, 17994 * { 'user': 'fred', 'age': 40 }, 17995 * { 'user': 'barney', 'age': 36 } 17996 * ]; 17997 * 17998 * // Sort by `user` in ascending order and by `age` in descending order. 17999 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); 18000 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] 18001 */ 18002 function orderBy(collection, iteratees, orders, guard) { 18003 if (collection == null) { 18004 return []; 18005 } 18006 if (!isArray(iteratees)) { 18007 iteratees = iteratees == null ? [] : [iteratees]; 18008 } 18009 orders = guard ? undefined$1 : orders; 18010 if (!isArray(orders)) { 18011 orders = orders == null ? [] : [orders]; 18012 } 18013 return baseOrderBy(collection, iteratees, orders); 18014 } 18015 18016 /** 18017 * Creates an array of elements split into two groups, the first of which 18018 * contains elements `predicate` returns truthy for, the second of which 18019 * contains elements `predicate` returns falsey for. The predicate is 18020 * invoked with one argument: (value). 18021 * 18022 * @static 18023 * @memberOf _ 18024 * @since 3.0.0 18025 * @category Collection 18026 * @param {Array|Object} collection The collection to iterate over. 18027 * @param {Function} [predicate=_.identity] The function invoked per iteration. 18028 * @returns {Array} Returns the array of grouped elements. 18029 * @example 18030 * 18031 * var users = [ 18032 * { 'user': 'barney', 'age': 36, 'active': false }, 18033 * { 'user': 'fred', 'age': 40, 'active': true }, 18034 * { 'user': 'pebbles', 'age': 1, 'active': false } 18035 * ]; 18036 * 18037 * _.partition(users, function(o) { return o.active; }); 18038 * // => objects for [['fred'], ['barney', 'pebbles']] 18039 * 18040 * // The `_.matches` iteratee shorthand. 18041 * _.partition(users, { 'age': 1, 'active': false }); 18042 * // => objects for [['pebbles'], ['barney', 'fred']] 18043 * 18044 * // The `_.matchesProperty` iteratee shorthand. 18045 * _.partition(users, ['active', false]); 18046 * // => objects for [['barney', 'pebbles'], ['fred']] 18047 * 18048 * // The `_.property` iteratee shorthand. 18049 * _.partition(users, 'active'); 18050 * // => objects for [['fred'], ['barney', 'pebbles']] 18051 */ 18052 var partition = createAggregator(function(result, value, key) { 18053 result[key ? 0 : 1].push(value); 18054 }, function() { return [[], []]; }); 18055 18056 /** 18057 * Reduces `collection` to a value which is the accumulated result of running 18058 * each element in `collection` thru `iteratee`, where each successive 18059 * invocation is supplied the return value of the previous. If `accumulator` 18060 * is not given, the first element of `collection` is used as the initial 18061 * value. The iteratee is invoked with four arguments: 18062 * (accumulator, value, index|key, collection). 18063 * 18064 * Many lodash methods are guarded to work as iteratees for methods like 18065 * `_.reduce`, `_.reduceRight`, and `_.transform`. 18066 * 18067 * The guarded methods are: 18068 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, 18069 * and `sortBy` 18070 * 18071 * @static 18072 * @memberOf _ 18073 * @since 0.1.0 18074 * @category Collection 18075 * @param {Array|Object} collection The collection to iterate over. 18076 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 18077 * @param {*} [accumulator] The initial value. 18078 * @returns {*} Returns the accumulated value. 18079 * @see _.reduceRight 18080 * @example 18081 * 18082 * _.reduce([1, 2], function(sum, n) { 18083 * return sum + n; 18084 * }, 0); 18085 * // => 3 18086 * 18087 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { 18088 * (result[value] || (result[value] = [])).push(key); 18089 * return result; 18090 * }, {}); 18091 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) 18092 */ 18093 function reduce(collection, iteratee, accumulator) { 18094 var func = isArray(collection) ? arrayReduce : baseReduce, 18095 initAccum = arguments.length < 3; 18096 18097 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach); 18098 } 18099 18100 /** 18101 * This method is like `_.reduce` except that it iterates over elements of 18102 * `collection` from right to left. 18103 * 18104 * @static 18105 * @memberOf _ 18106 * @since 0.1.0 18107 * @category Collection 18108 * @param {Array|Object} collection The collection to iterate over. 18109 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 18110 * @param {*} [accumulator] The initial value. 18111 * @returns {*} Returns the accumulated value. 18112 * @see _.reduce 18113 * @example 18114 * 18115 * var array = [[0, 1], [2, 3], [4, 5]]; 18116 * 18117 * _.reduceRight(array, function(flattened, other) { 18118 * return flattened.concat(other); 18119 * }, []); 18120 * // => [4, 5, 2, 3, 0, 1] 18121 */ 18122 function reduceRight(collection, iteratee, accumulator) { 18123 var func = isArray(collection) ? arrayReduceRight : baseReduce, 18124 initAccum = arguments.length < 3; 18125 18126 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight); 18127 } 18128 18129 /** 18130 * The opposite of `_.filter`; this method returns the elements of `collection` 18131 * that `predicate` does **not** return truthy for. 18132 * 18133 * @static 18134 * @memberOf _ 18135 * @since 0.1.0 18136 * @category Collection 18137 * @param {Array|Object} collection The collection to iterate over. 18138 * @param {Function} [predicate=_.identity] The function invoked per iteration. 18139 * @returns {Array} Returns the new filtered array.
18140 * @see _.filter 18141 * @example 18142 * 18143 * var users = [ 18144 * { 'user': 'barney', 'age': 36, 'active': false }, 18145 * { 'user': 'fred', 'age': 40, 'active': true } 18146 * ]; 18147 * 18148 * _.reject(users, function(o) { return !o.active; }); 18149 * // => objects for ['fred'] 18150 * 18151 * // The `_.matches` iteratee shorthand. 18152 * _.reject(users, { 'age': 40, 'active': true }); 18153 * // => objects for ['barney'] 18154 * 18155 * // The `_.matchesProperty` iteratee shorthand. 18156 * _.reject(users, ['active', false]); 18157 * // => objects for ['fred'] 18158 * 18159 * // The `_.property` iteratee shorthand. 18160 * _.reject(users, 'active'); 18161 * // => objects for ['barney'] 18162 */ 18163 function reject(collection, predicate) { 18164 var func = isArray(collection) ? arrayFilter : baseFilter; 18165 return func(collection, negate(getIteratee(predicate, 3))); 18166 } 18167 18168 /** 18169 * Gets a random element from `collection`. 18170 * 18171 * @static 18172 * @memberOf _ 18173 * @since 2.0.0 18174 * @category Collection 18175 * @param {Array|Object} collection The collection to sample. 18176 * @returns {*} Returns the random element. 18177 * @example 18178 * 18179 * _.sample([1, 2, 3, 4]); 18180 * // => 2 18181 */ 18182 function sample(collection) { 18183 var func = isArray(collection) ? arraySample : baseSample; 18184 return func(collection); 18185 } 18186 18187 /** 18188 * Gets `n` random elements at unique keys from `collection` up to the 18189 * size of `collection`. 18190 * 18191 * @static 18192 * @memberOf _ 18193 * @since 4.0.0 18194 * @category Collection 18195 * @param {Array|Object} collection The collection to sample. 18196 * @param {number} [n=1] The number of elements to sample. 18197 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 18198 * @returns {Array} Returns the random elements. 18199 * @example 18200 * 18201 * _.sampleSize([1, 2, 3], 2); 18202 * // => [3, 1] 18203 * 18204 * _.sampleSize([1, 2, 3], 4); 18205 * // => [2, 3, 1] 18206 */ 18207 function sampleSize(collection, n, guard) { 18208 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined$1)) { 18209 n = 1; 18210 } else { 18211 n = toInteger(n); 18212 } 18213 var func = isArray(collection) ? arraySampleSize : baseSampleSize; 18214 return func(collection, n); 18215 } 18216 18217 /** 18218 * Creates an array of shuffled values, using a version of the 18219 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). 18220 * 18221 * @static 18222 * @memberOf _ 18223 * @since 0.1.0 18224 * @category Collection 18225 * @param {Array|Object} collection The collection to shuffle. 18226 * @returns {Array} Returns the new shuffled array. 18227 * @example 18228 * 18229 * _.shuffle([1, 2, 3, 4]); 18230 * // => [4, 1, 3, 2] 18231 */ 18232 function shuffle(collection) { 18233 var func = isArray(collection) ? arrayShuffle : baseShuffle; 18234 return func(collection); 18235 } 18236 18237 /** 18238 * Gets the size of `collection` by returning its length for array-like 18239 * values or the number of own enumerable string keyed properties for objects. 18240 * 18241 * @static 18242 * @memberOf _ 18243 * @since 0.1.0 18244 * @category Collection 18245 * @param {Array|Object|string} collection The collection to inspect. 18246 * @returns {number} Returns the collection size. 18247 * @example 18248 * 18249 * _.size([1, 2, 3]); 18250 * // => 3 18251 * 18252 * _.size({ 'a': 1, 'b': 2 }); 18253 * // => 2 18254 * 18255 * _.size('pebbles'); 18256 * // => 7 18257 */ 18258 function size(collection) { 18259 if (collection == null) { 18260 return 0; 18261 } 18262 if (isArrayLike(collection)) { 18263 return isString(collection) ? stringSize(collection) : collection.length; 18264 } 18265 var tag = getTag(collection); 18266 if (tag == mapTag || tag == setTag) { 18267 return collection.size; 18268 } 18269 return baseKeys(collection).length; 18270 } 18271 18272 /** 18273 * Checks if `predicate` returns truthy for **any** element of `collection`. 18274 * Iteration is stopped once `predicate` returns truthy. The predicate is 18275 * invoked with three arguments: (value, index|key, collection). 18276 * 18277 * @static 18278 * @memberOf _ 18279 * @since 0.1.0 18280 * @category Collection 18281 * @param {Array|Object} collection The collection to iterate over. 18282 * @param {Function} [predicate=_.identity] The function invoked per iteration. 18283 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 18284 * @returns {boolean} Returns `true` if any element passes the predicate check, 18285 * else `false`. 18286 * @example 18287 * 18288 * _.some([null, 0, 'yes', false], Boolean); 18289 * // => true 18290 * 18291 * var users = [ 18292 * { 'user': 'barney', 'active': true }, 18293 * { 'user': 'fred', 'active': false } 18294 * ]; 18295 * 18296 * // The `_.matches` iteratee shorthand. 18297 * _.some(users, { 'user': 'barney', 'active': false }); 18298 * // => false 18299 * 18300 * // The `_.matchesProperty` iteratee shorthand. 18301 * _.some(users, ['active', false]); 18302 * // => true 18303 * 18304 * // The `_.property` iteratee shorthand. 18305 * _.some(users, 'active'); 18306 * // => true 18307 */ 18308 function some(collection, predicate, guard) { 18309 var func = isArray(collection) ? arraySome : baseSome; 18310 if (guard && isIterateeCall(collection, predicate, guard)) { 18311 predicate = undefined$1; 18312 } 18313 return func(collection, getIteratee(predicate, 3)); 18314 } 18315 18316 /** 18317 * Creates an array of elements, sorted in ascending order by the results of 18318 * running each element in a collection thru each iteratee. This method 18319 * performs a stable sort, that is, it preserves the original sort order of 18320 * equal elements. The iteratees are invoked with one argument: (value). 18321 * 18322 * @static 18323 * @memberOf _ 18324 * @since 0.1.0 18325 * @category Collection 18326 * @param {Array|Object} collection The collection to iterate over. 18327 * @param {...(Function|Function[])} [iteratees=[_.identity]] 18328 * The iteratees to sort by. 18329 * @returns {Array} Returns the new sorted array.
18330 * @example 18331 * 18332 * var users = [ 18333 * { 'user': 'fred', 'age': 48 }, 18334 * { 'user': 'barney', 'age': 36 }, 18335 * { 'user': 'fred', 'age': 30 }, 18336 * { 'user': 'barney', 'age': 34 } 18337 * ]; 18338 * 18339 * _.sortBy(users, [function(o) { return o.user; }]); 18340 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]] 18341 * 18342 * _.sortBy(users, ['user', 'age']); 18343 * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]] 18344 */ 18345 var sortBy = baseRest(function(collection, iteratees) { 18346 if (collection == null) { 18347 return []; 18348 } 18349 var length = iteratees.length; 18350 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { 18351 iteratees = []; 18352 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { 18353 iteratees = [iteratees[0]]; 18354 } 18355 return baseOrderBy(collection, baseFlatten(iteratees, 1), []); 18356 }); 18357 18358 /*------------------------------------------------------------------------*/ 18359 18360 /** 18361 * Gets the timestamp of the number of milliseconds that have elapsed since 18362 * the Unix epoch (1 January 1970 00:00:00 UTC). 18363 * 18364 * @static 18365 * @memberOf _ 18366 * @since 2.4.0 18367 * @category Date 18368 * @returns {number} Returns the timestamp. 18369 * @example 18370 * 18371 * _.defer(function(stamp) { 18372 * console.log(_.now() - stamp); 18373 * }, _.now()); 18374 * // => Logs the number of milliseconds it took for the deferred invocation. 18375 */ 18376 var now = ctxNow || function() { 18377 return root.Date.now(); 18378 }; 18379 18380 /*------------------------------------------------------------------------*/ 18381 18382 /** 18383 * The opposite of `_.before`; this method creates a function that invokes 18384 * `func` once it's called `n` or more times. 18385 * 18386 * @static 18387 * @memberOf _ 18388 * @since 0.1.0 18389 * @category Function 18390 * @param {number} n The number of calls before `func` is invoked. 18391 * @param {Function} func The function to restrict. 18392 * @returns {Function} Returns the new restricted function. 18393 * @example 18394 * 18395 * var saves = ['profile', 'settings']; 18396 * 18397 * var done = _.after(saves.length, function() { 18398 * console.log('done saving!'); 18399 * }); 18400 * 18401 * _.forEach(saves, function(type) { 18402 * asyncSave({ 'type': type, 'complete': done }); 18403 * }); 18404 * // => Logs 'done saving!' after the two async saves have completed. 18405 */ 18406 function after(n, func) { 18407 if (typeof func != 'function') { 18408 throw new TypeError(FUNC_ERROR_TEXT); 18409 } 18410 n = toInteger(n); 18411 return function() { 18412 if (--n < 1) { 18413 return func.apply(this, arguments); 18414 } 18415 }; 18416 } 18417 18418 /** 18419 * Creates a function that invokes `func`, with up to `n` arguments, 18420 * ignoring any additional arguments. 18421 * 18422 * @static 18423 * @memberOf _ 18424 * @since 3.0.0 18425 * @category Function 18426 * @param {Function} func The function to cap arguments for. 18427 * @param {number} [n=func.length] The arity cap. 18428 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 18429 * @returns {Function} Returns the new capped function. 18430 * @example 18431 * 18432 * _.map(['6', '8', '10'], _.ary(parseInt, 1)); 18433 * // => [6, 8, 10] 18434 */ 18435 function ary(func, n, guard) { 18436 n = guard ? undefined$1 : n; 18437 n = (func && n == null) ? func.length : n; 18438 return createWrap(func, WRAP_ARY_FLAG, undefined$1, undefined$1, undefined$1, undefined$1, n); 18439 } 18440 18441 /** 18442 * Creates a function that invokes `func`, with the `this` binding and arguments 18443 * of the created function, while it's called less than `n` times. Subsequent 18444 * calls to the created function return the result of the last `func` invocation. 18445 * 18446 * @static 18447 * @memberOf _ 18448 * @since 3.0.0 18449 * @category Function 18450 * @param {number} n The number of calls at which `func` is no longer invoked. 18451 * @param {Function} func The function to restrict. 18452 * @returns {Function} Returns the new restricted function. 18453 * @example 18454 * 18455 * jQuery(element).on('click', _.before(5, addContactToList)); 18456 * // => Allows adding up to 4 contacts to the list. 18457 */ 18458 function before(n, func) { 18459 var result; 18460 if (typeof func != 'function') { 18461 throw new TypeError(FUNC_ERROR_TEXT); 18462 } 18463 n = toInteger(n); 18464 return function() { 18465 if (--n > 0) { 18466 result = func.apply(this, arguments); 18467 } 18468 if (n <= 1) { 18469 func = undefined$1; 18470 } 18471 return result; 18472 }; 18473 } 18474 18475 /** 18476 * Creates a function that invokes `func` with the `this` binding of `thisArg` 18477 * and `partials` prepended to the arguments it receives. 18478 * 18479 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, 18480 * may be used as a placeholder for partially applied arguments. 18481 * 18482 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length" 18483 * property of bound functions. 18484 * 18485 * @static 18486 * @memberOf _ 18487 * @since 0.1.0 18488 * @category Function 18489 * @param {Function} func The function to bind. 18490 * @param {*} thisArg The `this` binding of `func`. 18491 * @param {...*} [partials] The arguments to be partially applied. 18492 * @returns {Function} Returns the new bound function. 18493 * @example 18494 * 18495 * function greet(greeting, punctuation) { 18496 * return greeting + ' ' + this.user + punctuation; 18497 * } 18498 * 18499 * var object = { 'user': 'fred' }; 18500 * 18501 * var bound = _.bind(greet, object, 'hi'); 18502 * bound('!'); 18503 * // => 'hi fred!' 18504 * 18505 * // Bound with placeholders. 18506 * var bound = _.bind(greet, object, _, '!'); 18507 * bound('hi'); 18508 * // => 'hi fred!' 18509 */ 18510 var bind = baseRest(function(func, thisArg, partials) { 18511 var bitmask = WRAP_BIND_FLAG; 18512 if (partials.length) { 18513 var holders = replaceHolders(partials, getHolder(bind)); 18514 bitmask |= WRAP_PARTIAL_FLAG; 18515 } 18516 return createWrap(func, bitmask, thisArg, partials, holders); 18517 }); 18518 18519 /** 18520 * Creates a function that invokes the method at `object[key]` with `partials` 18521 * prepended to the arguments it receives. 18522 * 18523 * This method differs from `_.bind` by allowing bound functions to reference 18524 * methods that may be redefined or don't yet exist. See 18525 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) 18526 * for more details. 18527 * 18528 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic 18529 * builds, may be used as a placeholder for partially applied arguments. 18530 * 18531 * @static 18532 * @memberOf _
18533 * @since 0.10.0 18534 * @category Function 18535 * @param {Object} object The object to invoke the method on. 18536 * @param {string} key The key of the method. 18537 * @param {...*} [partials] The arguments to be partially applied. 18538 * @returns {Function} Returns the new bound function. 18539 * @example 18540 * 18541 * var object = { 18542 * 'user': 'fred', 18543 * 'greet': function(greeting, punctuation) { 18544 * return greeting + ' ' + this.user + punctuation; 18545 * } 18546 * }; 18547 * 18548 * var bound = _.bindKey(object, 'greet', 'hi'); 18549 * bound('!'); 18550 * // => 'hi fred!' 18551 * 18552 * object.greet = function(greeting, punctuation) { 18553 * return greeting + 'ya ' + this.user + punctuation; 18554 * }; 18555 * 18556 * bound('!'); 18557 * // => 'hiya fred!' 18558 * 18559 * // Bound with placeholders. 18560 * var bound = _.bindKey(object, 'greet', _, '!'); 18561 * bound('hi'); 18562 * // => 'hiya fred!' 18563 */ 18564 var bindKey = baseRest(function(object, key, partials) { 18565 var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG; 18566 if (partials.length) { 18567 var holders = replaceHolders(partials, getHolder(bindKey)); 18568 bitmask |= WRAP_PARTIAL_FLAG; 18569 } 18570 return createWrap(key, bitmask, object, partials, holders); 18571 }); 18572 18573 /** 18574 * Creates a function that accepts arguments of `func` and either invokes 18575 * `func` returning its result, if at least `arity` number of arguments have 18576 * been provided, or returns a function that accepts the remaining `func` 18577 * arguments, and so on. The arity of `func` may be specified if `func.length` 18578 * is not sufficient. 18579 * 18580 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, 18581 * may be used as a placeholder for provided arguments. 18582 * 18583 * **Note:** This method doesn't set the "length" property of curried functions. 18584 * 18585 * @static 18586 * @memberOf _ 18587 * @since 2.0.0 18588 * @category Function 18589 * @param {Function} func The function to curry. 18590 * @param {number} [arity=func.length] The arity of `func`. 18591 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 18592 * @returns {Function} Returns the new curried function. 18593 * @example 18594 * 18595 * var abc = function(a, b, c) { 18596 * return [a, b, c]; 18597 * }; 18598 * 18599 * var curried = _.curry(abc); 18600 * 18601 * curried(1)(2)(3); 18602 * // => [1, 2, 3] 18603 * 18604 * curried(1, 2)(3); 18605 * // => [1, 2, 3] 18606 * 18607 * curried(1, 2, 3); 18608 * // => [1, 2, 3] 18609 * 18610 * // Curried with placeholders. 18611 * curried(1)(_, 3)(2); 18612 * // => [1, 2, 3] 18613 */ 18614 function curry(func, arity, guard) { 18615 arity = guard ? undefined$1 : arity; 18616 var result = createWrap(func, WRAP_CURRY_FLAG, undefined$1, undefined$1, undefined$1, undefined$1, undefined$1, arity); 18617 result.placeholder = curry.placeholder; 18618 return result; 18619 } 18620 18621 /** 18622 * This method is like `_.curry` except that arguments are applied to `func` 18623 * in the manner of `_.partialRight` instead of `_.partial`. 18624 * 18625 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic 18626 * builds, may be used as a placeholder for provided arguments. 18627 * 18628 * **Note:** This method doesn't set the "length" property of curried functions. 18629 * 18630 * @static 18631 * @memberOf _ 18632 * @since 3.0.0 18633 * @category Function 18634 * @param {Function} func The function to curry. 18635 * @param {number} [arity=func.length] The arity of `func`. 18636 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 18637 * @returns {Function} Returns the new curried function. 18638 * @example 18639 * 18640 * var abc = function(a, b, c) { 18641 * return [a, b, c]; 18642 * }; 18643 * 18644 * var curried = _.curryRight(abc); 18645 * 18646 * curried(3)(2)(1); 18647 * // => [1, 2, 3] 18648 * 18649 * curried(2, 3)(1); 18650 * // => [1, 2, 3] 18651 * 18652 * curried(1, 2, 3); 18653 * // => [1, 2, 3] 18654 * 18655 * // Curried with placeholders. 18656 * curried(3)(1, _)(2); 18657 * // => [1, 2, 3] 18658 */ 18659 function curryRight(func, arity, guard) { 18660 arity = guard ? undefined$1 : arity; 18661 var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined$1, undefined$1, undefined$1, undefined$1, undefined$1, arity); 18662 result.placeholder = curryRight.placeholder; 18663 return result; 18664 } 18665 18666 /** 18667 * Creates a debounced function that delays invoking `func` until after `wait` 18668 * milliseconds have elapsed since the last time the debounced function was 18669 * invoked. The debounced function comes with a `cancel` method to cancel 18670 * delayed `func` invocations and a `flush` method to immediately invoke them. 18671 * Provide `options` to indicate whether `func` should be invoked on the 18672 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked 18673 * with the last arguments provided to the debounced function. Subsequent 18674 * calls to the debounced function return the result of the last `func` 18675 * invocation. 18676 * 18677 * **Note:** If `leading` and `trailing` options are `true`, `func` is 18678 * invoked on the trailing edge of the timeout only if the debounced function 18679 * is invoked more than once during the `wait` timeout. 18680 * 18681 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred 18682 * until to the next tick, similar to `setTimeout` with a timeout of `0`. 18683 *
18684 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) 18685 * for details over the differences between `_.debounce` and `_.throttle`. 18686 * 18687 * @static 18688 * @memberOf _ 18689 * @since 0.1.0 18690 * @category Function 18691 * @param {Function} func The function to debounce. 18692 * @param {number} [wait=0] The number of milliseconds to delay. 18693 * @param {Object} [options={}] The options object. 18694 * @param {boolean} [options.leading=false] 18695 * Specify invoking on the leading edge of the timeout. 18696 * @param {number} [options.maxWait] 18697 * The maximum time `func` is allowed to be delayed before it's invoked. 18698 * @param {boolean} [options.trailing=true] 18699 * Specify invoking on the trailing edge of the timeout. 18700 * @returns {Function} Returns the new debounced function. 18701 * @example 18702 * 18703 * // Avoid costly calculations while the window size is in flux. 18704 * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); 18705 * 18706 * // Invoke `sendMail` when clicked, debouncing subsequent calls. 18707 * jQuery(element).on('click', _.debounce(sendMail, 300, { 18708 * 'leading': true, 18709 * 'trailing': false 18710 * })); 18711 * 18712 * // Ensure `batchLog` is invoked once after 1 second of debounced calls. 18713 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); 18714 * var source = new EventSource('/stream'); 18715 * jQuery(source).on('message', debounced); 18716 * 18717 * // Cancel the trailing debounced invocation. 18718 * jQuery(window).on('popstate', debounced.cancel); 18719 */ 18720 function debounce(func, wait, options) { 18721 var lastArgs, 18722 lastThis, 18723 maxWait, 18724 result, 18725 timerId, 18726 lastCallTime, 18727 lastInvokeTime = 0, 18728 leading = false, 18729 maxing = false, 18730 trailing = true; 18731 18732 if (typeof func != 'function') { 18733 throw new TypeError(FUNC_ERROR_TEXT); 18734 } 18735 wait = toNumber(wait) || 0; 18736 if (isObject(options)) { 18737 leading = !!options.leading; 18738 maxing = 'maxWait' in options; 18739 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; 18740 trailing = 'trailing' in options ? !!options.trailing : trailing; 18741 } 18742 18743 function invokeFunc(time) { 18744 var args = lastArgs, 18745 thisArg = lastThis; 18746 18747 lastArgs = lastThis = undefined$1; 18748 lastInvokeTime = time; 18749 result = func.apply(thisArg, args); 18750 return result; 18751 } 18752 18753 function leadingEdge(time) { 18754 // Reset any `maxWait` timer. 18755 lastInvokeTime = time; 18756 // Start the timer for the trailing edge. 18757 timerId = setTimeout(timerExpired, wait); 18758 // Invoke the leading edge. 18759 return leading ? invokeFunc(time) : result; 18760 } 18761 18762 function remainingWait(time) { 18763 var timeSinceLastCall = time - lastCallTime, 18764 timeSinceLastInvoke = time - lastInvokeTime, 18765 timeWaiting = wait - timeSinceLastCall; 18766 18767 return maxing 18768 ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) 18769 : timeWaiting; 18770 } 18771 18772 function shouldInvoke(time) { 18773 var timeSinceLastCall = time - lastCallTime, 18774 timeSinceLastInvoke = time - lastInvokeTime; 18775 18776 // Either this is the first call, activity has stopped and we're at the 18777 // trailing edge, the system time has gone backwards and we're treating 18778 // it as the trailing edge, or we've hit the `maxWait` limit. 18779 return (lastCallTime === undefined$1 || (timeSinceLastCall >= wait) || 18780 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); 18781 } 18782 18783 function timerExpired() { 18784 var time = now(); 18785 if (shouldInvoke(time)) { 18786 return trailingEdge(time); 18787 } 18788 // Restart the timer. 18789 timerId = setTimeout(timerExpired, remainingWait(time)); 18790 } 18791 18792 function trailingEdge(time) { 18793 timerId = undefined$1; 18794 18795 // Only invoke if we have `lastArgs` which means `func` has been 18796 // debounced at least once. 18797 if (trailing && lastArgs) { 18798 return invokeFunc(time); 18799 } 18800 lastArgs = lastThis = undefined$1; 18801 return result; 18802 } 18803 18804 function cancel() { 18805 if (timerId !== undefined$1) { 18806 clearTimeout(timerId); 18807 } 18808 lastInvokeTime = 0; 18809 lastArgs = lastCallTime = lastThis = timerId = undefined$1; 18810 } 18811 18812 function flush() { 18813 return timerId === undefined$1 ? result : trailingEdge(now()); 18814 } 18815 18816 function debounced() { 18817 var time = now(), 18818 isInvoking = shouldInvoke(time); 18819 18820 lastArgs = arguments; 18821 lastThis = this; 18822 lastCallTime = time; 18823 18824 if (isInvoking) { 18825 if (timerId === undefined$1) { 18826 return leadingEdge(lastCallTime); 18827 } 18828 if (maxing) { 18829 // Handle invocations in a tight loop. 18830 clearTimeout(timerId); 18831 timerId = setTimeout(timerExpired, wait); 18832 return invokeFunc(lastCallTime); 18833 } 18834 } 18835 if (timerId === undefined$1) { 18836 timerId = setTimeout(timerExpired, wait); 18837 } 18838 return result; 18839 } 18840 debounced.cancel = cancel; 18841 debounced.flush = flush; 18842 return debounced; 18843 } 18844 18845 /** 18846 * Defers invoking the `func` until the current call stack has cleared. Any 18847 * additional arguments are provided to `func` when it's invoked. 18848 * 18849 * @static 18850 * @memberOf _ 18851 * @since 0.1.0 18852 * @category Function 18853 * @param {Function} func The function to defer. 18854 * @param {...*} [args] The arguments to invoke `func` with. 18855 * @returns {number} Returns the timer id. 18856 * @example 18857 * 18858 * _.defer(function(text) { 18859 * console.log(text); 18860 * }, 'deferred'); 18861 * // => Logs 'deferred' after one millisecond. 18862 */ 18863 var defer = baseRest(function(func, args) { 18864 return baseDelay(func, 1, args); 18865 }); 18866 18867 /** 18868 * Invokes `func` after `wait` milliseconds. Any additional arguments are 18869 * provided to `func` when it's invoked. 18870 * 18871 * @static 18872 * @memberOf _ 18873 * @since 0.1.0 18874 * @category Function 18875 * @param {Function} func The function to delay. 18876 * @param {number} wait The number of milliseconds to delay invocation. 18877 * @param {...*} [args] The arguments to invoke `func` with. 18878 * @returns {number} Returns the timer id. 18879 * @example 18880 * 18881 * _.delay(function(text) { 18882 * console.log(text); 18883 * }, 1000, 'later'); 18884 * // => Logs 'later' after one second. 18885 */
vendor: 10,871 bytes, lines 18886-19189
18886 var delay = baseRest(function(func, wait, args) { 18887 return baseDelay(func, toNumber(wait) || 0, args); 18888 }); 18889 18890 /** 18891 * Creates a function that invokes `func` with arguments reversed. 18892 * 18893 * @static 18894 * @memberOf _ 18895 * @since 4.0.0 18896 * @category Function 18897 * @param {Function} func The function to flip arguments for. 18898 * @returns {Function} Returns the new flipped function. 18899 * @example 18900 * 18901 * var flipped = _.flip(function() { 18902 * return _.toArray(arguments); 18903 * }); 18904 * 18905 * flipped('a', 'b', 'c', 'd'); 18906 * // => ['d', 'c', 'b', 'a'] 18907 */ 18908 function flip(func) { 18909 return createWrap(func, WRAP_FLIP_FLAG); 18910 } 18911 18912 /** 18913 * Creates a function that memoizes the result of `func`. If `resolver` is 18914 * provided, it determines the cache key for storing the result based on the 18915 * arguments provided to the memoized function. By default, the first argument 18916 * provided to the memoized function is used as the map cache key. The `func` 18917 * is invoked with the `this` binding of the memoized function. 18918 * 18919 * **Note:** The cache is exposed as the `cache` property on the memoized 18920 * function. Its creation may be customized by replacing the `_.memoize.Cache` 18921 * constructor with one whose instances implement the 18922 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) 18923 * method interface of `clear`, `delete`, `get`, `has`, and `set`. 18924 * 18925 * @static 18926 * @memberOf _ 18927 * @since 0.1.0 18928 * @category Function 18929 * @param {Function} func The function to have its output memoized. 18930 * @param {Function} [resolver] The function to resolve the cache key. 18931 * @returns {Function} Returns the new memoized function. 18932 * @example 18933 * 18934 * var object = { 'a': 1, 'b': 2 }; 18935 * var other = { 'c': 3, 'd': 4 }; 18936 * 18937 * var values = _.memoize(_.values); 18938 * values(object); 18939 * // => [1, 2] 18940 * 18941 * values(other); 18942 * // => [3, 4] 18943 * 18944 * object.a = 2; 18945 * values(object); 18946 * // => [1, 2] 18947 * 18948 * // Modify the result cache. 18949 * values.cache.set(object, ['a', 'b']); 18950 * values(object); 18951 * // => ['a', 'b'] 18952 * 18953 * // Replace `_.memoize.Cache`. 18954 * _.memoize.Cache = WeakMap; 18955 */ 18956 function memoize(func, resolver) { 18957 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { 18958 throw new TypeError(FUNC_ERROR_TEXT); 18959 } 18960 var memoized = function() { 18961 var args = arguments, 18962 key = resolver ? resolver.apply(this, args) : args[0], 18963 cache = memoized.cache; 18964 18965 if (cache.has(key)) { 18966 return cache.get(key); 18967 } 18968 var result = func.apply(this, args); 18969 memoized.cache = cache.set(key, result) || cache; 18970 return result; 18971 }; 18972 memoized.cache = new (memoize.Cache || MapCache); 18973 return memoized; 18974 } 18975 18976 // Expose `MapCache`. 18977 memoize.Cache = MapCache; 18978 18979 /** 18980 * Creates a function that negates the result of the predicate `func`. The 18981 * `func` predicate is invoked with the `this` binding and arguments of the 18982 * created function. 18983 * 18984 * @static 18985 * @memberOf _ 18986 * @since 3.0.0 18987 * @category Function 18988 * @param {Function} predicate The predicate to negate. 18989 * @returns {Function} Returns the new negated function. 18990 * @example 18991 * 18992 * function isEven(n) { 18993 * return n % 2 == 0; 18994 * } 18995 * 18996 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); 18997 * // => [1, 3, 5] 18998 */ 18999 function negate(predicate) { 19000 if (typeof predicate != 'function') { 19001 throw new TypeError(FUNC_ERROR_TEXT); 19002 } 19003 return function() { 19004 var args = arguments; 19005 switch (args.length) { 19006 case 0: return !predicate.call(this); 19007 case 1: return !predicate.call(this, args[0]); 19008 case 2: return !predicate.call(this, args[0], args[1]); 19009 case 3: return !predicate.call(this, args[0], args[1], args[2]); 19010 } 19011 return !predicate.apply(this, args); 19012 }; 19013 } 19014 19015 /** 19016 * Creates a function that is restricted to invoking `func` once. Repeat calls 19017 * to the function return the value of the first invocation. The `func` is 19018 * invoked with the `this` binding and arguments of the created function. 19019 * 19020 * @static 19021 * @memberOf _ 19022 * @since 0.1.0 19023 * @category Function 19024 * @param {Function} func The function to restrict. 19025 * @returns {Function} Returns the new restricted function. 19026 * @example 19027 * 19028 * var initialize = _.once(createApplication); 19029 * initialize(); 19030 * initialize(); 19031 * // => `createApplication` is invoked once 19032 */ 19033 function once(func) { 19034 return before(2, func); 19035 } 19036 19037 /** 19038 * Creates a function that invokes `func` with its arguments transformed. 19039 * 19040 * @static 19041 * @since 4.0.0 19042 * @memberOf _ 19043 * @category Function 19044 * @param {Function} func The function to wrap. 19045 * @param {...(Function|Function[])} [transforms=[_.identity]] 19046 * The argument transforms. 19047 * @returns {Function} Returns the new function. 19048 * @example 19049 * 19050 * function doubled(n) { 19051 * return n * 2; 19052 * } 19053 * 19054 * function square(n) { 19055 * return n * n; 19056 * } 19057 * 19058 * var func = _.overArgs(function(x, y) { 19059 * return [x, y]; 19060 * }, [square, doubled]); 19061 * 19062 * func(9, 3); 19063 * // => [81, 6] 19064 * 19065 * func(10, 5); 19066 * // => [100, 10] 19067 */ 19068 var overArgs = castRest(function(func, transforms) { 19069 transforms = (transforms.length == 1 && isArray(transforms[0])) 19070 ? arrayMap(transforms[0], baseUnary(getIteratee())) 19071 : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee())); 19072 19073 var funcsLength = transforms.length; 19074 return baseRest(function(args) { 19075 var index = -1, 19076 length = nativeMin(args.length, funcsLength); 19077 19078 while (++index < length) { 19079 args[index] = transforms[index].call(this, args[index]); 19080 } 19081 return apply(func, this, args); 19082 }); 19083 }); 19084 19085 /** 19086 * Creates a function that invokes `func` with `partials` prepended to the 19087 * arguments it receives. This method is like `_.bind` except it does **not** 19088 * alter the `this` binding. 19089 * 19090 * The `_.partial.placeholder` value, which defaults to `_` in monolithic 19091 * builds, may be used as a placeholder for partially applied arguments. 19092 * 19093 * **Note:** This method doesn't set the "length" property of partially 19094 * applied functions. 19095 * 19096 * @static 19097 * @memberOf _ 19098 * @since 0.2.0 19099 * @category Function 19100 * @param {Function} func The function to partially apply arguments to. 19101 * @param {...*} [partials] The arguments to be partially applied. 19102 * @returns {Function} Returns the new partially applied function. 19103 * @example 19104 * 19105 * function greet(greeting, name) { 19106 * return greeting + ' ' + name; 19107 * } 19108 * 19109 * var sayHelloTo = _.partial(greet, 'hello'); 19110 * sayHelloTo('fred'); 19111 * // => 'hello fred' 19112 * 19113 * // Partially applied with placeholders. 19114 * var greetFred = _.partial(greet, _, 'fred'); 19115 * greetFred('hi'); 19116 * // => 'hi fred' 19117 */ 19118 var partial = baseRest(function(func, partials) { 19119 var holders = replaceHolders(partials, getHolder(partial)); 19120 return createWrap(func, WRAP_PARTIAL_FLAG, undefined$1, partials, holders); 19121 }); 19122 19123 /** 19124 * This method is like `_.partial` except that partially applied arguments 19125 * are appended to the arguments it receives. 19126 * 19127 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic 19128 * builds, may be used as a placeholder for partially applied arguments. 19129 * 19130 * **Note:** This method doesn't set the "length" property of partially 19131 * applied functions. 19132 * 19133 * @static 19134 * @memberOf _ 19135 * @since 1.0.0 19136 * @category Function 19137 * @param {Function} func The function to partially apply arguments to. 19138 * @param {...*} [partials] The arguments to be partially applied. 19139 * @returns {Function} Returns the new partially applied function. 19140 * @example 19141 * 19142 * function greet(greeting, name) { 19143 * return greeting + ' ' + name; 19144 * } 19145 * 19146 * var greetFred = _.partialRight(greet, 'fred'); 19147 * greetFred('hi'); 19148 * // => 'hi fred' 19149 * 19150 * // Partially applied with placeholders. 19151 * var sayHelloTo = _.partialRight(greet, 'hello', _); 19152 * sayHelloTo('fred'); 19153 * // => 'hello fred' 19154 */ 19155 var partialRight = baseRest(function(func, partials) { 19156 var holders = replaceHolders(partials, getHolder(partialRight)); 19157 return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined$1, partials, holders); 19158 }); 19159 19160 /** 19161 * Creates a function that invokes `func` with arguments arranged according 19162 * to the specified `indexes` where the argument value at the first index is 19163 * provided as the first argument, the argument value at the second index is 19164 * provided as the second argument, and so on. 19165 * 19166 * @static 19167 * @memberOf _ 19168 * @since 3.0.0 19169 * @category Function 19170 * @param {Function} func The function to rearrange arguments for. 19171 * @param {...(number|number[])} indexes The arranged argument indexes. 19172 * @returns {Function} Returns the new function. 19173 * @example 19174 * 19175 * var rearged = _.rearg(function(a, b, c) { 19176 * return [a, b, c]; 19177 * }, [2, 0, 1]); 19178 * 19179 * rearged('b', 'c', 'a') 19180 * // => ['a', 'b', 'c'] 19181 */ 19182 var rearg = flatRest(function(func, indexes) { 19183 return createWrap(func, WRAP_REARG_FLAG, undefined$1, undefined$1, undefined$1, indexes); 19184 }); 19185 19186 /** 19187 * Creates a function that invokes `func` with the `this` binding of the 19188 * created function and arguments from `start` and beyond provided as 19189 * an array.
19190 * 19191 * **Note:** This method is based on the 19192 * [rest parameter](https://mdn.io/rest_parameters). 19193 * 19194 * @static 19195 * @memberOf _ 19196 * @since 4.0.0 19197 * @category Function 19198 * @param {Function} func The function to apply a rest parameter to. 19199 * @param {number} [start=func.length-1] The start position of the rest parameter. 19200 * @returns {Function} Returns the new function. 19201 * @example 19202 * 19203 * var say = _.rest(function(what, names) { 19204 * return what + ' ' + _.initial(names).join(', ') + 19205 * (_.size(names) > 1 ? ', & ' : '') + _.last(names); 19206 * }); 19207 * 19208 * say('hello', 'fred', 'barney', 'pebbles'); 19209 * // => 'hello fred, barney, & pebbles' 19210 */ 19211 function rest(func, start) { 19212 if (typeof func != 'function') { 19213 throw new TypeError(FUNC_ERROR_TEXT); 19214 } 19215 start = start === undefined$1 ? start : toInteger(start); 19216 return baseRest(func, start); 19217 } 19218 19219 /** 19220 * Creates a function that invokes `func` with the `this` binding of the 19221 * create function and an array of arguments much like 19222 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply). 19223 * 19224 * **Note:** This method is based on the 19225 * [spread operator](https://mdn.io/spread_operator). 19226 * 19227 * @static 19228 * @memberOf _ 19229 * @since 3.2.0 19230 * @category Function 19231 * @param {Function} func The function to spread arguments over. 19232 * @param {number} [start=0] The start position of the spread. 19233 * @returns {Function} Returns the new function. 19234 * @example 19235 * 19236 * var say = _.spread(function(who, what) { 19237 * return who + ' says ' + what; 19238 * }); 19239 * 19240 * say(['fred', 'hello']); 19241 * // => 'fred says hello' 19242 * 19243 * var numbers = Promise.all([ 19244 * Promise.resolve(40), 19245 * Promise.resolve(36) 19246 * ]); 19247 * 19248 * numbers.then(_.spread(function(x, y) { 19249 * return x + y; 19250 * })); 19251 * // => a Promise of 76 19252 */ 19253 function spread(func, start) { 19254 if (typeof func != 'function') { 19255 throw new TypeError(FUNC_ERROR_TEXT); 19256 } 19257 start = start == null ? 0 : nativeMax(toInteger(start), 0); 19258 return baseRest(function(args) { 19259 var array = args[start], 19260 otherArgs = castSlice(args, 0, start); 19261 19262 if (array) { 19263 arrayPush(otherArgs, array); 19264 } 19265 return apply(func, this, otherArgs); 19266 }); 19267 } 19268 19269 /** 19270 * Creates a throttled function that only invokes `func` at most once per 19271 * every `wait` milliseconds. The throttled function comes with a `cancel` 19272 * method to cancel delayed `func` invocations and a `flush` method to 19273 * immediately invoke them. Provide `options` to indicate whether `func` 19274 * should be invoked on the leading and/or trailing edge of the `wait` 19275 * timeout. The `func` is invoked with the last arguments provided to the 19276 * throttled function. Subsequent calls to the throttled function return the 19277 * result of the last `func` invocation. 19278 * 19279 * **Note:** If `leading` and `trailing` options are `true`, `func` is 19280 * invoked on the trailing edge of the timeout only if the throttled function 19281 * is invoked more than once during the `wait` timeout. 19282 * 19283 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred 19284 * until to the next tick, similar to `setTimeout` with a timeout of `0`. 19285 * 19286 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) 19287 * for details over the differences between `_.throttle` and `_.debounce`. 19288 * 19289 * @static 19290 * @memberOf _ 19291 * @since 0.1.0 19292 * @category Function 19293 * @param {Function} func The function to throttle. 19294 * @param {number} [wait=0] The number of milliseconds to throttle invocations to. 19295 * @param {Object} [options={}] The options object. 19296 * @param {boolean} [options.leading=true] 19297 * Specify invoking on the leading edge of the timeout. 19298 * @param {boolean} [options.trailing=true] 19299 * Specify invoking on the trailing edge of the timeout. 19300 * @returns {Function} Returns the new throttled function. 19301 * @example 19302 * 19303 * // Avoid excessively updating the position while scrolling. 19304 * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); 19305 * 19306 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. 19307 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); 19308 * jQuery(element).on('click', throttled); 19309 * 19310 * // Cancel the trailing throttled invocation. 19311 * jQuery(window).on('popstate', throttled.cancel); 19312 */ 19313 function throttle(func, wait, options) { 19314 var leading = true, 19315 trailing = true; 19316 19317 if (typeof func != 'function') { 19318 throw new TypeError(FUNC_ERROR_TEXT); 19319 } 19320 if (isObject(options)) { 19321 leading = 'leading' in options ? !!options.leading : leading; 19322 trailing = 'trailing' in options ? !!options.trailing : trailing; 19323 } 19324 return debounce(func, wait, { 19325 'leading': leading, 19326 'maxWait': wait, 19327 'trailing': trailing 19328 }); 19329 } 19330 19331 /** 19332 * Creates a function that accepts up to one argument, ignoring any 19333 * additional arguments. 19334 * 19335 * @static 19336 * @memberOf _ 19337 * @since 4.0.0 19338 * @category Function 19339 * @param {Function} func The function to cap arguments for. 19340 * @returns {Function} Returns the new capped function. 19341 * @example 19342 * 19343 * _.map(['6', '8', '10'], _.unary(parseInt)); 19344 * // => [6, 8, 10] 19345 */ 19346 function unary(func) { 19347 return ary(func, 1); 19348 } 19349 19350 /** 19351 * Creates a function that provides `value` to `wrapper` as its first 19352 * argument. Any additional arguments provided to the function are appended 19353 * to those provided to the `wrapper`. The wrapper is invoked with the `this` 19354 * binding of the created function. 19355 * 19356 * @static 19357 * @memberOf _ 19358 * @since 0.1.0 19359 * @category Function 19360 * @param {*} value The value to wrap. 19361 * @param {Function} [wrapper=identity] The wrapper function. 19362 * @returns {Function} Returns the new function. 19363 * @example 19364 *
19365 * var p = _.wrap(_.escape, function(func, text) { 19366 * return '<p>' + func(text) + '</p>'; 19367 * }); 19368 * 19369 * p('fred, barney, & pebbles'); 19370 * // => '<p>fred, barney, & pebbles</p>' 19371 */ 19372 function wrap(value, wrapper) { 19373 return partial(castFunction(wrapper), value); 19374 } 19375 19376 /*------------------------------------------------------------------------*/ 19377 19378 /** 19379 * Casts `value` as an array if it's not one. 19380 * 19381 * @static 19382 * @memberOf _ 19383 * @since 4.4.0 19384 * @category Lang 19385 * @param {*} value The value to inspect. 19386 * @returns {Array} Returns the cast array. 19387 * @example 19388 * 19389 * _.castArray(1); 19390 * // => [1] 19391 * 19392 * _.castArray({ 'a': 1 }); 19393 * // => [{ 'a': 1 }] 19394 * 19395 * _.castArray('abc'); 19396 * // => ['abc'] 19397 * 19398 * _.castArray(null); 19399 * // => [null] 19400 * 19401 * _.castArray(undefined); 19402 * // => [undefined] 19403 * 19404 * _.castArray(); 19405 * // => [] 19406 * 19407 * var array = [1, 2, 3]; 19408 * console.log(_.castArray(array) === array); 19409 * // => true 19410 */ 19411 function castArray() { 19412 if (!arguments.length) { 19413 return []; 19414 } 19415 var value = arguments[0]; 19416 return isArray(value) ? value : [value]; 19417 } 19418 19419 /** 19420 * Creates a shallow clone of `value`. 19421 * 19422 * **Note:** This method is loosely based on the 19423 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) 19424 * and supports cloning arrays, array buffers, booleans, date objects, maps, 19425 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed 19426 * arrays. The own enumerable properties of `arguments` objects are cloned 19427 * as plain objects. An empty object is returned for uncloneable values such 19428 * as error objects, functions, DOM nodes, and WeakMaps. 19429 * 19430 * @static 19431 * @memberOf _ 19432 * @since 0.1.0 19433 * @category Lang 19434 * @param {*} value The value to clone. 19435 * @returns {*} Returns the cloned value. 19436 * @see _.cloneDeep 19437 * @example 19438 * 19439 * var objects = [{ 'a': 1 }, { 'b': 2 }]; 19440 * 19441 * var shallow = _.clone(objects); 19442 * console.log(shallow[0] === objects[0]); 19443 * // => true 19444 */ 19445 function clone(value) { 19446 return baseClone(value, CLONE_SYMBOLS_FLAG); 19447 } 19448 19449 /** 19450 * This method is like `_.clone` except that it accepts `customizer` which 19451 * is invoked to produce the cloned value. If `customizer` returns `undefined`, 19452 * cloning is handled by the method instead. The `customizer` is invoked with 19453 * up to four arguments; (value [, index|key, object, stack]). 19454 * 19455 * @static 19456 * @memberOf _ 19457 * @since 4.0.0 19458 * @category Lang 19459 * @param {*} value The value to clone. 19460 * @param {Function} [customizer] The function to customize cloning. 19461 * @returns {*} Returns the cloned value. 19462 * @see _.cloneDeepWith 19463 * @example 19464 * 19465 * function customizer(value) { 19466 * if (_.isElement(value)) { 19467 * return value.cloneNode(false); 19468 * } 19469 * } 19470 * 19471 * var el = _.cloneWith(document.body, customizer); 19472 * 19473 * console.log(el === document.body); 19474 * // => false 19475 * console.log(el.nodeName); 19476 * // => 'BODY' 19477 * console.log(el.childNodes.length); 19478 * // => 0 19479 */ 19480 function cloneWith(value, customizer) { 19481 customizer = typeof customizer == 'function' ? customizer : undefined$1; 19482 return baseClone(value, CLONE_SYMBOLS_FLAG, customizer); 19483 } 19484 19485 /** 19486 * This method is like `_.clone` except that it recursively clones `value`. 19487 * 19488 * @static 19489 * @memberOf _ 19490 * @since 1.0.0 19491 * @category Lang 19492 * @param {*} value The value to recursively clone. 19493 * @returns {*} Returns the deep cloned value. 19494 * @see _.clone 19495 * @example 19496 * 19497 * var objects = [{ 'a': 1 }, { 'b': 2 }]; 19498 * 19499 * var deep = _.cloneDeep(objects); 19500 * console.log(deep[0] === objects[0]); 19501 * // => false 19502 */ 19503 function cloneDeep(value) { 19504 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG); 19505 } 19506 19507 /** 19508 * This method is like `_.cloneWith` except that it recursively clones `value`. 19509 * 19510 * @static 19511 * @memberOf _ 19512 * @since 4.0.0 19513 * @category Lang 19514 * @param {*}
19514 value The value to recursively clone. 19515 * @param {Function} [customizer] The function to customize cloning. 19516 * @returns {*} Returns the deep cloned value. 19517 * @see _.cloneWith 19518 * @example 19519 * 19520 * function customizer(value) { 19521 * if (_.isElement(value)) { 19522 * return value.cloneNode(true); 19523 * } 19524 * } 19525 * 19526 * var el = _.cloneDeepWith(document.body, customizer); 19527 * 19528 * console.log(el === document.body); 19529 * // => false 19530 * console.log(el.nodeName); 19531 * // => 'BODY' 19532 * console.log(el.childNodes.length); 19533 * // => 20 19534 */ 19535 function cloneDeepWith(value, customizer) { 19536 customizer = typeof customizer == 'function' ? customizer : undefined$1; 19537 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer); 19538 } 19539 19540 /** 19541 * Checks if `object` conforms to `source` by invoking the predicate 19542 * properties of `source` with the corresponding property values of `object`. 19543 * 19544 * **Note:** This method is equivalent to `_.conforms` when `source` is 19545 * partially applied. 19546 * 19547 * @static 19548 * @memberOf _ 19549 * @since 4.14.0 19550 * @category Lang 19551 * @param {Object} object The object to inspect. 19552 * @param {Object} source The object of property predicates to conform to. 19553 * @returns {boolean} Returns `true` if `object` conforms, else `false`. 19554 * @example 19555 * 19556 * var object = { 'a': 1, 'b': 2 }; 19557 * 19558 * _.conformsTo(object, { 'b': function(n) { return n > 1; } }); 19559 * // => true 19560 * 19561 * _.conformsTo(object, { 'b': function(n) { return n > 2; } }); 19562 * // => false 19563 */ 19564 function conformsTo(object, source) { 19565 return source == null || baseConformsTo(object, source, keys(source)); 19566 } 19567 19568 /** 19569 * Performs a 19570 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 19571 * comparison between two values to determine if they are equivalent. 19572 * 19573 * @static 19574 * @memberOf _ 19575 * @since 4.0.0 19576 * @category Lang 19577 * @param {*} value The value to compare. 19578 * @param {*} other The other value to compare. 19579 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 19580 * @example 19581 * 19582 * var object = { 'a': 1 }; 19583 * var other = { 'a': 1 }; 19584 * 19585 * _.eq(object, object); 19586 * // => true 19587 * 19588 * _.eq(object, other); 19589 * // => false 19590 * 19591 * _.eq('a', 'a'); 19592 * // => true 19593 * 19594 * _.eq('a', Object('a')); 19595 * // => false 19596 * 19597 * _.eq(NaN, NaN); 19598 * // => true 19599 */ 19600 function eq(value, other) { 19601 return value === other || (value !== value && other !== other); 19602 } 19603 19604 /** 19605 * Checks if `value` is greater than `other`. 19606 * 19607 * @static 19608 * @memberOf _ 19609 * @since 3.9.0 19610 * @category Lang 19611 * @param {*} value The value to compare. 19612 * @param {*} other The other value to compare. 19613 * @returns {boolean} Returns `true` if `value` is greater than `other`, 19614 * else `false`. 19615 * @see _.lt 19616 * @example 19617 * 19618 * _.gt(3, 1); 19619 * // => true 19620 * 19621 * _.gt(3, 3); 19622 * // => false 19623 * 19624 * _.gt(1, 3); 19625 * // => false 19626 */ 19627 var gt = createRelationalOperation(baseGt); 19628 19629 /** 19630 * Checks if `value` is greater than or equal to `other`. 19631 * 19632 * @static 19633 * @memberOf _ 19634 * @since 3.9.0 19635 * @category Lang 19636 * @param {*} value The value to compare. 19637 * @param {*} other The other value to compare. 19638 * @returns {boolean} Returns `true` if `value` is greater than or equal to 19639 * `other`, else `false`. 19640 * @see _.lte 19641 * @example 19642 * 19643 * _.gte(3, 1); 19644 * // => true 19645 * 19646 * _.gte(3, 3); 19647 * // => true 19648 * 19649 * _.gte(1, 3); 19650 * // => false 19651 */ 19652 var gte = createRelationalOperation(function(value, other) { 19653 return value >= other; 19654 }); 19655 19656 /** 19657 * Checks if `value` is likely an `arguments` object. 19658 * 19659 * @static 19660 * @memberOf _ 19661 * @since 0.1.0 19662 * @category Lang 19663 * @param {*} value The value to check. 19664 * @returns {boolean} Returns `true` if `value` is an `arguments` object, 19665 * else `false`. 19666 * @example 19667 * 19668 * _.isArguments(function() { return arguments; }()); 19669 * // => true 19670 * 19671 * _.isArguments([1, 2, 3]); 19672 * // => false 19673 */ 19674 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { 19675 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && 19676 !propertyIsEnumerable.call(value, 'callee'); 19677 }; 19678 19679 /** 19680 * Checks if `value` is classified as an `Array` object. 19681 * 19682 * @static 19683 * @memberOf _ 19684 * @since 0.1.0 19685 * @category Lang 19686 * @param {*} value The value to check. 19687 * @returns {boolean} Returns `true` if `value` is an array, else `false`. 19688 * @example 19689 * 19690 * _.isArray([1, 2, 3]); 19691 * // => true 19692 * 19693 * _.isArray(document.body.children); 19694 * // => false 19695 * 19696 * _.isArray('abc'); 19697 * // => false 19698 * 19699 * _.isArray(_.noop); 19700 * // => false 19701 */ 19702 var isArray = Array.isArray; 19703 19704 /** 19705 * Checks if `value` is classified as an `ArrayBuffer` object. 19706 * 19707 * @static 19708 * @memberOf _ 19709 * @since 4.3.0 19710 * @category Lang 19711 * @param {*} value The value to check. 19712 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. 19713 * @example 19714 * 19715 * _.isArrayBuffer(new ArrayBuffer(2)); 19716 * // => true 19717 * 19718 * _.isArrayBuffer(new Array(2)); 19719 * // => false 19720 */ 19721 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; 19722 19723 /** 19724 * Checks if `value` is array-like. A value is considered array-like if it's 19725 * not a function and has a `value.length` that's an integer greater than or 19726 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. 19727 * 19728 * @static 19729 * @memberOf _ 19730 * @since 4.0.0 19731 * @category Lang 19732 * @param {*} value The value to check. 19733 * @returns {boolean} Returns `true` if `value` is array-like, else `false`. 19734 * @example 19735 * 19736 * _.isArrayLike([1, 2, 3]); 19737 * // => true 19738 * 19739 * _.isArrayLike(document.body.children); 19740 * // => true 19741 * 19742 * _.isArrayLike('abc'); 19743 * // => true 19744 * 19745 * _.isArrayLike(_.noop); 19746 * // => false 19747 */ 19748 function isArrayLike(value) { 19749 return value != null && isLength(value.length) && !isFunction(value); 19750 } 19751 19752 /** 19753 * This method is like `_.isArrayLike` except that it also checks if `value` 19754 * is an object. 19755 * 19756 * @static 19757 * @memberOf _ 19758 * @since 4.0.0 19759 * @category Lang 19760 * @param {*} value The value to check. 19761 * @returns {boolean} Returns `true` if `value` is an array-like object, 19762 * else `false`. 19763 * @example 19764 * 19765 * _.isArrayLikeObject([1, 2, 3]); 19766 * // => true 19767 * 19768 * _.isArrayLikeObject(document.body.children); 19769 * // => true 19770 * 19771 * _.isArrayLikeObject('abc'); 19772 * // => false 19773 * 19774 * _.isArrayLikeObject(_.noop); 19775 * // => false 19776 */ 19777 function isArrayLikeObject(value) { 19778 return isObjectLike(value) && isArrayLike(value); 19779 } 19780 19781 /** 19782 * Checks if `value` is classified as a boolean primitive or object. 19783 * 19784 * @static 19785 * @memberOf _ 19786 * @since 0.1.0 19787 * @category Lang 19788 * @param {*} value The value to check. 19789 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. 19790 * @example 19791 * 19792 * _.isBoolean(false); 19793 * // => true 19794 * 19795 * _.isBoolean(null); 19796 * // => false 19797 */ 19798 function isBoolean(value) { 19799 return value === true || value === false || 19800 (isObjectLike(value) && baseGetTag(value) == boolTag); 19801 } 19802 19803 /** 19804 * Checks if `value` is a buffer. 19805 * 19806 * @static 19807 * @memberOf _ 19808 * @since 4.3.0 19809 * @category Lang 19810 * @param {*} value The value to check. 19811 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. 19812 * @example 19813 * 19814 * _.isBuffer(new Buffer(2)); 19815 * // => true 19816 * 19817 * _.isBuffer(new Uint8Array(2)); 19818 * // => false 19819 */ 19820 var isBuffer = nativeIsBuffer || stubFalse; 19821 19822 /** 19823 * Checks if `value` is classified as a `Date` object. 19824 * 19825 * @static 19826 * @memberOf _ 19827 * @since 0.1.0 19828 * @category Lang 19829 * @param {*} value The value to check. 19830 * @returns {boolean} Returns `true` if `value` is a date object, else `false`. 19831 * @example 19832 * 19833 * _.isDate(new Date); 19834 * // => true 19835 * 19836 * _.isDate('Mon April 23 2012'); 19837 * // => false 19838 */ 19839 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; 19840 19841 /** 19842 * Checks if `value` is likely a DOM element. 19843 * 19844 * @static 19845 * @memberOf _ 19846 * @since 0.1.0 19847 * @category Lang 19848 * @param {*} value The value to check. 19849 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. 19850 * @example 19851 * 19852 * _.isElement(document.body); 19853 * // => true 19854 * 19855 * _.isElement('<body>'); 19856 * // => false 19857 */ 19858 function isElement(value) { 19859 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); 19860 } 19861 19862 /** 19863 * Checks if `value` is an empty object, collection, map, or set. 19864 * 19865 * Objects are considered empty if they have no own enumerable str
19865ing keyed 19866 * properties. 19867 * 19868 * Array-like values such as `arguments` objects, arrays, buffers, strings, or 19869 * jQuery-like collections are considered empty if they have a `length` of `0`. 19870 * Similarly, maps and sets are considered empty if they have a `size` of `0`. 19871 * 19872 * @static 19873 * @memberOf _ 19874 * @since 0.1.0 19875 * @category Lang 19876 * @param {*} value The value to check. 19877 * @returns {boolean} Returns `true` if `value` is empty, else `false`. 19878 * @example 19879 * 19880 * _.isEmpty(null); 19881 * // => true 19882 * 19883 * _.isEmpty(true); 19884 * // => true 19885 * 19886 * _.isEmpty(1); 19887 * // => true 19888 * 19889 * _.isEmpty([1, 2, 3]); 19890 * // => false 19891 * 19892 * _.isEmpty({ 'a': 1 }); 19893 * // => false 19894 */ 19895 function isEmpty(value) { 19896 if (value == null) { 19897 return true; 19898 } 19899 if (isArrayLike(value) && 19900 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || 19901 isBuffer(value) || isTypedArray(value) || isArguments(value))) { 19902 return !value.length; 19903 } 19904 var tag = getTag(value); 19905 if (tag == mapTag || tag == setTag) { 19906 return !value.size; 19907 } 19908 if (isPrototype(value)) { 19909 return !baseKeys(value).length; 19910 } 19911 for (var key in value) { 19912 if (hasOwnProperty.call(value, key)) { 19913 return false; 19914 } 19915 } 19916 return true; 19917 } 19918 19919 /** 19920 * Performs a deep comparison between two values to determine if they are 19921 * equivalent. 19922 * 19923 * **Note:** This method supports comparing arrays, array buffers, booleans, 19924 * date objects, error objects, maps, numbers, `Object` objects, regexes, 19925 * sets, strings, symbols, and typed arrays. `Object` objects are compared 19926 * by their own, not inherited, enumerable properties. Functions and DOM 19927 * nodes are compared by strict equality, i.e. `===`. 19928 * 19929 * @static 19930 * @memberOf _ 19931 * @since 0.1.0 19932 * @category Lang 19933 * @param {*} value The value to compare. 19934 * @param {*} other The other value to compare. 19935 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 19936 * @example 19937 * 19938 * var object = { 'a': 1 }; 19939 * var other = { 'a': 1 }; 19940 * 19941 * _.isEqual(object, other); 19942 * // => true 19943 * 19944 * object === other; 19945 * // => false 19946 */ 19947 function isEqual(value, other) { 19948 return baseIsEqual(value, other); 19949 } 19950 19951 /** 19952 * This method is like `_.isEqual` except that it accepts `customizer` which 19953 * is invoked to compare values. If `customizer` returns `undefined`, comparisons 19954 * are handled by the method instead. The `customizer` is invoked with up to 19955 * six arguments: (objValue, othValue [, index|key, object, other, stack]). 19956 * 19957 * @static 19958 * @memberOf _ 19959 * @since 4.0.0 19960 * @category Lang 19961 * @param {*} value The value to compare. 19962 * @param {*} other The other value to compare. 19963 * @param {Function} [customizer] The function to customize comparisons. 19964 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 19965 * @example 19966 * 19967 * function isGreeting(value) { 19968 * return /^h(?:i|ello)$/.test(value); 19969 * } 19970 * 19971 * function customizer(objValue, othValue) { 19972 * if (isGreeting(objValue) && isGreeting(othValue)) { 19973 * return true; 19974 * } 19975 * } 19976 * 19977 * var array = ['hello', 'goodbye']; 19978 * var other = ['hi', 'goodbye']; 19979 * 19980 * _.isEqualWith(array, other, customizer); 19981 * // => true 19982 */ 19983 function isEqualWith(value, other, customizer) { 19984 customizer = typeof customizer == 'function' ? customizer : undefined$1; 19985 var result = customizer ? customizer(value, other) : undefined$1; 19986 return result === undefined$1 ? baseIsEqual(value, other, undefined$1, customizer) : !!result; 19987 } 19988 19989 /** 19990 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, 19991 * `SyntaxError`, `TypeError`, or `URIError` object. 19992 * 19993 * @static 19994 * @memberOf _ 19995 * @since 3.0.0 19996 * @category Lang 19997 * @param {*} value The value to check. 19998 * @returns {boolean} Returns `true` if `value` is an error object, else `false`. 19999 * @example 20000 * 20001 * _.isError(new Error); 20002 * // => true 20003 * 20004 * _.isError(Error); 20005 * // => false 20006 */ 20007 function isError(value) { 20008 if (!isObjectLike(value)) { 20009 return false;
vendor: 7,294 bytes, lines 20010-20247
20010 } 20011 var tag = baseGetTag(value); 20012 return tag == errorTag || tag == domExcTag || 20013 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); 20014 } 20015 20016 /** 20017 * Checks if `value` is a finite primitive number. 20018 * 20019 * **Note:** This method is based on 20020 * [`Number.isFinite`](https://mdn.io/Number/isFinite). 20021 * 20022 * @static 20023 * @memberOf _ 20024 * @since 0.1.0 20025 * @category Lang 20026 * @param {*} value The value to check. 20027 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. 20028 * @example 20029 * 20030 * _.isFinite(3); 20031 * // => true 20032 * 20033 * _.isFinite(Number.MIN_VALUE); 20034 * // => true 20035 * 20036 * _.isFinite(Infinity); 20037 * // => false 20038 * 20039 * _.isFinite('3'); 20040 * // => false 20041 */ 20042 function isFinite(value) { 20043 return typeof value == 'number' && nativeIsFinite(value); 20044 } 20045 20046 /** 20047 * Checks if `value` is classified as a `Function` object. 20048 * 20049 * @static 20050 * @memberOf _ 20051 * @since 0.1.0 20052 * @category Lang 20053 * @param {*} value The value to check. 20054 * @returns {boolean} Returns `true` if `value` is a function, else `false`. 20055 * @example 20056 * 20057 * _.isFunction(_); 20058 * // => true 20059 * 20060 * _.isFunction(/abc/); 20061 * // => false 20062 */ 20063 function isFunction(value) { 20064 if (!isObject(value)) { 20065 return false; 20066 } 20067 // The use of `Object#toString` avoids issues with the `typeof` operator 20068 // in Safari 9 which returns 'object' for typed arrays and other constructors. 20069 var tag = baseGetTag(value); 20070 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; 20071 } 20072 20073 /** 20074 * Checks if `value` is an integer. 20075 * 20076 * **Note:** This method is based on 20077 * [`Number.isInteger`](https://mdn.io/Number/isInteger). 20078 * 20079 * @static 20080 * @memberOf _ 20081 * @since 4.0.0 20082 * @category Lang 20083 * @param {*} value The value to check. 20084 * @returns {boolean} Returns `true` if `value` is an integer, else `false`. 20085 * @example 20086 * 20087 * _.isInteger(3); 20088 * // => true 20089 * 20090 * _.isInteger(Number.MIN_VALUE); 20091 * // => false 20092 * 20093 * _.isInteger(Infinity); 20094 * // => false 20095 * 20096 * _.isInteger('3'); 20097 * // => false 20098 */ 20099 function isInteger(value) { 20100 return typeof value == 'number' && value == toInteger(value); 20101 } 20102 20103 /** 20104 * Checks if `value` is a valid array-like length. 20105 * 20106 * **Note:** This method is loosely based on 20107 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). 20108 * 20109 * @static 20110 * @memberOf _ 20111 * @since 4.0.0 20112 * @category Lang 20113 * @param {*} value The value to check. 20114 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. 20115 * @example 20116 * 20117 * _.isLength(3); 20118 * // => true 20119 * 20120 * _.isLength(Number.MIN_VALUE); 20121 * // => false 20122 * 20123 * _.isLength(Infinity); 20124 * // => false 20125 * 20126 * _.isLength('3'); 20127 * // => false 20128 */ 20129 function isLength(value) { 20130 return typeof value == 'number' && 20131 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; 20132 } 20133 20134 /** 20135 * Checks if `value` is the 20136 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) 20137 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) 20138 * 20139 * @static 20140 * @memberOf _ 20141 * @since 0.1.0 20142 * @category Lang 20143 * @param {*} value The value to check. 20144 * @returns {boolean} Returns `true` if `value` is an object, else `false`. 20145 * @example 20146 * 20147 * _.isObject({}); 20148 * // => true 20149 * 20150 * _.isObject([1, 2, 3]); 20151 * // => true 20152 * 20153 * _.isObject(_.noop); 20154 * // => true 20155 * 20156 * _.isObject(null); 20157 * // => false 20158 */ 20159 function isObject(value) { 20160 var type = typeof value; 20161 return value != null && (type == 'object' || type == 'function'); 20162 } 20163 20164 /** 20165 * Checks if `value` is object-like. A value is object-like if it's not `null` 20166 * and has a `typeof` result of "object". 20167 * 20168 * @static 20169 * @memberOf _ 20170 * @since 4.0.0 20171 * @category Lang 20172 * @param {*} value The value to check. 20173 * @returns {boolean} Returns `true` if `value` is object-like, else `false`. 20174 * @example 20175 * 20176 * _.isObjectLike({}); 20177 * // => true 20178 * 20179 * _.isObjectLike([1, 2, 3]); 20180 * // => true 20181 * 20182 * _.isObjectLike(_.noop); 20183 * // => false 20184 * 20185 * _.isObjectLike(null); 20186 * // => false 20187 */ 20188 function isObjectLike(value) { 20189 return value != null && typeof value == 'object'; 20190 } 20191 20192 /** 20193 * Checks if `value` is classified as a `Map` object. 20194 * 20195 * @static 20196 * @memberOf _ 20197 * @since 4.3.0 20198 * @category Lang 20199 * @param {*} value The value to check. 20200 * @returns {boolean} Returns `true` if `value` is a map, else `false`. 20201 * @example 20202 * 20203 * _.isMap(new Map); 20204 * // => true 20205 * 20206 * _.isMap(new WeakMap); 20207 * // => false 20208 */ 20209 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; 20210 20211 /** 20212 * Performs a partial deep comparison between `object` and `source` to 20213 * determine if `object` contains equivalent property values. 20214 * 20215 * **Note:** This method is equivalent to `_.matches` when `source` is 20216 * partially applied. 20217 * 20218 * Partial comparisons will match empty array and empty object `source` 20219 * values against any array or object value, respectively. See `_.isEqual` 20220 * for a list of supported value comparisons. 20221 * 20222 * @static 20223 * @memberOf _ 20224 * @since 3.0.0 20225 * @category Lang 20226 * @param {Object} object The object to inspect. 20227 * @param {Object} source The object of property values to match. 20228 * @returns {boolean} Returns `true` if `object` is a match, else `false`. 20229 * @example 20230 * 20231 * var object = { 'a': 1, 'b': 2 }; 20232 * 20233 * _.isMatch(object, { 'b': 2 }); 20234 * // => true 20235 * 20236 * _.isMatch(object, { 'b': 1 }); 20237 * // => false 20238 */ 20239 function isMatch(object, source) { 20240 return object === source || baseIsMatch(object, source, getMatchData(source)); 20241 } 20242 20243 /** 20244 * This method is like `_.isMatch` except that it accepts `customizer` which 20245 * is invoked to compare values. If `customizer` returns `undefined`, comparisons 20246 * are handled by the method instead. The `customizer` is invoked with five 20247 * arguments: (objValue, srcValue, index|key, object, source).
20248 * 20249 * @static 20250 * @memberOf _ 20251 * @since 4.0.0 20252 * @category Lang 20253 * @param {Object} object The object to inspect. 20254 * @param {Object} source The object of property values to match. 20255 * @param {Function} [customizer] The function to customize comparisons. 20256 * @returns {boolean} Returns `true` if `object` is a match, else `false`. 20257 * @example 20258 * 20259 * function isGreeting(value) { 20260 * return /^h(?:i|ello)$/.test(value); 20261 * } 20262 * 20263 * function customizer(objValue, srcValue) { 20264 * if (isGreeting(objValue) && isGreeting(srcValue)) { 20265 * return true; 20266 * } 20267 * } 20268 * 20269 * var object = { 'greeting': 'hello' }; 20270 * var source = { 'greeting': 'hi' }; 20271 * 20272 * _.isMatchWith(object, source, customizer); 20273 * // => true 20274 */ 20275 function isMatchWith(object, source, customizer) { 20276 customizer = typeof customizer == 'function' ? customizer : undefined$1; 20277 return baseIsMatch(object, source, getMatchData(source), customizer); 20278 } 20279 20280 /** 20281 * Checks if `value` is `NaN`. 20282 * 20283 * **Note:** This method is based on 20284 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as 20285 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for 20286 * `undefined` and other non-number values. 20287 * 20288 * @static 20289 * @memberOf _ 20290 * @since 0.1.0 20291 * @category Lang 20292 * @param {*} value The value to check. 20293 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. 20294 * @example 20295 * 20296 * _.isNaN(NaN); 20297 * // => true 20298 * 20299 * _.isNaN(new Number(NaN)); 20300 * // => true 20301 * 20302 * isNaN(undefined); 20303 * // => true 20304 * 20305 * _.isNaN(undefined); 20306 * // => false 20307 */ 20308 function isNaN(value) { 20309 // An `NaN` primitive is the only value that is not equal to itself. 20310 // Perform the `toStringTag` check first to avoid errors with some 20311 // ActiveX objects in IE. 20312 return isNumber(value) && value != +value; 20313 } 20314 20315 /** 20316 * Checks if `value` is a pristine native function. 20317 * 20318 * **Note:** This method can't reliably detect native functions in the presence 20319 * of the core-js package because core-js circumvents this kind of detection. 20320 * Despite multiple requests, the core-js maintainer has made it clear: any 20321 * attempt to fix the detection will be obstructed. As a result, we're left 20322 * with little choice but to throw an error. Unfortunately, this also affects 20323 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), 20324 * which rely on core-js. 20325 * 20326 * @static 20327 * @memberOf _ 20328 * @since 3.0.0 20329 * @category Lang 20330 * @param {*} value The value to check. 20331 * @returns {boolean} Returns `true` if `value` is a native function, 20332 * else `false`. 20333 * @example 20334 * 20335 * _.isNative(Array.prototype.push); 20336 * // => true 20337 * 20338 * _.isNative(_); 20339 * // => false 20340 */ 20341 function isNative(value) { 20342 if (isMaskable(value)) { 20343 throw new Error(CORE_ERROR_TEXT); 20344 } 20345 return baseIsNative(value); 20346 } 20347 20348 /** 20349 * Checks if `value` is `null`. 20350 * 20351 * @static 20352 * @memberOf _ 20353 * @since 0.1.0 20354 * @category Lang 20355 * @param {*} value The value to check. 20356 * @returns {boolean} Returns `true` if `value` is `null`, else `false`. 20357 * @example 20358 * 20359 * _.isNull(null); 20360 * // => true 20361 * 20362 * _.isNull(void 0); 20363 * // => false 20364 */ 20365 function isNull(value) { 20366 return value === null; 20367 } 20368 20369 /** 20370 * Checks if `value` is `null` or `undefined`. 20371 * 20372 * @static 20373 * @memberOf _ 20374 * @since 4.0.0 20375 * @category Lang 20376 * @param {*} value The value to check. 20377 * @returns {boolean} Returns `true` if `value` is nullish, else `false`. 20378 * @example 20379 * 20380 * _.isNil(null); 20381 * // => true 20382 * 20383 * _.isNil(void 0); 20384 * // => true 20385 * 20386 * _.isNil(NaN); 20387 * // => false 20388 */ 20389 function isNil(value) { 20390 return value == null; 20391 } 20392 20393 /** 20394 * Checks if `value` is classified as a `Number` primitive or object. 20395 * 20396 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are 20397 * classified as numbers, use the `_.isFinite` method. 20398 * 20399 * @static 20400 * @memberOf _ 20401 * @since 0.1.0 20402 * @category Lang 20403 * @param {*} value The value to check. 20404 * @returns {boolean} Returns `true` if `value` is a number, else `false`. 20405 * @example 20406 * 20407 * _.isNumber(3); 20408 * // => true 20409 * 20410 * _.isNumber(Number.MIN_VALUE); 20411 * // => true 20412 * 20413 * _.isNumber(Infinity); 20414 * // => true 20415 * 20416 * _.isNumber('3'); 20417 * // => false 20418 */ 20419 function isNumber(value) { 20420 return typeof value == 'number' || 20421 (isObjectLike(value) && baseGetTag(value) == numberTag); 20422 } 20423 20424 /** 20425 * Checks if `value` is a plain object, that is, an object created by the 20426 * `Object` constructor or one with a `[[Prototype]]` of `null`. 20427 * 20428 * @static 20429 * @memberOf _ 20430 * @since 0.8.0 20431 * @category Lang 20432 * @param {*} value The value to check. 20433 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. 20434 * @example 20435 * 20436 * function Foo() { 20437 * this.a = 1; 20438 * } 20439 * 20440 * _.isPlainObject(new Foo); 20441 * // => false 20442 * 20443 * _.isPlainObject([1, 2, 3]); 20444 * // => false 20445 * 20446 * _.isPlainObject({ 'x': 0, 'y': 0 }); 20447 * // => true 20448 * 20449 * _.isPlainObject(Object.create(null)); 20450 * // => true 20451 */ 20452 function isPlainObject(value) { 20453 if (!isObjectLike(value) || baseGetTag(value) != objectTag) { 20454 return false;
vendor: 7,287 bytes, lines 20455-20713
20455 } 20456 var proto = getPrototype(value); 20457 if (proto === null) { 20458 return true; 20459 } 20460 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; 20461 return typeof Ctor == 'function' && Ctor instanceof Ctor && 20462 funcToString.call(Ctor) == objectCtorString; 20463 } 20464 20465 /** 20466 * Checks if `value` is classified as a `RegExp` object. 20467 * 20468 * @static 20469 * @memberOf _ 20470 * @since 0.1.0 20471 * @category Lang 20472 * @param {*} value The value to check. 20473 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. 20474 * @example 20475 * 20476 * _.isRegExp(/abc/); 20477 * // => true 20478 * 20479 * _.isRegExp('/abc/'); 20480 * // => false 20481 */ 20482 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; 20483 20484 /** 20485 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 20486 * double precision number which isn't the result of a rounded unsafe integer. 20487 * 20488 * **Note:** This method is based on 20489 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). 20490 * 20491 * @static 20492 * @memberOf _ 20493 * @since 4.0.0 20494 * @category Lang 20495 * @param {*} value The value to check. 20496 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. 20497 * @example 20498 * 20499 * _.isSafeInteger(3); 20500 * // => true 20501 * 20502 * _.isSafeInteger(Number.MIN_VALUE); 20503 * // => false 20504 * 20505 * _.isSafeInteger(Infinity); 20506 * // => false 20507 * 20508 * _.isSafeInteger('3'); 20509 * // => false 20510 */ 20511 function isSafeInteger(value) { 20512 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER; 20513 } 20514 20515 /** 20516 * Checks if `value` is classified as a `Set` object. 20517 * 20518 * @static 20519 * @memberOf _ 20520 * @since 4.3.0 20521 * @category Lang 20522 * @param {*} value The value to check. 20523 * @returns {boolean} Returns `true` if `value` is a set, else `false`. 20524 * @example 20525 * 20526 * _.isSet(new Set); 20527 * // => true 20528 * 20529 * _.isSet(new WeakSet); 20530 * // => false 20531 */ 20532 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; 20533 20534 /** 20535 * Checks if `value` is classified as a `String` primitive or object. 20536 * 20537 * @static 20538 * @since 0.1.0 20539 * @memberOf _ 20540 * @category Lang 20541 * @param {*} value The value to check. 20542 * @returns {boolean} Returns `true` if `value` is a string, else `false`. 20543 * @example 20544 * 20545 * _.isString('abc'); 20546 * // => true 20547 * 20548 * _.isString(1); 20549 * // => false 20550 */ 20551 function isString(value) { 20552 return typeof value == 'string' || 20553 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); 20554 } 20555 20556 /** 20557 * Checks if `value` is classified as a `Symbol` primitive or object. 20558 * 20559 * @static 20560 * @memberOf _ 20561 * @since 4.0.0 20562 * @category Lang 20563 * @param {*} value The value to check. 20564 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. 20565 * @example 20566 * 20567 * _.isSymbol(Symbol.iterator); 20568 * // => true 20569 * 20570 * _.isSymbol('abc'); 20571 * // => false 20572 */ 20573 function isSymbol(value) { 20574 return typeof value == 'symbol' || 20575 (isObjectLike(value) && baseGetTag(value) == symbolTag); 20576 } 20577 20578 /** 20579 * Checks if `value` is classified as a typed array. 20580 * 20581 * @static 20582 * @memberOf _ 20583 * @since 3.0.0 20584 * @category Lang 20585 * @param {*} value The value to check. 20586 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. 20587 * @example 20588 * 20589 * _.isTypedArray(new Uint8Array); 20590 * // => true 20591 * 20592 * _.isTypedArray([]); 20593 * // => false 20594 */ 20595 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; 20596 20597 /** 20598 * Checks if `value` is `undefined`. 20599 * 20600 * @static 20601 * @since 0.1.0 20602 * @memberOf _ 20603 * @category Lang 20604 * @param {*} value The value to check. 20605 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. 20606 * @example 20607 * 20608 * _.isUndefined(void 0); 20609 * // => true 20610 * 20611 * _.isUndefined(null); 20612 * // => false 20613 */ 20614 function isUndefined(value) { 20615 return value === undefined$1; 20616 } 20617 20618 /** 20619 * Checks if `value` is classified as a `WeakMap` object. 20620 * 20621 * @static 20622 * @memberOf _ 20623 * @since 4.3.0 20624 * @category Lang 20625 * @param {*} value The value to check. 20626 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. 20627 * @example 20628 * 20629 * _.isWeakMap(new WeakMap); 20630 * // => true 20631 * 20632 * _.isWeakMap(new Map); 20633 * // => false 20634 */ 20635 function isWeakMap(value) { 20636 return isObjectLike(value) && getTag(value) == weakMapTag; 20637 } 20638 20639 /** 20640 * Checks if `value` is classified as a `WeakSet` object. 20641 * 20642 * @static 20643 * @memberOf _ 20644 * @since 4.3.0 20645 * @category Lang 20646 * @param {*} value The value to check. 20647 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. 20648 * @example 20649 * 20650 * _.isWeakSet(new WeakSet); 20651 * // => true 20652 * 20653 * _.isWeakSet(new Set); 20654 * // => false 20655 */ 20656 function isWeakSet(value) { 20657 return isObjectLike(value) && baseGetTag(value) == weakSetTag; 20658 } 20659 20660 /** 20661 * Checks if `value` is less than `other`. 20662 * 20663 * @static 20664 * @memberOf _ 20665 * @since 3.9.0 20666 * @category Lang 20667 * @param {*} value The value to compare. 20668 * @param {*} other The other value to compare. 20669 * @returns {boolean} Returns `true` if `value` is less than `other`, 20670 * else `false`. 20671 * @see _.gt 20672 * @example 20673 * 20674 * _.lt(1, 3); 20675 * // => true 20676 * 20677 * _.lt(3, 3); 20678 * // => false 20679 * 20680 * _.lt(3, 1); 20681 * // => false 20682 */ 20683 var lt = createRelationalOperation(baseLt); 20684 20685 /** 20686 * Checks if `value` is less than or equal to `other`. 20687 * 20688 * @static 20689 * @memberOf _ 20690 * @since 3.9.0 20691 * @category Lang 20692 * @param {*} value The value to compare. 20693 * @param {*} other The other value to compare. 20694 * @returns {boolean} Returns `true` if `value` is less than or equal to 20695 * `other`, else `false`. 20696 * @see _.gte 20697 * @example 20698 * 20699 * _.lte(1, 3); 20700 * // => true 20701 * 20702 * _.lte(3, 3); 20703 * // => true 20704 * 20705 * _.lte(3, 1); 20706 * // => false 20707 */ 20708 var lte = createRelationalOperation(function(value, other) { 20709 return value <= other; 20710 }); 20711 20712 /** 20713 * Converts `value` to an array.
20714 * 20715 * @static 20716 * @since 0.1.0 20717 * @memberOf _ 20718 * @category Lang 20719 * @param {*} value The value to convert. 20720 * @returns {Array} Returns the converted array. 20721 * @example 20722 * 20723 * _.toArray({ 'a': 1, 'b': 2 }); 20724 * // => [1, 2] 20725 * 20726 * _.toArray('abc'); 20727 * // => ['a', 'b', 'c'] 20728 * 20729 * _.toArray(1); 20730 * // => [] 20731 * 20732 * _.toArray(null); 20733 * // => [] 20734 */ 20735 function toArray(value) { 20736 if (!value) { 20737 return []; 20738 } 20739 if (isArrayLike(value)) { 20740 return isString(value) ? stringToArray(value) : copyArray(value); 20741 } 20742 if (symIterator && value[symIterator]) { 20743 return iteratorToArray(value[symIterator]()); 20744 } 20745 var tag = getTag(value), 20746 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); 20747 20748 return func(value); 20749 } 20750 20751 /** 20752 * Converts `value` to a finite number. 20753 * 20754 * @static 20755 * @memberOf _ 20756 * @since 4.12.0 20757 * @category Lang 20758 * @param {*} value The value to convert. 20759 * @returns {number} Returns the converted number. 20760 * @example 20761 * 20762 * _.toFinite(3.2); 20763 * // => 3.2 20764 * 20765 * _.toFinite(Number.MIN_VALUE); 20766 * // => 5e-324 20767 * 20768 * _.toFinite(Infinity); 20769 * // => 1.7976931348623157e+308 20770 * 20771 * _.toFinite('3.2'); 20772 * // => 3.2 20773 */ 20774 function toFinite(value) { 20775 if (!value) { 20776 return value === 0 ? value : 0; 20777 } 20778 value = toNumber(value); 20779 if (value === INFINITY || value === -INFINITY) { 20780 var sign = (value < 0 ? -1 : 1); 20781 return sign * MAX_INTEGER; 20782 } 20783 return value === value ? value : 0; 20784 } 20785 20786 /** 20787 * Converts `value` to an integer. 20788 * 20789 * **Note:** This method is loosely based on 20790 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). 20791 * 20792 * @static 20793 * @memberOf _ 20794 * @since 4.0.0 20795 * @category Lang 20796 * @param {*} value The value to convert. 20797 * @returns {number} Returns the converted integer. 20798 * @example 20799 * 20800 * _.toInteger(3.2); 20801 * // => 3 20802 * 20803 * _.toInteger(Number.MIN_VALUE); 20804 * // => 0 20805 * 20806 * _.toInteger(Infinity); 20807 * // => 1.7976931348623157e+308 20808 * 20809 * _.toInteger('3.2'); 20810 * // => 3 20811 */ 20812 function toInteger(value) { 20813 var result = toFinite(value), 20814 remainder = result % 1; 20815 20816 return result === result ? (remainder ? result - remainder : result) : 0; 20817 } 20818 20819 /** 20820 * Converts `value` to an integer suitable for use as the length of an 20821 * array-like object. 20822 * 20823 * **Note:** This method is based on 20824 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). 20825 * 20826 * @static 20827 * @memberOf _ 20828 * @since 4.0.0 20829 * @category Lang 20830 * @param {*} value The value to convert. 20831 * @returns {number} Returns the converted integer. 20832 * @example 20833 * 20834 * _.toLength(3.2); 20835 * // => 3 20836 * 20837 * _.toLength(Number.MIN_VALUE); 20838 * // => 0 20839 * 20840 * _.toLength(Infinity); 20841 * // => 4294967295 20842 * 20843 * _.toLength('3.2'); 20844 * // => 3 20845 */ 20846 function toLength(value) { 20847 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0; 20848 } 20849 20850 /** 20851 * Converts `value` to a number. 20852 * 20853 * @static 20854 * @memberOf _ 20855 * @since 4.0.0 20856 * @category Lang 20857 * @param {*} value The value to process. 20858 * @returns {number} Returns the number. 20859 * @example 20860 * 20861 * _.toNumber(3.2); 20862 * // => 3.2 20863 * 20864 * _.toNumber(Number.MIN_VALUE); 20865 * // => 5e-324 20866 * 20867 * _.toNumber(Infinity); 20868 * // => Infinity 20869 * 20870 * _.toNumber('3.2'); 20871 * // => 3.2 20872 */ 20873 function toNumber(value) { 20874 if (typeof value == 'number') { 20875 return value; 20876 } 20877 if (isSymbol(value)) { 20878 return NAN; 20879 } 20880 if (isObject(value)) { 20881 var other = typeof value.valueOf == 'function' ? value.valueOf() : value; 20882 value = isObject(other) ? (other + '') : other; 20883 } 20884 if (typeof value != 'string') { 20885 return value === 0 ? value : +value; 20886 } 20887 value = baseTrim(value); 20888 var isBinary = reIsBinary.test(value); 20889 return (isBinary || reIsOctal.test(value)) 20890 ? freeParseInt(value.slice(2), isBinary ? 2 : 8) 20891 : (reIsBadHex.test(value) ? NAN : +value); 20892 } 20893 20894 /** 20895 * Converts `value` to a plain object flattening inherited enumerable str
20895ing 20896 * keyed properties of `value` to own properties of the plain object. 20897 * 20898 * @static 20899 * @memberOf _ 20900 * @since 3.0.0 20901 * @category Lang 20902 * @param {*} value The value to convert. 20903 * @returns {Object} Returns the converted plain object. 20904 * @example 20905 * 20906 * function Foo() { 20907 * this.b = 2; 20908 * } 20909 * 20910 * Foo.prototype.c = 3; 20911 * 20912 * _.assign({ 'a': 1 }, new Foo); 20913 * // => { 'a': 1, 'b': 2 } 20914 * 20915 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); 20916 * // => { 'a': 1, 'b': 2, 'c': 3 } 20917 */ 20918 function toPlainObject(value) { 20919 return copyObject(value, keysIn(value)); 20920 } 20921 20922 /** 20923 * Converts `value` to a safe integer. A safe integer can be compared and 20924 * represented correctly. 20925 * 20926 * @static 20927 * @memberOf _ 20928 * @since 4.0.0 20929 * @category Lang 20930 * @param {*} value The value to convert. 20931 * @returns {number} Returns the converted integer. 20932 * @example 20933 * 20934 * _.toSafeInteger(3.2); 20935 * // => 3 20936 * 20937 * _.toSafeInteger(Number.MIN_VALUE); 20938 * // => 0 20939 * 20940 * _.toSafeInteger(Infinity); 20941 * // => 9007199254740991 20942 * 20943 * _.toSafeInteger('3.2'); 20944 * // => 3 20945 */ 20946 function toSafeInteger(value) { 20947 return value 20948 ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) 20949 : (value === 0 ? value : 0); 20950 } 20951 20952 /** 20953 * Converts `value` to a string. An empty string is returned for `null` 20954 * and `undefined` values. The sign of `-0` is preserved. 20955 * 20956 * @static 20957 * @memberOf _ 20958 * @since 4.0.0 20959 * @category Lang 20960 * @param {*} value The value to convert. 20961 * @returns {string} Returns the converted string. 20962 * @example 20963 * 20964 * _.toString(null); 20965 * // => '' 20966 * 20967 * _.toString(-0); 20968 * // => '-0' 20969 * 20970 * _.toString([1, 2, 3]); 20971 * // => '1,2,3' 20972 */ 20973 function toString(value) { 20974 return value == null ? '' : baseToString(value); 20975 } 20976 20977 /*------------------------------------------------------------------------*/ 20978 20979 /** 20980 * Assigns own enumerable string keyed properties of source objects to the 20981 * destination object. Source objects are applied from left to right. 20982 * Subsequent sources overwrite property assignments of previous sources. 20983 * 20984 * **Note:** This method mutates `object` and is loosely based on 20985 * [`Object.assign`](https://mdn.io/Object/assign). 20986 * 20987 * @static 20988 * @memberOf _
20989 * @since 0.10.0 20990 * @category Object 20991 * @param {Object} object The destination object. 20992 * @param {...Object} [sources] The source objects. 20993 * @returns {Object} Returns `object`. 20994 * @see _.assignIn 20995 * @example 20996 * 20997 * function Foo() { 20998 * this.a = 1; 20999 * } 21000 * 21001 * function Bar() { 21002 * this.c = 3; 21003 * } 21004 * 21005 * Foo.prototype.b = 2; 21006 * Bar.prototype.d = 4; 21007 * 21008 * _.assign({ 'a': 0 }, new Foo, new Bar); 21009 * // => { 'a': 1, 'c': 3 } 21010 */ 21011 var assign = createAssigner(function(object, source) { 21012 if (isPrototype(source) || isArrayLike(source)) { 21013 copyObject(source, keys(source), object); 21014 return; 21015 } 21016 for (var key in source) { 21017 if (hasOwnProperty.call(source, key)) { 21018 assignValue(object, key, source[key]); 21019 } 21020 } 21021 }); 21022 21023 /** 21024 * This method is like `_.assign` except that it iterates over own and 21025 * inherited source properties. 21026 * 21027 * **Note:** This method mutates `object`. 21028 * 21029 * @static 21030 * @memberOf _ 21031 * @since 4.0.0 21032 * @alias extend 21033 * @category Object 21034 * @param {Object} object The destination object. 21035 * @param {...Object} [sources] The source objects. 21036 * @returns {Object} Returns `object`. 21037 * @see _.assign 21038 * @example 21039 * 21040 * function Foo() { 21041 * this.a = 1; 21042 * } 21043 * 21044 * function Bar() { 21045 * this.c = 3; 21046 * } 21047 * 21048 * Foo.prototype.b = 2; 21049 * Bar.prototype.d = 4; 21050 * 21051 * _.assignIn({ 'a': 0 }, new Foo, new Bar); 21052 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } 21053 */ 21054 var assignIn = createAssigner(function(object, source) { 21055 copyObject(source, keysIn(source), object); 21056 }); 21057 21058 /** 21059 * This method is like `_.assignIn` except that it accepts `customizer` 21060 * which is invoked to produce the assigned values. If `customizer` returns 21061 * `undefined`, assignment is handled by the method instead. The `customizer` 21062 * is invoked with five arguments: (objValue, srcValue, key, object, source). 21063 * 21064 * **Note:** This method mutates `object`. 21065 * 21066 * @static 21067 * @memberOf _ 21068 * @since 4.0.0 21069 * @alias extendWith 21070 * @category Object 21071 * @param {Object} object The destination object. 21072 * @param {...Object} sources The source objects. 21073 * @param {Function} [customizer] The function to customize assigned values. 21074 * @returns {Object} Returns `object`. 21075 * @see _.assignWith 21076 * @example 21077 * 21078 * function customizer(objValue, srcValue) { 21079 * return _.isUndefined(objValue) ? srcValue : objValue; 21080 * } 21081 * 21082 * var defaults = _.partialRight(_.assignInWith, customizer); 21083 * 21084 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); 21085 * // => { 'a': 1, 'b': 2 } 21086 */ 21087 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { 21088 copyObject(source, keysIn(source), object, customizer); 21089 }); 21090 21091 /** 21092 * This method is like `_.assign` except that it accepts `customizer` 21093 * which is invoked to produce the assigned values. If `customizer` returns 21094 * `undefined`, assignment is handled by the method instead. The `customizer` 21095 * is invoked with five arguments: (objValue, srcValue, key, object, source). 21096 * 21097 * **Note:** This method mutates `object`. 21098 * 21099 * @static 21100 * @memberOf _ 21101 * @since 4.0.0 21102 * @category Object 21103 * @param {Object} object The destination object. 21104 * @param {...Object} sources The source objects. 21105 * @param {Function} [customizer] The function to customize assigned values. 21106 * @returns {Object} Returns `object`. 21107 * @see _.assignInWith 21108 * @example 21109 * 21110 * function customizer(objValue, srcValue) { 21111 * return _.isUndefined(objValue) ? srcValue : objValue; 21112 * } 21113 * 21114 * var defaults = _.partialRight(_.assignWith, customizer); 21115 * 21116 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); 21117 * // => { 'a': 1, 'b': 2 } 21118 */ 21119 var assignWith = createAssigner(function(object, source, srcIndex, customizer) { 21120 copyObject(source, keys(source), object, customizer); 21121 }); 21122 21123 /** 21124 * Creates an array of values corresponding to `paths` of `object`. 21125 * 21126 * @static 21127 * @memberOf _ 21128 * @since 1.0.0 21129 * @category Object 21130 * @param {Object} object The object to iterate over. 21131 * @param {...(string|string[])} [paths] The property paths to pick. 21132 * @returns {Array} Returns the picked values. 21133 * @example 21134 * 21135 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; 21136 * 21137 * _.at(object, ['a[0].b.c', 'a[1]']); 21138 * // => [3, 4] 21139 */ 21140 var at = flatRest(baseAt); 21141 21142 /** 21143 * Creates an object that inherits from the `prototype` object. If a
21144 * `properties` object is given, its own enumerable string keyed properties 21145 * are assigned to the created object. 21146 * 21147 * @static 21148 * @memberOf _ 21149 * @since 2.3.0 21150 * @category Object 21151 * @param {Object} prototype The object to inherit from. 21152 * @param {Object} [properties] The properties to assign to the object. 21153 * @returns {Object} Returns the new object. 21154 * @example 21155 * 21156 * function Shape() { 21157 * this.x = 0; 21158 * this.y = 0; 21159 * } 21160 * 21161 * function Circle() { 21162 * Shape.call(this); 21163 * } 21164 * 21165 * Circle.prototype = _.create(Shape.prototype, { 21166 * 'constructor': Circle 21167 * }); 21168 * 21169 * var circle = new Circle; 21170 * circle instanceof Circle; 21171 * // => true 21172 * 21173 * circle instanceof Shape; 21174 * // => true 21175 */ 21176 function create(prototype, properties) { 21177 var result = baseCreate(prototype); 21178 return properties == null ? result : baseAssign(result, properties); 21179 } 21180 21181 /** 21182 * Assigns own and inherited enumerable string keyed properties of source 21183 * objects to the destination object for all destination properties that 21184 * resolve to `undefined`. Source objects are applied from left to right. 21185 * Once a property is set, additional values of the same property are ignored. 21186 * 21187 * **Note:** This method mutates `object`. 21188 * 21189 * @static 21190 * @since 0.1.0 21191 * @memberOf _ 21192 * @category Object 21193 * @param {Object} object The destination object. 21194 * @param {...Object} [sources] The source objects. 21195 * @returns {Object} Returns `object`. 21196 * @see _.defaultsDeep 21197 * @example 21198 * 21199 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); 21200 * // => { 'a': 1, 'b': 2 } 21201 */ 21202 var defaults = baseRest(function(object, sources) { 21203 object = Object(object); 21204 21205 var index = -1; 21206 var length = sources.length; 21207 var guard = length > 2 ? sources[2] : undefined$1; 21208 21209 if (guard && isIterateeCall(sources[0], sources[1], guard)) { 21210 length = 1; 21211 } 21212 21213 while (++index < length) { 21214 var source = sources[index]; 21215 var props = keysIn(source); 21216 var propsIndex = -1; 21217 var propsLength = props.length; 21218 21219 while (++propsIndex < propsLength) { 21220 var key = props[propsIndex]; 21221 var value = object[key]; 21222 21223 if (value === undefined$1 || 21224 (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { 21225 object[key] = source[key]; 21226 } 21227 } 21228 } 21229 21230 return object; 21231 }); 21232 21233 /** 21234 * This method is like `_.defaults` except that it recursively assigns 21235 * default properties. 21236 * 21237 * **Note:** This method mutates `object`. 21238 * 21239 * @static 21240 * @memberOf _ 21241 * @since 3.10.0 21242 * @category Object 21243 * @param {Object} object The destination object. 21244 * @param {...Object} [sources] The source objects. 21245 * @returns {Object} Returns `object`. 21246 * @see _.defaults 21247 * @example 21248 * 21249 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); 21250 * // => { 'a': { 'b': 2, 'c': 3 } } 21251 */ 21252 var defaultsDeep = baseRest(function(args) { 21253 args.push(undefined$1, customDefaultsMerge); 21254 return apply(mergeWith, undefined$1, args); 21255 }); 21256 21257 /** 21258 * This method is like `_.find` except that it returns the key of the first 21259 * element `predicate` returns truthy for instead of the element itself. 21260 * 21261 * @static 21262 * @memberOf _ 21263 * @since 1.1.0 21264 * @category Object 21265 * @param {Object} object The object to inspect. 21266 * @param {Function} [predicate=_.identity] The function invoked per iteration. 21267 * @returns {string|undefined} Returns the key of the matched element, 21268 * else `undefined`. 21269 * @example 21270 * 21271 * var users = { 21272 * 'barney': { 'age': 36, 'active': true }, 21273 * 'fred': { 'age': 40, 'active': false }, 21274 * 'pebbles': { 'age': 1, 'active': true } 21275 * }; 21276 * 21277 * _.findKey(users, function(o) { return o.age < 40; }); 21278 * // => 'barney' (iteration order is not guaranteed) 21279 * 21280 * // The `_.matches` iteratee shorthand. 21281 * _.findKey(users, { 'age': 1, 'active': true }); 21282 * // => 'pebbles' 21283 * 21284 * // The `_.matchesProperty` iteratee shorthand. 21285 * _.findKey(users, ['active', false]); 21286 * // => 'fred' 21287 * 21288 * // The `_.property` iteratee shorthand. 21289 * _.findKey(users, 'active'); 21290 * // => 'barney' 21291 */ 21292 function findKey(object, predicate) { 21293 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn); 21294 } 21295 21296 /** 21297 * This method is like `_.findKey` except that it iterates over elements of 21298 * a collection in the opposite order. 21299 * 21300 * @static 21301 * @memberOf _ 21302 * @since 2.0.0 21303 * @category Object 21304 * @param {Object} object The object to inspect. 21305 * @param {Function} [predicate=_.identity] The function invoked per iteration. 21306 * @returns {string|undefined} Returns the key of the matched element, 21307 * else `undefined`. 21308 * @example 21309 * 21310 * var users = { 21311 * 'barney': { 'age': 36, 'active': true }, 21312 * 'fred': { 'age': 40, 'active': false }, 21313 * 'pebbles': { 'age': 1, 'active': true } 21314 * }; 21315 * 21316 * _.findLastKey(users, function(o) { return o.age < 40; }); 21317 * // => returns 'pebbles' assuming `_.findKey` returns 'barney' 21318 * 21319 * // The `_.matches` iteratee shorthand. 21320 * _.findLastKey(users, { 'age': 36, 'active': true }); 21321 * // => 'barney' 21322 * 21323 * // The `_.matchesProperty` iteratee shorthand. 21324 * _.findLastKey(users, ['active', false]); 21325 * // => 'fred' 21326 * 21327 * // The `_.property` iteratee shorthand. 21328 * _.findLastKey(users, 'active'); 21329 * // => 'pebbles' 21330 */ 21331 function findLastKey(object, predicate) { 21332 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight); 21333 } 21334 21335 /**
21336 * Iterates over own and inherited enumerable string keyed properties of an 21337 * object and invokes `iteratee` for each property. The iteratee is invoked 21338 * with three arguments: (value, key, object). Iteratee functions may exit 21339 * iteration early by explicitly returning `false`. 21340 * 21341 * @static 21342 * @memberOf _ 21343 * @since 0.3.0 21344 * @category Object 21345 * @param {Object} object The object to iterate over. 21346 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 21347 * @returns {Object} Returns `object`. 21348 * @see _.forInRight 21349 * @example 21350 * 21351 * function Foo() { 21352 * this.a = 1; 21353 * this.b = 2; 21354 * } 21355 * 21356 * Foo.prototype.c = 3; 21357 * 21358 * _.forIn(new Foo, function(value, key) { 21359 * console.log(key); 21360 * }); 21361 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). 21362 */ 21363 function forIn(object, iteratee) { 21364 return object == null 21365 ? object 21366 : baseFor(object, getIteratee(iteratee, 3), keysIn); 21367 } 21368 21369 /** 21370 * This method is like `_.forIn` except that it iterates over properties of 21371 * `object` in the opposite order. 21372 * 21373 * @static 21374 * @memberOf _ 21375 * @since 2.0.0 21376 * @category Object 21377 * @param {Object} object The object to iterate over. 21378 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 21379 * @returns {Object} Returns `object`. 21380 * @see _.forIn 21381 * @example 21382 * 21383 * function Foo() { 21384 * this.a = 1; 21385 * this.b = 2; 21386 * } 21387 * 21388 * Foo.prototype.c = 3; 21389 * 21390 * _.forInRight(new Foo, function(value, key) { 21391 * console.log(key); 21392 * }); 21393 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. 21394 */ 21395 function forInRight(object, iteratee) { 21396 return object == null 21397 ? object 21398 : baseForRight(object, getIteratee(iteratee, 3), keysIn); 21399 } 21400 21401 /** 21402 * Iterates over own enumerable string keyed properties of an object and 21403 * invokes `iteratee` for each property. The iteratee is invoked with three 21404 * arguments: (value, key, object). Iteratee functions may exit iteration 21405 * early by explicitly returning `false`. 21406 * 21407 * @static 21408 * @memberOf _ 21409 * @since 0.3.0 21410 * @category Object 21411 * @param {Object} object The object to iterate over. 21412 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 21413 * @returns {Object} Returns `object`. 21414 * @see _.forOwnRight 21415 * @example 21416 * 21417 * function Foo() { 21418 * this.a = 1; 21419 * this.b = 2; 21420 * } 21421 * 21422 * Foo.prototype.c = 3; 21423 * 21424 * _.forOwn(new Foo, function(value, key) { 21425 * console.log(key); 21426 * }); 21427 * // => Logs 'a' then 'b' (iteration order is not guaranteed). 21428 */ 21429 function forOwn(object, iteratee) { 21430 return object && baseForOwn(object, getIteratee(iteratee, 3)); 21431 } 21432 21433 /** 21434 * This method is like `_.forOwn` except that it iterates over properties of 21435 * `object` in the opposite order. 21436 * 21437 * @static 21438 * @memberOf _ 21439 * @since 2.0.0 21440 * @category Object 21441 * @param {Object} object The object to iterate over. 21442 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 21443 * @returns {Object} Returns `object`. 21444 * @see _.forOwn 21445 * @example 21446 * 21447 * function Foo() { 21448 * this.a = 1; 21449 * this.b = 2; 21450 * } 21451 * 21452 * Foo.prototype.c = 3; 21453 * 21454 * _.forOwnRight(new Foo, function(value, key) { 21455 * console.log(key); 21456 * }); 21457 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. 21458 */ 21459 function forOwnRight(object, iteratee) { 21460 return object && baseForOwnRight(object, getIteratee(iteratee, 3)); 21461 } 21462 21463 /** 21464 * Creates an array of function property names from own enumerable properties 21465 * of `object`. 21466 * 21467 * @static 21468 * @since 0.1.0 21469 * @memberOf _ 21470 * @category Object 21471 * @param {Object} object The object to inspect. 21472 * @returns {Array} Returns the function names. 21473 * @see _.functionsIn 21474 * @example 21475 * 21476 * function Foo() { 21477 * this.a = _.constant('a'); 21478 * this.b = _.constant('b'); 21479 * } 21480 * 21481 * Foo.prototype.c = _.constant('c'); 21482 * 21483 * _.functions(new Foo); 21484 * // => ['a', 'b'] 21485 */ 21486 function functions(object) { 21487 return object == null ? [] : baseFunctions(object, keys(object)); 21488 } 21489 21490 /** 21491 * Creates an array of function property names from own and inherited 21492 * enumerable properties of `object`. 21493 * 21494 * @static 21495 * @memberOf _ 21496 * @since 4.0.0 21497 * @category Object 21498 * @param {Object} object The object to inspect. 21499 * @returns {Array} Returns the function names. 21500 * @see _.functions 21501 * @example 21502 * 21503 * function Foo() { 21504 * this.a = _.constant('a'); 21505 * this.b = _.constant('b'); 21506 * } 21507 * 21508 * Foo.prototype.c = _.constant('c'); 21509 * 21510 * _.functionsIn(new Foo); 21511 * // => ['a', 'b', 'c'] 21512 */ 21513 function functionsIn(object) { 21514 return object == null ? [] : baseFunctions(object, keysIn(object)); 21515 } 21516 21517 /** 21518 * Gets the value at `path` of `object`. If the resolved value is 21519 * `undefined`, the `defaultValue` is returned in its place. 21520 * 21521 * @static 21522 * @memberOf _ 21523 * @since 3.7.0 21524 * @category Object 21525 * @param {Object} object The object to query. 21526 * @param {Array|string} path The path of the property to get. 21527 * @param {*} [defaultValue] The value returned for `undefined` resolved values. 21528 * @returns {*} Returns the resolved value. 21529 * @example 21530 * 21531 * var object = { 'a': [{ 'b': { 'c': 3 } }] }; 21532 * 21533 * _.get(object, 'a[0].b.c'); 21534 * // => 3 21535 * 21536 * _.get(object, ['a', '0', 'b', 'c']); 21537 * // => 3 21538 * 21539 * _.get(object, 'a.b.c', 'default'); 21540 * // => 'default' 21541 */ 21542 function get(object, path, defaultValue) { 21543 var result = object == null ? undefined$1 : baseGet(object, path); 21544 return result === undefined$1 ? defaultValue : result; 21545 } 21546 21547 /** 21548 * Checks if `path` is a direct property of `object`. 21549 * 21550 * @static 21551 * @since 0.1.0 21552 * @memberOf _ 21553 * @category Object 21554 * @param {Object} object The object to query. 21555 * @param {Array|string} path The path to check. 21556 * @returns {boolean} Returns `true` if `path` exists, else `false`. 21557 * @example 21558 * 21559 * var object = { 'a': { 'b': 2 } }; 21560 * var other = _.create({ 'a': _.create({ 'b': 2 }) }); 21561 * 21562 * _.has(object, 'a'); 21563 * // => true 21564 * 21565 * _.has(object, 'a.b'); 21566 * // => true 21567 * 21568 * _.has(object, ['a', 'b']); 21569 * // => true 21570 * 21571 * _.has(other, 'a'); 21572 * // => false 21573 */ 21574 function has(object, path) { 21575 return object != null && hasPath(object, path, baseHas); 21576 } 21577 21578 /** 21579 * Checks if `path` is a direct or inherited property of `object`. 21580 * 21581 * @static 21582 * @memberOf _ 21583 * @since 4.0.0 21584 * @category Object 21585 * @param {Object} object The object to query. 21586 * @param {Array|string} path The path to check. 21587 * @returns {boolean} Returns `true` if `path` exists, else `false`. 21588 * @example 21589 * 21590 * var object = _.create({ 'a': _.create({ 'b': 2 }) }); 21591 * 21592 * _.hasIn(object, 'a'); 21593 * // => true 21594 * 21595 * _.hasIn(object, 'a.b'); 21596 * // => true 21597 * 21598 * _.hasIn(object, ['a', 'b']); 21599 * // => true 21600 * 21601 * _.hasIn(object, 'b'); 21602 * // => false 21603 */ 21604 function hasIn(object, path) { 21605 return object != null && hasPath(object, path, baseHasIn); 21606 } 21607 21608 /**
21609 * Creates an object composed of the inverted keys and values of `object`. 21610 * If `object` contains duplicate values, subsequent values overwrite 21611 * property assignments of previous values. 21612 * 21613 * @static 21614 * @memberOf _ 21615 * @since 0.7.0 21616 * @category Object 21617 * @param {Object} object The object to invert. 21618 * @returns {Object} Returns the new inverted object. 21619 * @example 21620 * 21621 * var object = { 'a': 1, 'b': 2, 'c': 1 }; 21622 * 21623 * _.invert(object); 21624 * // => { '1': 'c', '2': 'b' } 21625 */ 21626 var invert = createInverter(function(result, value, key) { 21627 if (value != null && 21628 typeof value.toString != 'function') { 21629 value = nativeObjectToString.call(value); 21630 } 21631 21632 result[value] = key; 21633 }, constant(identity)); 21634 21635 /** 21636 * This method is like `_.invert` except that the inverted object is generated 21637 * from the results of running each element of `object` thru `iteratee`. The 21638 * corresponding inverted value of each inverted key is an array of keys 21639 * responsible for generating the inverted value. The iteratee is invoked 21640 * with one argument: (value). 21641 * 21642 * @static 21643 * @memberOf _ 21644 * @since 4.1.0 21645 * @category Object 21646 * @param {Object} object The object to invert. 21647 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 21648 * @returns {Object} Returns the new inverted object. 21649 * @example 21650 * 21651 * var object = { 'a': 1, 'b': 2, 'c': 1 }; 21652 * 21653 * _.invertBy(object); 21654 * // => { '1': ['a', 'c'], '2': ['b'] } 21655 * 21656 * _.invertBy(object, function(value) { 21657 * return 'group' + value; 21658 * }); 21659 * // => { 'group1': ['a', 'c'], 'group2': ['b'] } 21660 */ 21661 var invertBy = createInverter(function(result, value, key) { 21662 if (value != null && 21663 typeof value.toString != 'function') { 21664 value = nativeObjectToString.call(value); 21665 } 21666 21667 if (hasOwnProperty.call(result, value)) { 21668 result[value].push(key); 21669 } else { 21670 result[value] = [key]; 21671 } 21672 }, getIteratee); 21673 21674 /** 21675 * Invokes the method at `path` of `object`. 21676 * 21677 * @static 21678 * @memberOf _ 21679 * @since 4.0.0 21680 * @category Object 21681 * @param {Object} object The object to query. 21682 * @param {Array|string} path The path of the method to invoke. 21683 * @param {...*} [args] The arguments to invoke the method with. 21684 * @returns {*} Returns the result of the invoked method. 21685 * @example 21686 * 21687 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] }; 21688 * 21689 * _.invoke(object, 'a[0].b.c.slice', 1, 3); 21690 * // => [2, 3] 21691 */ 21692 var invoke = baseRest(baseInvoke); 21693 21694 /** 21695 * Creates an array of the own enumerable property names of `object`. 21696 * 21697 * **Note:** Non-object values are coerced to objects. See the 21698 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) 21699 * for more details. 21700 * 21701 * @static 21702 * @since 0.1.0 21703 * @memberOf _ 21704 * @category Object 21705 * @param {Object} object The object to query. 21706 * @returns {Array} Returns the array of property names. 21707 * @example 21708 * 21709 * function Foo() { 21710 * this.a = 1; 21711 * this.b = 2; 21712 * } 21713 * 21714 * Foo.prototype.c = 3; 21715 * 21716 * _.keys(new Foo); 21717 * // => ['a', 'b'] (iteration order is not guaranteed) 21718 * 21719 * _.keys('hi'); 21720 * // => ['0', '1'] 21721 */ 21722 function keys(object) { 21723 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); 21724 } 21725 21726 /** 21727 * Creates an array of the own and inherited enumerable property names of `object`. 21728 * 21729 * **Note:** Non-object values are coerced to objects. 21730 * 21731 * @static 21732 * @memberOf _ 21733 * @since 3.0.0 21734 * @category Object 21735 * @param {Object} object The object to query. 21736 * @returns {Array} Returns the array of property names. 21737 * @example 21738 * 21739 * function Foo() { 21740 * this.a = 1; 21741 * this.b = 2; 21742 * } 21743 * 21744 * Foo.prototype.c = 3; 21745 * 21746 * _.keysIn(new Foo); 21747 * // => ['a', 'b', 'c'] (iteration order is not guaranteed) 21748 */ 21749 function keysIn(object) { 21750 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); 21751 } 21752 21753 /** 21754 * The opposite of `_.mapValues`; this method creates an object with the 21755 * same values as `object` and keys generated by running each own enumerable 21756 * string keyed property of `object` thru `iteratee`. The iteratee is invoked 21757 * with three arguments: (value, key, object). 21758 * 21759 * @static 21760 * @memberOf _ 21761 * @since 3.8.0 21762 * @category Object 21763 * @param {Object} object The object to iterate over. 21764 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 21765 * @returns {Object} Returns the new mapped object. 21766 * @see _.mapValues 21767 * @example 21768 * 21769 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { 21770 * return key + value; 21771 * }); 21772 * // => { 'a1': 1, 'b2': 2 } 21773 */ 21774 function mapKeys(object, iteratee) { 21775 var result = {}; 21776 iteratee = getIteratee(iteratee, 3); 21777 21778 baseForOwn(object, function(value, key, object) { 21779 baseAssignValue(result, iteratee(value, key, object), value); 21780 }); 21781 return result; 21782 } 21783 21784 /** 21785 * Creates an object with the same keys as `object` and values generated
21786 * by running each own enumerable string keyed property of `object` thru 21787 * `iteratee`. The iteratee is invoked with three arguments: 21788 * (value, key, object). 21789 * 21790 * @static 21791 * @memberOf _ 21792 * @since 2.4.0 21793 * @category Object 21794 * @param {Object} object The object to iterate over. 21795 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 21796 * @returns {Object} Returns the new mapped object. 21797 * @see _.mapKeys 21798 * @example 21799 * 21800 * var users = { 21801 * 'fred': { 'user': 'fred', 'age': 40 }, 21802 * 'pebbles': { 'user': 'pebbles', 'age': 1 } 21803 * }; 21804 * 21805 * _.mapValues(users, function(o) { return o.age; }); 21806 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) 21807 * 21808 * // The `_.property` iteratee shorthand. 21809 * _.mapValues(users, 'age'); 21810 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) 21811 */ 21812 function mapValues(object, iteratee) { 21813 var result = {}; 21814 iteratee = getIteratee(iteratee, 3); 21815 21816 baseForOwn(object, function(value, key, object) { 21817 baseAssignValue(result, key, iteratee(value, key, object)); 21818 }); 21819 return result; 21820 } 21821 21822 /** 21823 * This method is like `_.assign` except that it recursively merges own and 21824 * inherited enumerable string keyed properties of source objects into the 21825 * destination object. Source properties that resolve to `undefined` are 21826 * skipped if a destination value exists. Array and plain object properties 21827 * are merged recursively. Other objects and value types are overridden by 21828 * assignment. Source objects are applied from left to right. Subsequent 21829 * sources overwrite property assignments of previous sources. 21830 * 21831 * **Note:** This method mutates `object`. 21832 * 21833 * @static 21834 * @memberOf _ 21835 * @since 0.5.0 21836 * @category Object 21837 * @param {Object} object The destination object. 21838 * @param {...Object} [sources] The source objects. 21839 * @returns {Object} Returns `object`. 21840 * @example 21841 * 21842 * var object = { 21843 * 'a': [{ 'b': 2 }, { 'd': 4 }] 21844 * }; 21845 * 21846 * var other = { 21847 * 'a': [{ 'c': 3 }, { 'e': 5 }] 21848 * }; 21849 * 21850 * _.merge(object, other); 21851 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } 21852 */ 21853 var merge = createAssigner(function(object, source, srcIndex) { 21854 baseMerge(object, source, srcIndex); 21855 }); 21856 21857 /** 21858 * This method is like `_.merge` except that it accepts `customizer` which 21859 * is invoked to produce the merged values of the destination and source 21860 * properties. If `customizer` returns `undefined`, merging is handled by the 21861 * method instead. The `customizer` is invoked with six arguments: 21862 * (objValue, srcValue, key, object, source, stack). 21863 * 21864 * **Note:** This method mutates `object`. 21865 * 21866 * @static 21867 * @memberOf _ 21868 * @since 4.0.0 21869 * @category Object 21870 * @param {Object} object The destination object. 21871 * @param {...Object} sources The source objects. 21872 * @param {Function} customizer The function to customize assigned values. 21873 * @returns {Object} Returns `object`. 21874 * @example 21875 * 21876 * function customizer(objValue, srcValue) { 21877 * if (_.isArray(objValue)) { 21878 * return objValue.concat(srcValue); 21879 * } 21880 * } 21881 * 21882 * var object = { 'a': [1], 'b': [2] }; 21883 * var other = { 'a': [3], 'b': [4] }; 21884 * 21885 * _.mergeWith(object, other, customizer); 21886 * // => { 'a': [1, 3], 'b': [2, 4] } 21887 */ 21888 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { 21889 baseMerge(object, source, srcIndex, customizer); 21890 }); 21891 21892 /** 21893 * The opposite of `_.pick`;
21893 this method creates an object composed of the 21894 * own and inherited enumerable property paths of `object` that are not omitted. 21895 * 21896 * **Note:** This method is considerably slower than `_.pick`. 21897 * 21898 * @static 21899 * @since 0.1.0 21900 * @memberOf _ 21901 * @category Object 21902 * @param {Object} object The source object. 21903 * @param {...(string|string[])} [paths] The property paths to omit. 21904 * @returns {Object} Returns the new object. 21905 * @example 21906 * 21907 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 21908 * 21909 * _.omit(object, ['a', 'c']); 21910 * // => { 'b': '2' } 21911 */ 21912 var omit = flatRest(function(object, paths) { 21913 var result = {}; 21914 if (object == null) { 21915 return result; 21916 } 21917 var isDeep = false; 21918 paths = arrayMap(paths, function(path) { 21919 path = castPath(path, object); 21920 isDeep || (isDeep = path.length > 1); 21921 return path; 21922 }); 21923 copyObject(object, getAllKeysIn(object), result); 21924 if (isDeep) { 21925 result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone); 21926 } 21927 var length = paths.length; 21928 while (length--) { 21929 baseUnset(result, paths[length]); 21930 } 21931 return result; 21932 }); 21933 21934 /** 21935 * The opposite of `_.pickBy`;
21935 this method creates an object composed of 21936 * the own and inherited enumerable string keyed properties of `object` that 21937 * `predicate` doesn't return truthy for. The predicate is invoked with two 21938 * arguments: (value, key). 21939 * 21940 * @static 21941 * @memberOf _ 21942 * @since 4.0.0 21943 * @category Object 21944 * @param {Object} object The source object. 21945 * @param {Function} [predicate=_.identity] The function invoked per property. 21946 * @returns {Object} Returns the new object. 21947 * @example 21948 * 21949 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 21950 * 21951 * _.omitBy(object, _.isNumber); 21952 * // => { 'b': '2' } 21953 */ 21954 function omitBy(object, predicate) { 21955 return pickBy(object, negate(getIteratee(predicate))); 21956 } 21957 21958 /** 21959 * Creates an object composed of the picked `object` properties. 21960 * 21961 * @static 21962 * @since 0.1.0 21963 * @memberOf _ 21964 * @category Object 21965 * @param {Object} object The source object. 21966 * @param {...(string|string[])} [paths] The property paths to pick. 21967 * @returns {Object} Returns the new object. 21968 * @example 21969 * 21970 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 21971 * 21972 * _.pick(object, ['a', 'c']); 21973 * // => { 'a': 1, 'c': 3 } 21974 */ 21975 var pick = flatRest(function(object, paths) { 21976 return object == null ? {} : basePick(object, paths); 21977 }); 21978 21979 /**
21980 * Creates an object composed of the `object` properties `predicate` returns 21981 * truthy for. The predicate is invoked with two arguments: (value, key). 21982 * 21983 * @static 21984 * @memberOf _ 21985 * @since 4.0.0 21986 * @category Object 21987 * @param {Object} object The source object. 21988 * @param {Function} [predicate=_.identity] The function invoked per property. 21989 * @returns {Object} Returns the new object. 21990 * @example 21991 * 21992 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 21993 * 21994 * _.pickBy(object, _.isNumber); 21995 * // => { 'a': 1, 'c': 3 } 21996 */ 21997 function pickBy(object, predicate) { 21998 if (object == null) { 21999 return {}; 22000 } 22001 var props = arrayMap(getAllKeysIn(object), function(prop) { 22002 return [prop]; 22003 }); 22004 predicate = getIteratee(predicate); 22005 return basePickBy(object, props, function(value, path) { 22006 return predicate(value, path[0]); 22007 }); 22008 } 22009 22010 /** 22011 * This method is like `_.get` except that if the resolved value is a 22012 * function it's invoked with the `this` binding of its parent object and 22013 * its result is returned. 22014 * 22015 * @static 22016 * @since 0.1.0 22017 * @memberOf _ 22018 * @category Object 22019 * @param {Object} object The object to query. 22020 * @param {Array|string} path The path of the property to resolve. 22021 * @param {*} [defaultValue] The value returned for `undefined` resolved values. 22022 * @returns {*} Returns the resolved value. 22023 * @example 22024 * 22025 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; 22026 * 22027 * _.result(object, 'a[0].b.c1'); 22028 * // => 3 22029 * 22030 * _.result(object, 'a[0].b.c2'); 22031 * // => 4 22032 * 22033 * _.result(object, 'a[0].b.c3', 'default'); 22034 * // => 'default' 22035 * 22036 * _.result(object, 'a[0].b.c3', _.constant('default')); 22037 * // => 'default' 22038 */ 22039 function result(object, path, defaultValue) { 22040 path = castPath(path, object); 22041 22042 var index = -1, 22043 length = path.length; 22044 22045 // Ensure the loop is entered when path is empty. 22046 if (!length) { 22047 length = 1; 22048 object = undefined$1; 22049 } 22050 while (++index < length) { 22051 var value = object == null ? undefined$1 : object[toKey(path[index])]; 22052 if (value === undefined$1) { 22053 index = length; 22054 value = defaultValue; 22055 } 22056 object = isFunction(value) ? value.call(object) : value; 22057 } 22058 return object; 22059 } 22060 22061 /** 22062 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist, 22063 * it's created. Arrays are created for missing index properties while objects 22064 * are created for all other missing properties. Use `_.setWith` to customize 22065 * `path` creation. 22066 * 22067 * **Note:** This method mutates `object`. 22068 * 22069 * @static 22070 * @memberOf _ 22071 * @since 3.7.0 22072 * @category Object 22073 * @param {Object} object The object to modify. 22074 * @param {Array|string} path The path of the property to set. 22075 * @param {*} value The value to set. 22076 * @returns {Object} Returns `object`. 22077 * @example 22078 * 22079 * var object = { 'a': [{ 'b': { 'c': 3 } }] }; 22080 * 22081 * _.set(object, 'a[0].b.c', 4); 22082 * console.log(object.a[0].b.c); 22083 * // => 4 22084 * 22085 * _.set(object, ['x', '0', 'y', 'z'], 5); 22086 * console.log(object.x[0].y.z); 22087 * // => 5 22088 */ 22089 function set(object, path, value) { 22090 return object == null ? object : baseSet(object, path, value); 22091 } 22092 22093 /** 22094 * This method is like `_.set` except that it accepts `customizer` which is 22095 * invoked to produce the objects of `path`. If `customizer` returns `undefined` 22096 * path creation is handled by the method instead. The `customizer` is invoked 22097 * with three arguments: (nsValue, key, nsObject). 22098 * 22099 * **Note:** This method mutates `object`. 22100 * 22101 * @static 22102 * @memberOf _ 22103 * @since 4.0.0 22104 * @category Object 22105 * @param {Object} object The object to modify. 22106 * @param {Array|string} path The path of the property to set. 22107 * @param {*} value The value to set. 22108 * @param {Function} [customizer] The function to customize assigned values. 22109 * @returns {Object} Returns `object`. 22110 * @example 22111 * 22112 * var object = {}; 22113 * 22114 * _.setWith(object, '[0][1]', 'a', Object); 22115 * // => { '0': { '1': 'a' } } 22116 */ 22117 function setWith(object, path, value, customizer) { 22118 customizer = typeof customizer == 'function' ? customizer : undefined$1; 22119 return object == null ? object : baseSet(object, path, value, customizer); 22120 } 22121 22122 /**
22123 * Creates an array of own enumerable string keyed-value pairs for `object` 22124 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its 22125 * entries are returned. 22126 * 22127 * @static 22128 * @memberOf _ 22129 * @since 4.0.0 22130 * @alias entries 22131 * @category Object 22132 * @param {Object} object The object to query. 22133 * @returns {Array} Returns the key-value pairs. 22134 * @example 22135 * 22136 * function Foo() { 22137 * this.a = 1; 22138 * this.b = 2; 22139 * } 22140 * 22141 * Foo.prototype.c = 3; 22142 * 22143 * _.toPairs(new Foo); 22144 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) 22145 */ 22146 var toPairs = createToPairs(keys); 22147 22148 /** 22149 * Creates an array of own and inherited enumerable string keyed-value pairs 22150 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map 22151 * or set, its entries are returned. 22152 * 22153 * @static 22154 * @memberOf _ 22155 * @since 4.0.0 22156 * @alias entriesIn 22157 * @category Object 22158 * @param {Object} object The object to query. 22159 * @returns {Array} Returns the key-value pairs. 22160 * @example 22161 * 22162 * function Foo() { 22163 * this.a = 1; 22164 * this.b = 2; 22165 * } 22166 * 22167 * Foo.prototype.c = 3; 22168 * 22169 * _.toPairsIn(new Foo); 22170 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) 22171 */ 22172 var toPairsIn = createToPairs(keysIn); 22173 22174 /** 22175 * An alternative to `_.reduce`; this method transforms `object` to a new 22176 * `accumulator` object which is the result of running each of its own 22177 * enumerable string keyed properties thru `iteratee`, with each invocation 22178 * potentially mutating the `accumulator` object. If `accumulator` is not 22179 * provided, a new object with the same `[[Prototype]]` will be used. The 22180 * iteratee is invoked with four arguments: (accumulator, value, key, object). 22181 * Iteratee functions may exit iteration early by explicitly returning `false`. 22182 * 22183 * @static 22184 * @memberOf _ 22185 * @since 1.3.0 22186 * @category Object 22187 * @param {Object} object The object to iterate over. 22188 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 22189 * @param {*} [accumulator] The custom accumulator value. 22190 * @returns {*} Returns the accumulated value. 22191 * @example 22192 * 22193 * _.transform([2, 3, 4], function(result, n) { 22194 * result.push(n *= n); 22195 * return n % 2 == 0; 22196 * }, []); 22197 * // => [4, 9] 22198 * 22199 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { 22200 * (result[value] || (result[value] = [])).push(key); 22201 * }, {}); 22202 * // => { '1': ['a', 'c'], '2': ['b'] } 22203 */ 22204 function transform(object, iteratee, accumulator) { 22205 var isArr = isArray(object), 22206 isArrLike = isArr || isBuffer(object) || isTypedArray(object); 22207 22208 iteratee = getIteratee(iteratee, 4); 22209 if (accumulator == null) { 22210 var Ctor = object && object.constructor; 22211 if (isArrLike) { 22212 accumulator = isArr ? new Ctor : []; 22213 } 22214 else if (isObject(object)) { 22215 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; 22216 } 22217 else { 22218 accumulator = {}; 22219 } 22220 } 22221 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) { 22222 return iteratee(accumulator, value, index, object); 22223 }); 22224 return accumulator; 22225 } 22226 22227 /** 22228 * Removes the property at `path` of `object`. 22229 * 22230 * **Note:** This method mutates `object`. 22231 * 22232 * @static 22233 * @memberOf _ 22234 * @since 4.0.0 22235 * @category Object 22236 * @param {Object} object The object to modify. 22237 * @param {Array|string} path The path of the property to unset. 22238 * @returns {boolean} Returns `true` if the property is deleted, else `false`. 22239 * @example 22240 * 22241 * var object = { 'a': [{ 'b': { 'c': 7 } }] }; 22242 * _.unset(object, 'a[0].b.c'); 22243 * // => true 22244 * 22245 * console.log(object); 22246 * // => { 'a': [{ 'b': {} }] }; 22247 * 22248 * _.unset(object, ['a', '0', 'b', 'c']); 22249 * // => true 22250 * 22251 * console.log(object); 22252 * // => { 'a': [{ 'b': {} }] }; 22253 */ 22254 function unset(object, path) { 22255 return object == null ? true : baseUnset(object, path); 22256 } 22257 22258 /** 22259 * This method is like `_.set` except that accepts `updater` to produce the 22260 * value to set. Use `_.updateWith` to customize `path` creation. The `updater` 22261 * is invoked with one argument: (value). 22262 * 22263 * **Note:** This method mutates `object`. 22264 * 22265 * @static 22266 * @memberOf _ 22267 * @since 4.6.0 22268 * @category Object 22269 * @param {Object} object The object to modify. 22270 * @param {Array|string} path The path of the property to set. 22271 * @param {Function} updater The function to produce the updated value. 22272 * @returns {Object} Returns `object`. 22273 * @example 22274 * 22275 * var object = { 'a': [{ 'b': { 'c': 3 } }] }; 22276 * 22277 * _.update(object, 'a[0].b.c', function(n) { return n * n; }); 22278 * console.log(object.a[0].b.c); 22279 * // => 9 22280 * 22281 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; }); 22282 * console.log(object.x[0].y.z); 22283 * // => 0 22284 */ 22285 function update(object, path, updater) { 22286 return object == null ? object : baseUpdate(object, path, castFunction(updater)); 22287 } 22288 22289 /** 22290 * This method is like `_.update` except that it accepts `customizer` which is 22291 * invoked to produce the objects of `path`. If `customizer` returns `undefined` 22292 * path creation is handled by the method instead. The `customizer` is invoked 22293 * with three arguments: (nsValue, key, nsObject). 22294 * 22295 * **Note:** This method mutates `object`. 22296 * 22297 * @static 22298 * @memberOf _ 22299 * @since 4.6.0 22300 * @category Object 22301 * @param {Object} object The object to modify. 22302 * @param {Array|string} path The path of the property to set. 22303 * @param {Function} updater The function to produce the updated value. 22304 * @param {Function} [customizer] The function to customize assigned values. 22305 * @returns {Object} Returns `object`. 22306 * @example 22307 * 22308 * var object = {}; 22309 * 22310 * _.updateWith(object, '[0][1]', _.constant('a'), Object); 22311 * // => { '0': { '1': 'a' } } 22312 */ 22313 function updateWith(object, path, updater, customizer) { 22314 customizer = typeof customizer == 'function' ? customizer : undefined$1; 22315 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer); 22316 } 22317 22318 /**
22319 * Creates an array of the own enumerable string keyed property values of `object`. 22320 * 22321 * **Note:** Non-object values are coerced to objects. 22322 * 22323 * @static 22324 * @since 0.1.0 22325 * @memberOf _ 22326 * @category Object 22327 * @param {Object} object The object to query. 22328 * @returns {Array} Returns the array of property values. 22329 * @example 22330 * 22331 * function Foo() { 22332 * this.a = 1; 22333 * this.b = 2; 22334 * } 22335 * 22336 * Foo.prototype.c = 3; 22337 * 22338 * _.values(new Foo); 22339 * // => [1, 2] (iteration order is not guaranteed) 22340 * 22341 * _.values('hi'); 22342 * // => ['h', 'i'] 22343 */ 22344 function values(object) { 22345 return object == null ? [] : baseValues(object, keys(object)); 22346 } 22347 22348 /** 22349 * Creates an array of the own and inherited enumerable string keyed property 22350 * values of `object`. 22351 * 22352 * **Note:** Non-object values are coerced to objects. 22353 * 22354 * @static 22355 * @memberOf _ 22356 * @since 3.0.0 22357 * @category Object 22358 * @param {Object} object The object to query. 22359 * @returns {Array} Returns the array of property values. 22360 * @example 22361 * 22362 * function Foo() { 22363 * this.a = 1; 22364 * this.b = 2; 22365 * } 22366 * 22367 * Foo.prototype.c = 3; 22368 *
vendor: 9,973 bytes, lines 22369-22669
22369 * _.valuesIn(new Foo); 22370 * // => [1, 2, 3] (iteration order is not guaranteed) 22371 */ 22372 function valuesIn(object) { 22373 return object == null ? [] : baseValues(object, keysIn(object)); 22374 } 22375 22376 /*------------------------------------------------------------------------*/ 22377 22378 /** 22379 * Clamps `number` within the inclusive `lower` and `upper` bounds. 22380 * 22381 * @static 22382 * @memberOf _ 22383 * @since 4.0.0 22384 * @category Number 22385 * @param {number} number The number to clamp. 22386 * @param {number} [lower] The lower bound. 22387 * @param {number} upper The upper bound. 22388 * @returns {number} Returns the clamped number. 22389 * @example 22390 * 22391 * _.clamp(-10, -5, 5); 22392 * // => -5 22393 * 22394 * _.clamp(10, -5, 5); 22395 * // => 5 22396 */ 22397 function clamp(number, lower, upper) { 22398 if (upper === undefined$1) { 22399 upper = lower; 22400 lower = undefined$1; 22401 } 22402 if (upper !== undefined$1) { 22403 upper = toNumber(upper); 22404 upper = upper === upper ? upper : 0; 22405 } 22406 if (lower !== undefined$1) { 22407 lower = toNumber(lower); 22408 lower = lower === lower ? lower : 0; 22409 } 22410 return baseClamp(toNumber(number), lower, upper); 22411 } 22412 22413 /** 22414 * Checks if `n` is between `start` and up to, but not including, `end`. If 22415 * `end` is not specified, it's set to `start` with `start` then set to `0`. 22416 * If `start` is greater than `end` the params are swapped to support 22417 * negative ranges. 22418 * 22419 * @static 22420 * @memberOf _ 22421 * @since 3.3.0 22422 * @category Number 22423 * @param {number} number The number to check. 22424 * @param {number} [start=0] The start of the range. 22425 * @param {number} end The end of the range. 22426 * @returns {boolean} Returns `true` if `number` is in the range, else `false`. 22427 * @see _.range, _.rangeRight 22428 * @example 22429 * 22430 * _.inRange(3, 2, 4); 22431 * // => true 22432 * 22433 * _.inRange(4, 8); 22434 * // => true 22435 * 22436 * _.inRange(4, 2); 22437 * // => false 22438 * 22439 * _.inRange(2, 2); 22440 * // => false 22441 * 22442 * _.inRange(1.2, 2); 22443 * // => true 22444 * 22445 * _.inRange(5.2, 4); 22446 * // => false 22447 * 22448 * _.inRange(-3, -2, -6); 22449 * // => true 22450 */ 22451 function inRange(number, start, end) { 22452 start = toFinite(start); 22453 if (end === undefined$1) { 22454 end = start; 22455 start = 0; 22456 } else { 22457 end = toFinite(end); 22458 } 22459 number = toNumber(number); 22460 return baseInRange(number, start, end); 22461 } 22462 22463 /** 22464 * Produces a random number between the inclusive `lower` and `upper` bounds. 22465 * If only one argument is provided a number between `0` and the given number 22466 * is returned. If `floating` is `true`, or either `lower` or `upper` are 22467 * floats, a floating-point number is returned instead of an integer. 22468 * 22469 * **Note:** JavaScript follows the IEEE-754 standard for resolving 22470 * floating-point values which can produce unexpected results. 22471 * 22472 * @static 22473 * @memberOf _ 22474 * @since 0.7.0 22475 * @category Number 22476 * @param {number} [lower=0] The lower bound. 22477 * @param {number} [upper=1] The upper bound. 22478 * @param {boolean} [floating] Specify returning a floating-point number. 22479 * @returns {number} Returns the random number. 22480 * @example 22481 * 22482 * _.random(0, 5); 22483 * // => an integer between 0 and 5 22484 * 22485 * _.random(5); 22486 * // => also an integer between 0 and 5 22487 * 22488 * _.random(5, true); 22489 * // => a floating-point number between 0 and 5 22490 * 22491 * _.random(1.2, 5.2); 22492 * // => a floating-point number between 1.2 and 5.2 22493 */ 22494 function random(lower, upper, floating) { 22495 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) { 22496 upper = floating = undefined$1; 22497 } 22498 if (floating === undefined$1) { 22499 if (typeof upper == 'boolean') { 22500 floating = upper; 22501 upper = undefined$1; 22502 } 22503 else if (typeof lower == 'boolean') { 22504 floating = lower; 22505 lower = undefined$1; 22506 } 22507 } 22508 if (lower === undefined$1 && upper === undefined$1) { 22509 lower = 0; 22510 upper = 1; 22511 } 22512 else { 22513 lower = toFinite(lower); 22514 if (upper === undefined$1) { 22515 upper = lower; 22516 lower = 0; 22517 } else { 22518 upper = toFinite(upper); 22519 } 22520 } 22521 if (lower > upper) { 22522 var temp = lower; 22523 lower = upper; 22524 upper = temp; 22525 } 22526 if (floating || lower % 1 || upper % 1) { 22527 var rand = nativeRandom(); 22528 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper); 22529 } 22530 return baseRandom(lower, upper); 22531 } 22532 22533 /*------------------------------------------------------------------------*/ 22534 22535 /** 22536 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). 22537 * 22538 * @static 22539 * @memberOf _ 22540 * @since 3.0.0 22541 * @category String 22542 * @param {string} [string=''] The string to convert. 22543 * @returns {string} Returns the camel cased string. 22544 * @example 22545 * 22546 * _.camelCase('Foo Bar'); 22547 * // => 'fooBar' 22548 * 22549 * _.camelCase('--foo-bar--'); 22550 * // => 'fooBar' 22551 * 22552 * _.camelCase('__FOO_BAR__'); 22553 * // => 'fooBar' 22554 */ 22555 var camelCase = createCompounder(function(result, word, index) { 22556 word = word.toLowerCase(); 22557 return result + (index ? capitalize(word) : word); 22558 }); 22559 22560 /** 22561 * Converts the first character of `string` to upper case and the remaining 22562 * to lower case. 22563 * 22564 * @static 22565 * @memberOf _ 22566 * @since 3.0.0 22567 * @category String 22568 * @param {string} [string=''] The string to capitalize. 22569 * @returns {string} Returns the capitalized string. 22570 * @example 22571 * 22572 * _.capitalize('FRED'); 22573 * // => 'Fred' 22574 */ 22575 function capitalize(string) { 22576 return upperFirst(toString(string).toLowerCase()); 22577 } 22578 22579 /** 22580 * Deburrs `string` by converting 22581 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) 22582 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) 22583 * letters to basic Latin letters and removing 22584 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). 22585 * 22586 * @static 22587 * @memberOf _ 22588 * @since 3.0.0 22589 * @category String 22590 * @param {string} [string=''] The string to deburr. 22591 * @returns {string} Returns the deburred string. 22592 * @example 22593 * 22594 * _.deburr('déjà vu'); 22595 * // => 'deja vu' 22596 */ 22597 function deburr(string) { 22598 string = toString(string); 22599 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); 22600 } 22601 22602 /** 22603 * Checks if `string` ends with the given target string. 22604 * 22605 * @static 22606 * @memberOf _ 22607 * @since 3.0.0 22608 * @category String 22609 * @param {string} [string=''] The string to inspect. 22610 * @param {string} [target] The string to search for. 22611 * @param {number} [position=string.length] The position to search up to. 22612 * @returns {boolean} Returns `true` if `string` ends with `target`, 22613 * else `false`. 22614 * @example 22615 * 22616 * _.endsWith('abc', 'c'); 22617 * // => true 22618 * 22619 * _.endsWith('abc', 'b'); 22620 * // => false 22621 * 22622 * _.endsWith('abc', 'b', 2); 22623 * // => true 22624 */ 22625 function endsWith(string, target, position) { 22626 string = toString(string); 22627 target = baseToString(target); 22628 22629 var length = string.length; 22630 position = position === undefined$1 22631 ? length 22632 : baseClamp(toInteger(position), 0, length); 22633 22634 var end = position; 22635 position -= target.length; 22636 return position >= 0 && string.slice(position, end) == target; 22637 } 22638 22639 /** 22640 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their 22641 * corresponding HTML entities. 22642 * 22643 * **Note:** No other characters are escaped. To escape additional 22644 * characters use a third-party library like [_he_](https://mths.be/he). 22645 * 22646 * Though the ">" character is escaped for symmetry, characters like 22647 * ">" and "/" don't need escaping in HTML and have no special meaning 22648 * unless they're part of a tag or unquoted attribute value. See 22649 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) 22650 * (under "semi-related fun fact") for more details. 22651 * 22652 * When working with HTML you should always 22653 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce 22654 * XSS vectors. 22655 * 22656 * @static 22657 * @since 0.1.0 22658 * @memberOf _ 22659 * @category String 22660 * @param {string} [string=''] The string to escape. 22661 * @returns {string} Returns the escaped string. 22662 * @example 22663 * 22664 * _.escape('fred, barney, & pebbles'); 22665 * // => 'fred, barney, & pebbles' 22666 */ 22667 function escape(string) { 22668 string = toString(string); 22669 return (string && reHasUnescapedHtml.test(string))
vendor: 4,755 bytes, lines 22670-22826
22670 ? string.replace(reUnescapedHtml, escapeHtmlChar) 22671 : string; 22672 } 22673 22674 /** 22675 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", 22676 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. 22677 * 22678 * @static 22679 * @memberOf _ 22680 * @since 3.0.0 22681 * @category String 22682 * @param {string} [string=''] The string to escape. 22683 * @returns {string} Returns the escaped string. 22684 * @example 22685 * 22686 * _.escapeRegExp('[lodash](https://lodash.com/)'); 22687 * // => '\[lodash\]\(https://lodash\.com/\)' 22688 */ 22689 function escapeRegExp(string) { 22690 string = toString(string); 22691 return (string && reHasRegExpChar.test(string)) 22692 ? string.replace(reRegExpChar, '\\$&') 22693 : string; 22694 } 22695 22696 /** 22697 * Converts `string` to 22698 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). 22699 * 22700 * @static 22701 * @memberOf _ 22702 * @since 3.0.0 22703 * @category String 22704 * @param {string} [string=''] The string to convert. 22705 * @returns {string} Returns the kebab cased string. 22706 * @example 22707 * 22708 * _.kebabCase('Foo Bar'); 22709 * // => 'foo-bar' 22710 * 22711 * _.kebabCase('fooBar'); 22712 * // => 'foo-bar' 22713 * 22714 * _.kebabCase('__FOO_BAR__'); 22715 * // => 'foo-bar' 22716 */ 22717 var kebabCase = createCompounder(function(result, word, index) { 22718 return result + (index ? '-' : '') + word.toLowerCase(); 22719 }); 22720 22721 /** 22722 * Converts `string`, as space separated words, to lower case. 22723 * 22724 * @static 22725 * @memberOf _ 22726 * @since 4.0.0 22727 * @category String 22728 * @param {string} [string=''] The string to convert. 22729 * @returns {string} Returns the lower cased string. 22730 * @example 22731 * 22732 * _.lowerCase('--Foo-Bar--'); 22733 * // => 'foo bar' 22734 * 22735 * _.lowerCase('fooBar'); 22736 * // => 'foo bar' 22737 * 22738 * _.lowerCase('__FOO_BAR__'); 22739 * // => 'foo bar' 22740 */ 22741 var lowerCase = createCompounder(function(result, word, index) { 22742 return result + (index ? ' ' : '') + word.toLowerCase(); 22743 }); 22744 22745 /** 22746 * Converts the first character of `string` to lower case. 22747 * 22748 * @static 22749 * @memberOf _ 22750 * @since 4.0.0 22751 * @category String 22752 * @param {string} [string=''] The string to convert. 22753 * @returns {string} Returns the converted string. 22754 * @example 22755 * 22756 * _.lowerFirst('Fred'); 22757 * // => 'fred' 22758 * 22759 * _.lowerFirst('FRED'); 22760 * // => 'fRED' 22761 */ 22762 var lowerFirst = createCaseFirst('toLowerCase'); 22763 22764 /** 22765 * Pads `string` on the left and right sides if it's shorter than `length`. 22766 * Padding characters are truncated if they can't be evenly divided by `length`. 22767 * 22768 * @static 22769 * @memberOf _ 22770 * @since 3.0.0 22771 * @category String 22772 * @param {string} [string=''] The string to pad. 22773 * @param {number} [length=0] The padding length. 22774 * @param {string} [chars=' '] The string used as padding. 22775 * @returns {string} Returns the padded string. 22776 * @example 22777 * 22778 * _.pad('abc', 8); 22779 * // => ' abc ' 22780 * 22781 * _.pad('abc', 8, '_-'); 22782 * // => '_-abc_-_' 22783 * 22784 * _.pad('abc', 3); 22785 * // => 'abc' 22786 */ 22787 function pad(string, length, chars) { 22788 string = toString(string); 22789 length = toInteger(length); 22790 22791 var strLength = length ? stringSize(string) : 0; 22792 if (!length || strLength >= length) { 22793 return string; 22794 } 22795 var mid = (length - strLength) / 2; 22796 return ( 22797 createPadding(nativeFloor(mid), chars) + 22798 string + 22799 createPadding(nativeCeil(mid), chars) 22800 ); 22801 } 22802 22803 /** 22804 * Pads `string` on the right side if it's shorter than `length`. Padding 22805 * characters are truncated if they exceed `length`. 22806 * 22807 * @static 22808 * @memberOf _ 22809 * @since 4.0.0 22810 * @category String 22811 * @param {string} [string=''] The string to pad. 22812 * @param {number} [length=0] The padding length. 22813 * @param {string} [chars=' '] The string used as padding. 22814 * @returns {string} Returns the padded string. 22815 * @example 22816 * 22817 * _.padEnd('abc', 6); 22818 * // => 'abc ' 22819 * 22820 * _.padEnd('abc', 6, '_-'); 22821 * // => 'abc_-_' 22822 * 22823 * _.padEnd('abc', 3); 22824 * // => 'abc' 22825 */ 22826 function padEnd(string, length, chars) {
vendor: 11,805 bytes, lines 22827-23152
22827 string = toString(string); 22828 length = toInteger(length); 22829 22830 var strLength = length ? stringSize(string) : 0; 22831 return (length && strLength < length) 22832 ? (string + createPadding(length - strLength, chars)) 22833 : string; 22834 } 22835 22836 /** 22837 * Pads `string` on the left side if it's shorter than `length`. Padding 22838 * characters are truncated if they exceed `length`. 22839 * 22840 * @static 22841 * @memberOf _ 22842 * @since 4.0.0 22843 * @category String 22844 * @param {string} [string=''] The string to pad. 22845 * @param {number} [length=0] The padding length. 22846 * @param {string} [chars=' '] The string used as padding. 22847 * @returns {string} Returns the padded string. 22848 * @example 22849 * 22850 * _.padStart('abc', 6); 22851 * // => ' abc' 22852 * 22853 * _.padStart('abc', 6, '_-'); 22854 * // => '_-_abc' 22855 * 22856 * _.padStart('abc', 3); 22857 * // => 'abc' 22858 */ 22859 function padStart(string, length, chars) { 22860 string = toString(string); 22861 length = toInteger(length); 22862 22863 var strLength = length ? stringSize(string) : 0; 22864 return (length && strLength < length) 22865 ? (createPadding(length - strLength, chars) + string) 22866 : string; 22867 } 22868 22869 /** 22870 * Converts `string` to an integer of the specified radix. If `radix` is 22871 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a 22872 * hexadecimal, in which case a `radix` of `16` is used. 22873 * 22874 * **Note:** This method aligns with the 22875 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. 22876 * 22877 * @static 22878 * @memberOf _ 22879 * @since 1.1.0 22880 * @category String 22881 * @param {string} string The string to convert. 22882 * @param {number} [radix=10] The radix to interpret `value` by. 22883 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 22884 * @returns {number} Returns the converted integer. 22885 * @example 22886 * 22887 * _.parseInt('08'); 22888 * // => 8 22889 * 22890 * _.map(['6', '08', '10'], _.parseInt); 22891 * // => [6, 8, 10] 22892 */ 22893 function parseInt(string, radix, guard) { 22894 if (guard || radix == null) { 22895 radix = 0; 22896 } else if (radix) { 22897 radix = +radix; 22898 } 22899 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0); 22900 } 22901 22902 /** 22903 * Repeats the given string `n` times. 22904 * 22905 * @static 22906 * @memberOf _ 22907 * @since 3.0.0 22908 * @category String 22909 * @param {string} [string=''] The string to repeat. 22910 * @param {number} [n=1] The number of times to repeat the string. 22911 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 22912 * @returns {string} Returns the repeated string. 22913 * @example 22914 * 22915 * _.repeat('*', 3); 22916 * // => '***' 22917 * 22918 * _.repeat('abc', 2); 22919 * // => 'abcabc' 22920 * 22921 * _.repeat('abc', 0); 22922 * // => '' 22923 */ 22924 function repeat(string, n, guard) { 22925 if ((guard ? isIterateeCall(string, n, guard) : n === undefined$1)) { 22926 n = 1; 22927 } else { 22928 n = toInteger(n); 22929 } 22930 return baseRepeat(toString(string), n); 22931 } 22932 22933 /** 22934 * Replaces matches for `pattern` in `string` with `replacement`. 22935 * 22936 * **Note:** This method is based on 22937 * [`String#replace`](https://mdn.io/String/replace). 22938 * 22939 * @static 22940 * @memberOf _ 22941 * @since 4.0.0 22942 * @category String 22943 * @param {string} [string=''] The string to modify. 22944 * @param {RegExp|string} pattern The pattern to replace. 22945 * @param {Function|string} replacement The match replacement. 22946 * @returns {string} Returns the modified string. 22947 * @example 22948 * 22949 * _.replace('Hi Fred', 'Fred', 'Barney'); 22950 * // => 'Hi Barney' 22951 */ 22952 function replace() { 22953 var args = arguments, 22954 string = toString(args[0]); 22955 22956 return args.length < 3 ? string : string.replace(args[1], args[2]); 22957 } 22958 22959 /** 22960 * Converts `string` to 22961 * [snake case](https://en.wikipedia.org/wiki/Snake_case). 22962 * 22963 * @static 22964 * @memberOf _ 22965 * @since 3.0.0 22966 * @category String 22967 * @param {string} [string=''] The string to convert. 22968 * @returns {string} Returns the snake cased string. 22969 * @example 22970 * 22971 * _.snakeCase('Foo Bar'); 22972 * // => 'foo_bar' 22973 * 22974 * _.snakeCase('fooBar'); 22975 * // => 'foo_bar' 22976 * 22977 * _.snakeCase('--FOO-BAR--'); 22978 * // => 'foo_bar' 22979 */ 22980 var snakeCase = createCompounder(function(result, word, index) { 22981 return result + (index ? '_' : '') + word.toLowerCase(); 22982 }); 22983 22984 /** 22985 * Splits `string` by `separator`. 22986 * 22987 * **Note:** This method is based on 22988 * [`String#split`](https://mdn.io/String/split). 22989 * 22990 * @static 22991 * @memberOf _ 22992 * @since 4.0.0 22993 * @category String 22994 * @param {string} [string=''] The string to split. 22995 * @param {RegExp|string} separator The separator pattern to split by. 22996 * @param {number} [limit] The length to truncate results to. 22997 * @returns {Array} Returns the string segments. 22998 * @example 22999 * 23000 * _.split('a-b-c', '-', 2); 23001 * // => ['a', 'b'] 23002 */ 23003 function split(string, separator, limit) { 23004 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { 23005 separator = limit = undefined$1; 23006 } 23007 limit = limit === undefined$1 ? MAX_ARRAY_LENGTH : limit >>> 0; 23008 if (!limit) { 23009 return []; 23010 } 23011 string = toString(string); 23012 if (string && ( 23013 typeof separator == 'string' || 23014 (separator != null && !isRegExp(separator)) 23015 )) { 23016 separator = baseToString(separator); 23017 if (!separator && hasUnicode(string)) { 23018 return castSlice(stringToArray(string), 0, limit); 23019 } 23020 } 23021 return string.split(separator, limit); 23022 } 23023 23024 /** 23025 * Converts `string` to 23026 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). 23027 * 23028 * @static 23029 * @memberOf _ 23030 * @since 3.1.0 23031 * @category String 23032 * @param {string} [string=''] The string to convert. 23033 * @returns {string} Returns the start cased string. 23034 * @example 23035 * 23036 * _.startCase('--foo-bar--'); 23037 * // => 'Foo Bar' 23038 * 23039 * _.startCase('fooBar'); 23040 * // => 'Foo Bar' 23041 * 23042 * _.startCase('__FOO_BAR__'); 23043 * // => 'FOO BAR' 23044 */ 23045 var startCase = createCompounder(function(result, word, index) { 23046 return result + (index ? ' ' : '') + upperFirst(word); 23047 }); 23048 23049 /** 23050 * Checks if `string` starts with the given target string. 23051 * 23052 * @static 23053 * @memberOf _ 23054 * @since 3.0.0 23055 * @category String 23056 * @param {string} [string=''] The string to inspect. 23057 * @param {string} [target] The string to search for. 23058 * @param {number} [position=0] The position to search from. 23059 * @returns {boolean} Returns `true` if `string` starts with `target`, 23060 * else `false`. 23061 * @example 23062 * 23063 * _.startsWith('abc', 'a'); 23064 * // => true 23065 * 23066 * _.startsWith('abc', 'b'); 23067 * // => false 23068 * 23069 * _.startsWith('abc', 'b', 1); 23070 * // => true 23071 */ 23072 function startsWith(string, target, position) { 23073 string = toString(string); 23074 position = position == null 23075 ? 0 23076 : baseClamp(toInteger(position), 0, string.length); 23077 23078 target = baseToString(target); 23079 return string.slice(position, position + target.length) == target; 23080 } 23081 23082 /** 23083 * Creates a compiled template function that can interpolate data properties 23084 * in "interpolate" delimiters, HTML-escape interpolated data properties in 23085 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data 23086 * properties may be accessed as free variables in the template. If a setting 23087 * object is given, it takes precedence over `_.templateSettings` values. 23088 * 23089 * **Note:** In the development build `_.template` utilizes 23090 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) 23091 * for easier debugging. 23092 * 23093 * For more information on precompiling templates see 23094 * [lodash's custom builds documentation](https://lodash.com/custom-builds). 23095 * 23096 * For more information on Chrome extension sandboxes see 23097 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). 23098 * 23099 * @static 23100 * @since 0.1.0 23101 * @memberOf _ 23102 * @category String 23103 * @param {string} [string=''] The template string. 23104 * @param {Object} [options={}] The options object. 23105 * @param {RegExp} [options.escape=_.templateSettings.escape] 23106 * The HTML "escape" delimiter. 23107 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] 23108 * The "evaluate" delimiter. 23109 * @param {Object} [options.imports=_.templateSettings.imports] 23110 * An object to import into the template as free variables. 23111 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] 23112 * The "interpolate" delimiter. 23113 * @param {string} [options.sourceURL='lodash.templateSources[n]'] 23114 * The sourceURL of the compiled template. 23115 * @param {string} [options.variable='obj'] 23116 * The data object variable name. 23117 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 23118 * @returns {Function} Returns the compiled template function. 23119 * @example 23120 * 23121 * // Use the "interpolate" delimiter to create a compiled template. 23122 * var compiled = _.template('hello <%= user %>!'); 23123 * compiled({ 'user': 'fred' }); 23124 * // => 'hello fred!' 23125 * 23126 * // Use the HTML "escape" delimiter to escape data property values. 23127 * var compiled = _.template('<b><%- value %></b>'); 23128 * compiled({ 'value': '<script>' }); 23129 * // => '<b><script></b>' 23130 * 23131 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML. 23132 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>'); 23133 * compiled({ 'users': ['fred', 'barney'] }); 23134 * // => '<li>fred</li><li>barney</li>' 23135 * 23136 * // Use the internal `print` function in "evaluate" delimiters. 23137 * var compiled = _.template('<% print("hello " + user); %>!'); 23138 * compiled({ 'user': 'barney' }); 23139 * // => 'hello barney!' 23140 * 23141 * // Use the ES template literal delimiter as an "interpolate" delimiter. 23142 * // Disable support by replacing the "interpolate" delimiter. 23143 * var compiled = _.template('hello ${ user }!'); 23144 * compiled({ 'user': 'pebbles' }); 23145 * // => 'hello pebbles!' 23146 * 23147 * // Use backslashes to treat delimiters as plain text. 23148 * var compiled = _.template('<%= "\\<%- value %\\>" %>'); 23149 * compiled({ 'value': 'ignored' }); 23150 * // => '<%- value %>' 23151 * 23152 * // Use the `imports` option to import `jQuery` as `jq`.
23153 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>'; 23154 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); 23155 * compiled({ 'users': ['fred', 'barney'] }); 23156 * // => '<li>fred</li><li>barney</li>' 23157 * 23158 * // Use the `sourceURL` option to specify a custom sourceURL for the template. 23159 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); 23160 * compiled(data); 23161 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector. 23162 * 23163 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template. 23164 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); 23165 * compiled.source; 23166 * // => function(data) { 23167 * // var __t, __p = ''; 23168 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!'; 23169 * // return __p; 23170 * // } 23171 * 23172 * // Use custom template delimiters. 23173 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; 23174 * var compiled = _.template('hello {{ user }}!'); 23175 * compiled({ 'user': 'mustache' }); 23176 * // => 'hello mustache!' 23177 * 23178 * // Use the `source` property to inline compiled templates for meaningful 23179 * // line numbers in error messages and stack traces. 23180 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\ 23181 * var JST = {\ 23182 * "main": ' + _.template(mainText).source + '\ 23183 * };\ 23184 * '); 23185 */ 23186 function template(string, options, guard) { 23187 // Based on John Resig's `tmpl` implementation 23188 // (http://ejohn.org/blog/javascript-micro-templating/) 23189 // and Laura Doktorova's doT.js (https://github.com/olado/doT). 23190 var settings = lodash.templateSettings; 23191 23192 if (guard && isIterateeCall(string, options, guard)) { 23193 options = undefined$1; 23194 } 23195 string = toString(string); 23196 options = assignInWith({}, options, settings, customDefaultsAssignIn); 23197 23198 var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), 23199 importsKeys = keys(imports), 23200 importsValues = baseValues(imports, importsKeys); 23201 23202 var isEscaping, 23203 isEvaluating, 23204 index = 0, 23205 interpolate = options.interpolate || reNoMatch, 23206 source = "__p += '"; 23207 23208 // Compile the regexp to match each delimiter. 23209 var reDelimiters = RegExp( 23210 (options.escape || reNoMatch).source + '|' + 23211 interpolate.source + '|' + 23212 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + 23213 (options.evaluate || reNoMatch).source + '|$' 23214 , 'g'); 23215 23216 // Use a sourceURL for easier debugging. 23217 // The sourceURL gets injected into the source that's eval-ed, so be careful 23218 // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in 23219 // and escape the comment, thus injecting code that gets evaled. 23220 var sourceURL = '//# sourceURL=' + 23221 (hasOwnProperty.call(options, 'sourceURL') 23222 ? (options.sourceURL + '').replace(/\s/g, ' ') 23223 : ('lodash.templateSources[' + (++templateCounter) + ']') 23224 ) + '\n'; 23225 23226 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { 23227 interpolateValue || (interpolateValue = esTemplateValue); 23228 23229 // Escape characters that can't be included in string literals. 23230 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar); 23231 23232 // Replace delimiters with snippets. 23233 if (escapeValue) { 23234 isEscaping = true; 23235 source += "' +\n__e(" + escapeValue + ") +\n'"; 23236 } 23237 if (evaluateValue) { 23238 isEvaluating = true; 23239 source += "';\n" + evaluateValue + ";\n__p += '"; 23240 } 23241 if (interpolateValue) { 23242 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'"; 23243 } 23244 index = offset + match.length; 23245 23246 // The JS engine embedded in Adobe products needs `match` returned in 23247 // order to produce the correct `offset` value. 23248 return match; 23249 }); 23250 23251 source += "';\n"; 23252 23253 // If `variable` is not specified wrap a with-statement around the generated 23254 // code to add the data object to the top of the scope chain.
vendor: 16,963 bytes, lines 23255-23757
23255 var variable = hasOwnProperty.call(options, 'variable') && options.variable; 23256 if (!variable) { 23257 source = 'with (obj) {\n' + source + '\n}\n'; 23258 } 23259 // Throw an error if a forbidden character was found in `variable`, to prevent 23260 // potential command injection attacks. 23261 else if (reForbiddenIdentifierChars.test(variable)) { 23262 throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT); 23263 } 23264 23265 // Cleanup code by stripping empty strings. 23266 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) 23267 .replace(reEmptyStringMiddle, '$1') 23268 .replace(reEmptyStringTrailing, '$1;'); 23269 23270 // Frame code as the function body. 23271 source = 'function(' + (variable || 'obj') + ') {\n' + 23272 (variable 23273 ? '' 23274 : 'obj || (obj = {});\n' 23275 ) + 23276 "var __t, __p = ''" + 23277 (isEscaping 23278 ? ', __e = _.escape' 23279 : '' 23280 ) + 23281 (isEvaluating 23282 ? ', __j = Array.prototype.join;\n' + 23283 "function print() { __p += __j.call(arguments, '') }\n" 23284 : ';\n' 23285 ) + 23286 source + 23287 'return __p\n}'; 23288 23289 var result = attempt(function() { 23290 return Function(importsKeys, sourceURL + 'return ' + source) 23291 .apply(undefined$1, importsValues); 23292 }); 23293 23294 // Provide the compiled function's source by its `toString` method or 23295 // the `source` property as a convenience for inlining compiled templates. 23296 result.source = source; 23297 if (isError(result)) { 23298 throw result; 23299 } 23300 return result; 23301 } 23302 23303 /** 23304 * Converts `string`, as a whole, to lower case just like 23305 * [String#toLowerCase](https://mdn.io/toLowerCase). 23306 * 23307 * @static 23308 * @memberOf _ 23309 * @since 4.0.0 23310 * @category String 23311 * @param {string} [string=''] The string to convert. 23312 * @returns {string} Returns the lower cased string. 23313 * @example 23314 * 23315 * _.toLower('--Foo-Bar--'); 23316 * // => '--foo-bar--' 23317 * 23318 * _.toLower('fooBar'); 23319 * // => 'foobar' 23320 * 23321 * _.toLower('__FOO_BAR__'); 23322 * // => '__foo_bar__' 23323 */ 23324 function toLower(value) { 23325 return toString(value).toLowerCase(); 23326 } 23327 23328 /** 23329 * Converts `string`, as a whole, to upper case just like 23330 * [String#toUpperCase](https://mdn.io/toUpperCase). 23331 * 23332 * @static 23333 * @memberOf _ 23334 * @since 4.0.0 23335 * @category String 23336 * @param {string} [string=''] The string to convert. 23337 * @returns {string} Returns the upper cased string. 23338 * @example 23339 * 23340 * _.toUpper('--foo-bar--'); 23341 * // => '--FOO-BAR--' 23342 * 23343 * _.toUpper('fooBar'); 23344 * // => 'FOOBAR' 23345 * 23346 * _.toUpper('__foo_bar__'); 23347 * // => '__FOO_BAR__' 23348 */ 23349 function toUpper(value) { 23350 return toString(value).toUpperCase(); 23351 } 23352 23353 /** 23354 * Removes leading and trailing whitespace or specified characters from `string`. 23355 * 23356 * @static 23357 * @memberOf _ 23358 * @since 3.0.0 23359 * @category String 23360 * @param {string} [string=''] The string to trim. 23361 * @param {string} [chars=whitespace] The characters to trim. 23362 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 23363 * @returns {string} Returns the trimmed string. 23364 * @example 23365 * 23366 * _.trim(' abc '); 23367 * // => 'abc' 23368 * 23369 * _.trim('-_-abc-_-', '_-'); 23370 * // => 'abc' 23371 * 23372 * _.map([' foo ', ' bar '], _.trim); 23373 * // => ['foo', 'bar'] 23374 */ 23375 function trim(string, chars, guard) { 23376 string = toString(string); 23377 if (string && (guard || chars === undefined$1)) { 23378 return baseTrim(string); 23379 } 23380 if (!string || !(chars = baseToString(chars))) { 23381 return string; 23382 } 23383 var strSymbols = stringToArray(string), 23384 chrSymbols = stringToArray(chars), 23385 start = charsStartIndex(strSymbols, chrSymbols), 23386 end = charsEndIndex(strSymbols, chrSymbols) + 1; 23387 23388 return castSlice(strSymbols, start, end).join(''); 23389 } 23390 23391 /** 23392 * Removes trailing whitespace or specified characters from `string`. 23393 * 23394 * @static 23395 * @memberOf _ 23396 * @since 4.0.0 23397 * @category String 23398 * @param {string} [string=''] The string to trim. 23399 * @param {string} [chars=whitespace] The characters to trim. 23400 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 23401 * @returns {string} Returns the trimmed string. 23402 * @example 23403 * 23404 * _.trimEnd(' abc '); 23405 * // => ' abc' 23406 * 23407 * _.trimEnd('-_-abc-_-', '_-'); 23408 * // => '-_-abc' 23409 */ 23410 function trimEnd(string, chars, guard) { 23411 string = toString(string); 23412 if (string && (guard || chars === undefined$1)) { 23413 return string.slice(0, trimmedEndIndex(string) + 1); 23414 } 23415 if (!string || !(chars = baseToString(chars))) { 23416 return string; 23417 } 23418 var strSymbols = stringToArray(string), 23419 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1; 23420 23421 return castSlice(strSymbols, 0, end).join(''); 23422 } 23423 23424 /** 23425 * Removes leading whitespace or specified characters from `string`. 23426 * 23427 * @static 23428 * @memberOf _ 23429 * @since 4.0.0 23430 * @category String 23431 * @param {string} [string=''] The string to trim. 23432 * @param {string} [chars=whitespace] The characters to trim. 23433 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 23434 * @returns {string} Returns the trimmed string. 23435 * @example 23436 * 23437 * _.trimStart(' abc '); 23438 * // => 'abc ' 23439 * 23440 * _.trimStart('-_-abc-_-', '_-'); 23441 * // => 'abc-_-' 23442 */ 23443 function trimStart(string, chars, guard) { 23444 string = toString(string); 23445 if (string && (guard || chars === undefined$1)) { 23446 return string.replace(reTrimStart, ''); 23447 } 23448 if (!string || !(chars = baseToString(chars))) { 23449 return string; 23450 } 23451 var strSymbols = stringToArray(string), 23452 start = charsStartIndex(strSymbols, stringToArray(chars)); 23453 23454 return castSlice(strSymbols, start).join(''); 23455 } 23456 23457 /** 23458 * Truncates `string` if it's longer than the given maximum string length. 23459 * The last characters of the truncated string are replaced with the omission 23460 * string which defaults to "...". 23461 * 23462 * @static 23463 * @memberOf _ 23464 * @since 4.0.0 23465 * @category String 23466 * @param {string} [string=''] The string to truncate. 23467 * @param {Object} [options={}] The options object. 23468 * @param {number} [options.length=30] The maximum string length. 23469 * @param {string} [options.omission='...'] The string to indicate text is omitted. 23470 * @param {RegExp|string} [options.separator] The separator pattern to truncate to. 23471 * @returns {string} Returns the truncated string. 23472 * @example 23473 * 23474 * _.truncate('hi-diddly-ho there, neighborino'); 23475 * // => 'hi-diddly-ho there, neighbo...' 23476 * 23477 * _.truncate('hi-diddly-ho there, neighborino', { 23478 * 'length': 24, 23479 * 'separator': ' ' 23480 * }); 23481 * // => 'hi-diddly-ho there,...' 23482 * 23483 * _.truncate('hi-diddly-ho there, neighborino', { 23484 * 'length': 24, 23485 * 'separator': /,? +/ 23486 * }); 23487 * // => 'hi-diddly-ho there...' 23488 * 23489 * _.truncate('hi-diddly-ho there, neighborino', { 23490 * 'omission': ' [...]' 23491 * }); 23492 * // => 'hi-diddly-ho there, neig [...]' 23493 */ 23494 function truncate(string, options) { 23495 var length = DEFAULT_TRUNC_LENGTH, 23496 omission = DEFAULT_TRUNC_OMISSION; 23497 23498 if (isObject(options)) { 23499 var separator = 'separator' in options ? options.separator : separator; 23500 length = 'length' in options ? toInteger(options.length) : length; 23501 omission = 'omission' in options ? baseToString(options.omission) : omission; 23502 } 23503 string = toString(string); 23504 23505 var strLength = string.length; 23506 if (hasUnicode(string)) { 23507 var strSymbols = stringToArray(string); 23508 strLength = strSymbols.length; 23509 } 23510 if (length >= strLength) { 23511 return string; 23512 } 23513 var end = length - stringSize(omission); 23514 if (end < 1) { 23515 return omission; 23516 } 23517 var result = strSymbols 23518 ? castSlice(strSymbols, 0, end).join('') 23519 : string.slice(0, end); 23520 23521 if (separator === undefined$1) { 23522 return result + omission; 23523 } 23524 if (strSymbols) { 23525 end += (result.length - end); 23526 } 23527 if (isRegExp(separator)) { 23528 if (string.slice(end).search(separator)) { 23529 var match, 23530 substring = result; 23531 23532 if (!separator.global) { 23533 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g'); 23534 } 23535 separator.lastIndex = 0; 23536 while ((match = separator.exec(substring))) { 23537 var newEnd = match.index; 23538 } 23539 result = result.slice(0, newEnd === undefined$1 ? end : newEnd); 23540 } 23541 } else if (string.indexOf(baseToString(separator), end) != end) { 23542 var index = result.lastIndexOf(separator); 23543 if (index > -1) { 23544 result = result.slice(0, index); 23545 } 23546 } 23547 return result + omission; 23548 } 23549 23550 /** 23551 * The inverse of `_.escape`; this method converts the HTML entities 23552 * `&`, `<`, `>`, `"`, and `'` in `string` to 23553 * their corresponding characters. 23554 * 23555 * **Note:** No other HTML entities are unescaped. To unescape additional 23556 * HTML entities use a third-party library like [_he_](https://mths.be/he). 23557 * 23558 * @static 23559 * @memberOf _ 23560 * @since 0.6.0 23561 * @category String 23562 * @param {string} [string=''] The string to unescape. 23563 * @returns {string} Returns the unescaped string. 23564 * @example 23565 * 23566 * _.unescape('fred, barney, & pebbles'); 23567 * // => 'fred, barney, & pebbles' 23568 */ 23569 function unescape(string) { 23570 string = toString(string); 23571 return (string && reHasEscapedHtml.test(string)) 23572 ? string.replace(reEscapedHtml, unescapeHtmlChar) 23573 : string; 23574 } 23575 23576 /** 23577 * Converts `string`, as space separated words, to upper case. 23578 * 23579 * @static 23580 * @memberOf _ 23581 * @since 4.0.0 23582 * @category String 23583 * @param {string} [string=''] The string to convert. 23584 * @returns {string} Returns the upper cased string. 23585 * @example 23586 * 23587 * _.upperCase('--foo-bar'); 23588 * // => 'FOO BAR' 23589 * 23590 * _.upperCase('fooBar'); 23591 * // => 'FOO BAR' 23592 * 23593 * _.upperCase('__foo_bar__'); 23594 * // => 'FOO BAR' 23595 */ 23596 var upperCase = createCompounder(function(result, word, index) { 23597 return result + (index ? ' ' : '') + word.toUpperCase(); 23598 }); 23599 23600 /** 23601 * Converts the first character of `string` to upper case. 23602 * 23603 * @static 23604 * @memberOf _ 23605 * @since 4.0.0 23606 * @category String 23607 * @param {string} [string=''] The string to convert. 23608 * @returns {string} Returns the converted string. 23609 * @example 23610 * 23611 * _.upperFirst('fred'); 23612 * // => 'Fred' 23613 * 23614 * _.upperFirst('FRED'); 23615 * // => 'FRED' 23616 */ 23617 var upperFirst = createCaseFirst('toUpperCase'); 23618 23619 /** 23620 * Splits `string` into an array of its words. 23621 * 23622 * @static 23623 * @memberOf _ 23624 * @since 3.0.0 23625 * @category String 23626 * @param {string} [string=''] The string to inspect. 23627 * @param {RegExp|string} [pattern] The pattern to match words. 23628 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 23629 * @returns {Array} Returns the words of `string`. 23630 * @example 23631 * 23632 * _.words('fred, barney, & pebbles'); 23633 * // => ['fred', 'barney', 'pebbles'] 23634 * 23635 * _.words('fred, barney, & pebbles', /[^, ]+/g); 23636 * // => ['fred', 'barney', '&', 'pebbles'] 23637 */ 23638 function words(string, pattern, guard) { 23639 string = toString(string); 23640 pattern = guard ? undefined$1 : pattern; 23641 23642 if (pattern === undefined$1) { 23643 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string); 23644 } 23645 return string.match(pattern) || []; 23646 } 23647 23648 /*------------------------------------------------------------------------*/ 23649 23650 /** 23651 * Attempts to invoke `func`, returning either the result or the caught error 23652 * object. Any additional arguments are provided to `func` when it's invoked. 23653 * 23654 * @static 23655 * @memberOf _ 23656 * @since 3.0.0 23657 * @category Util 23658 * @param {Function} func The function to attempt. 23659 * @param {...*} [args] The arguments to invoke `func` with. 23660 * @returns {*} Returns the `func` result or error object. 23661 * @example 23662 * 23663 * // Avoid throwing errors for invalid selectors. 23664 * var elements = _.attempt(function(selector) { 23665 * return document.querySelectorAll(selector); 23666 * }, '>_>'); 23667 * 23668 * if (_.isError(elements)) { 23669 * elements = []; 23670 * } 23671 */ 23672 var attempt = baseRest(function(func, args) { 23673 try { 23674 return apply(func, undefined$1, args); 23675 } catch (e) { 23676 return isError(e) ? e : new Error(e); 23677 } 23678 }); 23679 23680 /** 23681 * Binds methods of an object to the object itself, overwriting the existing 23682 * method. 23683 * 23684 * **Note:** This method doesn't set the "length" property of bound functions. 23685 * 23686 * @static 23687 * @since 0.1.0 23688 * @memberOf _ 23689 * @category Util 23690 * @param {Object} object The object to bind and assign the bound methods to. 23691 * @param {...(string|string[])} methodNames The object method names to bind. 23692 * @returns {Object} Returns `object`. 23693 * @example 23694 * 23695 * var view = { 23696 * 'label': 'docs', 23697 * 'click': function() { 23698 * console.log('clicked ' + this.label); 23699 * } 23700 * }; 23701 * 23702 * _.bindAll(view, ['click']); 23703 * jQuery(element).on('click', view.click); 23704 * // => Logs 'clicked docs' when clicked. 23705 */ 23706 var bindAll = flatRest(function(object, methodNames) { 23707 arrayEach(methodNames, function(key) { 23708 key = toKey(key); 23709 baseAssignValue(object, key, bind(object[key], object)); 23710 }); 23711 return object; 23712 }); 23713 23714 /** 23715 * Creates a function that iterates over `pairs` and invokes the corresponding 23716 * function of the first predicate to return truthy. The predicate-function 23717 * pairs are invoked with the `this` binding and arguments of the created 23718 * function. 23719 * 23720 * @static 23721 * @memberOf _ 23722 * @since 4.0.0 23723 * @category Util 23724 * @param {Array} pairs The predicate-function pairs. 23725 * @returns {Function} Returns the new composite function. 23726 * @example 23727 * 23728 * var func = _.cond([ 23729 * [_.matches({ 'a': 1 }), _.constant('matches A')], 23730 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')], 23731 * [_.stubTrue, _.constant('no match')] 23732 * ]); 23733 * 23734 * func({ 'a': 1, 'b': 2 }); 23735 * // => 'matches A' 23736 * 23737 * func({ 'a': 0, 'b': 1 }); 23738 * // => 'matches B' 23739 * 23740 * func({ 'a': '1', 'b': '2' }); 23741 * // => 'no match' 23742 */ 23743 function cond(pairs) { 23744 var length = pairs == null ? 0 : pairs.length, 23745 toIteratee = getIteratee(); 23746 23747 pairs = !length ? [] : arrayMap(pairs, function(pair) { 23748 if (typeof pair[1] != 'function') { 23749 throw new TypeError(FUNC_ERROR_TEXT); 23750 } 23751 return [toIteratee(pair[0]), pair[1]]; 23752 }); 23753 23754 return baseRest(function(args) { 23755 var index = -1; 23756 while (++index < length) { 23757 var pair = pairs[index];
vendor: 11,259 bytes, lines 23758-24090
23758 if (apply(pair[0], this, args)) { 23759 return apply(pair[1], this, args); 23760 } 23761 } 23762 }); 23763 } 23764 23765 /** 23766 * Creates a function that invokes the predicate properties of `source` with 23767 * the corresponding property values of a given object, returning `true` if 23768 * all predicates return truthy, else `false`. 23769 * 23770 * **Note:** The created function is equivalent to `_.conformsTo` with 23771 * `source` partially applied. 23772 * 23773 * @static 23774 * @memberOf _ 23775 * @since 4.0.0 23776 * @category Util 23777 * @param {Object} source The object of property predicates to conform to. 23778 * @returns {Function} Returns the new spec function. 23779 * @example 23780 * 23781 * var objects = [ 23782 * { 'a': 2, 'b': 1 }, 23783 * { 'a': 1, 'b': 2 } 23784 * ]; 23785 * 23786 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } })); 23787 * // => [{ 'a': 1, 'b': 2 }] 23788 */ 23789 function conforms(source) { 23790 return baseConforms(baseClone(source, CLONE_DEEP_FLAG)); 23791 } 23792 23793 /** 23794 * Creates a function that returns `value`. 23795 * 23796 * @static 23797 * @memberOf _ 23798 * @since 2.4.0 23799 * @category Util 23800 * @param {*} value The value to return from the new function. 23801 * @returns {Function} Returns the new constant function. 23802 * @example 23803 * 23804 * var objects = _.times(2, _.constant({ 'a': 1 })); 23805 * 23806 * console.log(objects); 23807 * // => [{ 'a': 1 }, { 'a': 1 }] 23808 * 23809 * console.log(objects[0] === objects[1]); 23810 * // => true 23811 */ 23812 function constant(value) { 23813 return function() { 23814 return value; 23815 }; 23816 } 23817 23818 /** 23819 * Checks `value` to determine whether a default value should be returned in 23820 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`, 23821 * or `undefined`. 23822 * 23823 * @static 23824 * @memberOf _ 23825 * @since 4.14.0 23826 * @category Util 23827 * @param {*} value The value to check. 23828 * @param {*} defaultValue The default value. 23829 * @returns {*} Returns the resolved value. 23830 * @example 23831 * 23832 * _.defaultTo(1, 10); 23833 * // => 1 23834 * 23835 * _.defaultTo(undefined, 10); 23836 * // => 10 23837 */ 23838 function defaultTo(value, defaultValue) { 23839 return (value == null || value !== value) ? defaultValue : value; 23840 } 23841 23842 /** 23843 * Creates a function that returns the result of invoking the given functions 23844 * with the `this` binding of the created function, where each successive 23845 * invocation is supplied the return value of the previous. 23846 * 23847 * @static 23848 * @memberOf _ 23849 * @since 3.0.0 23850 * @category Util 23851 * @param {...(Function|Function[])} [funcs] The functions to invoke. 23852 * @returns {Function} Returns the new composite function. 23853 * @see _.flowRight 23854 * @example 23855 * 23856 * function square(n) { 23857 * return n * n; 23858 * } 23859 * 23860 * var addSquare = _.flow([_.add, square]); 23861 * addSquare(1, 2); 23862 * // => 9 23863 */ 23864 var flow = createFlow(); 23865 23866 /** 23867 * This method is like `_.flow` except that it creates a function that 23868 * invokes the given functions from right to left. 23869 * 23870 * @static 23871 * @since 3.0.0 23872 * @memberOf _ 23873 * @category Util 23874 * @param {...(Function|Function[])} [funcs] The functions to invoke. 23875 * @returns {Function} Returns the new composite function. 23876 * @see _.flow 23877 * @example 23878 * 23879 * function square(n) { 23880 * return n * n; 23881 * } 23882 * 23883 * var addSquare = _.flowRight([square, _.add]); 23884 * addSquare(1, 2); 23885 * // => 9 23886 */ 23887 var flowRight = createFlow(true); 23888 23889 /** 23890 * This method returns the first argument it receives. 23891 * 23892 * @static 23893 * @since 0.1.0 23894 * @memberOf _ 23895 * @category Util 23896 * @param {*} value Any value. 23897 * @returns {*} Returns `value`. 23898 * @example 23899 * 23900 * var object = { 'a': 1 }; 23901 * 23902 * console.log(_.identity(object) === object); 23903 * // => true 23904 */ 23905 function identity(value) { 23906 return value; 23907 } 23908 23909 /** 23910 * Creates a function that invokes `func` with the arguments of the created 23911 * function. If `func` is a property name, the created function returns the 23912 * property value for a given element. If `func` is an array or object, the 23913 * created function returns `true` for elements that contain the equivalent 23914 * source properties, otherwise it returns `false`. 23915 * 23916 * @static 23917 * @since 4.0.0 23918 * @memberOf _ 23919 * @category Util 23920 * @param {*} [func=_.identity] The value to convert to a callback. 23921 * @returns {Function} Returns the callback. 23922 * @example 23923 * 23924 * var users = [ 23925 * { 'user': 'barney', 'age': 36, 'active': true }, 23926 * { 'user': 'fred', 'age': 40, 'active': false } 23927 * ]; 23928 * 23929 * // The `_.matches` iteratee shorthand. 23930 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true })); 23931 * // => [{ 'user': 'barney', 'age': 36, 'active': true }] 23932 * 23933 * // The `_.matchesProperty` iteratee shorthand. 23934 * _.filter(users, _.iteratee(['user', 'fred'])); 23935 * // => [{ 'user': 'fred', 'age': 40 }] 23936 * 23937 * // The `_.property` iteratee shorthand. 23938 * _.map(users, _.iteratee('user')); 23939 * // => ['barney', 'fred'] 23940 * 23941 * // Create custom iteratee shorthands. 23942 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) { 23943 * return !_.isRegExp(func) ? iteratee(func) : function(string) { 23944 * return func.test(string); 23945 * }; 23946 * }); 23947 * 23948 * _.filter(['abc', 'def'], /ef/); 23949 * // => ['def'] 23950 */ 23951 function iteratee(func) { 23952 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG)); 23953 } 23954 23955 /** 23956 * Creates a function that performs a partial deep comparison between a given 23957 * object and `source`, returning `true` if the given object has equivalent 23958 * property values, else `false`. 23959 * 23960 * **Note:** The created function is equivalent to `_.isMatch` with `source` 23961 * partially applied. 23962 * 23963 * Partial comparisons will match empty array and empty object `source` 23964 * values against any array or object value, respectively. See `_.isEqual` 23965 * for a list of supported value comparisons. 23966 * 23967 * **Note:** Multiple values can be checked by combining several matchers 23968 * using `_.overSome` 23969 * 23970 * @static 23971 * @memberOf _ 23972 * @since 3.0.0 23973 * @category Util 23974 * @param {Object} source The object of property values to match. 23975 * @returns {Function} Returns the new spec function. 23976 * @example 23977 * 23978 * var objects = [ 23979 * { 'a': 1, 'b': 2, 'c': 3 }, 23980 * { 'a': 4, 'b': 5, 'c': 6 } 23981 * ]; 23982 * 23983 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 })); 23984 * // => [{ 'a': 4, 'b': 5, 'c': 6 }] 23985 * 23986 * // Checking for several possible values 23987 * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })])); 23988 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }] 23989 */ 23990 function matches(source) { 23991 return baseMatches(baseClone(source, CLONE_DEEP_FLAG)); 23992 } 23993 23994 /** 23995 * Creates a function that performs a partial deep comparison between the 23996 * value at `path` of a given object to `srcValue`, returning `true` if the 23997 * object value is equivalent, else `false`. 23998 * 23999 * **Note:** Partial comparisons will match empty array and empty object 24000 * `srcValue` values against any array or object value, respectively. See 24001 * `_.isEqual` for a list of supported value comparisons. 24002 * 24003 * **Note:** Multiple values can be checked by combining several matchers 24004 * using `_.overSome` 24005 * 24006 * @static 24007 * @memberOf _ 24008 * @since 3.2.0 24009 * @category Util 24010 * @param {Array|string} path The path of the property to get. 24011 * @param {*} srcValue The value to match. 24012 * @returns {Function} Returns the new spec function. 24013 * @example 24014 * 24015 * var objects = [ 24016 * { 'a': 1, 'b': 2, 'c': 3 }, 24017 * { 'a': 4, 'b': 5, 'c': 6 } 24018 * ]; 24019 * 24020 * _.find(objects, _.matchesProperty('a', 4)); 24021 * // => { 'a': 4, 'b': 5, 'c': 6 } 24022 * 24023 * // Checking for several possible values 24024 * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)])); 24025 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }] 24026 */ 24027 function matchesProperty(path, srcValue) { 24028 return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG)); 24029 } 24030 24031 /** 24032 * Creates a function that invokes the method at `path` of a given object. 24033 * Any additional arguments are provided to the invoked method. 24034 * 24035 * @static 24036 * @memberOf _ 24037 * @since 3.7.0 24038 * @category Util 24039 * @param {Array|string} path The path of the method to invoke. 24040 * @param {...*} [args] The arguments to invoke the method with. 24041 * @returns {Function} Returns the new invoker function. 24042 * @example 24043 * 24044 * var objects = [ 24045 * { 'a': { 'b': _.constant(2) } }, 24046 * { 'a': { 'b': _.constant(1) } } 24047 * ]; 24048 * 24049 * _.map(objects, _.method('a.b')); 24050 * // => [2, 1] 24051 * 24052 * _.map(objects, _.method(['a', 'b'])); 24053 * // => [2, 1] 24054 */ 24055 var method = baseRest(function(path, args) { 24056 return function(object) { 24057 return baseInvoke(object, path, args); 24058 }; 24059 }); 24060 24061 /** 24062 * The opposite of `_.method`; this method creates a function that invokes 24063 * the method at a given path of `object`. Any additional arguments are 24064 * provided to the invoked method. 24065 * 24066 * @static 24067 * @memberOf _ 24068 * @since 3.7.0 24069 * @category Util 24070 * @param {Object} object The object to query. 24071 * @param {...*} [args] The arguments to invoke the method with. 24072 * @returns {Function} Returns the new invoker function. 24073 * @example 24074 * 24075 * var array = _.times(3, _.constant), 24076 * object = { 'a': array, 'b': array, 'c': array }; 24077 * 24078 * _.map(['a[2]', 'c[0]'], _.methodOf(object)); 24079 * // => [2, 0] 24080 * 24081 * _.map([['a', '2'], ['c', '0']], _.methodOf(object)); 24082 * // => [2, 0] 24083 */ 24084 var methodOf = baseRest(function(object, args) { 24085 return function(path) { 24086 return baseInvoke(object, path, args); 24087 }; 24088 }); 24089 24090 /**
24091 * Adds all own enumerable string keyed function properties of a source 24092 * object to the destination object. If `object` is a function, then methods 24093 * are added to its prototype as well. 24094 * 24095 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to 24096 * avoid conflicts caused by modifying the original. 24097 * 24098 * @static 24099 * @since 0.1.0 24100 * @memberOf _ 24101 * @category Util 24102 * @param {Function|Object} [object=lodash] The destination object. 24103 * @param {Object} source The object of functions to add. 24104 * @param {Object} [options={}] The options object. 24105 * @param {boolean} [options.chain=true] Specify whether mixins are chainable. 24106 * @returns {Function|Object} Returns `object`. 24107 * @example 24108 * 24109 * function vowels(string) { 24110 * return _.filter(string, function(v) { 24111 * return /[aeiou]/i.test(v); 24112 * }); 24113 * } 24114 * 24115 * _.mixin({ 'vowels': vowels }); 24116 * _.vowels('fred'); 24117 * // => ['e'] 24118 * 24119 * _('fred').vowels().value(); 24120 * // => ['e'] 24121 * 24122 * _.mixin({ 'vowels': vowels }, { 'chain': false }); 24123 * _('fred').vowels(); 24124 * // => ['e'] 24125 */ 24126 function mixin(object, source, options) { 24127 var props = keys(source), 24128 methodNames = baseFunctions(source, props); 24129 24130 if (options == null && 24131 !(isObject(source) && (methodNames.length || !props.length))) { 24132 options = source; 24133 source = object; 24134 object = this; 24135 methodNames = baseFunctions(source, keys(source)); 24136 } 24137 var chain = !(isObject(options) && 'chain' in options) || !!options.chain, 24138 isFunc = isFunction(object); 24139 24140 arrayEach(methodNames, function(methodName) { 24141 var func = source[methodName]; 24142 object[methodName] = func; 24143 if (isFunc) { 24144 object.prototype[methodName] = function() { 24145 var chainAll = this.__chain__; 24146 if (chain || chainAll) { 24147 var result = object(this.__wrapped__), 24148 actions = result.__actions__ = copyArray(this.__actions__); 24149 24150 actions.push({ 'func': func, 'args': arguments, 'thisArg': object }); 24151 result.__chain__ = chainAll; 24152 return result; 24153 } 24154 return func.apply(object, arrayPush([this.value()], arguments)); 24155 }; 24156 } 24157 }); 24158 24159 return object; 24160 } 24161 24162 /** 24163 * Reverts the `_` variable to its previous value and returns a reference to 24164 * the `lodash` function. 24165 * 24166 * @static 24167 * @since 0.1.0 24168 * @memberOf _ 24169 * @category Util 24170 * @returns {Function} Returns the `lodash` function. 24171 * @example 24172 * 24173 * var lodash = _.noConflict(); 24174 */ 24175 function noConflict() { 24176 if (root._ === this) { 24177 root._ = oldDash; 24178 } 24179 return this; 24180 } 24181 24182 /** 24183 * This method returns `undefined`. 24184 * 24185 * @static 24186 * @memberOf _ 24187 * @since 2.3.0 24188 * @category Util 24189 * @example 24190 * 24191 * _.times(2, _.noop); 24192 * // => [undefined, undefined] 24193 */ 24194 function noop() { 24195 // No operation performed. 24196 } 24197 24198 /** 24199 * Creates a function that gets the argument at index `n`. If `n` is negative, 24200 * the nth argument from the end is returned. 24201 * 24202 * @static 24203 * @memberOf _ 24204 * @since 4.0.0 24205 * @category Util 24206 * @param {number} [n=0] The index of the argument to return. 24207 * @returns {Function} Returns the new pass-thru function. 24208 * @example 24209 * 24210 * var func = _.nthArg(1); 24211 * func('a', 'b', 'c', 'd'); 24212 * // => 'b' 24213 * 24214 * var func = _.nthArg(-2); 24215 * func('a', 'b', 'c', 'd'); 24216 * // => 'c' 24217 */ 24218 function nthArg(n) { 24219 n = toInteger(n); 24220 return baseRest(function(args) { 24221 return baseNth(args, n); 24222 }); 24223 } 24224 24225 /** 24226 * Creates a function that invokes `iteratees` with the arguments it receives 24227 * and returns their results. 24228 * 24229 * @static 24230 * @memberOf _ 24231 * @since 4.0.0 24232 * @category Util 24233 * @param {...(Function|Function[])} [iteratees=[_.identity]] 24234 * The iteratees to invoke. 24235 * @returns {Function} Returns the new function. 24236 * @example 24237 * 24238 * var func = _.over([Math.max, Math.min]); 24239 * 24240 * func(1, 2, 3, 4); 24241 * // => [4, 1] 24242 */ 24243 var over = createOver(arrayMap); 24244 24245 /** 24246 * Creates a function that checks if **all** of the `predicates` return 24247 * truthy when invoked with the arguments it receives. 24248 * 24249 * Following shorthands are possible for providing predicates. 24250 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate. 24251 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them. 24252 * 24253 * @static 24254 * @memberOf _ 24255 * @since 4.0.0 24256 * @category Util 24257 * @param {...(Function|Function[])} [predicates=[_.identity]] 24258 * The predicates to check. 24259 * @returns {Function} Returns the new function. 24260 * @example 24261 * 24262 * var func = _.overEvery([Boolean, isFinite]); 24263 * 24264 * func('1'); 24265 * // => true 24266 * 24267 * func(null); 24268 * // => false 24269 * 24270 * func(NaN); 24271 * // => false 24272 */ 24273 var overEvery = createOver(arrayEvery); 24274 24275 /** 24276 * Creates a function that checks if **any** of the `predicates` return 24277 * truthy when invoked with the arguments it receives. 24278 * 24279 * Following shorthands are possible for providing predicates. 24280 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate. 24281 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them. 24282 * 24283 * @static 24284 * @memberOf _ 24285 * @since 4.0.0 24286 * @category Util 24287 * @param {...(Function|Function[])} [predicates=[_.identity]] 24288 * The predicates to check. 24289 * @returns {Function} Returns the new function. 24290 * @example 24291 * 24292 * var func = _.overSome([Boolean, isFinite]); 24293 * 24294 * func('1'); 24295 * // => true 24296 * 24297 * func(null); 24298 * // => true 24299 * 24300 * func(NaN); 24301 * // => false 24302 * 24303 * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }]) 24304 * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]]) 24305 */ 24306 var overSome = createOver(arraySome); 24307 24308 /** 24309 * Creates a function that returns the value at `path` of a given object. 24310 * 24311 * @static 24312 * @memberOf _ 24313 * @since 2.4.0 24314 * @category Util 24315 * @param {Array|string} path The path of the property to get. 24316 * @returns {Function} Returns the new accessor function. 24317 * @example 24318 * 24319 * var objects = [ 24320 * { 'a': { 'b': 2 } }, 24321 * { 'a': { 'b': 1 } } 24322 * ]; 24323 * 24324 * _.map(objects, _.property('a.b')); 24325 * // => [2, 1] 24326 * 24327 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b'); 24328 * // => [1, 2] 24329 */ 24330 function property(path) { 24331 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path); 24332 } 24333 24334 /** 24335 * The opposite of `_.property`; this method creates a function that returns 24336 * the value at a given path of `object`. 24337 * 24338 * @static 24339 * @memberOf _ 24340 * @since 3.0.0 24341 * @category Util 24342 * @param {Object} object The object to query. 24343 * @returns {Function} Returns the new accessor function. 24344 * @example 24345 * 24346 * var array = [0, 1, 2], 24347 * object = { 'a': array, 'b': array, 'c': array }; 24348 * 24349 * _.map(['a[2]', 'c[0]'], _.propertyOf(object)); 24350 * // => [2, 0] 24351 * 24352 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object)); 24353 * // => [2, 0] 24354 */ 24355 function propertyOf(object) { 24356 return function(path) { 24357 return object == null ? undefined$1 : baseGet(object, path); 24358 }; 24359 } 24360 24361 /** 24362 * Creates an array of numbers (positive and/or negative) progressing from 24363 * `start` up to, but not including, `end`. A step of `-1` is used if a negative 24364 * `start` is specified without an `end` or `step`. If `end` is not specified, 24365 * it's set to `start` with `start` then set to `0`. 24366 * 24367 * **Note:** JavaScript follows the IEEE-754 standard for resolving 24368 * floating-point values which can produce unexpected results. 24369 * 24370 * @static 24371 * @since 0.1.0 24372 * @memberOf _ 24373 * @category Util 24374 * @param {number} [start=0] The start of the range. 24375 * @param {number} end The end of the range. 24376 * @param {number} [step=1] The value to increment or decrement by. 24377 * @returns {Array} Returns the range of numbers. 24378 * @see _.inRange, _.rangeRight 24379 * @example 24380 * 24381 * _.range(4); 24382 * // => [0, 1, 2, 3] 24383 * 24384 * _.range(-4); 24385 * // => [0, -1, -2, -3] 24386 * 24387 * _.range(1, 5); 24388 * // => [1, 2, 3, 4] 24389 * 24390 * _.range(0, 20, 5); 24391 * // => [0, 5, 10, 15] 24392 * 24393 * _.range(0, -4, -1); 24394 * // => [0, -1, -2, -3] 24395 * 24396 * _.range(1, 4, 0); 24397 * // => [1, 1, 1] 24398 * 24399 * _.range(0); 24400 * // => [] 24401 */ 24402 var range = createRange(); 24403 24404 /** 24405 * This method is like `_.range` except that it populates values in 24406 * descending order. 24407 * 24408 * @static 24409 * @memberOf _ 24410 * @since 4.0.0 24411 * @category Util 24412 * @param {number} [start=0] The start of the range. 24413 * @param {number} end The end of the range. 24414 * @param {number} [step=1] The value to increment or decrement by. 24415 * @returns {Array} Returns the range of numbers. 24416 * @see _.inRange, _.range 24417 * @example 24418 * 24419 * _.rangeRight(4); 24420 * // => [3, 2, 1, 0] 24421 * 24422 * _.rangeRight(-4); 24423 * // => [-3, -2, -1, 0] 24424 * 24425 * _.rangeRight(1, 5); 24426 * // => [4, 3, 2, 1] 24427 * 24428 * _.rangeRight(0, 20, 5); 24429 * // => [15, 10, 5, 0] 24430 * 24431 * _.rangeRight(0, -4, -1); 24432 * // => [-3, -2, -1, 0] 24433 * 24434 * _.rangeRight(1, 4, 0); 24435 * // => [1, 1, 1] 24436 * 24437 * _.rangeRight(0); 24438 * // => [] 24439 */ 24440 var rangeRight = createRange(true); 24441 24442 /** 24443 * This method returns a new empty array. 24444 * 24445 * @static 24446 * @memberOf _ 24447 * @since 4.13.0 24448 * @category Util 24449 * @returns {Array} Returns the new empty array. 24450 * @example 24451 * 24452 * var arrays = _.times(2, _.stubArray); 24453 * 24454 * console.log(arrays); 24455 * // => [[], []] 24456 * 24457 * console.log(arrays[0] === arrays[1]); 24458 * // => false 24459 */ 24460 function stubArray() { 24461 return []; 24462 } 24463 24464 /** 24465 * This method returns `false`. 24466 * 24467 * @static 24468 * @memberOf _ 24469 * @since 4.13.0 24470 * @category Util 24471 * @returns {boolean} Returns `false`. 24472 * @example 24473 * 24474 * _.times(2, _.stubFalse); 24475 * // => [false, false] 24476 */ 24477 function stubFalse() { 24478 return false;
24479 } 24480 24481 /** 24482 * This method returns a new empty object. 24483 * 24484 * @static 24485 * @memberOf _ 24486 * @since 4.13.0 24487 * @category Util 24488 * @returns {Object} Returns the new empty object. 24489 * @example 24490 * 24491 * var objects = _.times(2, _.stubObject); 24492 * 24493 * console.log(objects); 24494 * // => [{}, {}] 24495 * 24496 * console.log(objects[0] === objects[1]); 24497 * // => false 24498 */ 24499 function stubObject() { 24500 return {}; 24501 } 24502 24503 /** 24504 * This method returns an empty string. 24505 * 24506 * @static 24507 * @memberOf _ 24508 * @since 4.13.0 24509 * @category Util 24510 * @returns {string} Returns the empty string. 24511 * @example 24512 * 24513 * _.times(2, _.stubString); 24514 * // => ['', ''] 24515 */ 24516 function stubString() { 24517 return ''; 24518 } 24519 24520 /** 24521 * This method returns `true`. 24522 * 24523 * @static 24524 * @memberOf _ 24525 * @since 4.13.0 24526 * @category Util 24527 * @returns {boolean} Returns `true`. 24528 * @example 24529 * 24530 * _.times(2, _.stubTrue); 24531 * // => [true, true] 24532 */
vendor: 4,171 bytes, lines 24533-24683
24533 function stubTrue() { 24534 return true; 24535 } 24536 24537 /** 24538 * Invokes the iteratee `n` times, returning an array of the results of 24539 * each invocation. The iteratee is invoked with one argument; (index). 24540 * 24541 * @static 24542 * @since 0.1.0 24543 * @memberOf _ 24544 * @category Util 24545 * @param {number} n The number of times to invoke `iteratee`. 24546 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 24547 * @returns {Array} Returns the array of results. 24548 * @example 24549 * 24550 * _.times(3, String); 24551 * // => ['0', '1', '2'] 24552 * 24553 * _.times(4, _.constant(0)); 24554 * // => [0, 0, 0, 0] 24555 */ 24556 function times(n, iteratee) { 24557 n = toInteger(n); 24558 if (n < 1 || n > MAX_SAFE_INTEGER) { 24559 return []; 24560 } 24561 var index = MAX_ARRAY_LENGTH, 24562 length = nativeMin(n, MAX_ARRAY_LENGTH); 24563 24564 iteratee = getIteratee(iteratee); 24565 n -= MAX_ARRAY_LENGTH; 24566 24567 var result = baseTimes(length, iteratee); 24568 while (++index < n) { 24569 iteratee(index); 24570 } 24571 return result; 24572 } 24573 24574 /** 24575 * Converts `value` to a property path array. 24576 * 24577 * @static 24578 * @memberOf _ 24579 * @since 4.0.0 24580 * @category Util 24581 * @param {*} value The value to convert. 24582 * @returns {Array} Returns the new property path array. 24583 * @example 24584 * 24585 * _.toPath('a.b.c'); 24586 * // => ['a', 'b', 'c'] 24587 * 24588 * _.toPath('a[0].b.c'); 24589 * // => ['a', '0', 'b', 'c'] 24590 */ 24591 function toPath(value) { 24592 if (isArray(value)) { 24593 return arrayMap(value, toKey); 24594 } 24595 return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value))); 24596 } 24597 24598 /** 24599 * Generates a unique ID. If `prefix` is given, the ID is appended to it. 24600 * 24601 * @static 24602 * @since 0.1.0 24603 * @memberOf _ 24604 * @category Util 24605 * @param {string} [prefix=''] The value to prefix the ID with. 24606 * @returns {string} Returns the unique ID. 24607 * @example 24608 * 24609 * _.uniqueId('contact_'); 24610 * // => 'contact_104' 24611 * 24612 * _.uniqueId(); 24613 * // => '105' 24614 */ 24615 function uniqueId(prefix) { 24616 var id = ++idCounter; 24617 return toString(prefix) + id; 24618 } 24619 24620 /*------------------------------------------------------------------------*/ 24621 24622 /** 24623 * Adds two numbers. 24624 * 24625 * @static 24626 * @memberOf _ 24627 * @since 3.4.0 24628 * @category Math 24629 * @param {number} augend The first number in an addition. 24630 * @param {number} addend The second number in an addition. 24631 * @returns {number} Returns the total. 24632 * @example 24633 * 24634 * _.add(6, 4); 24635 * // => 10 24636 */ 24637 var add = createMathOperation(function(augend, addend) { 24638 return augend + addend; 24639 }, 0); 24640 24641 /** 24642 * Computes `number` rounded up to `precision`. 24643 * 24644 * @static 24645 * @memberOf _ 24646 * @since 3.10.0 24647 * @category Math 24648 * @param {number} number The number to round up. 24649 * @param {number} [precision=0] The precision to round up to. 24650 * @returns {number} Returns the rounded up number. 24651 * @example 24652 * 24653 * _.ceil(4.006); 24654 * // => 5 24655 * 24656 * _.ceil(6.004, 2); 24657 * // => 6.01 24658 * 24659 * _.ceil(6040, -2); 24660 * // => 6100 24661 */ 24662 var ceil = createRound('ceil'); 24663 24664 /** 24665 * Divide two numbers. 24666 * 24667 * @static 24668 * @memberOf _ 24669 * @since 4.7.0 24670 * @category Math 24671 * @param {number} dividend The first number in a division. 24672 * @param {number} divisor The second number in a division. 24673 * @returns {number} Returns the quotient. 24674 * @example 24675 * 24676 * _.divide(6, 4); 24677 * // => 1.5 24678 */ 24679 var divide = createMathOperation(function(dividend, divisor) { 24680 return dividend / divisor; 24681 }, 1); 24682 24683 /**
24684 * Computes `number` rounded down to `precision`. 24685 * 24686 * @static 24687 * @memberOf _ 24688 * @since 3.10.0 24689 * @category Math 24690 * @param {number} number The number to round down. 24691 * @param {number} [precision=0] The precision to round down to. 24692 * @returns {number} Returns the rounded down number. 24693 * @example 24694 * 24695 * _.floor(4.006); 24696 * // => 4 24697 * 24698 * _.floor(0.046, 2); 24699 * // => 0.04 24700 * 24701 * _.floor(4060, -2); 24702 * // => 4000 24703 */ 24704 var floor = createRound('floor'); 24705 24706 /** 24707 * Computes the maximum value of `array`. If `array` is empty or falsey, 24708 * `undefined` is returned. 24709 * 24710 * @static 24711 * @since 0.1.0 24712 * @memberOf _ 24713 * @category Math 24714 * @param {Array} array The array to iterate over. 24715 * @returns {*} Returns the maximum value. 24716 * @example 24717 * 24718 * _.max([4, 2, 8, 6]); 24719 * // => 8 24720 * 24721 * _.max([]); 24722 * // => undefined 24723 */ 24724 function max(array) { 24725 return (array && array.length) 24726 ? baseExtremum(array, identity, baseGt) 24727 : undefined$1; 24728 } 24729 24730 /** 24731 * This method is like `_.max` except that it accepts `iteratee` which is 24732 * invoked for each element in `array` to generate the criterion by which 24733 * the value is ranked. The iteratee is invoked with one argument: (value). 24734 * 24735 * @static 24736 * @memberOf _ 24737 * @since 4.0.0 24738 * @category Math 24739 * @param {Array} array The array to iterate over. 24740 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 24741 * @returns {*} Returns the maximum value. 24742 * @example 24743 * 24744 * var objects = [{ 'n': 1 }, { 'n': 2 }]; 24745 * 24746 * _.maxBy(objects, function(o) { return o.n; }); 24747 * // => { 'n': 2 } 24748 * 24749 * // The `_.property` iteratee shorthand. 24750 * _.maxBy(objects, 'n'); 24751 * // => { 'n': 2 } 24752 */ 24753 function maxBy(array, iteratee) { 24754 return (array && array.length) 24755 ? baseExtremum(array, getIteratee(iteratee, 2), baseGt) 24756 : undefined$1; 24757 } 24758 24759 /** 24760 * Computes the mean of the values in `array`. 24761 * 24762 * @static 24763 * @memberOf _ 24764 * @since 4.0.0 24765 * @category Math 24766 * @param {Array} array The array to iterate over. 24767 * @returns {number} Returns the mean. 24768 * @example 24769 * 24770 * _.mean([4, 2, 8, 6]); 24771 * // => 5 24772 */ 24773 function mean(array) { 24774 return baseMean(array, identity); 24775 } 24776 24777 /** 24778 * This method is like `_.mean` except that it accepts `iteratee` which is 24779 * invoked for each element in `array` to generate the value to be averaged. 24780 * The iteratee is invoked with one argument: (value). 24781 * 24782 * @static 24783 * @memberOf _ 24784 * @since 4.7.0 24785 * @category Math 24786 * @param {Array} array The array to iterate over. 24787 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 24788 * @returns {number} Returns the mean. 24789 * @example 24790 * 24791 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]; 24792 * 24793 * _.meanBy(objects, function(o) { return o.n; }); 24794 * // => 5 24795 * 24796 * // The `_.property` iteratee shorthand. 24797 * _.meanBy(objects, 'n'); 24798 * // => 5 24799 */ 24800 function meanBy(array, iteratee) { 24801 return baseMean(array, getIteratee(iteratee, 2)); 24802 } 24803 24804 /** 24805 * Computes the minimum value of `array`. If `array` is empty or falsey, 24806 * `undefined` is returned. 24807 * 24808 * @static 24809 * @since 0.1.0 24810 * @memberOf _ 24811 * @category Math 24812 * @param {Array} array The array to iterate over. 24813 * @returns {*} Returns the minimum value. 24814 * @example 24815 * 24816 * _.min([4, 2, 8, 6]); 24817 * // => 2 24818 * 24819 * _.min([]); 24820 * // => undefined 24821 */ 24822 function min(array) { 24823 return (array && array.length) 24824 ? baseExtremum(array, identity, baseLt) 24825 : undefined$1; 24826 } 24827 24828 /** 24829 * This method is like `_.min` except that it accepts `iteratee` which is 24830 * invoked for each element in `array` to generate the criterion by which 24831 * the value is ranked. The iteratee is invoked with one argument: (value). 24832 * 24833 * @static 24834 * @memberOf _ 24835 * @since 4.0.0 24836 * @category Math 24837 * @param {Array} array The array to iterate over. 24838 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 24839 * @returns {*} Returns the minimum value. 24840 * @example 24841 * 24842 * var objects = [{ 'n': 1 }, { 'n': 2 }]; 24843 * 24844 * _.minBy(objects, function(o) { return o.n; }); 24845 * // => { 'n': 1 } 24846 * 24847 * // The `_.property` iteratee shorthand. 24848 * _.minBy(objects, 'n'); 24849 * // => { 'n': 1 } 24850 */ 24851 function minBy(array, iteratee) { 24852 return (array && array.length) 24853 ? baseExtremum(array, getIteratee(iteratee, 2), baseLt) 24854 : undefined$1; 24855 } 24856 24857 /** 24858 * Multiply two numbers. 24859 * 24860 * @static 24861 * @memberOf _ 24862 * @since 4.7.0 24863 * @category Math 24864 * @param {number} multiplier The first number in a multiplication. 24865 * @param {number} multiplicand The second number in a multiplication. 24866 * @returns {number} Returns the product. 24867 * @example 24868 * 24869 * _.multiply(6, 4); 24870 * // => 24 24871 */ 24872 var multiply = createMathOperation(function(multiplier, multiplicand) { 24873 return multiplier * multiplicand; 24874 }, 1); 24875 24876 /**
24877 * Computes `number` rounded to `precision`. 24878 * 24879 * @static 24880 * @memberOf _ 24881 * @since 3.10.0 24882 * @category Math 24883 * @param {number} number The number to round. 24884 * @param {number} [precision=0] The precision to round to. 24885 * @returns {number} Returns the rounded number. 24886 * @example 24887 * 24888 * _.round(4.006); 24889 * // => 4 24890 * 24891 * _.round(4.006, 2); 24892 * // => 4.01 24893 * 24894 * _.round(4060, -2); 24895 * // => 4100 24896 */ 24897 var round = createRound('round'); 24898 24899 /** 24900 * Subtract two numbers. 24901 * 24902 * @static 24903 * @memberOf _ 24904 * @since 4.0.0 24905 * @category Math 24906 * @param {number} minuend The first number in a subtraction. 24907 * @param {number} subtrahend The second number in a subtraction. 24908 * @returns {number} Returns the difference. 24909 * @example 24910 * 24911 * _.subtract(6, 4); 24912 * // => 2 24913 */ 24914 var subtract = createMathOperation(function(minuend, subtrahend) { 24915 return minuend - subtrahend; 24916 }, 0); 24917 24918 /** 24919 * Computes the sum of the values in `array`. 24920 * 24921 * @static 24922 * @memberOf _ 24923 * @since 3.4.0 24924 * @category Math 24925 * @param {Array} array The array to iterate over. 24926 * @returns {number} Returns the sum. 24927 * @example 24928 * 24929 * _.sum([4, 2, 8, 6]); 24930 * // => 20 24931 */ 24932 function sum(array) { 24933 return (array && array.length) 24934 ? baseSum(array, identity) 24935 : 0; 24936 } 24937 24938 /** 24939 * This method is like `_.sum` except that it accepts `iteratee` which is 24940 * invoked for each element in `array` to generate the value to be summed. 24941 * The iteratee is invoked with one argument: (value). 24942 * 24943 * @static 24944 * @memberOf _ 24945 * @since 4.0.0 24946 * @category Math 24947 * @param {Array} array The array to iterate over. 24948 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 24949 * @returns {number} Returns the sum. 24950 * @example 24951 * 24952 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]; 24953 * 24954 * _.sumBy(objects, function(o) { return o.n; }); 24955 * // => 20 24956 * 24957 * // The `_.property` iteratee shorthand. 24958 * _.sumBy(objects, 'n'); 24959 * // => 20 24960 */ 24961 function sumBy(array, iteratee) { 24962 return (array && array.length) 24963 ? baseSum(array, getIteratee(iteratee, 2)) 24964 : 0; 24965 } 24966 24967 /*------------------------------------------------------------------------*/ 24968 24969 // Add methods that return wrapped values in chain sequences. 24970 lodash.after = after; 24971 lodash.ary = ary; 24972 lodash.assign = assign; 24973 lodash.assignIn = assignIn; 24974 lodash.assignInWith = assignInWith; 24975 lodash.assignWith = assignWith; 24976 lodash.at = at; 24977 lodash.before = before; 24978 lodash.bind = bind; 24979 lodash.bindAll = bindAll; 24980 lodash.bindKey = bindKey; 24981 lodash.castArray = castArray; 24982 lodash.chain = chain; 24983 lodash.chunk = chunk; 24984 lodash.compact = compact; 24985 lodash.concat = concat; 24986 lodash.cond = cond; 24987 lodash.conforms = conforms; 24988 lodash.constant = constant; 24989 lodash.countBy = countBy; 24990 lodash.create = create; 24991 lodash.curry = curry; 24992 lodash.curryRight = curryRight; 24993 lodash.debounce = debounce; 24994 lodash.defaults = defaults; 24995 lodash.defaultsDeep = defaultsDeep; 24996 lodash.defer = defer; 24997 lodash.delay = delay; 24998 lodash.difference = difference; 24999 lodash.differenceBy = differenceBy; 25000 lodash.differenceWith = differenceWith; 25001 lodash.drop = drop; 25002 lodash.dropRight = dropRight; 25003 lodash.dropRightWhile = dropRightWhile; 25004 lodash.dropWhile = dropWhile; 25005 lodash.fill = fill; 25006 lodash.filter = filter; 25007 lodash.flatMap = flatMap; 25008 lodash.flatMapDeep = flatMapDeep; 25009 lodash.flatMapDepth = flatMapDepth; 25010 lodash.flatten = flatten;
25011 lodash.flattenDeep = flattenDeep; 25012 lodash.flattenDepth = flattenDepth; 25013 lodash.flip = flip; 25014 lodash.flow = flow; 25015 lodash.flowRight = flowRight; 25016 lodash.fromPairs = fromPairs; 25017 lodash.functions = functions; 25018 lodash.functionsIn = functionsIn; 25019 lodash.groupBy = groupBy; 25020 lodash.initial = initial; 25021 lodash.intersection = intersection; 25022 lodash.intersectionBy = intersectionBy; 25023 lodash.intersectionWith = intersectionWith; 25024 lodash.invert = invert; 25025 lodash.invertBy = invertBy; 25026 lodash.invokeMap = invokeMap; 25027 lodash.iteratee = iteratee; 25028 lodash.keyBy = keyBy; 25029 lodash.keys = keys; 25030 lodash.keysIn = keysIn; 25031 lodash.map = map; 25032 lodash.mapKeys = mapKeys; 25033 lodash.mapValues = mapValues; 25034 lodash.matches = matches; 25035 lodash.matchesProperty = matchesProperty; 25036 lodash.memoize = memoize; 25037 lodash.merge = merge; 25038 lodash.mergeWith = mergeWith; 25039 lodash.method = method; 25040 lodash.methodOf = methodOf; 25041 lodash.mixin = mixin; 25042 lodash.negate = negate; 25043 lodash.nthArg = nthArg; 25044 lodash.omit = omit; 25045 lodash.omitBy = omitBy; 25046 lodash.once = once; 25047 lodash.orderBy = orderBy; 25048 lodash.over = over; 25049 lodash.overArgs = overArgs; 25050 lodash.overEvery = overEvery; 25051 lodash.overSome = overSome; 25052 lodash.partial = partial; 25053 lodash.partialRight = partialRight; 25054 lodash.partition = partition; 25055 lodash.pick = pick; 25056 lodash.pickBy = pickBy; 25057 lodash.property = property; 25058 lodash.propertyOf = propertyOf; 25059 lodash.pull = pull; 25060 lodash.pullAll = pullAll; 25061 lodash.pullAllBy = pullAllBy; 25062 lodash.pullAllWith = pullAllWith; 25063 lodash.pullAt = pullAt; 25064 lodash.range = range; 25065 lodash.rangeRight = rangeRight; 25066 lodash.rearg = rearg; 25067 lodash.reject = reject; 25068 lodash.remove = remove; 25069 lodash.rest = rest; 25070 lodash.reverse = reverse; 25071 lodash.sampleSize = sampleSize; 25072 lodash.set = set; 25073 lodash.setWith = setWith; 25074 lodash.shuffle = shuffle; 25075 lodash.slice = slice; 25076 lodash.sortBy = sortBy; 25077 lodash.sortedUniq = sortedUniq; 25078 lodash.sortedUniqBy = sortedUniqBy; 25079 lodash.split = split; 25080 lodash.spread = spread; 25081 lodash.tail = tail; 25082 lodash.take = take; 25083 lodash.takeRight = takeRight; 25084 lodash.takeRightWhile = takeRightWhile; 25085 lodash.takeWhile = takeWhile; 25086 lodash.tap = tap; 25087 lodash.throttle = throttle; 25088 lodash.thru = thru; 25089 lodash.toArray = toArray; 25090 lodash.toPairs = toPairs; 25091 lodash.toPairsIn = toPairsIn; 25092 lodash.toPath = toPath; 25093 lodash.toPlainObject = toPlainObject; 25094 lodash.transform = transform; 25095 lodash.unary = unary; 25096 lodash.union = union; 25097 lodash.unionBy = unionBy; 25098 lodash.unionWith = unionWith; 25099 lodash.uniq = uniq; 25100 lodash.uniqBy = uniqBy; 25101 lodash.uniqWith = uniqWith; 25102 lodash.unset = unset; 25103 lodash.unzip = unzip; 25104 lodash.unzipWith = unzipWith; 25105 lodash.update = update; 25106 lodash.updateWith = updateWith; 25107 lodash.values = values; 25108 lodash.valuesIn = valuesIn; 25109 lodash.without = without; 25110 lodash.words = words; 25111 lodash.wrap = wrap; 25112 lodash.xor = xor; 25113 lodash.xorBy = xorBy; 25114 lodash.xorWith = xorWith; 25115 lodash.zip = zip; 25116 lodash.zipObject = zipObject; 25117 lodash.zipObjectDeep = zipObjectDeep; 25118 lodash.zipWith = zipWith; 25119 25120 // Add aliases. 25121 lodash.entries = toPairs; 25122 lodash.entriesIn = toPairsIn; 25123 lodash.extend = assignIn; 25124 lodash.extendWith = assignInWith; 25125 25126 // Add methods to `lodash.prototype`. 25127 mixin(lodash, lodash); 25128 25129 /*------------------------------------------------------------------------*/ 25130 25131 // Add methods that return unwrapped values in chain sequences. 25132 lodash.add = add; 25133 lodash.attempt = attempt; 25134 lodash.camelCase = camelCase; 25135 lodash.capitalize = capitalize; 25136 lodash.ceil = ceil; 25137 lodash.clamp = clamp; 25138 lodash.clone = clone; 25139 lodash.cloneDeep = cloneDeep; 25140 lodash.cloneDeepWith = cloneDeepWith; 25141 lodash.cloneWith = cloneWith; 25142 lodash.conformsTo = conformsTo; 25143 lodash.deburr = deburr; 25144 lodash.defaultTo = defaultTo; 25145 lodash.divide = divide; 25146 lodash.endsWith = endsWith; 25147 lodash.eq = eq; 25148 lodash.escape = escape; 25149 lodash.escapeRegExp = escapeRegExp; 25150 lodash.every = every; 25151 lodash.find = find; 25152 lodash.findIndex = findIndex; 25153 lodash.findKey = findKey; 25154 lodash.findLast = findLast; 25155 lodash.findLastIndex = findLastIndex; 25156 lodash.findLastKey = findLastKey; 25157 lodash.floor = floor;
vendor: 5,355 bytes, lines 25158-25315
25158 lodash.forEach = forEach; 25159 lodash.forEachRight = forEachRight; 25160 lodash.forIn = forIn; 25161 lodash.forInRight = forInRight; 25162 lodash.forOwn = forOwn; 25163 lodash.forOwnRight = forOwnRight; 25164 lodash.get = get; 25165 lodash.gt = gt; 25166 lodash.gte = gte; 25167 lodash.has = has; 25168 lodash.hasIn = hasIn; 25169 lodash.head = head; 25170 lodash.identity = identity; 25171 lodash.includes = includes; 25172 lodash.indexOf = indexOf; 25173 lodash.inRange = inRange; 25174 lodash.invoke = invoke; 25175 lodash.isArguments = isArguments; 25176 lodash.isArray = isArray; 25177 lodash.isArrayBuffer = isArrayBuffer; 25178 lodash.isArrayLike = isArrayLike; 25179 lodash.isArrayLikeObject = isArrayLikeObject; 25180 lodash.isBoolean = isBoolean; 25181 lodash.isBuffer = isBuffer; 25182 lodash.isDate = isDate; 25183 lodash.isElement = isElement; 25184 lodash.isEmpty = isEmpty; 25185 lodash.isEqual = isEqual; 25186 lodash.isEqualWith = isEqualWith; 25187 lodash.isError = isError; 25188 lodash.isFinite = isFinite; 25189 lodash.isFunction = isFunction; 25190 lodash.isInteger = isInteger; 25191 lodash.isLength = isLength; 25192 lodash.isMap = isMap; 25193 lodash.isMatch = isMatch; 25194 lodash.isMatchWith = isMatchWith; 25195 lodash.isNaN = isNaN; 25196 lodash.isNative = isNative; 25197 lodash.isNil = isNil; 25198 lodash.isNull = isNull; 25199 lodash.isNumber = isNumber; 25200 lodash.isObject = isObject; 25201 lodash.isObjectLike = isObjectLike; 25202 lodash.isPlainObject = isPlainObject; 25203 lodash.isRegExp = isRegExp; 25204 lodash.isSafeInteger = isSafeInteger; 25205 lodash.isSet = isSet; 25206 lodash.isString = isString; 25207 lodash.isSymbol = isSymbol; 25208 lodash.isTypedArray = isTypedArray; 25209 lodash.isUndefined = isUndefined; 25210 lodash.isWeakMap = isWeakMap; 25211 lodash.isWeakSet = isWeakSet; 25212 lodash.join = join; 25213 lodash.kebabCase = kebabCase; 25214 lodash.last = last; 25215 lodash.lastIndexOf = lastIndexOf; 25216 lodash.lowerCase = lowerCase; 25217 lodash.lowerFirst = lowerFirst; 25218 lodash.lt = lt; 25219 lodash.lte = lte; 25220 lodash.max = max; 25221 lodash.maxBy = maxBy; 25222 lodash.mean = mean; 25223 lodash.meanBy = meanBy; 25224 lodash.min = min; 25225 lodash.minBy = minBy; 25226 lodash.stubArray = stubArray; 25227 lodash.stubFalse = stubFalse; 25228 lodash.stubObject = stubObject; 25229 lodash.stubString = stubString; 25230 lodash.stubTrue = stubTrue; 25231 lodash.multiply = multiply; 25232 lodash.nth = nth; 25233 lodash.noConflict = noConflict; 25234 lodash.noop = noop; 25235 lodash.now = now; 25236 lodash.pad = pad; 25237 lodash.padEnd = padEnd; 25238 lodash.padStart = padStart; 25239 lodash.parseInt = parseInt; 25240 lodash.random = random; 25241 lodash.reduce = reduce; 25242 lodash.reduceRight = reduceRight; 25243 lodash.repeat = repeat; 25244 lodash.replace = replace; 25245 lodash.result = result; 25246 lodash.round = round; 25247 lodash.runInContext = runInContext; 25248 lodash.sample = sample; 25249 lodash.size = size; 25250 lodash.snakeCase = snakeCase; 25251 lodash.some = some; 25252 lodash.sortedIndex = sortedIndex; 25253 lodash.sortedIndexBy = sortedIndexBy; 25254 lodash.sortedIndexOf = sortedIndexOf; 25255 lodash.sortedLastIndex = sortedLastIndex; 25256 lodash.sortedLastIndexBy = sortedLastIndexBy; 25257 lodash.sortedLastIndexOf = sortedLastIndexOf; 25258 lodash.startCase = startCase; 25259 lodash.startsWith = startsWith; 25260 lodash.subtract = subtract; 25261 lodash.sum = sum; 25262 lodash.sumBy = sumBy; 25263 lodash.template = template; 25264 lodash.times = times; 25265 lodash.toFinite = toFinite; 25266 lodash.toInteger = toInteger; 25267 lodash.toLength = toLength; 25268 lodash.toLower = toLower; 25269 lodash.toNumber = toNumber; 25270 lodash.toSafeInteger = toSafeInteger; 25271 lodash.toString = toString; 25272 lodash.toUpper = toUpper; 25273 lodash.trim = trim; 25274 lodash.trimEnd = trimEnd; 25275 lodash.trimStart = trimStart; 25276 lodash.truncate = truncate; 25277 lodash.unescape = unescape; 25278 lodash.uniqueId = uniqueId; 25279 lodash.upperCase = upperCase; 25280 lodash.upperFirst = upperFirst; 25281 25282 // Add aliases. 25283 lodash.each = forEach; 25284 lodash.eachRight = forEachRight; 25285 lodash.first = head; 25286 25287 mixin(lodash, (function() { 25288 var source = {}; 25289 baseForOwn(lodash, function(func, methodName) { 25290 if (!hasOwnProperty.call(lodash.prototype, methodName)) { 25291 source[methodName] = func; 25292 } 25293 }); 25294 return source; 25295 }()), { 'chain': false }); 25296 25297 /*------------------------------------------------------------------------*/ 25298 25299 /** 25300 * The semantic version number. 25301 * 25302 * @static 25303 * @memberOf _ 25304 * @type {string} 25305 */ 25306 lodash.VERSION = VERSION; 25307 25308 // Assign default placeholders. 25309 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) { 25310 lodash[methodName].placeholder = lodash; 25311 }); 25312 25313 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants. 25314 arrayEach(['drop', 'take'], function(methodName, index) { 25315 LazyWrapper.prototype[methodName] = function(n) {
vendor: 4,790 bytes, lines 25316-25448
25316 n = n === undefined$1 ? 1 : nativeMax(toInteger(n), 0); 25317 25318 var result = (this.__filtered__ && !index) 25319 ? new LazyWrapper(this) 25320 : this.clone(); 25321 25322 if (result.__filtered__) { 25323 result.__takeCount__ = nativeMin(n, result.__takeCount__); 25324 } else { 25325 result.__views__.push({ 25326 'size': nativeMin(n, MAX_ARRAY_LENGTH), 25327 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') 25328 }); 25329 } 25330 return result; 25331 }; 25332 25333 LazyWrapper.prototype[methodName + 'Right'] = function(n) { 25334 return this.reverse()[methodName](n).reverse(); 25335 }; 25336 }); 25337 25338 // Add `LazyWrapper` methods that accept an `iteratee` value. 25339 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) { 25340 var type = index + 1, 25341 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG; 25342 25343 LazyWrapper.prototype[methodName] = function(iteratee) { 25344 var result = this.clone(); 25345 result.__iteratees__.push({ 25346 'iteratee': getIteratee(iteratee, 3), 25347 'type': type 25348 }); 25349 result.__filtered__ = result.__filtered__ || isFilter; 25350 return result; 25351 }; 25352 }); 25353 25354 // Add `LazyWrapper` methods for `_.head` and `_.last`. 25355 arrayEach(['head', 'last'], function(methodName, index) { 25356 var takeName = 'take' + (index ? 'Right' : ''); 25357 25358 LazyWrapper.prototype[methodName] = function() { 25359 return this[takeName](1).value()[0]; 25360 }; 25361 }); 25362 25363 // Add `LazyWrapper` methods for `_.initial` and `_.tail`. 25364 arrayEach(['initial', 'tail'], function(methodName, index) { 25365 var dropName = 'drop' + (index ? '' : 'Right'); 25366 25367 LazyWrapper.prototype[methodName] = function() { 25368 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1); 25369 }; 25370 }); 25371 25372 LazyWrapper.prototype.compact = function() { 25373 return this.filter(identity); 25374 }; 25375 25376 LazyWrapper.prototype.find = function(predicate) { 25377 return this.filter(predicate).head(); 25378 }; 25379 25380 LazyWrapper.prototype.findLast = function(predicate) { 25381 return this.reverse().find(predicate); 25382 }; 25383 25384 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) { 25385 if (typeof path == 'function') { 25386 return new LazyWrapper(this); 25387 } 25388 return this.map(function(value) { 25389 return baseInvoke(value, path, args); 25390 }); 25391 }); 25392 25393 LazyWrapper.prototype.reject = function(predicate) { 25394 return this.filter(negate(getIteratee(predicate))); 25395 }; 25396 25397 LazyWrapper.prototype.slice = function(start, end) { 25398 start = toInteger(start); 25399 25400 var result = this; 25401 if (result.__filtered__ && (start > 0 || end < 0)) { 25402 return new LazyWrapper(result); 25403 } 25404 if (start < 0) { 25405 result = result.takeRight(-start); 25406 } else if (start) { 25407 result = result.drop(start); 25408 } 25409 if (end !== undefined$1) { 25410 end = toInteger(end); 25411 result = end < 0 ? result.dropRight(-end) : result.take(end - start); 25412 } 25413 return result; 25414 }; 25415 25416 LazyWrapper.prototype.takeRightWhile = function(predicate) { 25417 return this.reverse().takeWhile(predicate).reverse(); 25418 }; 25419 25420 LazyWrapper.prototype.toArray = function() { 25421 return this.take(MAX_ARRAY_LENGTH); 25422 }; 25423 25424 // Add `LazyWrapper` methods to `lodash.prototype`. 25425 baseForOwn(LazyWrapper.prototype, function(func, methodName) { 25426 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName), 25427 isTaker = /^(?:head|last)$/.test(methodName), 25428 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName], 25429 retUnwrapped = isTaker || /^find/.test(methodName); 25430 25431 if (!lodashFunc) { 25432 return; 25433 } 25434 lodash.prototype[methodName] = function() { 25435 var value = this.__wrapped__, 25436 args = isTaker ? [1] : arguments, 25437 isLazy = value instanceof LazyWrapper, 25438 iteratee = args[0], 25439 useLazy = isLazy || isArray(value); 25440 25441 var interceptor = function(value) { 25442 var result = lodashFunc.apply(lodash, arrayPush([value], args)); 25443 return (isTaker && chainAll) ? result[0] : result; 25444 }; 25445 25446 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) { 25447 // Avoid lazy use if the iteratee has a "length" value other than `1`. 25448 isLazy = useLazy = false;
25449 } 25450 var chainAll = this.__chain__, 25451 isHybrid = !!this.__actions__.length, 25452 isUnwrapped = retUnwrapped && !chainAll, 25453 onlyLazy = isLazy && !isHybrid; 25454 25455 if (!retUnwrapped && useLazy) { 25456 value = onlyLazy ? value : new LazyWrapper(this); 25457 var result = func.apply(value, args); 25458 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined$1 }); 25459 return new LodashWrapper(result, chainAll); 25460 } 25461 if (isUnwrapped && onlyLazy) { 25462 return func.apply(this, args); 25463 } 25464 result = this.thru(interceptor); 25465 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result; 25466 }; 25467 }); 25468 25469 // Add `Array` methods to `lodash.prototype`. 25470 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { 25471 var func = arrayProto[methodName], 25472 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', 25473 retUnwrapped = /^(?:pop|shift)$/.test(methodName); 25474 25475 lodash.prototype[methodName] = function() { 25476 var args = arguments; 25477 if (retUnwrapped && !this.__chain__) { 25478 var value = this.value(); 25479 return func.apply(isArray(value) ? value : [], args); 25480 } 25481 return this[chainName](function(value) { 25482 return func.apply(isArray(value) ? value : [], args); 25483 }); 25484 }; 25485 }); 25486 25487 // Map minified method names to their real names. 25488 baseForOwn(LazyWrapper.prototype, function(func, methodName) { 25489 var lodashFunc = lodash[methodName]; 25490 if (lodashFunc) { 25491 var key = lodashFunc.name + ''; 25492 if (!hasOwnProperty.call(realNames, key)) { 25493 realNames[key] = []; 25494 } 25495 realNames[key].push({ 'name': methodName, 'func': lodashFunc }); 25496 } 25497 }); 25498 25499 realNames[createHybrid(undefined$1, WRAP_BIND_KEY_FLAG).name] = [{ 25500 'name': 'wrapper', 25501 'func': undefined$1 25502 }]; 25503 25504 // Add methods to `LazyWrapper`. 25505 LazyWrapper.prototype.clone = lazyClone; 25506 LazyWrapper.prototype.reverse = lazyReverse; 25507 LazyWrapper.prototype.value = lazyValue; 25508 25509 // Add chain sequence methods to the `lodash` wrapper. 25510 lodash.prototype.at = wrapperAt; 25511 lodash.prototype.chain = wrapperChain; 25512 lodash.prototype.commit = wrapperCommit; 25513 lodash.prototype.next = wrapperNext; 25514 lodash.prototype.plant = wrapperPlant; 25515 lodash.prototype.reverse = wrapperReverse; 25516 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; 25517 25518 // Add lazy aliases. 25519 lodash.prototype.first = lodash.prototype.head; 25520 25521 if (symIterator) { 25522 lodash.prototype[symIterator] = wrapperToIterator; 25523 } 25524 return lodash; 25525 }); 25526 25527 /*--------------------------------------------------------------------------*/ 25528 25529 // Export lodash. 25530 var _ = runInContext(); 25531 25532 // Some AMD build optimizers, like r.js, check for condition patterns like: 25533 if (freeModule) { 25534 // Export for Node.js. 25535 (freeModule.exports = _)._ = _; 25536 // Export for CommonJS support. 25537 freeExports._ = _; 25538 } 25539 else { 25540 // Export to the global object. 25541 root._ = _; 25542 } 25543 }.call(lodash)); 25544 } (lodash$1, lodash$1.exports)); 25545 return lodash$1.exports; 25546 } 25547 25548 var lodashExports = requireLodash(); 25549 25550 let isEn = document.documentElement.lang === "en", 25551 defaultConf = { 25552 form : { 25553 input: { 25554 placeholder: isEn 25555 ? "Search into Québec.ca" 25556 : "Rechercher dans Québec.ca" 25557 25558 }, 25559 submit: { 25560 srText: isEn 25561 ? "Search" 25562 : "Lancer la recherche" 25563 } 25564 }, 25565 foldingPannel : { 25566 ariaLabel : isEn 25567 ? "Suggestion's list" 25568 : "Liste de suggestions" 25569 }, 25570 topics: { 25571 title: isEn 25572 ? "Related to this page" 25573 : "Lié à cette page", 25574 into: isEn 25575 ? "Into" 25576 : "Dans" 25577 }, 25578 suggest: { 25579 endpoint: '', 25580 maxResults: 5, 25581 queryStringTemplate: `?type=7384&tx_solr[queryString]=%search%`, 25582 topicFacetName: "themes", 25583 topicFilterTemplate: `&tx_solr[filter][]=%topic-facet-name%:%topic-id%`, 25584 debounceWait : 300, 25585 title : isEn 25586 ? "Suggested searches" 25587 : "Recherches suggérées", 25588 text: { 25589 noSearch: isEn 25590 ? "Type something for suggestions" 25591 : "Entrez du texte pour avoir des suggestions", 25592 noSuggestion: isEn 25593 ? "No suggestion found" 25594 : "Aucune suggestion trouvée", 25595 error: isEn 25596 ? "Sorry, suggestions are not currently available" 25597 : "Nous sommes désolés, les suggestions ne sont pas disponibles actuellement", 25598 srSuggestionsFound: isEn 25599 ? "%total% results are available, use up and down arrow keys to navigate." 25600 : "%total% résultats disponibles, utilisez les flèches directionnelles haut et bas pour vous déplacer dans la liste.", 25601 searching: isEn 25602 ? "Searching for suggestionsâ¦" 25603 : "Recherche de suggestionsâ¦" 25604 } 25605 }, 25606 css: { 25607 banner: '/assets/pgu_solr/Css/bannerAutosuggest.css', 25608 sdg: '/assets/pgu_core/Css/trousse-sdg/sdg.css' 25609 } 25610 }; 25611 25612 var on_keydown = (e, handleKeyDown) => handleKeyDown(e, -1); 25613 var root_2 = from_html(`<li role="listitem"><a><qc-icon></qc-icon> <div><div class="topic-search-part"> </div> <div class="topic-into-part"> </div></div></a></li>`, 2); 25614 var root_1 = from_html(`<div class="topics"><ul role="list"></ul></div>`); 25615 var root_6 = from_html(`<li role="listitem"><a><qc-icon></qc-icon><!></a></li>`, 2); 25616 var root_5 = from_html(`<span aria-live="assertive" class="qc-sr-only"> </span> <ul role="list"></ul>`, 1); 25617 var root_7 = from_html(`<p aria-live="assertive"> </p>`); 25618 var root_8 = from_html(`<p aria-live="assertive"> </p>`); 25619 var root_9 = from_html(`<p aria-live="assertive"> </p>`); 25620 var root_10 = from_html(`<p class="no-suggestions"> </p>`); 25621 var root = from_html(`<div class="qc-solr-suggest-component"><form><!></form> <div id="folding-root"><div id="folding-pannel"><!> <div class="suggestions"><p class="title"> </p> <!></div></div></div></div> <link rel="stylesheet"/> <link rel="stylesheet"/>`, 1); 25622 25623 function BannerAutosuggest($$anchor, $$props) { 25624 push($$props, true); 25625 25626 let conf = prop($$props, 'conf', 31, () => proxy({})), 25627 topicsConf = prop($$props, 'topicsConf', 31, () => proxy({})), 25628 devMode = prop($$props, 'devMode', 7, false); 25629 25630 let search = state(''), 25631 debounceSearch = state(() => {}), 25632 suggestions = state(proxy([])), 25633 collapsed = state(true), 25634 randomId = Math.floor(1000 * Math.random()), 25635 suggestionsUrl = '', 25636 suggestionPromise = state(proxy(Promise.resolve())), 25637 searchInput = state(void 0), 25638 form = state(void 0), 25639 options = state(void 0), 25640 rootElement = state(void 0), 25641 topics = state(proxy([])); 25642 25643 onMount(() => { 25644 set(searchInput, get(form).querySelector("input[type=search]"), true); 25645 25646 let id = -1; 25647 25648 set(options, { [id]: get(searchInput) }, true); 25649 }); 25650 25651 function getSuggestions(search) { 25652 if (!search) { 25653 suggestionsUrl = ''; 25654 25655 return; 25656 } 25657 25658 suggestionsUrl = conf().suggest.endpoint + conf().suggest.queryStringTemplate.replace("%search%", search); 25659 25660 set( 25661 suggestionPromise, 25662 fetch(suggestionsUrl).then((response) => response.json()).then((rawSolrResponse) => { 25663 set(suggestions, Object.keys(rawSolrResponse.suggestions ?? {}).slice(0, conf().suggest.maxResults ?? 5), true); 25664 25665 return get(suggestions); 25666 }), 25667 true 25668 ); 25669 } 25670 25671 function markInnerEvent(e) { 25672 e.innerEventFromFilter = randomId; 25673 } 25674 25675 function checkOutterEvent(e) { 25676 if ((e.innerEventFromFilter ?? -1) != randomId) { 25677 set(collapsed, true); 25678 } 25679 } 25680 25681 function getSuggestion(suggestion, search) { 25682 return suggestion.replace(search, `<span class="search">${search}</span>`); 25683 } 25684 25685 // en cas de perte de focus, on ferme le panneau de suggestion 25686 function hideSuggestPanelOnLostFocus(target) { 25687 let shadowRoot = target.getRootNode(); 25688 25689 requestAnimationFrame(() => { 25690 // wait for the DOM to update 25691 let activeElement = shadowRoot.activeElement, 25692 panelHasFocus = activeElement && get(rootElement).contains(activeElement); 25693 25694 // en cas de perte du focus dans le panneau de suggestion 25695 // on le ferme 25696 if (!panelHasFocus) { 25697 set(collapsed, true); 25698 } 25699 }); 25700 } 25701 25702 // gestion du choix des suggestion par touche directionnelle bas et haut 25703 function handleKeyDown(e, id) { 25704 hideSuggestPanelOnLostFocus(e.target); 25705 25706 if (!get(search)) { 25707 return; 25708 } 25709 25710 let offset = ({ "ArrowDown": 1, "ArrowUp": -1 })[e.code] ?? false; 25711 25712 if (!offset) { 25713 return; 25714 } 25715 25716 e.preventDefault(); 25717 e.stopPropagation(); 25718 25719 if (id === -1) { 25720 // keydown dans le champ recherche 25721 set(collapsed, offset === -1 // ouverture du panneau si fermé 25722 ); 25723 } 25724 25725 // si collapsed est mis à jour, il faut attendre le prochain tick 25726 // pour pouvoir focuser une option 25727 tick().then(() => { 25728 get(options)[id + offset]?.focus(); 25729 }); 25730 } 25731 25732 function getTopicFilter(topicEntry) { 25733 if (topicEntry[0] === 0) { 25734 // Québec.ca, pas de filtre 25735 return ""; 25736 } 25737 25738 // pour le datalayer, @see #9692 25739 return conf().suggest.topicFilterTemplate.replace("%topic-facet-name%", conf().suggest.topicFacetName).replace("%topic-label%", topicEntry[1]).replace("%topic-id%", topicEntry[0]) + "&rc=1"; 25740 } 25741 25742 run(() => { 25743 conf(lodashExports.merge({}, defaultConf, conf())); 25744 25745 let topicEntries = Object.entries(topicsConf()); 25746 25747 set(topics, topicEntries.length > 0 ? [[0, "Québec.ca"], ...topicEntries] : [], true); 25748 console.log("topics", get(topics), topicEntries); 25749 }); 25750 25751 set(debounceSearch, lodashExports.debounce(getSuggestions, conf().suggest.debounceWait), true); 25752 25753 run(() => { 25754 get(debounceSearch)(get(search)); 25755 }); 25756 25757 user_effect(() => { 25758 set(collapsed, !get(search)); 25759 25760 // console.log("collapsed ?", !search, collapsed) 25761 }); 25762 25763 var $$exports = { 25764 get conf() { 25765 return conf(); 25766 }, 25767 25768 set conf($$value = {}) { 25769 conf($$value); 25770 flushSync(); 25771 }, 25772 25773 get topicsConf() { 25774 return topicsConf(); 25775 }, 25776 25777 set topicsConf($$value = {}) { 25778 topicsConf($$value); 25779 flushSync(); 25780 }, 25781 25782 get devMode() { 25783 return devMode(); 25784 }, 25785 25786 set devMode($$value = false) { 25787 devMode($$value); 25788 flushSync(); 25789 } 25790 }; 25791 25792 var fragment = root(); 25793 25794 event('click', $document, checkOutterEvent); 25795 25796 var div = first_child(fragment); 25797 25798 div.__click = markInnerEvent;
25799 div.__keydown = [on_keydown, handleKeyDown]; 25800 25801 var form_1 = child(div); 25802 var node = child(form_1); 25803 25804 SearchBar(node, { 25805 pivBackground: true, 25806 name: 'tx_solr[q]', 25807 'input-maxlength': '200', 25808 'input-aria-controls': 'folding-pannel', 25809 'input-aria-haspopup': 'true', 25810 25811 get 'input-placeholder'() { 25812 return conf().form.input.placeholder; 25813 }, 25814 25815 get 'submit-aria-label'() { 25816 return conf().form.submit.srText; 25817 }, 25818 25819 get value() { 25820 return get(search); 25821 }, 25822 25823 set value($$value) { 25824 set(search, $$value, true); 25825 } 25826 }); 25827 25828 reset(form_1); 25829 bind_this(form_1, ($$value) => set(form, $$value), () => get(form)); 25830 25831 var div_1 = sibling(form_1, 2); 25832 var div_2 = child(div_1); 25833 let classes; 25834 var node_1 = child(div_2); 25835 25836 { 25837 var consequent = ($$anchor) => { 25838 var div_3 = root_1(); 25839 var ul = child(div_3); 25840 25841 each(ul, 21, () => get(topics), index, ($$anchor, topicEntry, index) => { 25842 var li = root_2(); 25843 var a = child(li); 25844 25845 a.__keydown = (e) => handleKeyDown(e, index); 25846 25847 var qc_icon = child(a); 25848 25849 set_custom_element_data(qc_icon, 'size', 'md'); 25850 set_custom_element_data(qc_icon, 'type', 'search-thin'); 25851 25852 var div_4 = sibling(qc_icon, 2); 25853 var div_5 = child(div_4); 25854 var text = child(div_5, true); 25855 25856 reset(div_5); 25857 25858 var div_6 = sibling(div_5, 2); 25859 var text_1 = child(div_6); 25860 25861 reset(div_6); 25862 reset(div_4); 25863 reset(a); 25864 bind_this(a, ($$value, index) => get(options)[index] = $$value, (index) => get(options)?.[index], () => [index]); 25865 reset(li); 25866 25867 template_effect( 25868 ($0) => { 25869 set_attribute(a, 'href', `${conf().suggest.endpoint ?? ''}?tx_solr[q]=${get(search) ?? ''}${$0 ?? ''}`); 25870 set_text(text, get(search)); 25871 set_text(text_1, `${conf().topics.into ?? ''} ${get(topicEntry)[1] ?? ''}`); 25872 }, 25873 [() => getTopicFilter(get(topicEntry))] 25874 ); 25875 25876 append($$anchor, li); 25877 }); 25878 25879 reset(ul); 25880 reset(div_3); 25881 append($$anchor, div_3); 25882 }; 25883 25884 if_block(node_1, ($$render) => { 25885 if (get(search) && get(topics).length > 1) $$render(consequent); 25886 }); 25887 } 25888 25889 var div_7 = sibling(node_1, 2); 25890 var p = child(div_7); 25891 var text_2 = child(p, true); 25892 25893 reset(p); 25894 25895 var node_2 = sibling(p, 2); 25896 25897 { 25898 var consequent_2 = ($$anchor) => { 25899 var fragment_1 = comment(); 25900 var node_3 = first_child(fragment_1); 25901 25902 await_block( 25903 node_3, 25904 () => get(suggestionPromise), 25905 ($$anchor) => { 25906 var p_3 = root_9(); 25907 var text_6 = child(p_3, true); 25908 25909 reset(p_3); 25910 template_effect(() => set_text(text_6, conf().suggest.text.searching)); 25911 append($$anchor, p_3); 25912 }, 25913 ($$anchor, response) => { 25914 var fragment_2 = comment(); 25915 var node_4 = first_child(fragment_2); 25916 25917 { 25918 var consequent_1 = ($$anchor) => { 25919 var fragment_3 = root_5(); 25920 var span = first_child(fragment_3); 25921 var text_3 = child(span, true); 25922 25923 reset(span); 25924 25925 var ul_1 = sibling(span, 2); 25926 25927 each(ul_1, 21, () => get(suggestions), index, ($$anchor, suggestion, id) => { 25928 var li_1 = root_6(); 25929 var a_1 = child(li_1); 25930 25931 a_1.__keydown = (e) => handleKeyDown(e, id + get(topics).length); 25932 25933 var qc_icon_1 = child(a_1); 25934 25935 set_custom_element_data(qc_icon_1, 'size', 'md'); 25936 set_custom_element_data(qc_icon_1, 'type', 'search-thin'); 25937 25938 var node_5 = sibling(qc_icon_1); 25939 25940 html(node_5, () => getSuggestion(get(suggestion), get(search))); 25941 reset(a_1); 25942 bind_this(a_1, ($$value, id) => get(options)[id + get(topics).length] = $$value, (id) => get(options)?.[id + get(topics).length], () => [id]); 25943 reset(li_1); 25944 template_effect(() => set_attribute(a_1, 'href', `${conf().suggest.endpoint ?? ''}?tx_solr[q]=${get(suggestion) ?? ''}`)); 25945 append($$anchor, li_1); 25946 }); 25947 25948 reset(ul_1); 25949 25950 template_effect(($0) => set_text(text_3, $0), [ 25951 () => conf().suggest.text.srSuggestionsFound.replace("%total%", get(suggestions).length) 25952 ]); 25953 25954 append($$anchor, fragment_3); 25955 }; 25956 25957 var alternate = ($$anchor) => { 25958 var p_1 = root_7(); 25959 var text_4 = child(p_1, true); 25960 25961 reset(p_1); 25962 template_effect(() => set_text(text_4, conf().suggest.text.noSuggestion)); 25963 append($$anchor, p_1); 25964 }; 25965 25966 if_block(node_4, ($$render) => { 25967 if (get(suggestions).length > 0) $$render(consequent_1); else $$render(alternate, false); 25968 }); 25969 } 25970 25971 append($$anchor, fragment_2); 25972 }, 25973 ($$anchor, error) => { 25974 var p_2 = root_8(); 25975 var text_5 = child(p_2, true); 25976 25977 reset(p_2); 25978 template_effect(() => set_text(text_5, conf().suggest.text.error)); 25979 append($$anchor, p_2); 25980 } 25981 ); 25982 25983 append($$anchor, fragment_1); 25984 }; 25985 25986 var alternate_1 = ($$anchor) => { 25987 var p_4 = root_10(); 25988 var text_7 = child(p_4, true); 25989 25990 reset(p_4); 25991 template_effect(() => set_text(text_7, conf().suggest.text.noSearch)); 25992 append($$anchor, p_4); 25993 }; 25994 25995 if_block(node_2, ($$render) => { 25996 if (get(search)) $$render(consequent_2); else $$render(alternate_1, false); 25997 }); 25998 } 25999 26000 reset(div_7); 26001 reset(div_2); 26002 reset(div_1); 26003 reset(div); 26004 bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement)); 26005 26006 var link = sibling(div, 2); 26007 var link_1 = sibling(link, 2); 26008 26009 template_effect( 26010 ($0, $1) => { 26011 set_attribute(form_1, 'action', conf().suggest.endpoint); 26012 set_attribute(div_2, 'aria-expanded', !get(collapsed)); 26013 set_attribute(div_2, 'aria-label', conf().foldingPannel.ariaLabel); 26014 classes = set_class(div_2, 1, '', null, classes, $0); 26015 set_text(text_2, conf().suggest.title); 26016 set_attribute(link, 'href', `${conf().css.banner ?? ''}${$1 ?? ''} `); 26017 set_attribute(link_1, 'href', conf().css.sdg); 26018 }, 26019 [ 26020 () => ({ collapsed: get(collapsed) }), 26021 () => devMode() ? `?cb=` + new Date().getTime() : '' 26022 ] 26023 ); 26024 26025 append($$anchor, fragment); 26026 26027 return pop($$exports); 26028 } 26029 26030 delegate(['click', 'keydown']);
26031 create_custom_element(BannerAutosuggest, { conf: {}, topicsConf: {}, devMode: {} }, [], [], true); 26032 26033 function BannerAutosuggestWC($$anchor, $$props) { 26034 push($$props, true); 26035 26036 let conf = prop($$props, 'conf', 23, () => ({})), 26037 topicsConf = prop($$props, 'topicsConf', 23, () => ({})), 26038 rest = rest_props($$props, [ 26039 '$$slots', 26040 '$$events', 26041 '$$legacy', 26042 '$$host', 26043 'conf', 26044 'topicsConf' 26045 ]); 26046 26047 var $$exports = { 26048 get conf() { 26049 return conf(); 26050 }, 26051 26052 set conf($$value = {}) { 26053 conf($$value); 26054 flushSync(); 26055 }, 26056 26057 get topicsConf() { 26058 return topicsConf(); 26059 }, 26060 26061 set topicsConf($$value = {}) { 26062 topicsConf($$value); 26063 flushSync(); 26064 } 26065 }; 26066 26067 BannerAutosuggest($$anchor, spread_props( 26068 { 26069 get conf() { 26070 return conf(); 26071 }, 26072 26073 get topicsConf() { 26074 return topicsConf(); 26075 } 26076 }, 26077 () => rest 26078 )); 26079 26080 return pop($$exports); 26081 } 26082 26083 customElements.define('qc-solr-banner-autosuggest', create_custom_element( 26084 BannerAutosuggestWC, 26085 { 26086 conf: { attribute: 'conf', type: 'Object' }, 26087 topicsConf: { attribute: 'topics', type: 'Object' }, 26088 devMode: { attribute: 'dev-mode', type: 'Boolean' } 26089 }, 26090 [], 26091 [], 26092 true 26093 )); 26094 26095})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.