<commit_before>var _ = require('lodash')
var superagent = require('superagent')

/**
 * make_bulkdoc_appender
 * initialize with options, optional callback
 *
 * opts object:
 * {
 *     db: the couchdb database name
 *     url: the couchdb url, defaults to  '127.0.0.1'
 *     port: the couchdb port, defaults to 5984
 *     auth: { 'username': couchdb user name
 *            ,'password': <PASSWORD>
 *           } // optional, but needed if your db requires it
 * }
 *
 * will either return the saver, or send it to the callback as the second argument
 *
 * then, with the returned function, to save bulkdocs, call with
 * saver({docs:[doc1,doc2,doc3,...],
 *       function(e,response){ callback function} )
 *
 * The first argument to the callback is whether there is an error in
 * the requqest, the second is the json object returned from couchdb,
 * whcih should have the save state of each document (ok or rejected,
 * depending)
 *
 * By using this library, there *should* be no rejected cases, but it
 * is possible that you might get a race condition where two requests
 * are trying to simultaneously save the same doc, and the other one
 * wins.  In which case, check this object that each doc response has
 * ok in it, and if not, just resubmit the request for those docs.
 *
 */

function recursive_assign(a,b){
    if(a === undefined){
        return b
    }
    if(b === undefined){
        return a
    }
    if(! _.isObject(b) ){
        return b
    }
    _.each(b,function(v,k){
        if(_.isPlainObject(a[k])){
            _.assign(a[k],v,recursive_assign)
        }else{
            _.assign(a[k],v)
        }
        return null
    });
    return a
}
<commit_msg>fixed a bug.  no test though, but the test was production run<commit_after>var _ = require('lodash')
var superagent = require('superagent')

/**
 * make_bulkdoc_appender
 * initialize with options, optional callback
 *
 * opts object:
 * {
 *     db: the couchdb database name
 *     url: the couchdb url, defaults to  '127.0.0.1'
 *     port: the couchdb port, defaults to 5984
 *     auth: { 'username': couchdb user name
 *            ,'password': <PASSWORD>
 *           } // optional, but needed if your db requires it
 * }
 *
 * will either return the saver, or send it to the callback as the second argument
 *
 * then, with the returned function, to save bulkdocs, call with
 * saver({docs:[doc1,doc2,doc3,...],
 *       function(e,response){ callback function} )
 *
 * The first argument to the callback is whether there is an error in
 * the requqest, the second is the json object returned from couchdb,
 * whcih should have the save state of each document (ok or rejected,
 * depending)
 *
 * By using this library, there *should* be no rejected cases, but it
 * is possible that you might get a race condition where two requests
 * are trying to simultaneously save the same doc, and the other one
 * wins.  In which case, check this object that each doc response has
 * ok in it, and if not, just resubmit the request for those docs.
 *
 */

function recursive_assign(a,b){
    if(a === undefined){
        return b
    }
    if(b === undefined){
        return a
    }
    if(! _.isObject(b) ){
        return b
    }
    _.each(b,function(v,k){
        if(_.isPlainObject(a[k])){
            var q = a[k]
            a[k] = _.assign(q,v,recursive_assign)

        }else{
            a[k]=v
        }
        return null
    });
    return a
}

{'fraction_non_alphanumeric': 0.10231884057971015, 'fraction_numerical': 0.007536231884057971, 'mean_word_length': 2.640295358649789, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3183766', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1012, 'n_words': 409}