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 5.3.0 to 5.4.0

16

index.d.ts
declare class InvalidNameErrorClass extends Error {}
declare namespace npmName {
interface Options {
/**
Registry URL to check name availability against.
Default: User's configured npm registry URL.
*/
readonly registryUrl: string;
}
}
declare const npmName: {

@@ -29,3 +40,3 @@ /**

*/
(name: string): Promise<boolean>;
(name: string, options?: npmName.Options): Promise<boolean>;

@@ -54,3 +65,4 @@ /**

many<NameType extends string>(
names: NameType[]
names: NameType[],
options?: npmName.Options
): Promise<Map<NameType, boolean>>;

@@ -57,0 +69,0 @@

28

index.js
'use strict';
const isUrl = require('is-url-superb');
const got = require('got');
const isScoped = require('is-scoped');
const registryUrl = require('registry-url')();
const configuredRegistryUrl = require('registry-url')();
const registryAuthToken = require('registry-auth-token');

@@ -11,3 +12,5 @@ const zip = require('lodash.zip');

const request = async name => {
const request = async (name, options) => {
const registryUrl = normalizeUrl(options.registryUrl || configuredRegistryUrl);
const isValid = validate(name);

@@ -50,3 +53,6 @@ if (!isValid.validForNewPackages) {

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

@@ -56,3 +62,7 @@ throw new Error('Package name required');

return request(name);
if (typeof options.registryUrl !== 'undefined' && !(typeof options.registryUrl === 'string' && isUrl(options.registryUrl))) {
throw new Error('The `registryUrl` option must be a valid string URL');
}
return request(name, options);
};

@@ -64,8 +74,12 @@

module.exports.many = async names => {
module.exports.many = async (names, options = {}) => {
if (!Array.isArray(names)) {
throw new TypeError(`Expected an array, got ${typeof names}`);
throw new TypeError(`Expected an array of names, got ${typeof names}`);
}
const result = await Promise.all(names.map(request));
if (typeof options.registryUrl !== 'undefined' && !(typeof options.registryUrl === 'string' && isUrl(options.registryUrl))) {
throw new Error('The `registryUrl` option must be a valid string URL');
}
const result = await Promise.all(names.map(name => request(name, options)));
return new Map(zip(names, result));

@@ -72,0 +86,0 @@ };

{
"name": "npm-name",
"version": "5.3.0",
"version": "5.4.0",
"description": "Check whether a package name is available on npm",

@@ -35,2 +35,3 @@ "license": "MIT",

"is-scoped": "^1.0.0",
"is-url-superb": "^3.0.0",
"lodash.zip": "^4.2.0",

@@ -37,0 +38,0 @@ "registry-auth-token": "^3.4.0",

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

### npmName(name)
### npmName(name, options?)

@@ -55,4 +55,16 @@ Returns a `Promise<boolean>` of whether the given name is available.

### npmName.many(names)
#### options
Type: `object`
##### registryUrl
Default: User's configured npm registry URL.
Registry URL to check name availability against.
**Note:** You're unlikely to need this option. Most use-cases are best solved by using the default. You should only use this option if you need to check a package name against a specific registry.
### npmName.many(names, options?)
Returns a `Promise<Map>` of name and status.

@@ -66,3 +78,9 @@

#### options
Type: `object`
Same as `npmName()`.
## Related

@@ -69,0 +87,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