@smithy/shared-ini-file-loader 2.0.12 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/parseIni.js +11 -6
- package/dist-es/parseIni.js +11 -6
- package/package.json +1 -1
package/dist-cjs/parseIni.js
CHANGED
|
@@ -5,10 +5,12 @@ const profileNameBlockList = ["__proto__", "profile __proto__"];
|
|
|
5
5
|
const parseIni = (iniData) => {
|
|
6
6
|
const map = {};
|
|
7
7
|
let currentSection;
|
|
8
|
+
let currentSubSection;
|
|
8
9
|
for (let line of iniData.split(/\r?\n/)) {
|
|
9
10
|
line = line.split(/(^|\s)[;#]/)[0].trim();
|
|
10
11
|
const isSection = line[0] === "[" && line[line.length - 1] === "]";
|
|
11
12
|
if (isSection) {
|
|
13
|
+
currentSubSection = undefined;
|
|
12
14
|
currentSection = line.substring(1, line.length - 1);
|
|
13
15
|
if (profileNameBlockList.includes(currentSection)) {
|
|
14
16
|
throw new Error(`Found invalid profile name "${currentSection}"`);
|
|
@@ -16,16 +18,19 @@ const parseIni = (iniData) => {
|
|
|
16
18
|
}
|
|
17
19
|
else if (currentSection) {
|
|
18
20
|
const indexOfEqualsSign = line.indexOf("=");
|
|
19
|
-
|
|
20
|
-
const end = line.length - 1;
|
|
21
|
-
const isAssignment = indexOfEqualsSign !== -1 && indexOfEqualsSign !== start && indexOfEqualsSign !== end;
|
|
22
|
-
if (isAssignment) {
|
|
21
|
+
if (![0, -1].includes(indexOfEqualsSign)) {
|
|
23
22
|
const [name, value] = [
|
|
24
23
|
line.substring(0, indexOfEqualsSign).trim(),
|
|
25
24
|
line.substring(indexOfEqualsSign + 1).trim(),
|
|
26
25
|
];
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (value === "") {
|
|
27
|
+
currentSubSection = name;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
map[currentSection] = map[currentSection] || {};
|
|
31
|
+
const key = currentSubSection ? `${currentSubSection}.${name}` : name;
|
|
32
|
+
map[currentSection][key] = value;
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
}
|
package/dist-es/parseIni.js
CHANGED
|
@@ -2,10 +2,12 @@ const profileNameBlockList = ["__proto__", "profile __proto__"];
|
|
|
2
2
|
export const parseIni = (iniData) => {
|
|
3
3
|
const map = {};
|
|
4
4
|
let currentSection;
|
|
5
|
+
let currentSubSection;
|
|
5
6
|
for (let line of iniData.split(/\r?\n/)) {
|
|
6
7
|
line = line.split(/(^|\s)[;#]/)[0].trim();
|
|
7
8
|
const isSection = line[0] === "[" && line[line.length - 1] === "]";
|
|
8
9
|
if (isSection) {
|
|
10
|
+
currentSubSection = undefined;
|
|
9
11
|
currentSection = line.substring(1, line.length - 1);
|
|
10
12
|
if (profileNameBlockList.includes(currentSection)) {
|
|
11
13
|
throw new Error(`Found invalid profile name "${currentSection}"`);
|
|
@@ -13,16 +15,19 @@ export const parseIni = (iniData) => {
|
|
|
13
15
|
}
|
|
14
16
|
else if (currentSection) {
|
|
15
17
|
const indexOfEqualsSign = line.indexOf("=");
|
|
16
|
-
|
|
17
|
-
const end = line.length - 1;
|
|
18
|
-
const isAssignment = indexOfEqualsSign !== -1 && indexOfEqualsSign !== start && indexOfEqualsSign !== end;
|
|
19
|
-
if (isAssignment) {
|
|
18
|
+
if (![0, -1].includes(indexOfEqualsSign)) {
|
|
20
19
|
const [name, value] = [
|
|
21
20
|
line.substring(0, indexOfEqualsSign).trim(),
|
|
22
21
|
line.substring(indexOfEqualsSign + 1).trim(),
|
|
23
22
|
];
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (value === "") {
|
|
24
|
+
currentSubSection = name;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
map[currentSection] = map[currentSection] || {};
|
|
28
|
+
const key = currentSubSection ? `${currentSubSection}.${name}` : name;
|
|
29
|
+
map[currentSection][key] = value;
|
|
30
|
+
}
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
}
|