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.

Revisions

  1. danielroe created this gist Aug 26, 2024.
    23 changes: 23 additions & 0 deletions check-names.mjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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()
    }
    }