<commit_before>// Generated by CoffeeScript 1.6.3
var Q, request;

Q = require('q');

request = require('request');

exports.parse = function(zip) {
  var deferred;
  deferred = Q.defer();
  request.get("http://zip.elevenbasetwo.com/v2/US/" + zip, function(err, res, body) {
    if (err) {
      return deferred.reject(new Error(err));
    } else {
      return deferred.resolve(JSON.parse(body));
    }
  });
  return deferred.promise;
};<commit_msg>Rewrite in plain JS and stop using deferreds<commit_after>'use strict';

var Promise = require('bluebird'),
    request = Promise.promisify(require('request')),
    _       = require('lodash');

var baseURL = 'http://zip.elevenbasetwo.com/v2';

var Ziptastic = {
	url: function(options) {
		return [baseURL, options.country, options.zip].join('/');
	},
	parse: Promise.method(function(options, callback) {
		options = _.defaults(options || {}, {
			country: 'US'
		});

		if (!options.zip) {
			throw new Error('A ZIP code must be supplied');
		}

		return request(this.url(options))
			.spread(function(response, body) {
				return body;
			})
			.nodeify(callback);
	})
};

module.exports = _.extend(Ziptastic.parse, Ziptastic);
{'fraction_non_alphanumeric': 0.1676545300592718, 'fraction_numerical': 0.004233700254022015, 'mean_word_length': 3.746987951807229, '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': '3250499', 'n_tokens_mistral': 425, 'n_tokens_neox': 392, 'n_words': 86}