Project

General

Profile

1 55415 konstantin
export class HelperFunctions {
2
3
  public static scroll() {
4 58739 argiro.kok
     HelperFunctions.scrollTo(0,0);
5
  }
6
  public static scrollTo(x,y) {
7 55415 konstantin
    if (typeof document !== 'undefined') {
8 58739 argiro.kok
      window.scrollTo(x,y);
9 55415 konstantin
    }
10
  }
11 56013 k.triantaf
12 58739 argiro.kok
  public static scrollToId(elementId:string) {
13
    if (typeof document !== 'undefined' && document.getElementById(elementId)) {
14
      document.getElementById(elementId).scrollIntoView();
15
    }
16
  }
17 56013 k.triantaf
  public static isTiny(url: string) {
18
    return (url.indexOf('tinyurl.com') !== -1);
19
  }
20 57573 k.triantaf
21 57665 k.triantaf
  public static copy(obj: any): any {
22
    let copy;
23
24
    // Handle the 3 simple types, and null or undefined
25
    if (null == obj || "object" != typeof obj) return obj;
26
27
    // Handle Date
28
    if (obj instanceof Date) {
29
      copy = new Date();
30
      copy.setTime(obj.getTime());
31
      return copy;
32
    }
33
34
    // Handle Array
35
    if (obj instanceof Array) {
36
      copy = [];
37
      for (let i = 0, len = obj.length; i < len; i++) {
38
        copy[i] = HelperFunctions.copy(obj[i]);
39
      }
40
      return copy;
41
    }
42
43
    // Handle Map
44
    if (obj instanceof Map) {
45 57672 k.triantaf
      return new Map(obj.entries());
46 57665 k.triantaf
    }
47
48
    // Handle Object
49
    if (obj instanceof Object) {
50
      copy = {};
51
      for (let attr in obj) {
52
        if (obj.hasOwnProperty(attr)) {
53
          copy[attr] = HelperFunctions.copy(obj[attr]);
54
        }
55
      }
56
      return copy;
57
    }
58
    throw new Error("Unable to copy obj! Its type isn't supported.");
59 57573 k.triantaf
  }
60 57590 k.triantaf
61
  public static encodeArray(elements: string[]): string[] {
62
    let encoded: string[] = [];
63
    elements.forEach(element => {
64
      encoded.push(encodeURIComponent(element));
65
    });
66
    return encoded;
67
  }
68 56013 k.triantaf
}