1
0
mirror of https://github.com/uetchy/namae.git synced 2026-06-01 19:19:45 +09:00

feat: add MVP

This commit is contained in:
2019-07-30 23:27:28 +09:00
parent f84667b2d6
commit d7872f9872
19 changed files with 770 additions and 194 deletions
+22
View File
@@ -0,0 +1,22 @@
const fetch = require('isomorphic-unfetch')
async function getGitHubAvailability(name) {
const githubURL = 'https://github.com'
const response = await fetch(`${githubURL}/${encodeURIComponent(name)}`)
return response.status === 404
}
module.exports = async (req, res) => {
const name = req.query.name
if (!name) {
return res.status(400).json({ error: 'no query given' })
}
try {
const availability = await getGitHubAvailability(name)
res.json({ availability })
} catch (err) {
res.status(400).json({ error: err.message })
}
}
+17
View File
@@ -0,0 +1,17 @@
const npmName = require('npm-name')
module.exports = async (req, res) => {
const name = req.query.name
if (!name) {
return res.status(400).json({ error: 'no query given' })
}
try {
const packageAvailability = await npmName(name)
const orgAvailability = await npmName(`@${name}`)
res.json({ packageAvailability, orgAvailability })
} catch (err) {
res.status(400).json({ error: err.message })
}
}
+22
View File
@@ -0,0 +1,22 @@
const fetch = require('isomorphic-unfetch')
async function getTwitterAvailability(name) {
const twitterURL = 'https://twitter.com'
const response = await fetch(`${twitterURL}/${encodeURIComponent(name)}`)
return response.status === 404
}
module.exports = async (req, res) => {
const name = req.query.name
if (!name) {
return res.status(400).json({ error: 'no query given' })
}
try {
const availability = await getTwitterAvailability(name)
res.json({ availability })
} catch (err) {
res.status(400).json({ error: err.message })
}
}