Skip to content

Commit 18dcf0c

Browse files
committed
feat: allow exact values
This just disables the inline comment escaping
1 parent bf6e203 commit 18dcf0c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ini.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const encode = (obj, options) => {
1717
whitespace: false,
1818
inlineArrays: false,
1919
allowEmptySection: false,
20+
exactValue: false,
2021
};
2122
}else{
2223
options = options || Object.create(null);
@@ -100,7 +101,12 @@ const decode = (str, options = {}) => {
100101
}
101102
let key = unsafe(match[2]);
102103
if(isConstructorOrProto(ref, key)){ continue; }
103-
let value = match[3] ? unsafe(match[3]) : defaultValue;
104+
let value = null;
105+
if(options.exactValue){
106+
value = match[3];
107+
}else{
108+
value = match[3] ? unsafe(match[3]) : defaultValue;
109+
}
104110
switch(value){
105111
case 'true':
106112
case 'True':
@@ -180,6 +186,10 @@ const safe = (val, key, options = {}) => {
180186
if(key && options.forceStringifyKeys && options.forceStringifyKeys.includes(key)){
181187
return JSON.stringify(val);
182188
}
189+
if(options.exactValue){
190+
// Don't try to escape a comment in a value
191+
return val;
192+
}
183193
// comments
184194
return val.replace(/;/g, '\\;').replace(/#/g, '\\#');
185195
};

0 commit comments

Comments
 (0)