gotiny
Advanced tools
Comparing version 1.4.1 to 1.4.2
// Import function to set new GoTiny links | ||
const set = require("./main/set") | ||
const get = require("./main/get") | ||
const set = require('./main/set'); | ||
const get = require('./main/get'); | ||
module.exports = { set, get } | ||
module.exports = { set, get }; |
@@ -1,16 +0,18 @@ | ||
const axios = require('axios') | ||
const axios = require('axios'); | ||
const get = async (code, opt = {}) => { | ||
const get = async (input, opt = {}) => { | ||
// If full link is provided, filter code out of it | ||
const fullLinkRegex = /gotiny.cc\/(.{4,32})/ | ||
const fullLinkRegex = /gotiny.cc\/(.{4,32})/; | ||
if (fullLinkRegex.test(code)) { | ||
code = code.match(fullLinkRegex)[1] | ||
let code = input; | ||
if (fullLinkRegex.test(input)) { | ||
[, code] = input.match(fullLinkRegex); | ||
} | ||
const requestURL = new URL('https://gotiny.cc/api/' + code) | ||
const requestURL = new URL(`https://gotiny.cc/api/${code}`); | ||
// If extended option is present, add corresponding query params | ||
if (opt.extended) { | ||
requestURL.searchParams.set('format', 'json') | ||
requestURL.searchParams.set('format', 'json'); | ||
} | ||
@@ -20,4 +22,4 @@ | ||
try { | ||
const res = await axios.get(requestURL.href) | ||
return res.data | ||
const res = await axios.get(requestURL.href); | ||
return res.data; | ||
} catch (err) { | ||
@@ -28,6 +30,6 @@ throw { | ||
message: 'GoTiny link not found', | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
module.exports = get | ||
module.exports = get; |
@@ -1,26 +0,25 @@ | ||
const axios = require("axios") | ||
const axios = require('axios'); | ||
const set = async (payload) => { | ||
const set = async (input) => { | ||
// Throw error if no input is provided | ||
if (!payload) { | ||
if (!input) { | ||
throw { | ||
source: "sdk", | ||
code: "missing-argument", | ||
message: "No input provided", | ||
} | ||
source: 'sdk', | ||
code: 'missing-argument', | ||
message: 'No input provided', | ||
}; | ||
} | ||
if (typeof payload === "string") { | ||
payload = { input: payload } | ||
} | ||
// Convert input to object if necessary | ||
const payload = typeof input === 'string' ? { input } : input; | ||
// Make request to API | ||
const res = await axios.post("https://gotiny.cc/api", payload) | ||
const data = res.data | ||
const res = await axios.post('https://gotiny.cc/api', payload); | ||
const { data } = res; | ||
if (data.error) { | ||
// Send back error if found | ||
throw data.error | ||
throw data.error; | ||
} else { | ||
const output = [] | ||
const output = []; | ||
@@ -34,9 +33,9 @@ // Loop through API response and create array with GoTiny objects | ||
link: `https://gotiny.cc/${doc.code}`, | ||
}) | ||
}) | ||
}); | ||
}); | ||
return output | ||
return output; | ||
} | ||
} | ||
}; | ||
module.exports = set | ||
module.exports = set; |
{ | ||
"name": "gotiny", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "SDK for GoTiny: A lightweight link shortener API", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"lint": "eslint ." | ||
}, | ||
@@ -13,3 +13,9 @@ "repository": { | ||
}, | ||
"keywords": ["url", "link", "shortener", "url shortener", "link shortener"], | ||
"keywords": [ | ||
"url", | ||
"link", | ||
"shortener", | ||
"url shortener", | ||
"link shortener" | ||
], | ||
"author": { | ||
@@ -27,3 +33,7 @@ "name": "Rob van Bakel", | ||
"axios": "^0.21.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.10.0", | ||
"eslint-config-airbnb-base": "^15.0.0" | ||
} | ||
} |
@@ -170,1 +170,2 @@ # GoTiny SDK | ||
- [robvanbakel/gotiny-discord-bot](https://github.com/robvanbakel/gotiny-discord-bot) | ||
- [robvanbakel/gotiny-slack-bot](https://github.com/robvanbakel/gotiny-slack-bot) |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
9096
7
74
0
171
2