Created
August 26, 2024 13:20
-
-
Save danielroe/58bba4ac204dcd85f15413deec980d47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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