<commit_before>var utils = require('./utils');

// regular expression patterns
var find_tmpl = /\{([\w\.]+)\}/g;
var find_braces = /\{|\}/g;

/**
 * Resolve data fields in for incoming configs.
 *
 * @private
 * @param {object} The config config.
 * @param {object} The data object.
 * @param {object} The module instance.
 */
module.exports = function (err, data, stream, options) {
  
    // ignore if data is null
    if (data === null) {
        return data;
    }
    
    // extend data with location data (hash, search, path)
    if (global.location) {
        handleStateValues(data);
    }
    
    var key;
    
    // "data": {"key": "{value}"}
    if (options.data) {
        for (key in options.data) {
          
            // parse the data field values
            data[key] = parsePath(options.data[key], this._, data);
        }
    }
    
    // search for path in data and module instance and set it to the cloned config
    // "set": {"key": "{path}", "key": "${#css:attr}"}    
    if (options.set) {
        for (key in options.set) {
            data[key] = parsePath(options.set[key], this._, data, true);
        }
    }

    // create nest objects with flat keys
    if (options.data || options.set) {
        data = utils.deep(data);
    }
    <commit_msg>ensure data object in transform<commit_after>var utils = require('./utils');

// regular expression patterns
var find_tmpl = /\{([\w\.]+)\}/g;
var find_braces = /\{|\}/g;

/**
 * Resolve data fields in for incoming configs.
 *
 * @private
 * @param {object} The config config.
 * @param {object} The data object.
 * @param {object} The module instance.
 */
module.exports = function (err, data, stream, options) {
  
    // ignore if data is null
    if (data === null) {
        return data;
    }
    
    // ensure data object
    if (options && (options.data || options.set)) {
        data = data || {};
    }
    
    // extend data with location data (hash, search, path)
    if (global.location) {
        handleStateValues(data);
    }
    
    var key;
    
    // "data": {"key": "{value}"}
    if (options.data) {
        for (key in options.data) {
          
            // parse the data field values
            data[key] = parsePath(options.data[key], this._, data);
        }
    }
    
    // search for path in data and module instance and set it to the cloned config
    // "set": {"key": "{path}", "key": "${#css:attr}"}    
    if (options.set) {
        for (key in options.set) {
            data[key] = parsePath(options.set[key], this._, data, true);
        }
    }

    // create nest objects with flat keys
    if (options.data || options.set) {
        data = utils.deep(data);
    }
    
{'fraction_non_alphanumeric': 0.15458579881656806, 'fraction_numerical': 0.0, 'mean_word_length': 2.0088987764182424, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, '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': '4297368', 'n_tokens_mistral': 837, 'n_tokens_neox': 836, 'n_words': 261}