//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// TypeScript helpers (universal micro-lib.) | Author: Sergei Y.Kitaev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// HTTP-address helpers for URL-paths (static class):
class HAddress
{
   static IsSlashChar(ch: string): boolean {
      return ch=='/' || ch=='\\'
   }
   static StartsWithSlash(value: string|null): boolean {
      return value!=null && (value.startsWith('/') || value.startsWith('\\'))
   }
   static EndsWithSlash(value: string|null): boolean {
      return value!=null && (value.endsWith('/') || value.endsWith('\\'))
   }
   static BackSlashesToNormal(value: string): string {
      let rslt = ''
      for (let i=0; i<value.length; i++) {
         let ch = value[i]
         rslt = rslt + (ch=='\\' ? '/' : ch)
      }
      return rslt
   }
   static NormalizeSlashes(address: string): string {
      address = HAddress.BackSlashesToNormal(address).toLowerCase()
      return HAddress.EndsWithSlash(address) ? address : address+'/'
   }
   static SlashCat(part_1: string, part_2: string, normalize: boolean=false): string {
      let ews_1 = HAddress.EndsWithSlash(part_1)
      let sws_2 = HAddress.StartsWithSlash(part_2)
      let concat = ews_1 && sws_2 ? part_1+part_2.substr(1) :
         part_1+(ews_1 || sws_2 ? '' : '/')+part_2
      return normalize ? HAddress.NormalizeSlashes(concat) : concat
   }
   static ToAbsolute(href: string): string {
      return href.indexOf(':')>=0 ?
         HAddress.EndsWithSlash(href) ? href : href+'/' :
            HAddress.SlashCat(window.location.origin, href, true)
   }
} // HAddress
