@firebase/util 1.7.0 → 1.7.1-20221010203322

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.
@@ -649,30 +649,13 @@ var getDefaultsFromGlobal = function () {
649
649
  * process.env.__FIREBASE_DEFAULTS_PATH__
650
650
  */
651
651
  var getDefaultsFromEnvVariable = function () {
652
- if (typeof process === 'undefined') {
652
+ if (typeof process === 'undefined' || typeof process.env === 'undefined') {
653
653
  return;
654
654
  }
655
655
  var defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
656
- var defaultsJsonPath = process.env.__FIREBASE_DEFAULTS_PATH__;
657
656
  if (defaultsJsonString) {
658
- if (defaultsJsonPath) {
659
- console.warn("Values were provided for both __FIREBASE_DEFAULTS__ " +
660
- "and __FIREBASE_DEFAULTS_PATH__. __FIREBASE_DEFAULTS_PATH__ " +
661
- "will be ignored.");
662
- }
663
657
  return JSON.parse(defaultsJsonString);
664
658
  }
665
- if (defaultsJsonPath && typeof require !== 'undefined') {
666
- try {
667
- // eslint-disable-next-line @typescript-eslint/no-require-imports
668
- var json = require(defaultsJsonPath);
669
- return json;
670
- }
671
- catch (e) {
672
- console.warn("Unable to read defaults from file provided to " +
673
- ("__FIREBASE_DEFAULTS_PATH__: " + defaultsJsonPath));
674
- }
675
- }
676
659
  };
677
660
  var getDefaultsFromCookie = function () {
678
661
  if (typeof document === 'undefined') {
@@ -696,9 +679,35 @@ var getDefaults = function () {
696
679
  /**
697
680
  * Returns emulator host stored in the __FIREBASE_DEFAULTS__ object
698
681
  * for the given product.
682
+ * @returns a URL host formatted like `127.0.0.1:9999` or `[::1]:4000` if available
699
683
  * @public
700
684
  */
701
685
  var getDefaultEmulatorHost = function (productName) { var _a, _b; return (_b = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.emulatorHosts) === null || _b === void 0 ? void 0 : _b[productName]; };
686
+ /**
687
+ * Returns emulator hostname and port stored in the __FIREBASE_DEFAULTS__ object
688
+ * for the given product.
689
+ * @returns a pair of hostname and port like `["::1", 4000]` if available
690
+ * @public
691
+ */
692
+ var getDefaultEmulatorHostnameAndPort = function (productName) {
693
+ var host = getDefaultEmulatorHost(productName);
694
+ if (!host) {
695
+ return undefined;
696
+ }
697
+ var separatorIndex = host.lastIndexOf(':'); // Finding the last since IPv6 addr also has colons.
698
+ if (separatorIndex <= 0 || separatorIndex + 1 === host.length) {
699
+ throw new Error("Invalid host " + host + " with no separate hostname and port!");
700
+ }
701
+ // eslint-disable-next-line no-restricted-globals
702
+ var port = parseInt(host.substring(separatorIndex + 1), 10);
703
+ if (host[0] === '[') {
704
+ // Bracket-quoted `[ipv6addr]:port` => return "ipv6addr" (without brackets).
705
+ return [host.substring(1, separatorIndex - 1), port];
706
+ }
707
+ else {
708
+ return [host.substring(0, separatorIndex), port];
709
+ }
710
+ };
702
711
  /**
703
712
  * Returns Firebase app config stored in the __FIREBASE_DEFAULTS__ object.
704
713
  * @public
@@ -2030,5 +2039,5 @@ function getModularInstance(service) {
2030
2039
  }
2031
2040
  }
2032
2041
 
2033
- export { CONSTANTS, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getDefaultAppConfig, getDefaultEmulatorHost, getExperimentalSetting, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
2042
+ export { CONSTANTS, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getDefaultAppConfig, getDefaultEmulatorHost, getDefaultEmulatorHostnameAndPort, getExperimentalSetting, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
2034
2043
  //# sourceMappingURL=index.esm5.js.map