How to use the username.sync function in username

To help you get started, we’ve selected a few username 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 sarbbottam / watch-and-rsync / src / index.js View on Github external
target = path.join(process.cwd(), target);
  }

  try {
    fs.accessSync(source, fs.F_OK);
  } catch (error) {
    console.log('source directory does not exist');
    process.exit(1);
  }

  source = tildify(source);
  target = tildify(target);

  let ssh = '';
  let {user, host} = config;
  user = user || username.sync();

  if (host) {
    target = `${user}@${host}:${target}`;
    ssh = 'ssh';
  }

  let exclude = '';
  if (config.excludes) {
    exclude = config.excludes.map(item => `--exclude ${item}`).join(' ');
  }

  // https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories-on-a-vps
  const command = `'rsync -azOte ${ssh} --inplace --delete ${exclude} ${source}/ ${target}'`;
  const watcher = path.join(__dirname, '../node_modules/.bin/watch-and-exec');

  if (option === 'start') {
github maxrimue / node-autostart / src / win32.js View on Github external
function getWinStartupPath() {
  /* istanbul ignore next */ // Requires Windows testing envrionment which travis-ci doesn't support right now
  if (os.release().substring(2, 0).replace('.', '') >= 6) {
    return 'C:\\Users\\' + username.sync() + '\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup';
  } else {
    return 'C:\\Documents and Settings\\' + username.sync() + '\\Start Menu\\Programs\\Startup';
  }
}
github microsoft / react-native-windows / RNWCPP / local-cli / generator-windows / index.js View on Github external
if (!destPath) {
    throw new Error('Need a path to copy to');
  }

  if (!newProjectName) {
    throw new Error('Need a project name');
  }

  createDir(path.join(destPath, windowsDir));
  createDir(path.join(destPath, windowsDir, newProjectName));
  createDir(path.join(destPath, windowsDir, newProjectName, reactAssetsDir));

  const ns = options.ns || newProjectName;
  const projectGuid = uuid.v4();
  const packageGuid = uuid.v4();
  const currentUser = username.sync(); // Gets the current username depending on the platform.
  const certificateThumbprint = generateCertificate(srcPath, destPath, newProjectName, currentUser);

  const templateVars = {
    '<%=ns%>': ns,
    '<%=name%>': newProjectName,
    '<%=projectGuid%>': projectGuid,
    '<%=packageGuid%>': packageGuid,
    '<%=currentUser%>': currentUser,
    '<%=certificateThumbprint%>': certificateThumbprint ? `${certificateThumbprint}` : ''
  };

  [
    { from: path.join(srcPath, 'App.windows.js'), to: 'App.windows.js' },
    { from: path.join(srcPath, projDir, 'MyApp.sln'), to: path.join(windowsDir, newProjectName + '.sln') },
    { from: path.join(srcPath, projDir, 'MyApp.csproj'), to: path.join(windowsDir, newProjectName, newProjectName + '.csproj') },
    { from: path.join(srcPath, projDir, 'react.overrides.props'), to: path.join(windowsDir, 'react.overrides.props') },
github microsoft / react-native-windows / local-cli / generator-windows / index.js View on Github external
if (!destPath) {
    throw new Error('Need a path to copy to');
  }

  if (!newProjectName) {
    throw new Error('Need a project name');
  }

  createDir(path.join(destPath, windowsDir));
  createDir(path.join(destPath, windowsDir, newProjectName));
  createDir(path.join(destPath, windowsDir, newProjectName, reactAssetsDir));

  const ns = options.ns || newProjectName;
  const projectGuid = uuid.v4();
  const packageGuid = uuid.v4();
  const currentUser = username.sync(); // Gets the current username depending on the platform.
  const certificateThumbprint = generateCertificate(srcPath, destPath, newProjectName, currentUser);

  const templateVars = {
    '<%=ns%>': ns,
    '<%=name%>': newProjectName,
    '<%=projectGuid%>': projectGuid,
    '<%=packageGuid%>': packageGuid,
    '<%=currentUser%>': currentUser,
    '<%=certificateThumbprint%>': certificateThumbprint ? `${certificateThumbprint}` : ''
  };

  [
    { from: path.join(srcPath, 'App.windows.js'), to: 'App.windows.js' },
    { from: path.join(srcPath, projDir, 'MyApp.sln'), to: path.join(windowsDir, newProjectName + '.sln') },
    { from: path.join(srcPath, projDir, 'MyApp.csproj'), to: path.join(windowsDir, newProjectName, newProjectName + '.csproj') },
    { from: path.join(srcPath, '_gitignore'), to: path.join(windowsDir, '.gitignore') },
github v1s1t0r1sh3r3 / get-airgeddon / main.js View on Github external
if (path === '') {
      canWrite('./', function (err, isWritable) {
        if (err) console.error(error('No write permissions, run as root'));
        if (isWritable) {
          if (!fs.existsSync('./airgeddon/')) { fs.mkdirSync('./airgeddon/') }
          download('./airgeddon/' + filenameOne,
                   './airgeddon/' + filenameTwo,
                   './airgeddon/' + filenameThree,
                   './airgeddon/' + filenameFour,
                   './airgeddon/' + filenameFive,
                   './airgeddon/' + filenameSix,
                  )
        }
      })
    } else if (path.charAt(0) === '~') {
      var fixedPath = '/home/' + whoami.sync() + '/';
      if (fs.existsSync(fixedPath)) {
        canWrite(fixedPath, function (err, isWritable) {
          if (err) console.error(error('No write permissions, run as root'));
          if (isWritable) {
            if (!fs.existsSync(fixedPath + 'airgeddon/')) { fs.mkdirSync(fixedPath + 'airgeddon/') }
            download(fixedPath + 'airgeddon/' + filenameOne,
                     fixedPath + 'airgeddon/' + filenameTwo,
                     fixedPath + 'airgeddon/' + filenameThree,
                     fixedPath + 'airgeddon/' + filenameFour,
                     fixedPath + 'airgeddon/' + filenameFive,
                     fixedPath + 'airgeddon/' + filenameSix,
                  )
          }
        })
      }
    } else if (path.slice(-1) === '/') {
github maxrimue / node-autostart / src / darwin.js View on Github external
function isAutostartEnabled(key, callback) {
  var err;

  if(process.env.FORCEERROR === 'true') {
    err = new Error('Test error');
  } else {
    err = null;
  }

  callback(err, fileExists('/Users/' + username.sync() + '/Library/LaunchAgents/' + key + '.plist'));
}
github RallyTechServices / 2d-matrix-grid / Gruntfile.js View on Github external
var fs = require('fs'),
            username = require('username');
            chk = 0x12345678,
            i;

        grunt.log.writeln('deploy file:', deploy_file_name);
        var deploy_file = grunt.file.read(deploy_file_name);

        string = deploy_file.replace(/var CHECKSUM = .*;/,"");
        string = string.replace(/var BUILDER  = .*;/,"");
        string = string.replace(/\s/g,"");  //Remove all whitespace from the string.

        for (i = 0; i < string.length; i++) {
            chk += (string.charCodeAt(i) * i);
        }
        var builder = username.sync();
        grunt.log.writeln('setting builder:', builder);

//
        grunt.template.addDelimiters('square-brackets','[%','%]');

        var data = { checksum: chk, builder: builder };
        var output = grunt.template.process(deploy_file, {
            data: data,
            delimiters: 'square-brackets'
        });

        grunt.file.write(deploy_file_name,output);
    });
github binci / binci / src / lib / parsers.js View on Github external
parseSvcObjName: (name, persist) => {
    let user = username.sync() || 'unknown'
    const uid = !persist ? `_${config.instance}` : ''
    return `devlab_${name}_${user}${uid}`.toLowerCase().replace(/[^A-Z0-9]/ig, '_')
  },
  /**
github parro-it / tunnels / src / model / new-tunnel.js View on Github external
import uuid from 'node-uuid';
import username from 'username';

const user = username.sync();

export default function newTunnel() {
	return {
		id: uuid.v4(),
		name: '',
		localPort: 80,
		remotePort: 8080,
		hostAddress: 'localhost',
		userName: user,
		password: '',
		openOnStart: false,
		keyFile: '',
		authType: 'password'
	};
}

username

Get the username of the current user

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis