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>>; |
54
index.js
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
8851
10
139
+ Addedis-name-taken@^2.0.0
+ Added@bconnorwhite/module@2.0.2(transitive)
+ Added@sindresorhus/is@4.6.0(transitive)
+ Addedaggregate-error@4.0.1(transitive)
+ Addedall-package-names@2.0.897(transitive)
+ Addedcacheable-lookup@5.0.4(transitive)
+ Addedclean-stack@4.2.0(transitive)
+ Addedcommander@6.2.1(transitive)
+ Addedcommander-version@1.1.0(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addedescape-string-regexp@5.0.0(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedgot@11.8.6(transitive)
+ Addedhttp2-wrapper@1.0.3(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedis-name-taken@2.0.0(transitive)
+ Addedis-scoped@3.0.0(transitive)
+ Addedis-url-superb@6.1.0(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedp-lock@2.1.0(transitive)
+ Addedp-map@5.5.0(transitive)
+ Addedpackage-name-conflict@1.0.3(transitive)
+ Addedparse-json-object@1.1.02.0.1(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedprogress@2.0.3(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedread-file-safe@1.0.10(transitive)
+ Addedread-json-safe@1.0.5(transitive)
+ Addedregistry-url@6.0.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedscoped-regex@3.0.0(transitive)
+ Addedtypes-eslintrc@1.0.3(transitive)
+ Addedtypes-json@1.2.2(transitive)
+ Addedtypes-pkg-json@1.2.1(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removed@sindresorhus/is@2.1.1(transitive)
- Removedaggregate-error@3.1.0(transitive)
- Removedcacheable-lookup@2.0.1(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removeddecompress-response@5.0.0(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedgot@10.7.0(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedis-scoped@2.1.0(transitive)
- Removedis-url-superb@4.0.0(transitive)
- Removedmimic-response@2.1.0(transitive)
- Removedp-event@4.2.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-map@3.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedregistry-url@5.1.0(transitive)
- Removedscoped-regex@2.1.0(transitive)
- Removedto-readable-stream@2.1.0(transitive)
- Removedtype-fest@0.10.0(transitive)
Updatedgot@^11.8.2
Updatedis-scoped@^3.0.0
Updatedis-url-superb@^6.0.0
Updatedp-map@^5.0.0
Updatedregistry-auth-token@^4.2.1
Updatedregistry-url@^6.0.0