@firebase/util 1.8.0-canary.20e5ef7fb → 1.8.0-canary.3ee35f9ae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -455,7 +455,7 @@ function isValidKey(key) {
455
455
 
456
456
  /**
457
457
  * @license
458
- * Copyright 2017 Google LLC
458
+ * Copyright 2022 Google LLC
459
459
  *
460
460
  * Licensed under the Apache License, Version 2.0 (the "License");
461
461
  * you may not use this file except in compliance with the License.
@@ -469,156 +469,10 @@ function isValidKey(key) {
469
469
  * See the License for the specific language governing permissions and
470
470
  * limitations under the License.
471
471
  */
472
- /**
473
- * Returns navigator.userAgent string or '' if it's not defined.
474
- * @return user agent string
475
- */
476
- function getUA() {
477
- if (typeof navigator !== 'undefined' &&
478
- typeof navigator['userAgent'] === 'string') {
479
- return navigator['userAgent'];
480
- }
481
- else {
482
- return '';
483
- }
484
- }
485
- /**
486
- * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
487
- *
488
- * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
489
- * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
490
- * wait for a callback.
491
- */
492
- function isMobileCordova() {
493
- return (typeof window !== 'undefined' &&
494
- // @ts-ignore Setting up an broadly applicable index signature for Window
495
- // just to deal with this case would probably be a bad idea.
496
- !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
497
- /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
498
- }
499
- /**
500
- * Detect Node.js.
501
- *
502
- * @return true if Node.js environment is detected.
503
- */
504
- // Node detection logic from: https://github.com/iliakan/detect-node/
505
- function isNode() {
506
- try {
507
- return (Object.prototype.toString.call(global.process) === '[object process]');
508
- }
509
- catch (e) {
510
- return false;
511
- }
512
- }
513
- /**
514
- * Detect Browser Environment
515
- */
516
- function isBrowser() {
517
- return typeof self === 'object' && self.self === self;
518
- }
519
- function isBrowserExtension() {
520
- var runtime = typeof chrome === 'object'
521
- ? chrome.runtime
522
- : typeof browser === 'object'
523
- ? browser.runtime
524
- : undefined;
525
- return typeof runtime === 'object' && runtime.id !== undefined;
526
- }
527
- /**
528
- * Detect React Native.
529
- *
530
- * @return true if ReactNative environment is detected.
531
- */
532
- function isReactNative() {
533
- return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
534
- }
535
- /** Detects Electron apps. */
536
- function isElectron() {
537
- return getUA().indexOf('Electron/') >= 0;
538
- }
539
- /** Detects Internet Explorer. */
540
- function isIE() {
541
- var ua = getUA();
542
- return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
543
- }
544
- /** Detects Universal Windows Platform apps. */
545
- function isUWP() {
546
- return getUA().indexOf('MSAppHost/') >= 0;
547
- }
548
- /**
549
- * Detect whether the current SDK build is the Node version.
550
- *
551
- * @return true if it's the Node SDK build.
552
- */
553
- function isNodeSdk() {
554
- return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
555
- }
556
- /** Returns true if we are running in Safari. */
557
- function isSafari() {
558
- return (!isNode() &&
559
- navigator.userAgent.includes('Safari') &&
560
- !navigator.userAgent.includes('Chrome'));
561
- }
562
- /**
563
- * This method checks if indexedDB is supported by current browser/service worker context
564
- * @return true if indexedDB is supported by current browser/service worker context
565
- */
566
- function isIndexedDBAvailable() {
567
- try {
568
- return typeof indexedDB === 'object';
569
- }
570
- catch (e) {
571
- return false;
572
- }
573
- }
574
- /**
575
- * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
576
- * if errors occur during the database open operation.
577
- *
578
- * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
579
- * private browsing)
580
- */
581
- function validateIndexedDBOpenable() {
582
- return new Promise(function (resolve, reject) {
583
- try {
584
- var preExist_1 = true;
585
- var DB_CHECK_NAME_1 = 'validate-browser-context-for-indexeddb-analytics-module';
586
- var request_1 = self.indexedDB.open(DB_CHECK_NAME_1);
587
- request_1.onsuccess = function () {
588
- request_1.result.close();
589
- // delete database only when it doesn't pre-exist
590
- if (!preExist_1) {
591
- self.indexedDB.deleteDatabase(DB_CHECK_NAME_1);
592
- }
593
- resolve(true);
594
- };
595
- request_1.onupgradeneeded = function () {
596
- preExist_1 = false;
597
- };
598
- request_1.onerror = function () {
599
- var _a;
600
- reject(((_a = request_1.error) === null || _a === void 0 ? void 0 : _a.message) || '');
601
- };
602
- }
603
- catch (error) {
604
- reject(error);
605
- }
606
- });
607
- }
608
- /**
609
- *
610
- * This method checks whether cookie is enabled within current browser
611
- * @return true if cookie is enabled within current browser
612
- */
613
- function areCookiesEnabled() {
614
- if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
615
- return false;
616
- }
617
- return true;
618
- }
619
472
  /**
620
473
  * Polyfill for `globalThis` object.
621
474
  * @returns the `globalThis` object for the given environment.
475
+ * @public
622
476
  */
623
477
  function getGlobal() {
624
478
  if (typeof self !== 'undefined') {
@@ -690,6 +544,7 @@ var getDefaultsFromCookie = function () {
690
544
  * (1) if such an object exists as a property of `globalThis`
691
545
  * (2) if such an object was provided on a shell environment variable
692
546
  * (3) if such an object exists in a cookie
547
+ * @public
693
548
  */
694
549
  var getDefaults = function () {
695
550
  try {
@@ -856,6 +711,178 @@ function createMockUserToken(token, projectId) {
856
711
  ].join('.');
857
712
  }
858
713
 
714
+ /**
715
+ * @license
716
+ * Copyright 2017 Google LLC
717
+ *
718
+ * Licensed under the Apache License, Version 2.0 (the "License");
719
+ * you may not use this file except in compliance with the License.
720
+ * You may obtain a copy of the License at
721
+ *
722
+ * http://www.apache.org/licenses/LICENSE-2.0
723
+ *
724
+ * Unless required by applicable law or agreed to in writing, software
725
+ * distributed under the License is distributed on an "AS IS" BASIS,
726
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
727
+ * See the License for the specific language governing permissions and
728
+ * limitations under the License.
729
+ */
730
+ /**
731
+ * Returns navigator.userAgent string or '' if it's not defined.
732
+ * @return user agent string
733
+ */
734
+ function getUA() {
735
+ if (typeof navigator !== 'undefined' &&
736
+ typeof navigator['userAgent'] === 'string') {
737
+ return navigator['userAgent'];
738
+ }
739
+ else {
740
+ return '';
741
+ }
742
+ }
743
+ /**
744
+ * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
745
+ *
746
+ * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
747
+ * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
748
+ * wait for a callback.
749
+ */
750
+ function isMobileCordova() {
751
+ return (typeof window !== 'undefined' &&
752
+ // @ts-ignore Setting up an broadly applicable index signature for Window
753
+ // just to deal with this case would probably be a bad idea.
754
+ !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
755
+ /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
756
+ }
757
+ /**
758
+ * Detect Node.js.
759
+ *
760
+ * @return true if Node.js environment is detected or specified.
761
+ */
762
+ // Node detection logic from: https://github.com/iliakan/detect-node/
763
+ function isNode() {
764
+ var _a;
765
+ var forceEnvironment = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.forceEnvironment;
766
+ if (forceEnvironment === 'node') {
767
+ return true;
768
+ }
769
+ else if (forceEnvironment === 'browser') {
770
+ return false;
771
+ }
772
+ try {
773
+ return (Object.prototype.toString.call(global.process) === '[object process]');
774
+ }
775
+ catch (e) {
776
+ return false;
777
+ }
778
+ }
779
+ /**
780
+ * Detect Browser Environment
781
+ */
782
+ function isBrowser() {
783
+ return typeof self === 'object' && self.self === self;
784
+ }
785
+ function isBrowserExtension() {
786
+ var runtime = typeof chrome === 'object'
787
+ ? chrome.runtime
788
+ : typeof browser === 'object'
789
+ ? browser.runtime
790
+ : undefined;
791
+ return typeof runtime === 'object' && runtime.id !== undefined;
792
+ }
793
+ /**
794
+ * Detect React Native.
795
+ *
796
+ * @return true if ReactNative environment is detected.
797
+ */
798
+ function isReactNative() {
799
+ return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
800
+ }
801
+ /** Detects Electron apps. */
802
+ function isElectron() {
803
+ return getUA().indexOf('Electron/') >= 0;
804
+ }
805
+ /** Detects Internet Explorer. */
806
+ function isIE() {
807
+ var ua = getUA();
808
+ return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
809
+ }
810
+ /** Detects Universal Windows Platform apps. */
811
+ function isUWP() {
812
+ return getUA().indexOf('MSAppHost/') >= 0;
813
+ }
814
+ /**
815
+ * Detect whether the current SDK build is the Node version.
816
+ *
817
+ * @return true if it's the Node SDK build.
818
+ */
819
+ function isNodeSdk() {
820
+ return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
821
+ }
822
+ /** Returns true if we are running in Safari. */
823
+ function isSafari() {
824
+ return (!isNode() &&
825
+ navigator.userAgent.includes('Safari') &&
826
+ !navigator.userAgent.includes('Chrome'));
827
+ }
828
+ /**
829
+ * This method checks if indexedDB is supported by current browser/service worker context
830
+ * @return true if indexedDB is supported by current browser/service worker context
831
+ */
832
+ function isIndexedDBAvailable() {
833
+ try {
834
+ return typeof indexedDB === 'object';
835
+ }
836
+ catch (e) {
837
+ return false;
838
+ }
839
+ }
840
+ /**
841
+ * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
842
+ * if errors occur during the database open operation.
843
+ *
844
+ * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
845
+ * private browsing)
846
+ */
847
+ function validateIndexedDBOpenable() {
848
+ return new Promise(function (resolve, reject) {
849
+ try {
850
+ var preExist_1 = true;
851
+ var DB_CHECK_NAME_1 = 'validate-browser-context-for-indexeddb-analytics-module';
852
+ var request_1 = self.indexedDB.open(DB_CHECK_NAME_1);
853
+ request_1.onsuccess = function () {
854
+ request_1.result.close();
855
+ // delete database only when it doesn't pre-exist
856
+ if (!preExist_1) {
857
+ self.indexedDB.deleteDatabase(DB_CHECK_NAME_1);
858
+ }
859
+ resolve(true);
860
+ };
861
+ request_1.onupgradeneeded = function () {
862
+ preExist_1 = false;
863
+ };
864
+ request_1.onerror = function () {
865
+ var _a;
866
+ reject(((_a = request_1.error) === null || _a === void 0 ? void 0 : _a.message) || '');
867
+ };
868
+ }
869
+ catch (error) {
870
+ reject(error);
871
+ }
872
+ });
873
+ }
874
+ /**
875
+ *
876
+ * This method checks whether cookie is enabled within current browser
877
+ * @return true if cookie is enabled within current browser
878
+ */
879
+ function areCookiesEnabled() {
880
+ if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
881
+ return false;
882
+ }
883
+ return true;
884
+ }
885
+
859
886
  /**
860
887
  * @license
861
888
  * Copyright 2017 Google LLC
@@ -2118,6 +2145,7 @@ exports.extractQuerystring = extractQuerystring;
2118
2145
  exports.getDefaultAppConfig = getDefaultAppConfig;
2119
2146
  exports.getDefaultEmulatorHost = getDefaultEmulatorHost;
2120
2147
  exports.getDefaultEmulatorHostnameAndPort = getDefaultEmulatorHostnameAndPort;
2148
+ exports.getDefaults = getDefaults;
2121
2149
  exports.getExperimentalSetting = getExperimentalSetting;
2122
2150
  exports.getGlobal = getGlobal;
2123
2151
  exports.getModularInstance = getModularInstance;