<commit_before>
'use strict';

var _ = require('lodash');
var mapstream = require('map-stream');
var mongoose;

// support npm-link include style
try {
    mongoose = require('mongoose');
} catch(e) {
    var prequire = require('parent-require');
    mongoose = prequire('mongoose');
}

module.exports = function(schema, options) {

    // discover properties for use with headers / serializing
    var props = find_props(schema);

    schema.statics.csv_header = function() {
        return array_to_row(props);
    };

    schema.methods.toCSV = function() {
        var doc = this;
        var json = doc.toJSON({ deleted : true, virtuals : true });

        // map the props to values in this doc
        return array_to_row(props.map(function(prop) {
            return _.get(json, prop);
        }));
    };

    // register a global static function to stream a file repsonse
    if (mongoose.Query.prototype.csv) return;
    mongoose.Query.prototype.csv = function(stream) {

        // write header
        stream.write(this.model.csv_header());
<commit_msg>core: supress promise deprecation warning<commit_after>
'use strict';

var _ = require('lodash');
var mapstream = require('map-stream');
var mongoose;

// support npm-link include style
try {
    mongoose = require('mongoose');
} catch(e) {
    var prequire = require('parent-require');
    mongoose = prequire('mongoose');
}

// supress mongoose promise warning
mongoose.Promise = global.Promise;

module.exports = function(schema, options) {

    // discover properties for use with headers / serializing
    var props = find_props(schema);

    schema.statics.csv_header = function() {
        return array_to_row(props);
    };

    schema.methods.toCSV = function() {
        var doc = this;
        var json = doc.toJSON({ deleted : true, virtuals : true });

        // map the props to values in this doc
        return array_to_row(props.map(function(prop) {
            return _.get(json, prop);
        }));
    };

    // register a global static function to stream a file repsonse
    if (mongoose.Query.prototype.csv) return;
    mongoose.Query.prototype.csv = function(stream) {

        // write header
        stream.write(this.model.csv_header());

{'fraction_non_alphanumeric': 0.1232078853046595, 'fraction_numerical': 0.0, 'mean_word_length': 2.85, 'pattern_counts': {'":': 0, '<': 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': '2152906', 'n_tokens_mistral': 658, 'n_tokens_neox': 656, 'n_words': 176}