Created
April 10, 2014 12:13
-
-
Save AutoSponge/10375201 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var part = require( 'part' ); | |
var _push = part._create( Array.prototype.push ); | |
// take, leave | |
var part = require( 'part' ); | |
var slice_ = part.create_( Array.prototype.slice ); | |
var take_ = slice_.bind( null, 0 ); | |
var apply_ = part.create_( Function.prototype.apply ); | |
var leave = function ( n ) { | |
return function ( fn ) { | |
return function () { | |
return fn.apply( this, take_( n )( arguments ) ); | |
}; | |
}; | |
}; | |
// trim | |
var part = require( 'part' ); | |
var replace_ = part.create_( String.prototype.replace ); | |
var trim = global.trim = replace_( /^\s*|\s*$/g, '' ); | |
// pluck | |
var perfget = require( 'perfget' ); | |
var pluck = perfget.get_; | |
var Promise = require( 'es6-promise' ).Promise; | |
var http = require( 'http' ); | |
var https = require( 'https' ); | |
var request = function ( options, body, ssl ) { | |
return new Promise( function ( resolve, reject ) { | |
var httpLib = ssl ? https : http, | |
req = httpLib.request( options, resolve ); | |
req.on( 'error', reject ); | |
if ( body ) { | |
req.write( body ); | |
} | |
req.end(); | |
} ); | |
} | |
var processResponse = function ( res ) { | |
var body = ''; | |
res.on( 'data', function ( chunk ) { | |
body += chunk; | |
} ); | |
return new Promise( function ( resolve ) { | |
res.on( 'end', function () { | |
return resolve( { | |
statusCode: res.statusCode, | |
headers: res.headers, | |
body: body | |
} ); | |
} ); | |
} ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment