mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 09:58:13 +09:00
add base
This commit is contained in:
16
availability/github.js
Normal file
16
availability/github.js
Normal file
@@ -0,0 +1,16 @@
|
||||
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' })
|
||||
}
|
||||
const availability = await getGitHubAvailability(name)
|
||||
res.json({ availability })
|
||||
}
|
18
availability/npm.js
Normal file
18
availability/npm.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const fetch = require('isomorphic-unfetch')
|
||||
const npmName = require('npm-name')
|
||||
|
||||
async function getNpmOrgAvailability(name) {
|
||||
const npmOrgURL = 'https://www.npmjs.com/org'
|
||||
const response = await fetch(`${npmOrgURL}/${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' })
|
||||
}
|
||||
const availability = await npmName.many([name])
|
||||
console.log(availability)
|
||||
res.json({ availability })
|
||||
}
|
Reference in New Issue
Block a user