<commit_before>import {nest, isArray} from "../util.js";

//Projection default props
let defaultProps = {
    "fields": [],
    "as": []
};

//Export projection transform
export const projectionTransform = {
    "transform": function (context, data, props) {
        let fields = isArray(props.fields) ? props.fields : [props.fields];
        let as = isArray(props.as) ? props.as : [props.as];
        if (as.length !== fields.length) {
            //TODO: throw error
            return [];
        }
        //Parse dataset rows
        return data.map(function (datum) {
            let newDatum = {}; //New datum object
            for (let i = 0; i < fields.length; i++) {
                newDatum[as[i]] = nest(datum, fields[i]); //Add field
            }
            //Return the new datum object
            return newDatum;
        });
    },
    "props": defaultProps,
    "sourceProps": []
};

<commit_msg>transforms: minor improvements in projection transform<commit_after>import {nest, isArray} from "../util.js";

//Projection default props
let defaultProps = {
    "fields": [],
    "as": []
};

//Export projection transform
export const projectionTransform = {
    "transform": function (context, data, props) {
        let fields = isArray(props.fields) ? props.fields : [props.fields];
        let as = isArray(props.as) ? props.as : [props.as];
        //Check if 'as' and 'fields' have the same length
        if (as.length !== fields.length) {
            return context.error("Error in projection transform: 'fields' and 'as' props must have the same length");
        }
        //Parse dataset rows
        return data.map(function (datum) {
            let newDatum = {}; //New datum object
            for (let i = 0; i < fields.length; i++) {
                newDatum[as[i]] = nest(datum, fields[i]); //Add field
            }
            //Return the new datum object
            return newDatum;
        });
    },
    "props": defaultProps,
    "sourceProps": []
};


{'fraction_non_alphanumeric': 0.14114114114114115, 'fraction_numerical': 0.001001001001001001, 'mean_word_length': 2.0801232665639446, 'pattern_counts': {'":': 10, '<': 5, '<?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': '7364150', 'n_tokens_mistral': 572, 'n_tokens_neox': 564, 'n_words': 170}