node-properties
node-properties copied to clipboard
Possibility to modify the key
Scenario: need to parse a Localizable.strings
file from an iOS project which looks like this
/* Some useful comments */
"LOGIN_TEXT_LOGIN" = "Login";
"LOGIN_TEXT_PASSWORD" = "Password";
"LOGIN_FIRSTNAME" = "First Name";
I can modify the options to use a specific character for comments
and a reviver
to modify the value:
var options = {
path:true,
comments: '/',
separators: '=',
strict: true,
reviver: function(key, value, section) {
return value.replace(/^"|";$/g, '');
}
};
properties.parse('en.lproj/Localizable.strings', options, function(error, obj) {
console.log(obj);
});
And obtain this output:
{
'"LOGIN_TEXT_LOGIN"': 'Login',
'"LOGIN_TEXT_PASSWORD"': 'Password',
'"LOGIN_FIRSTNAME"': 'First Name'
}
However, the key
still needs some tuning. For now, I am replacing the "
before using the object, but it would nice to be able to return a json in the modifier that could be the new tuple key|value|section
.