text: /**
   * Copyright 2017 Google Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *   http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  /**
   * @fileoverview Functionality related to the parsing/composition of bucket/
   * object location.
   */
  import * as errorsExports from './error';
  /**
   * @struct
   */
  var Location = /** @class */ (function () {
      function Location(bucket, path) {
          this.bucket = bucket;
          this.path_ = path;
      }
      Object.defineProperty(Location.prototype, "path", {
          get: function () {
              return this.path_;
          },
          enumerable: true,
          configurable: true
      });
      Location.prototype.fullServerUrl = function () {
          var encode = encodeURIComponent;
          return '/b/' + encode(this.bucket) + '/o/' + encode(this.path);
      };
      Location.prototype.bucketOnlyServerUrl = function () {
          var encode = encodeURIComponent;
          return '/b/' + encode(this.bucket) + '/o';
      };
      Location.makeFromBucketSpec = function (bucketString) {
          var bucketLocation;
          try {
              bucketLocation = Location.makeFromUrl(bucketString);
          }
          catch (e) {
              // Not valid URL, use as-is. This lets you put bare bucket names in
              // config.
              return new Location(bucketString, '');
          }
          if (bucketLocation.path === '') {
              return bucketLocation;
          }
          else {
              throw errorsExports.invalidDefaultBucket(bucketString);
          }
      };
      Location.makeFromUrl = function (url) {
          var location = null;
          var bucketDomain = '([A-Za-z0-9.\\-]+)';
          function gsModify(loc) {
              if (loc.path.charAt(loc.path.length - 1) === '/') {
                  loc.path_ = loc.path_.slice(0, -1);
              }
          }
          var gsPath = '(/(.*))?$';
          var path = '(/([^?#]*).*)?$';
          var gsRegex = new RegExp('^gs://' + bucketDomain + gsPath, 'i');
          var gsIndices = { bucket: 1, path: 3 };
          function httpModify(loc) {
              loc.path_ = decodeURIComponent(loc.path);
          }
          var version = 'v[A-Za-z0-9_]+';
          var httpRegex = new RegExp('^https?://firebasestorage\\.googleapis\\.com/' +
              version +
              '/b/' +
              bucketDomain +
              '/o' +
              path, 'i');
          var httpIndices = { bucket: 1, path: 3 };
          var groups = [
              { regex: gsRegex, indices: gsIndices, postModify: gsModify },
              { regex: httpRegex, indices: httpIndices, postModify: httpModify }
          ];
          for (var i = 0; i < groups.length; i++) {
              var group = groups[i];
              var captures = group.regex.exec(url);
              if (captures) {
                  var bucketValue = captures[group.indices.bucket];
                  var pathValue = captures[group.indices.path];
                  if (!pathValue) {
                      pathValue = '';
                  }
                  location = new Location(bucketValue, pathValue);
                  group.postModify(location);
                  break;
              }
          }
          if (location == null) {
              throw errorsExports.invalidUrl(url);
          }
          return location;
      };
      return Location;
  }());
  export { Location };
  
  //# sourceMappingURL=location.js.map
  