Skip to content

Allow string transforms to be applied to sections and conf keys#2

Open
mreis1 wants to merge 5 commits intoZachPerkitny:masterfrom
mreis1:master
Open

Allow string transforms to be applied to sections and conf keys#2
mreis1 wants to merge 5 commits intoZachPerkitny:masterfrom
mreis1:master

Conversation

@mreis1
Copy link

@mreis1 mreis1 commented Dec 12, 2018

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.

Copy link
Owner

@ZachPerkitny ZachPerkitny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left feedback regarding indentation, naming and the use of JS 'enums' instead of strings.

let transform = options.transform;
let curSec = null;
let upperCaseKey = function(key){
if (key === void 0 || key === null) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be an inconsistent use of spaces and tabs, could you use 4 space indentation please ?

if (!transform){
return key;
}
if (transform === 'upper') {
Copy link
Owner

@ZachPerkitny ZachPerkitny Jan 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 4 spaces for indentation please.

});


describe('Transform configuration keys', function(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 4 spaces for indentation please, I should really add a eslint file...

options = options || {};
let transform = options.transform;
let curSec = null;
let upperCaseKey = function(key){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be const and maybe rename it to transformKey

function ConfigParser() {
function ConfigParser(options) {
options = options || {};
this._transform = options.transform || 'none';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 Space Indentation please, and we could just use default params, so function ConfigParser(options = {}) {...}

function parseLines(lines) {
function parseLines(lines, options) {
options = options || {};
let transform = options.transform;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 4 space indentation.

}

function parseLines(lines) {
function parseLines(lines, options) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants