How to use validate-npm-package-name - 10 common examples

To help you get started, we’ve selected a few validate-npm-package-name examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github renke / auto-install-webpack-plugin / lib / index.js View on Github external
compiler.resolvers.normal.plugin("module", (req, next) => {
      var packageName = req.request.split("/")[0];

      // Make sure we only install a package once
      if (this.memory.has(packageName)) {
        return next();
      } else {
        this.memory.add(packageName);
      }

      // Avoid trying to install packages with invalid name
      if (!validatePackageName(packageName).validForNewPackages) {
        return next();
      }

      resolve(packageName, {basedir: req.path}).then(res => {
        next(); // Already installed
      }).catch(() => {
        let command = this.buildCommand(packageName);

        exec(command, (err, stdout, stderr) => {
          if (err) return next();

          console.log(command);
          print(stdout.toString());

          resolve(packageName, {basedir: req.path}).then(([path]) => {
            next(null, resolveRequest(req, path));
github PolymerX / polymerx-cli / src / commands / create.js View on Github external
const target = resolve(cwd, destFolder);
    const author = argv.author || await getAuthor();
    const installDeps = argv.install;

    // Check if dir exists
    const exists = isDir(target);
    const isForceEnabled = argv.force;
    // Side effects...
    await checkExistOrForce(exists, isForceEnabled, spinner);

    const repo = argv.template.includes('/') ? argv.template :
      `${ORG}/${argv.template}`;

    spinner.info(`Getting ${repo}...`);

    const {errors} = validateName(packageName);
    if (errors) {
      errors.unshift(`Invalid package name: ${packageName}`);
      errorAlert(errors.map(capitalize).join('\n  ~ '), spinner);
      return process.exit(1);
    }

    // Attempt to fetch the `template`
    const archive = await gittar.fetch(repo).catch(error => {
      const finalErr = error || {message: 'An error occured while fetching template.'};
      errorAlert(
        finalErr.code === 404 ? `Could not find repository: ${repo}` : finalErr.message, spinner
      );
      return process.exit(1);
    });

    spinner.text = '⚡️  Creating project';
github mjackson / unpkg / modules / actions / removeFromBlacklist.js View on Github external
export default function removeFromBlacklist(req, res) {
  // TODO: Remove req.packageName when DELETE
  // /_blacklist/:packageName API is removed
  const packageName = req.body.packageName || req.packageName;

  if (!packageName) {
    return res
      .status(403)
      .send({ error: 'Missing "packageName" body parameter' });
  }

  const nameErrors = validateNpmPackageName(packageName).errors;

  // Disallow invalid package names.
  if (nameErrors) {
    const reason = nameErrors.join(', ');
    return res.status(403).send({
      error: `Invalid package name "${packageName}" (${reason})`
    });
  }

  removePackage(packageName).then(
    removed => {
      if (removed) {
        const userId = req.user.jti;
        console.log(
          `Package "${packageName}" was removed from the blacklist by ${userId}`
        );
github teambit / bit / src / scope / models / version.js View on Github external
const _validatePackageDependency = (packageVersion, packageName) => {
      const packageNameValidateResult = packageNameValidate(packageName);
      if (!packageNameValidateResult.validForNewPackages && !packageNameValidateResult.validForOldPackages) {
        const errors = packageNameValidateResult.errors || [];
        throw new VersionInvalid(`${packageName} is invalid package name, errors:  ${errors.join()}`);
      }
      // don't use semver.valid and semver.validRange to validate the package version because it
      // can be also a URL, Git URL or Github URL. see here: https://docs.npmjs.com/files/package.json#dependencies
      validateType(message, packageVersion, `version of "${packageName}"`, 'string');
    };
    const _validatePackageDependencies = (packageDependencies) => {
github GDJiaMi / jm-cli / src / cmds / create / index.ts View on Github external
function validatePackageName(name: string) {
  const res = validateNpmName(name)
  if (!res.validForNewPackages) {
    message.error(`Could not create a project called ${chalk.red(name)} because of npm naming restrictions:`)
    printValidationResults(res.errors)
    printValidationResults(res.warnings)
    process.exit(1)
  }
}
github Yoctol / bottender / packages / create-bottender-app / src / index.ts View on Github external
const checkBotName = (botName: string): void => {
  const validationResult = validateProjectName(botName);

  if (!validationResult.validForNewPackages) {
    error(
      `Could not create a project called ${chalk.green(
        `"${botName}"`
      )} because of npm naming restrictions:`
    );
    printValidationResults(validationResult.errors);
    printValidationResults(validationResult.warnings);

    process.exit(1);
  }
};
github mjackson / unpkg / modules / middleware / validatePackageName.js View on Github external
export default function validatePackageName(req, res, next) {
  if (isHash(req.packageName)) {
    return res
      .status(403)
      .type('text')
      .send(`Invalid package name "${req.packageName}" (cannot be a hash)`);
  }

  const errors = validateNpmPackageName(req.packageName).errors;

  if (errors) {
    const reason = errors.join(', ');

    return res
      .status(403)
      .type('text')
      .send(`Invalid package name "${req.packageName}" (${reason})`);
  }

  next();
}
github elastic / kibana / src / cli_plugin / install / pack.js View on Github external
function assertValidPackageName(plugin) {
  const validation = validate(plugin.name);
  if (!validation.validForNewPackages) {
    throw new Error(`Invalid plugin name [${plugin.name}] in package.json`);
  }
}
github rocjs / roc / src / commands / init / generateTemplate / options.js View on Github external
opts.prompts.name.validate = (name) => {
            const its = validateName(name);

            if (!its.validForNewPackages) {
                const errors = (its.errors || []).concat(its.warnings || []);
                return `Sorry, ${errors.join(' and ')}.`;
            }

            return true;
        };
    }
github bitovi / landscaper / src / resolve / npm.js View on Github external
export function isValidPackage (name) {
  return validateNpmPackageName(name).validForNewPackages
}

validate-npm-package-name

Give me a string and I'll tell you if it's a valid npm package name

ISC
Latest version published 2 years ago

Package Health Score

85 / 100
Full package analysis

Popular validate-npm-package-name functions