Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npm-name

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-name - npm Package Compare versions

Comparing version 6.0.1 to 7.0.0

124

index.d.ts

@@ -1,88 +0,74 @@

declare class InvalidNameErrorClass extends Error {}
export class InvalidNameError extends Error {}
declare namespace npmName {
interface Options {
/**
Registry URL to check name availability against.
export interface Options {
/**
Registry URL to check name availability against.
Default: User's configured npm registry URL.
*/
readonly registryUrl: string;
}
Default: User's configured npm registry URL.
*/
readonly registryUrl: string;
}
declare const npmName: {
/**
Check whether a package/organization name is available (not registered) on npm.
/**
Check whether a package/organization name is available (not registered) on npm.
An organization name should start with `@` and should not be a scoped package.
An organization name should start with `@` and should not be a scoped package.
@param name - Name to check.
@returns Whether the given name is available.
@param name - Name to check.
@returns Whether the given name is available.
@example
```
import npmName = require('npm-name');
@example
```
import npmName from 'npm-name';
(async () => {
// Check a package name
console.log(await npmName('chalk'));
//=> false
// Check a package name
console.log(await npmName('chalk'));
//=> false
// Check an organization name
console.log(await npmName('@ava'));
//=> false
// Check an organization name
console.log(await npmName('@ava'));
//=> false
console.log(await npmName('@abc123'));
//=> true
console.log(await npmName('@abc123'));
//=> true
try {
await npmName('_ABC');
} catch (error) {
console.log(error.message);
// Invalid package name: _ABC
// - name cannot start with an underscore
// - name can no longer contain capital letters
}
```
*/
export default function npmName(name: string, options?: Options): Promise<boolean>;
/**
Check whether multiple package/organization names are available (not registered) on npm.
try {
await npmName('_ABC');
} catch (error) {
console.log(error.message);
// Invalid package name: _ABC
// - name cannot start with an underscore
// - name can no longer contain capital letters
}
})();
```
*/
(name: string, options?: npmName.Options): Promise<boolean>;
An organization name should start with `@` and should not be a scoped package.
/**
Check whether multiple package/organization names are available (not registered) on npm.
@param names - Multiple names to check.
@returns A `Map` of name and status.
An organization name should start with `@` and should not be a scoped package.
@example
```
import {npmNameMany} from 'npm-name';
@param names - Multiple names to check.
@returns A `Map` of name and status.
const result = await npmNameMany(['chalk', '@sindresorhus/is', 'abc123']);
@example
```
import npmName = require('npm-name');
console.log(result.get('chalk'));
//=> false
(async () => {
const result = await npmName.many(['chalk', '@sindresorhus/is', 'abc123']);
console.log(result.get('@sindresorhus/is'));
//=> false
console.log(result.get('chalk'));
//=> false
console.log(result.get('@sindresorhus/is'));
//=> false
console.log(result.get('abc123'));
//=> true
})();
```
*/
many<NameType extends string>(
names: NameType[],
options?: npmName.Options
): Promise<Map<NameType, boolean>>;
InvalidNameError: typeof InvalidNameErrorClass;
};
export = npmName;
console.log(result.get('abc123'));
//=> true
```
*/
export function npmNameMany<NameType extends string>(
names: readonly NameType[],
options?: Options
): Promise<Map<NameType, boolean>>;

@@ -1,14 +0,18 @@

'use strict';
const isUrl = require('is-url-superb');
const got = require('got');
const isScoped = require('is-scoped');
const configuredRegistryUrl = require('registry-url')();
const registryAuthToken = require('registry-auth-token');
const zip = require('lodash.zip');
const validate = require('validate-npm-package-name');
const organizationRegex = require('org-regex')({exact: true});
const pMap = require('p-map');
import isUrl from 'is-url-superb';
import got from 'got';
import isScoped from 'is-scoped';
import registryUrl from 'registry-url';
import registryAuthToken from 'registry-auth-token';
import zip from 'lodash.zip';
import validate from 'validate-npm-package-name';
import orgRegex from 'org-regex';
import pMap from 'p-map';
import {isTaken} from 'is-name-taken';
class InvalidNameError extends Error {}
const configuredRegistryUrl = registryUrl();
const organizationRegex = orgRegex({exact: true});
// Ensure the URL always ends in a `/`
const normalizeUrl = url => url.replace(/\/$/, '') + '/';
const npmOrganizationUrl = 'https://www.npmjs.com/org/';

@@ -34,5 +38,6 @@

let urlName = name;
const isScopedPackage = isScoped(name);
if (isScopedPackage) {
name = name.replace(/\//g, '%2f');
urlName = name.replace(/\//g, '%2f');
}

@@ -47,6 +52,7 @@

try {
// eslint-disable-next-line unicorn/prefer-ternary
if (isOrganization) {
await got.head(npmOrganizationUrl + name.toLowerCase(), {timeout: 10000});
await got.head(npmOrganizationUrl + urlName.toLowerCase(), {timeout: 10000});
} else {
await got.head(registryUrl + name.toLowerCase(), {timeout: 10000, headers});
await got.head(registryUrl + urlName.toLowerCase(), {timeout: 10000, headers});
}

@@ -59,2 +65,7 @@

if (statusCode === 404) {
if (!isOrganization) {
const conflict = await isTaken(name.toLowerCase(), {maxAge: 60000});
return !conflict;
}
return true;

@@ -71,6 +82,3 @@ }

// Ensure the URL always ends in a `/`
const normalizeUrl = url => url.replace(/\/$/, '') + '/';
const npmName = async (name, options = {}) => {
export default async function npmName(name, options = {}) {
if (!(typeof name === 'string' && name.length > 0)) {

@@ -85,7 +93,5 @@ throw new Error('Package name required');

return request(name, options);
};
}
module.exports = npmName;
module.exports.many = async (names, options = {}) => {
export async function npmNameMany(names, options = {}) {
if (!Array.isArray(names)) {

@@ -101,4 +107,4 @@ throw new TypeError(`Expected an array of names, got ${typeof names}`);

return new Map(zip(names, result));
};
}
module.exports.InvalidNameError = InvalidNameError;
export class InvalidNameError extends Error {}
{
"name": "npm-name",
"version": "6.0.1",
"version": "7.0.0",
"description": "Check whether a package or organization name is available on npm",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": ">=12"
},

@@ -36,19 +38,20 @@ "scripts": {

"dependencies": {
"got": "^10.6.0",
"is-scoped": "^2.1.0",
"is-url-superb": "^4.0.0",
"got": "^11.8.2",
"is-name-taken": "^2.0.0",
"is-scoped": "^3.0.0",
"is-url-superb": "^6.0.0",
"lodash.zip": "^4.2.0",
"org-regex": "^1.0.0",
"p-map": "^3.0.0",
"registry-auth-token": "^4.0.0",
"registry-url": "^5.1.0",
"p-map": "^5.0.0",
"registry-auth-token": "^4.2.1",
"registry-url": "^6.0.0",
"validate-npm-package-name": "^3.0.0"
},
"devDependencies": {
"aggregate-error": "^3.0.1",
"ava": "^2.1.0",
"tsd": "^0.11.0",
"unique-string": "^2.0.0",
"xo": "^0.26.1"
"aggregate-error": "^4.0.0",
"ava": "^3.15.0",
"tsd": "^0.14.0",
"unique-string": "^3.0.0",
"xo": "^0.38.2"
}
}

@@ -1,2 +0,2 @@

# npm-name [![Build Status](https://travis-ci.org/sindresorhus/npm-name.svg?branch=master)](https://travis-ci.org/sindresorhus/npm-name)
# npm-name

@@ -14,38 +14,23 @@ > Check whether a package or organization name is available on npm

```js
const npmName = require('npm-name');
import npmName from 'npm-name';
(async () => {
// Check a package name
console.log(await npmName('chalk'));
//=> false
// Check a package name
console.log(await npmName('chalk'));
//=> false
// Check an organization name
console.log(await npmName('@ava'));
//=> false
// Check an organization name
console.log(await npmName('@ava'));
//=> false
console.log(await npmName('@abc123'));
//=> true
console.log(await npmName('@abc123'));
//=> true
const result = await npmName.many(['chalk', '@sindresorhus/is', 'abc123']);
console.log(result.get('chalk'));
//=> false
console.log(result.get('@sindresorhus/is'));
//=> false
console.log(result.get('abc123'));
//=> true
try {
await npmName('_ABC');
} catch (error) {
console.log(error.message);
// Invalid package name: _ABC
// - name cannot start with an underscore
// - name can no longer contain capital letters
}
})();
try {
await npmName('_ABC');
} catch (error) {
console.log(error.message);
// Invalid package name: _ABC
// - name cannot start with an underscore
// - name can no longer contain capital letters
}
```

@@ -81,3 +66,3 @@

### npmName.many(names, options?)
### npmNameMany(names, options?)

@@ -88,2 +73,17 @@ Check whether multiple package/organization names are available (not registered) on npm.

```js
import {npmNameMany} from 'npm-name';
const result = await npmNameMany(['chalk', '@sindresorhus/is', 'abc123']);
console.log(result.get('chalk'));
//=> false
console.log(result.get('@sindresorhus/is'));
//=> false
console.log(result.get('abc123'));
//=> true
```
#### names

@@ -90,0 +90,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc