How to use the npm-user-validate.username function in npm-user-validate

To help you get started, we’ve selected a few npm-user-validate 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 entropic-dev / entropic / services / storage / lib / validations.js View on Github external
const { protocol, username, password, host, pathname } = new URL(
    `ent://${spec}`
  );

  if (protocol !== 'ent:') {
    warnings.push('Contained unexpected protocol portion');
    return false;
  }

  if (password) {
    warnings.push('Contained unexpected password in namespace portion');
    return false;
  }

  try {
    validate.username(username);
  } catch (err) {
    warnings.push('Username: ' + err.message);
    return false;
  }

  const name = pathname.slice(1);
  const errors = packageNameOK(name, username);
  if (errors) {
    warnings.push(String(errors));
    return false;
  }

  return {
    canonical: `${username}@${host}/${encodeURIComponent(name)}`,
    namespace: username,
    host: host,
github npm / npm-profile / cmds / util / read.js View on Github external
function readUsername (username, opts) {
  if (username) {
    const error = userValidate.username(username)
    if (error) {
      opts.log && opts.log.warn(error.message)
    } else {
      return username.trim()
    }
  }

  return read({prompt: 'Username: ', default: username || ''})
    .then(username => readUsername(username, opts))
}
github graalvm / graaljs / graal-nodejs / deps / npm / lib / utils / read-user-info.js View on Github external
function readUsername (msg, username, opts, isRetry) {
  if (!msg) msg = 'npm username: '
  if (isRetry && username) {
    const error = userValidate.username(username)
    if (error) {
      opts.log && opts.log.warn(error.message)
    } else {
      return Promise.resolve(username.trim())
    }
  }

  return read({prompt: msg, default: username || ''})
    .then((username) => readUsername(msg, username, opts, true))
}
github entropic-dev / entropic / services / web / handlers / auth.js View on Github external
async function signupAction(context) {
  const remoteAuth = context.session.get('remoteAuth');

  if (!remoteAuth) {
    return response.redirect('/login');
  }

  const { username, email } = querystring.parse(await text(context.request));
  context.username = username;
  context.email = email;

  try {
    validate.username(username);
  } catch (err) {
    context.errors = { username: err.message };
    return signup(context);
  }

  if (!isEmailMaybe(email)) {
    context.errors = { email: 'Sorry, that does not look like an email.' };
    return signup(context);
  }

  const [err, user] = await context.storageApi
    .signup({
      username,
      email,
      remoteAuth
    })

npm-user-validate

User validations for npm

BSD-2-Clause
Latest version published 4 months ago

Package Health Score

83 / 100
Full package analysis