GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

lib/config.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 70
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
cc 0
c 4
b 1
f 1
nc 1
dl 0
loc 70
rs 10
wmc 6
mnd 2
bc 7
fnc 3
bpm 2.3333
cpm 2
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A config.js ➔ Config 0 7 1
A config.js ➔ readFile 0 8 2
A config.js ➔ parseConfig 0 19 3
1
"use strict";
2
3
var fs = require('fs');
4
5
// Expose `Config`
6
7
module.exports = Config;
8
9
/**
10
 * Set up Config with `configPath`
11
 * which is responsible for loading and parsing config file.
12
 *
13
 * @param {Object} configPath
14
 * @return {Object}
15
 * @api public
16
 */
17
18
function Config(configPath) {
19
    this.configPath = configPath; // Save config file path
20
    this.raw = readFile(this.configPath); // Save config string
21
    this.parsed = parseConfig(this.raw); // Config as an object
22
23
    return this.parsed; // return as an object
24
}
25
26
27
/**
28
 * Read config file and return output
29
 *
30
 * @param {String} configPath
31
 * @return {String}
32
 * @api protected
33
 */
34
35
function readFile(configPath) {
36
    try {
37
        return fs.readFileSync(configPath, "utf-8");
38
    }
39
    catch (err) {
40
        throw err;
41
    }
42
}
43
44
/**
45
 * Return configuration file's content as a formatted object
46
 *
47
 * @param {String} configStr
48
 * @return {Object}
49
 * @api protected
50
 */
51
52
function parseConfig(configStr) {
53
    var config = {};
54
    var lines = configStr.split(/\r?\n/); // Split lines
55
    var lastCellLine = lines[0].split(' '); // Save first line
56
    var mowersLines = lines.splice(1, lines.length-1); // Array of mowers
57
    config.topRightPos = {x:parseInt(lastCellLine[0]), y:parseInt(lastCellLine[1])}; // Define first line in config object
58
    config.mowers = [];
59
    for(var i=0; i<mowersLines.length; i++) {
60
        if(i%2){
61
            var position = mowersLines[i-1].split(' ');
62
            config.mowers.push({
63
                pos:{x:parseInt(position[0]), y:parseInt(position[1])},
64
                cardinal:position[2],
65
                instructions:mowersLines[i].split('')
66
            });
67
        }
68
    }
69
    return config;
70
}
71