link-shortener
Advanced tools
Comparing version 1.1.2 to 1.1.3
41
index.js
@@ -1,2 +0,2 @@ | ||
module.exports.Shorten = async function(url) { | ||
module.exports.Shorten = async function(url, title) { | ||
const KEY = 'ed9eb20f1cb82d490b4059062d2d2bd97c2c4' | ||
@@ -8,16 +8,27 @@ const axios = require("axios"); | ||
if (Verify.isUri(url)) { | ||
if (title) { | ||
if (typeof title == 'string') { | ||
await axios | ||
.get('https://cutt.ly/api/api.php?key=ed9eb20f1cb82d490b4059062d2d2bd97c2c4&short=' + url + '&name=' + title) | ||
.then((response) => { | ||
result = response.data.url.shortLink | ||
}) | ||
.catch((err) => { | ||
return console.log(err) | ||
}) | ||
} else { | ||
"ERROR: Parameter #2 of the .Shorten() function is not a valid String\n\nTO FIX: Enter a valid String in the first parameter of the .Shorten() function" | ||
} | ||
await axios | ||
.get('https://cutt.ly/api/api.php?key=ed9eb20f1cb82d490b4059062d2d2bd97c2c4&short=' + url) | ||
.then((response) => { | ||
console.log("RESPONSE: " + response) | ||
return response | ||
}) | ||
.then((content) => { | ||
result = content.data.url.shortLink | ||
console.log("SHORT LINK:" + content.data.url.shortLink) | ||
}) | ||
.catch((err) => { | ||
return console.log(err) | ||
}) | ||
} else { | ||
await axios | ||
.get('https://cutt.ly/api/api.php?key=ed9eb20f1cb82d490b4059062d2d2bd97c2c4&short=' + url) | ||
.then((response) => { | ||
result = response.data.url.shortLink | ||
}) | ||
.catch((err) => { | ||
return console.log(err) | ||
}) | ||
} | ||
} else { | ||
@@ -29,4 +40,4 @@ return console.log("ERROR: Parameter #1 of the .Shorten() function is not a valid URL\n\nTO FIX: Enter a valid URL in the first parameter of the .Shorten() function") | ||
} | ||
// return result | ||
return result | ||
} |
{ | ||
"name": "link-shortener", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "A cuttly wrapper to shorten your url's", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
2175
37