Passed
Pull Request — master (#3)
by Alberto
02:16 queued 28s
created

lib/JsonApiData.js   A

Complexity

Total Complexity 24
Complexity/F 3.43

Size

Lines of Code 67
Function Count 7

Duplication

Duplicated Lines 11
Ratio 16.42 %

Importance

Changes 0
Metric Value
wmc 24
eloc 56
mnd 17
bc 17
fnc 7
dl 11
loc 67
bpm 2.4285
cpm 3.4285
noi 15
c 0
b 0
f 0
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"use strict";
2
var __assign = (this && this.__assign) || function () {
3
    __assign = Object.assign || function(t) {
4
        for (var s, i = 1, n = arguments.length; i < n; i++) {
5
            s = arguments[i];
6
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
                t[p] = s[p];
8
        }
9
        return t;
10
    };
11
    return __assign.apply(this, arguments);
12
};
13
var __rest = (this && this.__rest) || function (s, e) {
14
    var t = {};
15
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
        t[p] = s[p];
17
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
                t[p[i]] = s[p[i]];
21
        }
22
    return t;
23
};
24
var __importStar = (this && this.__importStar) || function (mod) {
25
    if (mod && mod.__esModule) return mod;
26
    var result = {};
27
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
28
    result["default"] = mod;
29
    return result;
30
};
31
Object.defineProperty(exports, "__esModule", { value: true });
32
var t = __importStar(require("io-ts"));
33
var ArrayC_1 = require("./io/ArrayC");
34
var EntityC_1 = require("./io/EntityC");
35
var Resource_1 = require("./Resource");
36
var fromRecord = function (_a, relationships) {
37
    var _type = _a._type, _id = _a._id, attributes = __rest(_a, ["_type", "_id"]);
38
    return (__assign(__assign(__assign({}, (EntityC_1.EntityC.is({ _type: _type, _id: _id })
39
        ? {
40
            type: '' + _type,
41
            id: '' + _id
42
        }
43
        : null)), (Object.keys(attributes).length > 0
44
        ? { attributes: attributes }
45
        : null)), (Object.keys(relationships).length > 0
46
        ? {
47
            relationships: Object.keys(relationships)
48
                .reduce(function (carry, key) {
49
                var _a;
50
                var resource = relationships[key];
51
                return __assign(__assign({}, carry), (_a = {}, _a[key] = {
52
                    data: ArrayC_1.ArrayC().is(resource)
53
                        ? resource.map(Resource_1.Resource.lens.identifier.get)
54
                        : Resource_1.Resource.lens.identifier.get(resource)
55
                }, _a));
56
            }, {})
57
        }
58
        : null)));
59
};
60
var fromJson = function (u, relationships) {
61
    return t.UnknownRecord.is(u)
62
        ? fromRecord(u, relationships)
63
        : u;
64
};
65
exports.JsonApiData = {
66
    fromJson: fromJson
67
};
68