<commit_before>"use strict";

var pn, db,
    path   = require("path"),
    fs     = require("fs"),
    dbFile = path.join(__dirname + "/db.json"),
    source = "https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv";

pn = function pn(port, protocol, cb) {
    if (typeof protocol === "function") {
        cb = protocol;
        protocol = "tcp";
    }
    lookup(port, protocol, cb);
};

function lookup(port, protocol, cb) {
    if (db && db.length) {
        cb(null, db[port + "/" + protocol]);
    } else {
        fs.readFile(dbFile, function (err, data) {
            db = JSON.parse(data);
            cb(err, db[port + "/" + protocol]);
        });
    }
}

pn.update = function update(cb) {
    var output = {},
        got    = require("got"),
        parse  = require("csv-parse");

    got(source, function (err, csv) {
        if (err) return cb(err);
        parse(csv, null, function (err, data) {
            data.forEach(function (entry) {
                if (entry[1] && entry[2] &&<commit_msg>Add type checks<commit_after>"use strict";

var pn, db,
    path   = require("path"),
    fs     = require("fs"),
    dbFile = path.join(__dirname + "/db.json"),
    source = "https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv";

pn = function pn(port, protocol, cb) {
    if (typeof protocol === "function") {
        cb = protocol;
        protocol = "tcp";
    }

    if (typeof port !== "number") {
        throw new Error("port is required an must be of type 'number'");
    }

    if (typeof cb !== "function") {
        throw new Error("callback is required an must be of type 'function'");
    }

    lookup(port, protocol, cb);
};

function lookup(port, protocol, cb) {
    if (db && db.length) {
        cb(null, db[port + "/" + protocol]);
    } else {
        fs.readFile(dbFile, function (err, data) {
            db = JSON.parse(data);
            cb(err, db[port + "/" + protocol]);
        });
    }
}

pn.update = function update(cb) {
    var output = {},
        got    = require("got"),
        parse  = require("csv-parse");

    got(source, function (err, csv) {
        if (err) return cb(err);
        parse(csv, null, function (err, data) {
            data.forEach(function (entry) {
                if (entry[1] && entry[2] &&
{'fraction_non_alphanumeric': 0.1697228144989339, 'fraction_numerical': 0.0017057569296375266, 'mean_word_length': 2.213698630136986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2570621', 'n_tokens_mistral': 752, 'n_tokens_neox': 738, 'n_words': 186}