1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.parsePropertiesFile = parsePropertiesFile;
7exports.propertiesListToString = propertiesListToString;
8
9function parsePropertiesFile(contents) {
10  const propertiesList = [];
11  const lines = contents.split('\n');
12
13  for (let i = 0; i < lines.length; i++) {
14    const line = lines[i].trim();
15
16    if (!line) {
17      propertiesList.push({
18        type: 'empty'
19      });
20    } else if (line.startsWith('#')) {
21      propertiesList.push({
22        type: 'comment',
23        value: line.substring(1).trimStart()
24      });
25    } else {
26      const eok = line.indexOf('=');
27      const key = line.slice(0, eok);
28      const value = line.slice(eok + 1, line.length);
29      propertiesList.push({
30        type: 'property',
31        key,
32        value
33      });
34    }
35  }
36
37  return propertiesList;
38}
39
40function propertiesListToString(props) {
41  let output = '';
42
43  for (let i = 0; i < props.length; i++) {
44    const prop = props[i];
45
46    if (prop.type === 'empty') {
47      output += '';
48    } else if (prop.type === 'comment') {
49      output += '# ' + prop.value;
50    } else if (prop.type === 'property') {
51      output += `${prop.key}=${prop.value}`;
52    } else {
53      // @ts-ignore: assertion
54      throw new Error(`Invalid properties type "${prop.type}"`);
55    }
56
57    if (i < props.length - 1) {
58      output += '\n';
59    }
60  }
61
62  return output;
63}
64//# sourceMappingURL=Properties.js.map