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

hetalang / heta-compiler / 18806189481

25 Oct 2025 05:22PM UTC coverage: 73.408% (-0.05%) from 73.46%
18806189481

push

github

metelkin
table module options check

2013 of 2960 branches covered (68.01%)

Branch coverage included in aggregate %.

2 of 7 new or added lines in 2 files covered. (28.57%)

3613 of 4704 relevant lines covered (76.81%)

101.13 hits per line

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

83.53
/src/module-system/table-module.js
1
const { convertExcelSync } = require('../xlsx-connector');
2✔
2

3
/**
4
 * To initialize a Heta module of the "table" type.
5
 * It includes reading and parsing of file formatted as Heta-tables,
6
 * see [Heta specifications](https://hetalang.github.io/#/specifications/modules?id=table-module)
7
 * 
8
 * @returns {Module} Self.
9
 */
10
function tableLoader(fileContent, { sheet = 0, omitRows = 0, transpose = false } = {}) {
4!
11
  // check sheet is non negative integer
12
  if (typeof sheet !== 'number' || !Number.isInteger(sheet) || sheet < 0) {
4!
NEW
13
    throw new TypeError(`Table module option 'sheet' must be a non-negative integer, got: ${sheet}`);
×
14
  }
15
  // check omitRows is non negative integer
16
  if (typeof omitRows !== 'number' || !Number.isInteger(omitRows) || omitRows < 0) {
4!
NEW
17
    throw new TypeError(`Table module option 'omitRows' must be a non-negative integer, got: ${omitRows}`);
×
18
  }
19

20
  let rawData = convertExcelSync(fileContent, null, { sheet, transpose });
4✔
21
  rawData.splice(0, omitRows); // remove rows
3✔
22

23
  let parsed = rawData
3✔
24
    .filter((x) => x.on) // ignore rows
21✔
25
    .map((x) => {      
26
      let cleaned = _cloneDeepWith(x, (value) => {
15✔
27
        if (typeof value?.valueOf() === 'string') {
114✔
28
          let s = clean(value);
58✔
29
          if (s !== '') { // if empty string return undefined
58!
30
            return s;
58✔
31
          }
32
        } else if (Array.isArray(value)) {
56✔
33
          return value.map((y) => clean(y))
6✔
34
            .filter((y) => y !== ''); // removes empty strings from array
6✔
35
        } else {
36
          return value;
52✔
37
        }
38
      });
39

40
      let booleanProperties = [
15✔
41
        'isAmount', 'free', 'boundary', 'ss', 'output', 'reversible',
42
        'active', 'atStart'
43
      ];
44

45
      let normalized = {};
15✔
46
      Object.entries(cleaned).forEach(([key, value]) => {
15✔
47
        if (booleanProperties.indexOf(key) !== -1) { // in the list
85✔
48
          normalized[key] = forceBool(value);
6✔
49
        } else {
50
          normalized[key] = value;
79✔
51
        }
52
      });
53

54
      return normalized;
15✔
55
    });
56

57
  return parsed;
3✔
58
}
59

60
// remove blanks and new lines symbols
61
// return x if not a string
62
function clean(x) {
63
  if (typeof x !== 'string') {
64!
64
    return x;
×
65
  }
66

67
  return x.trim()
64✔
68
    .replace(/_x000D_\n/g, '')
69
    .replace(/\r*\n+/g, '');
70
}
71

72
// converts 0/'0' -> false, 1/'1' -> true
73
function forceBool(x) {
74
  if (typeof x === 'string' && (x.trim() === 'true' || x.trim() === 'false')) {
6✔
75
    return x.trim() !== 'false';
4✔
76
  } else if (typeof x === 'number') {
2!
77
    return x !== 0;
2✔
78
  } else {
79
    return x;
×
80
  }
81
}
82

83
// clone all own properties and arrays
84
function _cloneDeepWith(o, handler = (x) => x) {
×
85
  if (o instanceof Array) {
114✔
86
    let clone = o.map((key) => _cloneDeepWith(key, handler));
6✔
87

88
    return handler(clone);
4✔
89
  } else if (o instanceof Object) {
110✔
90
    let clone = {};
23✔
91
    
92
    Object.entries(o).forEach(([key, value]) => {
23✔
93
      let propertyValue = _cloneDeepWith(value, handler);
93✔
94
      if (propertyValue !== undefined) { // do not clone undefined properties
93!
95
        clone[key] = propertyValue;
93✔
96
      }
97
    });
98
    
99
    return handler(clone);
23✔
100
  } else {
101
    return handler(o);
87✔
102
  }
103
}
104

105
module.exports = tableLoader;
2✔
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