How to use doc-path - 4 common examples

To help you get started, we’ve selected a few doc-path examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mrodrig / json-2-csv / src / json-2-csv.js View on Github external
return _.reduce(keys, function (output, key) {
        // Retrieve the appropriate field data
        let fieldData = path.evaluatePath(data, key);
        if (_.isUndefined(fieldData)) { fieldData = options.EMPTY_FIELD_VALUE; }
        // Add the CSV representation of the data at the key in the document to the output array
        return output.concat(convertField(fieldData));
    }, []);
}
github mrodrig / json-2-csv / src / csv-2-json.js View on Github external
return _.reduce(keys, function (document, key) {
        // If there is a value at the key's index in the line, set the value; otherwise null
        val = line[key.index] ? line[key.index] : null;
        
        // If the user wants to trim field values, trim the value
        val = options.TRIM_FIELD_VALUES && !_.isNull(val) ? val.trim() : val;

        // If the value is an array representation, convert it
        if (isArrayRepresentation(val)) {
            val = convertArrayRepresentation(val);
        }
        // Otherwise add the key and value to the document
        return path.setPath(document, key.value, val);
    }, {});
}
github mrodrig / json-2-csv / src / csv2json.js View on Github external
return keys.reduce((document, key) => {
            // If there is a value at the key's index in the line, set the value; otherwise null
            let value = retrieveRecordValueFromLine(line, key);

            // Otherwise add the key and value to the document
            return path.setPath(document, key.value, value);
        }, {});
    }
github mrodrig / json-2-csv / src / json2csv.js View on Github external
fields.forEach((field) => {
            let recordFieldValue = path.evaluatePath(record, field);

            if (!_.isUndefined(options.emptyFieldValue) && utils.isEmptyField(recordFieldValue)) {
                recordFieldValue = options.emptyFieldValue;
            } else if (options.expandArrayObjects && Array.isArray(recordFieldValue)) {
                recordFieldValue = processRecordFieldDataForExpandedArrayObject(recordFieldValue);
            }

            recordValues.push(recordFieldValue);
        });

doc-path

A document path library for Node

MIT
Latest version published 4 months ago

Package Health Score

67 / 100
Full package analysis

Popular doc-path functions