<commit_before>'use strict';

const DIR = './';
const fs = require('fs');
const path = require('path');
const jonny = require('jonny');
const mellow = require('mellow');
const ponse = require('ponse');
const WIN = process.platform === 'win32';
const CWD = process.cwd();
const Fs = {};

[
    'get',
    'put',
    'patch',
    'delete'
].forEach((name) => {
    Fs[name] = require(DIR + 'fs/' + name);
});

module.exports = (options) => middle.bind(null, options || {});

function middle(options, req, res, next) {
    const isFile  = /^\/restafary\.js/.test(req.url);
    const prefix  = options.prefix || '/fs';
    const root    = options.root || '/';
    
    const params  = {
        request : req,
        response: res,
        root    : root
    };
    
    let name = ponse.getPathName(req);
    const is = !name.indexOf(prefix);
    
    if (isFile)
        sendFile(req, res);
    else if (!is) {
        next();
    } else {
        name = name.replace(prefix, '') || '/';
        
        params.name = name;
        
        onFS(params, (error, options, data) => {
            params.gzip = !error;
            
            if (options.name)
                params.name = options.name;
            
            if (options.gzip !== undefined)
                params.gzip = options.gzip;
            
            if (options.query)
                params.query = options.query;
            
            if (error) {
                ponse.sendError(error, params);
            } else {
                if (!data)
                    data = getMsg(name, req);
                
                ponse.send(data, params);
            }
        });
    }
}

function sendFile(request, response) {
    const url = request.url;
    const name = path.join(__dirname, '..', 'dist', url);
    <commit_msg>refactor(restafary) middle: add early return<commit_after>'use strict';

const DIR = './';
const fs = require('fs');
const path = require('path');
const jonny = require('jonny');
const mellow = require('mellow');
const ponse = require('ponse');
const WIN = process.platform === 'win32';
const CWD = process.cwd();
const Fs = {};

[
    'get',
    'put',
    'patch',
    'delete'
].forEach((name) => {
    Fs[name] = require(DIR + 'fs/' + name);
});

module.exports = (options) => middle.bind(null, options || {});

function middle(options, req, res, next) {
    const isFile  = /^\/restafary\.js/.test(req.url);
    const prefix  = options.prefix || '/fs';
    const root    = options.root || '/';
    
    const params  = {
        request : req,
        response: res,
        root    : root
    };
    
    let name = ponse.getPathName(req);
    const is = !name.indexOf(prefix);
    
    if (isFile)
        sendFile(req, res);
    else if (!is) {
        next();
    } else {
        name = name.replace(prefix, '') || '/';
        
        params.name = name;
        
        onFS(params, (error, options, data) => {
            params.gzip = !error;
            
            if (options.name)
                params.name = options.name;
            
            if (options.gzip !== undefined)
                params.gzip = options.gzip;
            
            if (options.query)
                params.query = options.query;
            
            if (error)
                return ponse.sendError(error, params);
            
            if (!data)
                data = getMsg(name, req);
            
            ponse.send(data, params);
        });
    }
}

function sendFile(request, response) {
    const url = request.url;
    const name = path.join(__dirname, '..', 'dist', url);
    
{'fraction_non_alphanumeric': 0.1550580431177446, 'fraction_numerical': 0.001105583195135434, 'mean_word_length': 1.65712187958884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1505867', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1088, 'n_words': 254}