lib/os/user-management/delete-user.js
function deleteUser(user) {
  if (!runningAsRoot()) return;
  if (!user) throw new Error('You must provide an username');
  if (!userExists(user)) {
    return;
  }
  const userdelBin = _safeLocateBinary('userdel');
  const deluserBin = _safeLocateBinary('deluser');

  if (isPlatform('linux')) {
    if (userdelBin !== null) { // most modern systems
      runProgram(userdelBin, [user]);
    } else {
      if (_isBusyboxBinary(deluserBin)) { // busybox-based systems
        runProgram(deluserBin, [user]);
      } else {
        throw new Error(`Don't know how to delete user ${user} on this strange linux`);
      }
    }
  } else if (isPlatform('osx')) {
    runProgram('dscl', ['.', '-delete', `/Users/${user}`]);
  } else if (isPlatform('windows')) {
    throw new Error('Don\'t know how to delete user in Windows');
  } else {
    throw new Error('Don\'t know how to delete user in current platform');
  }
}
function deleteUser(user) {
  if (!runningAsRoot()) return;
  if (!user) throw new Error('You must provide an username');
  if (!userExists(user)) {
    return;
  }
  const userdelBin = _safeLocateBinary('userdel');
  const deluserBin = _safeLocateBinary('deluser');

  if (isPlatform('linux')) {
    if (userdelBin !== null) { // most modern systems
      runProgram(userdelBin, [user]);
    } else {
      if (_isBusyboxBinary(deluserBin)) { // busybox-based systems
        runProgram(deluserBin, [user]);
      } else {
        throw new Error(`Don't know how to delete user ${user} on this strange linux`);
      }
    }
  } else if (isPlatform('osx')) {
    runProgram('dscl', ['.', '-delete', `/Users/${user}`]);
  } else if (isPlatform('windows')) {
    throw new Error('Don\'t know how to delete user in Windows');
  } else {
    throw new Error('Don\'t know how to delete user in current platform');
  }
}
function deleteUser ( user ) { if ( ! runningAsRoot ( ) ) return ; if ( ! user ) throw new Error ( 'You must provide an username' ) ; if ( ! userExists ( user ) ) { return ; } const userdelBin = _safeLocateBinary ( 'userdel' ) ; const deluserBin = _safeLocateBinary ( 'deluser' ) ; if ( isPlatform ( 'linux' ) ) { if ( userdelBin !== null ) { // most modern systems runProgram ( userdelBin , [ user ] ) ; } else { if ( _isBusyboxBinary ( deluserBin ) ) { // busybox-based systems runProgram ( deluserBin , [ user ] ) ; } else { throw new Error ( ` ${ user } ` ) ; } } } else if ( isPlatform ( 'osx' ) ) { runProgram ( 'dscl' , [ '.' , '-delete' , ` ${ user } ` ] ) ; } else if ( isPlatform ( 'windows' ) ) { throw new Error ( 'Don\'t know how to delete user in Windows' ) ; } else { throw new Error ( 'Don\'t know how to delete user in current platform' ) ; } }
Delete system user
@function $os~deleteUser
@param {string|number} user - Username or user id
@example
// Delete mysql user
$os.deleteUser('mysql');
Delete system user