• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hetalang / heta-compiler / 16499499764

24 Jul 2025 02:20PM UTC coverage: 67.552% (+0.1%) from 67.43%
16499499764

push

github

metelkin
draft `getProperty` method for `Top`

1832 of 2849 branches covered (64.3%)

Branch coverage included in aggregate %.

25 of 28 new or added lines in 2 files covered. (89.29%)

26 existing lines in 4 files now uncovered.

3127 of 4492 relevant lines covered (69.61%)

82.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.96
/src/utils.js
1
/*
2
  auxiliary functions and objects
3
*/
4

5
// return array of elements by the selector
6
function uniqBy(array, selector = (x) => x) {
136✔
7
  let indexes = [];
250✔
8
  let output = [];
250✔
9
  array.forEach((x) => {
250✔
10
    let ind = selector(x);
256✔
11
    if (indexes.indexOf(ind) === -1) {
256✔
12
      indexes.push(ind);
230✔
13
      output.push(x);
230✔
14
    }
15
  });
16

17
  return output;
250✔
18
}
19

20
function intersection(array1, array2) {
21
  if (array1.length < array2.length) {
16✔
22
    var arrayA = array1; // shorter
2✔
23
    var arrayB = array2;
2✔
24
  } else {
25
    arrayA = array2;
14✔
26
    arrayB = array1;
14✔
27
  }
28

29
  let intersect = [];
16✔
30
  arrayA.forEach((value) => {
16✔
31
    if (arrayB.indexOf(value) !== -1 && intersect.indexOf(value) === -1) {
136✔
32
      intersect.push(value);
72✔
33
    }
34
  });
35

36
  return intersect;
16✔
37
}
38

UNCOV
39
function differenceBy(array1, array2, selector = (x) => x) {
×
UNCOV
40
  let result = [];
×
UNCOV
41
  array1.forEach((x) => {
×
UNCOV
42
    let selected1 = selector(x);
×
UNCOV
43
    if (array2.map(selector).indexOf(selected1) === -1) {
×
UNCOV
44
      result.push(x);
×
45
    }
46
  });
47

48
  return result;
×
49
}
50

51
function flatten(o){
52
  if (typeof o!== 'object')
127!
UNCOV
53
    throw new TypeError('Object required.');
×
54
  
55
  let res = {};
127✔
56
  Object.entries(o).forEach(([key, value]) => {
127✔
57
    if(value instanceof Array) {
407✔
58
      res[key + '[]'] = value.map((x) => {
4✔
59
        if(typeof x === 'object'){
9✔
60
          return JSON.stringify(x);
3✔
61
        }else{
62
          return x;
6✔
63
        }
64
      }).join('; ');
65
    } else if (typeof value !== 'object') {
403✔
66
      res[key] = value;
389✔
67
    } else {
68
      let flat = flatten(value);
14✔
69
      Object.entries(flat)
14✔
70
        .forEach(([keyDeep, valueDeep]) => res[key + '.' + keyDeep] = valueDeep);
17✔
71
    }
72
  });
73

74
  return res;
127✔
75
}
76

77
// clone all own properties and arrays
78
function cloneDeep(o) {
79
  if (o instanceof Object) {
869✔
80
    var clone;
81
    if (o instanceof Array) {
354✔
82
      clone = o.map((key) => cloneDeep(key));
101✔
83
    } else {
84
      clone = {};
273✔
85
      Object.keys(o).forEach((key) => {
273✔
86
        clone[key] = cloneDeep(o[key]);
622✔
87
      });
88
    }
89
    
90
    return clone;
354✔
91
  } else {
92
    return o;
515✔
93
  }
94
}
95

96
// take path of type 'a[1].b' and return array of parts
97
// e.g. ['a', 1, 'b']
98
function _parsePath(path) {
99
  // check if path is valid
100
  if (typeof path !== 'string') {
10!
NEW
101
    throw new TypeError(`Path must be a string, got ${typeof path}.`);
×
102
  }
103

104
  // parse string sequentially
105
  let pathArray = [];
10✔
106
  if (path === '') {
10✔
107
    return pathArray; // empty path
1✔
108
  }
109
  
110
  let parts1 = path.split('.');
9✔
111
  for (let part of parts1) {
9✔
112
    let regExpr = /^([a-zA-Z_][a-zA-Z0-9_]*)?(\[[0-9]+\])*$/;
18✔
113
    if (!regExpr.test(part)) {
18✔
114
      throw new TypeError(`Path "${part}" is not valid.`);
3✔
115
    }
116

117
    let parts2 = part.split('[');
15✔
118
    if (parts2[0] !== '') {
15✔
119
      pathArray.push(parts2[0]); // add property name
14✔
120
    }
121
    if (parts2.length > 1) {
15✔
122
      for (let i = 1; i < parts2.length; i++) {
7✔
123
        let subPart = parts2[i].replace(']', ''); // remove trailing ]
10✔
124
        if (subPart) {
10!
125
          pathArray.push(Number(subPart)); // convert to number
10✔
126
        }
127
      }
128
    }
129
  }
130
  
131
  return pathArray;
6✔
132
}
133

134
// take path of type ['a', 1, 'b'] and return value or undefined
135
function _getByPathArray(pathArray = []) {
×
136
  let current = this;
5✔
137

138
  for (let part of pathArray) {
5✔
139
    current = current[part];
13✔
140
    if (current === undefined) {
13✔
141
      return undefined;
2✔
142
    }
143
  }
144
  return current;
3✔
145
}
146

147
module.exports = {
1✔
148
  uniqBy,
149
  intersection,
150
  differenceBy,
151
  flatten,
152
  cloneDeep,
153
  _parsePath, // just to test
154
  _getByPathArray // just to test
155
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc