"use strict";

var normalizeValues = require('./utils').normalizeValues;

exports.linux = function (line, callback) {
    var parts = line.split(/\s/).filter(String);
    if (!parts.length || parts.length != 7) {
        return;
    }

    var item = {
        protocol: parts[0],
        local: parts[3],
        remote: parts[4],
        state: parts[5],
        pid: parts[6]
    };

    return callback(normalizeValues(item));
};

exports.darwin = function (line, callback) {
    var parts = line.split(/\s/).filter(String);
    if (!parts.length || parts.length != 6) {
        return;
    }

    var item = {
        protocol: parts[0] == 'tcp4' ? 'tcp' : parts[0],
        local: parts[3],
        remote: parts[4],
        state: parts[5]
        pid: '-'
    };

    return callback(normalizeValues(item));
};

exports.win32 = function (line, callback) {
    var parts = line.split(/\s/).filter(String);
    if (!parts.length || parts.length != 5) {
        return;
    }

    var item = {
        protocol: parts[0],
        local: parts[1],
        remote: parts[2],
        state: parts[3],
        pid: parts[4]
    };

    return callback(normalizeValues(item));
};

"use strict";

var normalizeValues = require('./utils').normalizeValues;

exports.linux = function (line, callback) {
    var parts = line.split(/\s/).filter(String);
    if (!parts.length || parts.length != 7) {
        return;
    }

    var item = {
        protocol: parts[0],
        local: parts[3],
        remote: parts[4],
        state: parts[5],
        pid: parts[6]
    };

    return callback(normalizeValues(item));
};

exports.darwin = function (line, callback) {
    var parts = line.split(/\s/).filter(String);
    if (!parts.length || parts.length != 6) {
        return;
    }

    var item = {
        protocol: parts[0] == 'tcp4' ? 'tcp' : parts[0],
        local: parts[3],
        remote: parts[4],
        state: parts[5],
        pid: '-'
    };

    return callback(normalizeValues(item));
};

exports.win32 = function (line, callback) {
    var parts = line.split(/\s/).filter(String);
    if (!parts.length || parts.length != 5) {
        return;
    }

    var item = {
        protocol: parts[0],
        local: parts[1],
        remote: parts[2],
        state: parts[3],
        pid: parts[4]
    };

    return callback(normalizeValues(item));
};

Update parsers.js