Skip to content

Commit

Permalink
feat: allow exact values
Browse files Browse the repository at this point in the history
This just disables the inline comment escaping
  • Loading branch information
mja00 committed Nov 26, 2024
1 parent bf6e203 commit 18dcf0c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const encode = (obj, options) => {
whitespace: false,
inlineArrays: false,
allowEmptySection: false,
exactValue: false,
};
}else{
options = options || Object.create(null);
Expand Down Expand Up @@ -100,7 +101,12 @@ const decode = (str, options = {}) => {
}
let key = unsafe(match[2]);
if(isConstructorOrProto(ref, key)){ continue; }
let value = match[3] ? unsafe(match[3]) : defaultValue;
let value = null;
if(options.exactValue){
value = match[3];
}else{
value = match[3] ? unsafe(match[3]) : defaultValue;
}
switch(value){
case 'true':
case 'True':
Expand Down Expand Up @@ -180,6 +186,10 @@ const safe = (val, key, options = {}) => {
if(key && options.forceStringifyKeys && options.forceStringifyKeys.includes(key)){
return JSON.stringify(val);
}
if(options.exactValue){
// Don't try to escape a comment in a value
return val;
}
// comments
return val.replace(/;/g, '\\;').replace(/#/g, '\\#');
};
Expand Down

0 comments on commit 18dcf0c

Please sign in to comment.