Skip to content

Instantly share code, notes, and snippets.

@danielroe
Created August 26, 2024 13:20
Show Gist options
  • Save danielroe/58bba4ac204dcd85f15413deec980d47 to your computer and use it in GitHub Desktop.
Save danielroe/58bba4ac204dcd85f15413deec980d47 to your computer and use it in GitHub Desktop.
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import pkg from '../packages.json' assert { type: 'json' }
const source = process.argv[2] || 'names.txt'
const names = fs.readFileSync(fileURLToPath(new URL(path.join('data', source), import.meta.url)), 'utf-8').split('\n')
const resumeFrom = process.argv[3]
let resumed = !resumeFrom
for (let name of names) {
name = name.trim().toLowerCase()
console.log(`Checking \`${name}\`.`)
if (!name || pkg.includes(name) || !/^\w+$/.test(name) || (!resumed && name !== resumeFrom)) continue
resumed = true
// check if package exists on npm
const data = await fetch(`https://registry.npmjs.org/${name}`).then(r => r.json())
if (data.error) {
console.log(`\`${name}\` is available.`)
process.exit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment