allows you to check whether a package or organization name is available on npm.
MIT License
This is a Node.js module that allows you to check whether a package or organization name is available on npm.
You can install this module using npm:
npm install npm-name-explorer
Here's an example of how you can use this module:
import checkNpmNameExists, { InvalidNameError } from "npm-name-explorer";
async function checkPackageExists() {
try {
const packageName = "your-package-name";
const exists = await checkNpmNameExists(packageName);
if (exists) {
console.log(`The package '${packageName}' exists on npm.`);
} else {
console.log(`The package '${packageName}' does not exist on npm.`);
}
} catch (error) {
if (error instanceof InvalidNameError) {
console.error("Invalid package name:", error.message);
} else {
console.error("An error occurred:", error.message);
}
}
}
checkPackageExists();
The checkNpmNameExists
function accepts two parameters:
name
(required): The name of the npm package or organization to check.options
(optional): Additional options for the function. The only supported option is registryUrl
, which allows you to specify a custom npm registry URL. If not provided, the default registry URL will be used.The function returns a promise that resolves to a boolean value indicating whether the package or organization exists on npm.
If the package name is invalid, an InvalidNameError
will be thrown with additional information about the validation errors and warnings.