Allow string transforms to be applied to sections and conf keys#2
Allow string transforms to be applied to sections and conf keys#2mreis1 wants to merge 5 commits intoZachPerkitny:masterfrom
Conversation
…uch as 'upper' or 'lower'
ZachPerkitny
left a comment
There was a problem hiding this comment.
I've left feedback regarding indentation, naming and the use of JS 'enums' instead of strings.
src/configparser.js
Outdated
| let transform = options.transform; | ||
| let curSec = null; | ||
| let upperCaseKey = function(key){ | ||
| if (key === void 0 || key === null) return; |
There was a problem hiding this comment.
There seems to be an inconsistent use of spaces and tabs, could you use 4 space indentation please ?
src/configparser.js
Outdated
| if (!transform){ | ||
| return key; | ||
| } | ||
| if (transform === 'upper') { |
There was a problem hiding this comment.
Maybe using a JS 'enum' by adding
const Transform = Object.freeze({
NONE: 0,
UPPER: 1,
LOWER: 2
});if (transform == Transform.UPPER) {
return key.toUpperCase();
} else if (transform == Transform.LOWER) {
return key.toLowerCase();
} else {
return key;
}| 'more_complex_interpolation' | ||
| ]); | ||
| }); | ||
| it('should return all sections in the config file', function () { |
There was a problem hiding this comment.
Use 4 spaces for indentation please.
| }); | ||
|
|
||
|
|
||
| describe('Transform configuration keys', function(){ |
There was a problem hiding this comment.
Use 4 spaces for indentation please, I should really add a eslint file...
src/configparser.js
Outdated
| options = options || {}; | ||
| let transform = options.transform; | ||
| let curSec = null; | ||
| let upperCaseKey = function(key){ |
There was a problem hiding this comment.
This could be const and maybe rename it to transformKey
src/configparser.js
Outdated
| function ConfigParser() { | ||
| function ConfigParser(options) { | ||
| options = options || {}; | ||
| this._transform = options.transform || 'none'; |
There was a problem hiding this comment.
4 Space Indentation please, and we could just use default params, so function ConfigParser(options = {}) {...}
src/configparser.js
Outdated
| function parseLines(lines) { | ||
| function parseLines(lines, options) { | ||
| options = options || {}; | ||
| let transform = options.transform; |
src/configparser.js
Outdated
| } | ||
|
|
||
| function parseLines(lines) { | ||
| function parseLines(lines, options) { |
There was a problem hiding this comment.
we could just use default params, so function parseLines(lines, options = {}) {...}
fix: Parsing error being misleading since a variable "file" was undefined during the parseLine function and as consequence parse would fail with no details such as error line
Reads configuration files in a case insensitive way thanks to the transform method that I implemented.
Some programming languages such as delphi reads
[Section1] or [SeCtion1] as being the same section. They are case insensitive.
In order to address this need I introduced transforms.
{transform: 'upper' | 'lower' | 'none' } (default: 'none')
[Section1] would be converted into [SECTION1]
And same to all configuration property's keys.