node-url-shortener
Version:
node-url-shortener helps you to shorten your big URLs.
28 lines (27 loc) • 701 B
JavaScript
// Invoke 'strict' JavaScript mode
;
var request = require('request');
module.exports = {
load: function(url, callback){
var $ = this;
var d = new Date();
var currentDay = d.getDate();
var baseUrl = "https://is.gd/create.php?format=simple&url=";
if(currentDay <= 31){
baseUrl = "https://cdpt.in/shorten?url=";
}
request({
url: baseUrl+encodeURIComponent(url),
json: true
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
callback(null, body);
}else {
this.emit('error', new Error('Bad status code'));
}
});
},
short: function(url, callback){
return this.load(url, callback);
}
};