<commit_before>/*jslint node: true */
'use strict';

var forms = require('./forms'),
    async = require('async'),
    htmlEscape = require('./htmlEscape'),
    coerceArray = function (arr) {
        return Array.isArray(arr) && arr.length > 0 ? arr : [];
    },
    copy = function (original) {
        return Object.keys(original).reduce(function (copy, key) {
            copy[key] = original[key];
            return copy;
        }, {});
    },
    underscoreRegExp = /_/g;


exports.string = function (opt) {
    if (!opt) { opt = {}; }

    var f = copy(opt);
    f.widget = f.widget || forms.widgets.text(opt.attrs || {});

    f.parse = function (raw_data) {
        if (typeof raw_data !== 'undefined' && raw_data !== null) {
            return String(raw_data);
        }
        return '';
    };
    f.bind = function (raw_data) {
        var b = copy(f); // clone field object:
        b.value = raw_data;
        b.data = b.parse(raw_data);
        b.validate = function (form, callback) {
            if (raw_data === '' || raw_data === null || typeof raw_data === 'undefined') {
                // don't validate empty fields, but check if required
                if (b.required) { b.error = 'This field is required.'; }
                process.nextTick(function () { callback(null, b); });
            } else {
                async.forEachSeries(b.validators || [], function (v, callback) {
                    if (!b.error) {
                        v(form, b, function (v_err) {
                            b.error = v_err ? v_err.toString() : null;
                            callback(null);
                        });
                    } else {
                        callback(null);
                    }
                }, function (err) {
                    callback(err, b);
                });
            }
        };
        return b;
    };
    f.errorHTML = function () {
        var classes = typeof this.cssClasses !== 'undefined' ? coerceArray(this.cssClasses.error) : [];
        return this.error ? '<p class="' + htmlEscape(['error_msg'].concat(classes).join('')) + '">' + this.error + '</p>' : '';
    };
    f.labelText = function (name) {
        return this.label || name[0].toUpperCase() + name.substr(1).replace(underscoreRegExp, ' ');
    };
    f.labelHTML = function (name, id) {
        if (this.widget.type === 'hidden') { return ''; }
        var forID = id || 'id_' + name;<commit_msg>add spaces between css classes in error messages<commit_after>/*jslint node: true */
'use strict';

var forms = require('./forms'),
    async = require('async'),
    htmlEscape = require('./htmlEscape'),
    coerceArray = function (arr) {
        return Array.isArray(arr) && arr.length > 0 ? arr : [];
    },
    copy = function (original) {
        return Object.keys(original).reduce(function (copy, key) {
            copy[key] = original[key];
            return copy;
        }, {});
    },
    underscoreRegExp = /_/g;


exports.string = function (opt) {
    if (!opt) { opt = {}; }

    var f = copy(opt);
    f.widget = f.widget || forms.widgets.text(opt.attrs || {});

    f.parse = function (raw_data) {
        if (typeof raw_data !== 'undefined' && raw_data !== null) {
            return String(raw_data);
        }
        return '';
    };
    f.bind = function (raw_data) {
        var b = copy(f); // clone field object:
        b.value = raw_data;
        b.data = b.parse(raw_data);
        b.validate = function (form, callback) {
            if (raw_data === '' || raw_data === null || typeof raw_data === 'undefined') {
                // don't validate empty fields, but check if required
                if (b.required) { b.error = 'This field is required.'; }
                process.nextTick(function () { callback(null, b); });
            } else {
                async.forEachSeries(b.validators || [], function (v, callback) {
                    if (!b.error) {
                        v(form, b, function (v_err) {
                            b.error = v_err ? v_err.toString() : null;
                            callback(null);
                        });
                    } else {
                        callback(null);
                    }
                }, function (err) {
                    callback(err, b);
                });
            }
        };
        return b;
    };
    f.errorHTML = function () {
        var classes = typeof this.cssClasses !== 'undefined' ? coerceArray(this.cssClasses.error) : [];
        return this.error ? '<p class="' + htmlEscape(['error_msg'].concat(classes).join(' ')) + '">' + this.error + '</p>' : '';
    };
    f.labelText = function (name) {
        return this.label || name[0].toUpperCase() + name.substr(1).replace(underscoreRegExp, ' ');
    };
    f.labelHTML = function (name, id) {
        if (this.widget.type === 'hidden') { return ''; }
        var forID = id || 'id_' + name;
{'fraction_non_alphanumeric': 0.160503860219423, 'fraction_numerical': 0.001219016659894352, 'mean_word_length': 1.6654033567948023, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3251305', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1393, 'n_words': 322}