github.com/argoproj/argo-cd/v2@v2.10.9/ui/src/app/shared/utils.ts (about)

     1  export function hashCode(str: string) {
     2      let hash = 0;
     3      for (let i = 0; i < str.length; i++) {
     4          // tslint:disable-next-line:no-bitwise
     5          hash = ~~((hash << 5) - hash + str.charCodeAt(i));
     6      }
     7      return hash;
     8  }
     9  
    10  // concatMaps merges two maps. Later args take precedence where there's a key conflict.
    11  export function concatMaps(...maps: (Map<string, string> | null)[]): Map<string, string> {
    12      const newMap = new Map<string, string>();
    13      for (const map of maps) {
    14          if (map) {
    15              for (const entry of Object.entries(map)) {
    16                  newMap.set(entry[0], entry[1]);
    17              }
    18          }
    19      }
    20      return newMap;
    21  }
    22  
    23  export function isValidURL(url: string): boolean {
    24      try {
    25          const parsedUrl = new URL(url);
    26          return parsedUrl.protocol !== 'javascript:' && parsedUrl.protocol !== 'data:' && parsedUrl.protocol !== 'vbscript:';
    27      } catch (TypeError) {
    28          try {
    29              // Try parsing as a relative URL.
    30              const parsedUrl = new URL(url, window.location.origin);
    31              return parsedUrl.protocol !== 'javascript:' && parsedUrl.protocol !== 'data:' && parsedUrl.protocol !== 'vbscript:';
    32          } catch (TypeError) {
    33              return false;
    34          }
    35      }
    36  }