module.exports = function()

in index.js [40:87]


module.exports = function (uuid, version) {
    var parsedUuid;
    // If the uuid is a biffer, parse it...
    if (Buffer.isBuffer(uuid)) {
        parsedUuid = unparse(uuid);
    }
    // If it's a string, it's already good.
    else if (Object.prototype.toString.call(uuid) === '[object String]') {
        parsedUuid = uuid;
    }
    // Otherwise, it's not valid.
    else {
        return false;
    }

    parsedUuid = parsedUuid.toLowerCase();

    // All UUIDs fit a basic schema. Match that.
    if (!pattern.test(parsedUuid)) {
        return false;
    }

    // Now extract the version...
    if (version === undefined) {
        version = extractVersion(parsedUuid);
    } else if (extractVersion(parsedUuid) !== version) {
        return false;
    }

    switch (version) {
        // For certain versions, the checks we did up to this point are fine.
        case 1:
        case 2:
            return true;

        // For versions 3 and 4, they must specify a variant.
        case 3:
        case 4:
        case 5:
            return ['8', '9', 'a', 'b'].indexOf(parsedUuid.charAt(19)) !== -1;

        default:
            // We should only be able to reach this if the consumer explicitly
            // provided an invalid version. Prior to extractVersion we check
            // that it's 1-4 in the regex.
            throw new Error('Invalid version provided.');
    }
};